1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

EnchantmentInstance class not found error

Discussion in 'Plugin Help' started by FiraasMCPE, Jul 18, 2020.

  1. FiraasMCPE

    FiraasMCPE Creeper

    Messages:
    4
    GitHub:
    firaasmcpe
    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!
     
  2. NutXzG

    NutXzG Baby Zombie

    Messages:
    132
    GitHub:
    NutXzG
    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);
     
    $enchantmentEnchantment::getEnchantment(9);
     
    $level 50;
    //Line 37 --->(Causing the error) 
    $enchantmentobj = new EnchantmentInstance($enchantment$level);
     
    $item->addEnchantment($enchantmentobj);
     
    $player->getInventory()->addItem($item);
     
  3. FiraasMCPE

    FiraasMCPE Creeper

    Messages:
    4
    GitHub:
    firaasmcpe
    Ok, what class should I delete and what should I use?
     
  4. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    Hello, why you didnt send your code with php format? (its hard to read)
    wait, i'll open it in my ide.
     
  5. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    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
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.