Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

addItem() not work

Comments in 'Plugin Development' started by IcePL, Mar 17, 2016.

  1. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    Hi I have a problem . Writes another plugin to drop to my server, but I have a problem because once added to the inventory item and the time does not add the item. Sorry for my bad english. I use google translate xd

    This is my code:
    PHP:
    public function onBreak(BlockBreakEvent $e){
            if(
    $e->getBlock()->getId() == && mt_rand(0,$this->getConfig()->get("d2-szansa")) == "1"){
                
    $p $e->getPlayer();
                
    $p->sendMessage("PocketMC! Diax!");
                foreach(
    $this->getConfig()->get("d1-item") as $loot){
                        
    $p->getInventory()->addItem(Item::get($loot,0,mt_rand(0,$this->getConfig()->get("d2-ilosc"))));
                }
            }
  2. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    And i have question - this code is good?
    I use multiple this code with:
    code
    else{
    }
    Code
    else{
    }
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    else{} is used after an if(){}. It is run if the preceding if(){} block does not run. What do you expect to happen if the if(){} block does not exist?
  4. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    PHP:
    public function onBreak(BlockBreakEvent $e){
            if(
    $e->getBlock()->getId() == && mt_rand(0,$this->getConfig()->get("d2-szansa")) == "1"){
                
    $p $e->getPlayer();
                
    $p->sendMessage("PocketMC Diax");
                foreach(
    $this->getConfig()->get("d2-item") as $loot){
                        
    $p->getInventory()->addItem(Item::get($loot,0,mt_rand(0,$this->getConfig()->get("d2-ilosc"))));
                }
            }
            else{
            }
            if(
    $e->getBlock()->getId() == && mt_rand(0,$this->getConfig()->get("d3-szansa")) == "1"){
                
    $p $e->getPlayer();
                
    $p->sendMessage("PocketMC coal");
                foreach(
    $this->getConfig()->get("d3-item") as $loot){
                        
    $p->getInventory()->addItem(Item::get($loot,0,mt_rand(0,$this->getConfig()->get("d3-ilosc"))));
                }
            }
            else{
            }
            if(
    $e->getBlock()->getId() == && mt_rand(0,$this->getConfig()->get("d4-szansa")) == "1"){
            
    $p->sendMessage("§f• Gratulacje znalazles item");
                foreach(
    $this->getConfig()->get("d4-item") as $loot){
                    
    $p->getInventory()->addItem(Item::get($loot,0,mt_rand(0,$this->getConfig()->get("d4-ilosc"))));
                }
            }
            else{
            }
        }
    Last edited: Mar 17, 2016
  5. Nawaf_Craft1b
    Offline

    Nawaf_Craft1b Active Member Plugin Developer

    Joined:
    May 8, 2015
    Posts:
    232
    Plugins:
    1
    Minecraft User:
    Nawaf_Craft1b
    Why You Use Else{} For Nothing TO DO
    PEMapModder likes this.
  6. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    Ahh xd ok i change to elseif{

Share This Page

Advertisement