I am trying to give a player an enchanted diamond sword every time they join the server, but this error shows up as an internal server error: [Server thread/CRITICAL]: Error: "Class 'test\EchantmentInstance' not found" (EXCEPTION) in "plugins/Test/src/test/Test1" at line 37 Does anyone have a solution for it? These are the classes I am using: use pocketmine\plugin\PluginBase; use pocketmine\Player; use pocketmine\Server; use pocketmine\event\Listener; use pocketmine\event\HandlerList; use pocketmine\event\player\PlayerJoinEvent; use pocketmine\item\enchantment\Enchantment; use pocketmine\item\enchantment\EnchantmentInstance; use pocketmine\item\enchantment\SharpnessEnchantment; use pocketmine\item\enchantment\EnchantmentEntry; use pocketmine\item\enchantment\EnchantmentList; use pocketmine\item\Item; The code that's causing the error: Public function onJoin(PlayerJoinEvent $event){ $this->getLogger()->info("working"); $player =$event->getPlayer(); $player->getInventory()->clearAll(); $item = Item::get(276); $enchantment= Enchantment::getEnchantment(9); $level = 50; Line 37 --->(Causing the error) $enchantmentobj = new EchantmentInstance($enchantment, $level); $item->addEnchantment($enchantmentobj); $player->getInventory()->addItem($item); Hope this is enough information for you to be able to help me!
Uhmm you witre wrong class PHP: use pocketmine\plugin\PluginBase;use pocketmine\Player;use pocketmine\Server;use pocketmine\event\Listener;use pocketmine\event\HandlerList;use pocketmine\event\player\PlayerJoinEvent;use pocketmine\item\enchantment\Enchantment;use pocketmine\item\enchantment\EnchantmentInstance;use pocketmine\item\enchantment\SharpnessEnchantment;use pocketmine\item\enchantment\EnchantmentEntry;use pocketmine\item\enchantment\EnchantmentList;use pocketmine\item\Item;public function onJoin(PlayerJoinEvent $event){ $this->getLogger()->info("working"); $player =$event->getPlayer(); $player->getInventory()->clearAll(); $item = Item::get(276); $enchantment= Enchantment::getEnchantment(9); $level = 50;//Line 37 --->(Causing the error) $enchantmentobj = new EnchantmentInstance($enchantment, $level); $item->addEnchantment($enchantmentobj); $player->getInventory()->addItem($item);
Hello, why you didnt send your code with php format? (its hard to read) wait, i'll open it in my ide.
so, for enchanting item use this code (im not in my pc, ican't read your own code) but you can just replace my code in to your plugin: PHP: use pocketmine\item\enchantment\Enchantment;use pocketmine\item\enchantment\EnchantmentInstance;use pocketmine\item\Item;//these are all use's for enchant Item in my Own Code :) and for example now i enchanting Bow for you: PHP: $BOW = Item::get(Item::BOW);$BOW->addEnchantment(new EnchantmentInstance(Enchantment::getEnchantment(Enchantment::FIRE_PROTECTION), 5));//5 is the level of enchant. and its DONE @FiraasMCPE