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(46, 0, 16); $inv->addItem(152, 0, 4); $inv->removeItem(Item::get(35, 1, 1));} And in console it says Spoiler: Error: [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
it should be PHP: $inv->addItem(Item::get(46, 0, 16));$inv->addItem(Item::get(152, 0, 4)); or PHP: $inv->addItem(Item::get(46, 0, 16),Item::get(152, 0, 4));
The addItem() method for PlayerInventory requires an Item object in it's parameter, not an integer. PHP: $item = Item::get(46, 0, 16);$inv->addItem($item);$item2 = Item::get(152, 0, 4);$inv->addItem($item2);
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.
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.