Code: $item = $player->getInventory()->getItemInHand(); $id = 0; //protection $level = 1; //level 1 $enchantment = new EnchantmentInstance(Enchantment::getEnchantment($id), $level); $item->addEnchantment($enchantment); $player->getInventory()->setItemInHand($item);
Lol I want to enchant this: PHP: case "getinfo"; $item = Item::get(369,0,1); $inv = $sender->getInventory(); $item->setCustomName("§l§bInfo"); $inv->addItem($item); return true; break; }[PHP][QUOTE="azk_, post: 57577, member: 1439"][CODE]$item = $player->getInventory()->getItemInHand();$id = 0; //protection$level = 1; //level 1$enchantment = new EnchantmentInstance(Enchantment::getEnchantment($id), $level);$item->addEnchantment($enchantment);$player->getInventory()->setItemInHand($item);[/CODE][/QUOTE]
Like this? PHP: case "getinfo"; $item = Item::get(369,0,1); $id = 0; //protection $level = 1; //level 1 $enchantment = new EnchantmentInstance(Enchantment::getEnchantment($id), $level); $inv = $sender->getInventory(); $item->setCustomName("§l§bInfo"); $item->addEnchantment($enchantment); $inv->addItem($item); return true; break; } Edit: Do not forget to add; PHP: use pocketmine\item\enchantment\Enchantment;use pocketmine\item\enchantment\EnchantmentInstance;