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

Help: Expected Item[]

Comments in 'Plugin Development' started by BSHRMG, Aug 18, 2016.

  1. BSHRMG
    Offline

    BSHRMG New Member

    Joined:
    Mar 15, 2016
    Posts:
    21
    Hello again xD
    I'm creating a plugin of kits for SkyWars but I'm having some troubles, I'm trying add iron boots but it gives me an error
    PHP:
    if($item->getId() == 35 and $item->getDamage() == 1){
                    
    $boots Item::get(309);
                    
    $fall Enchantment::getEnchantment(2);
                    
    $expl Enchantment::getEnchantment(3);
                    
    $fall->setLevel(3);
                    
    $expl->setLevel(3);
                    
    $boots->addEnchantment($fall);
                    
    $boots->addEnchantment($expl);
                    
    $inv->setBoots($boots);
                    
    $inv->addItem(46016);
                    
    $inv->addItem(15204);
                    
    $inv->removeItem(Item::get(3511));
    }
    And in console it says
    [22:10:31] [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'Hola v0.1': Expected Item[], got integer on kit\Main
    [22:10:31] [Server thread/CRITICAL]: InvalidArgumentException: "Expected Item[], got integer" (EXCEPTION) in "/src/pocketmine/inventory/BaseInventory" at line 258
  2. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    it should be
    PHP:
    $inv->addItem(Item::get(46016));
    $inv->addItem(Item::get(15204));
    or
    PHP:
    $inv->addItem(Item::get(46016),Item::get(15204));
    applqpak, BSHRMG and HotFireyDeath like this.
  3. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    The addItem() method for PlayerInventory requires an Item object in it's parameter, not an integer.
    PHP:
    $item Item::get(46016);
    $inv->addItem($item);
    $item2 Item::get(15204);
    $inv->addItem($item2);
    applqpak, wolfdale and BSHRMG like this.
  4. BSHRMG
    Offline

    BSHRMG New Member

    Joined:
    Mar 15, 2016
    Posts:
    21
    Thank you everyone now it works :D
  5. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Why creating those useless variables.
    SOFe likes this.
  6. HotFireyDeath
    Offline

    HotFireyDeath Notable Member Plugin Developer

    Joined:
    Mar 19, 2015
    Posts:
    328
    Plugins:
    1
    Minecraft User:
    HotFireyDeath
    Can you state a reason why not?
    applqpak and CraftYourBukkit like this.
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Although it's negligible amount of RAM that will be used but It's good practice that you don't create a variable if you use it's data only once.
    applqpak and HotFireyDeath like this.
  8. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Code readability? Fewer lines of code? Easier to type? Less trouble to think of new variable names and check if they override other variables? Less variables = doesn't need to type the name of variable again = less chance of typo = lower chance of bugs?
    Just call $this->getServer() once more rather than caching the return value into $server, and you are spending at least a thousand times more CPU than creating an extra variable. The spirit of the prevention of premature optimization is that while there are millions of other much more useful optimizations to make, don't look at the once that are useless, especially those that might even be optimized automatically.

Share This Page

Advertisement