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

CraftItemEvent error

Discussion in 'Development' started by Matrox, Feb 27, 2019.

  1. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    At line 38 error :/

    PHP:
    <?php

    namespace dellitem;

    use 
    pocketmine\Server;
    use 
    pocketmine\event\Cancellable;
    use 
    pocketmine\event\CancellableTrait;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\event\Event;
    use 
    pocketmine\inventory\CraftingRecipe;
    use 
    pocketmine\inventory\ShapedRecipe;
    use 
    pocketmine\inventory\transaction\CraftingTransaction;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\Player;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\entity\EffectInstance;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\inventory\CraftItemEvent;
    use 
    pocketmine\block\Block\getItemId;

    class 
    Main extends PluginBase implements Listener{

      public function 
    onEnable(){

              
    $this->getLogger()->info("§1[Blutonia]§r DellItem Loading... ━━━━━━M━━A━━T━━R━━O━━X━━P━━L━━A━━Y━━━━━━");
              
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
          }

        public function 
    onDisable(){
          
    $this->getLogger()->info("§1[Blutonia]§r DellItem Loading... ━━━━━━M━━A━━T━━R━━O━━X━━P━━L━━A━━Y━━━━━━");
        }



        public function 
    OnCraftEvent(CraftItemEvent $event){
         
           if(
    $event->getRecipe()->getResult()->getId() === Item::BOW){
                 
    $event->setCancelled();
            }
        }
    }

         

        
    and error on console


    [Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\inventory\ShapedRecipe::getResult()" (EXCEPTION) in "plugins/Delitem/src/dellitem/Main" at line 38 [17:14:36] [Server thread/DEBUG]: #0 src/pocketmine/plugin/MethodEventExecutor(38): dellitem\Main->OnCraftEvent(pocketmine\event\inventory\CraftItemEvent object) [17:14:36] [Server thread/DEBUG]: #1 src/pocketmine/plugin/RegisteredListener(98): pocketmine\plugin\MethodEventExecutor->execute(dellitem\Main object, pocketmine\event\inventory\CraftItemEvent object) [17:14:36] [Server thread/DEBUG]: #2 src/pocketmine/event/Event(99): pocketmine\plugin\RegisteredListener->callEvent(pocketmine\event\inventory\CraftItemEvent object) [17:14:36] [Server thread/DEBUG]: #3 src/pocketmine/inventory/transaction/CraftingTransaction(141): pocketmine\event\Event->call() [17:14:36] [Server thread/DEBUG]: #4 src/pocketmine/inventory/transaction/InventoryTransaction(276): pocketmine\inventory\transaction\CraftingTransaction->callExecuteEvent() [17:14:36] [Server thread/DEBUG]: #5 src/pocketmine/inventory/transaction/CraftingTransaction(160): pocketmine\inventory\transaction\InventoryTransaction->execute() [17:14:36] [Server thread/DEBUG]: #6 src/pocketmine/Player(2339): pocketmine\inventory\transaction\CraftingTransaction->execute() [17:14:36] [Server thread/DEBUG]: #7 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(148): pocketmine\Player->handleInventoryTransaction(pocketmine\network\mcpe\protocol\InventoryTransactionPacket object) [17:14:36] [Server thread/DEBUG]: #8 src/pocketmine/network/mcpe/protocol/InventoryTransactionPacket(156): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleInventoryTransaction(pocketmine\network\mcpe\protocol\InventoryTransactionPacket object
     
    Last edited: Feb 28, 2019
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Did you by chance try to read the error?
     
    xXNiceAssassinlo YT likes this.
  3. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    Yes but I have never had this error before and I'm French suid can you explain to me clearly this error? Thank you
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    There is only getResults() no getResult()
     
  5. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    Aaaaa ok, Thanks
     
  6. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    Error to getitem I did not understand why

    [Server thread/CRITICAL]: Error: "Call to a member function getId() on array" (EXCEPTION) in "plugins/Delitem/src/dellitem/Main" at line 38
    [07:36:29] [Server thread/DEBUG]: #0 src/pocketmine/plugin/MethodEventExecutor(38): dellitem\Main->OnCraftEvent(pocketmine\event\inventory\CraftItemEvent object)
    [07:36:29] [Server thread/DEBUG]: #1 src/pocketmine/plugin/RegisteredListener(98): pocketmine\plugin\MethodEventExecutor->execute(dellitem\Main object, pocketmine\event\inventory\CraftItemEvent object)
    [07:36:29] [Server thread/DEBUG]: #2 src/pocketmine/event/Event(99): pocketmine\plugin\RegisteredListener->callEvent(pocketmine\event\inventory\CraftItemEvent object)
    [07:36:29] [Server thread/DEBUG]: #3 src/pocketmine/inventory/transaction/CraftingTransaction(141): pocketmine\event\Event->call()
    [07:36:29] [Server thread/DEBUG]: #4 src/pocketmine/inventory/transaction/InventoryTransaction(276): pocketmine\inventory\transaction\CraftingTransaction->callExecuteEvent()
    [07:36:29] [Server thread/DEBUG]: #5 src/pocketmine/inventory/transaction/CraftingTransaction(160): pocketmine\inventory\transaction\InventoryTransaction->execute()
    [07:36:29] [Server thread/DEBUG]: #6 src/pocketmine/Player(2339): pocketmine\inventory\transaction\CraftingTransaction->execute()
    [07:36:29] [Server thread/DEBUG]: #7 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(148): pocketmine\Player->handleInventoryTransaction(pocketmine\network\mcpe\protocol\InventoryTransactionPacket object)
    [07:36:29] [Server thread/DEBUG]: #8 src/pocketmine/network/mcpe/protocol/InventoryTransactionPacket(156): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleInventoryTransaction(pocketmine\network\mcpe\protocol\InventoryTransactionPacket object)
    [07:36:29] [Server thread/DEBUG]: #9 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(108): pocketmine\network\mcpe\protocol\InventoryTransactionPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    [07:36:29] [Server thread/DEBUG]: #10 src/pocketmine/network/mcpe/protocol/BatchPacket(119): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\InventoryTransactionPacket object)
     
  7. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    The way you are using it is wrong, consider using an IDE to help you with this kind of errors
    PHP:
    foreach($event->getRecipe()->getResults() as $result)
        if(
    $result->getId() === Item::BED){
            
    $event->setCancelled();
            break;
        }
     
    jasonwynn10 likes this.
  8. Matrox

    Matrox Slime

    Messages:
    92
    GitHub:
    MatroxMC
    Here is the whole code for the curious :)

    PHP:

    <?php

    namespace dellitem;

    use 
    pocketmine\Server;
    use 
    pocketmine\event\Cancellable;
    use 
    pocketmine\event\CancellableTrait;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\event\Event;
    use 
    pocketmine\inventory\CraftingRecipe;
    use 
    pocketmine\inventory\ShapedRecipe;
    use 
    pocketmine\inventory\transaction\CraftingTransaction;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\Player;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\entity\EffectInstance;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\inventory\CraftItemEvent;
    use 
    pocketmine\block\Block\getItemId;

    class 
    Main extends PluginBase implements Listener{

      public function 
    onEnable(){

              
    $this->getLogger()->info("§1[Blutonia]§r DellItem Loading... ━━━━━━M━━A━━T━━R━━O━━X━━P━━L━━A━━Y━━━━━━");
              
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
          }

        public function 
    onDisable(){
          
    $this->getLogger()->info("§1[Blutonia]§r DellItem Loading... ━━━━━━M━━A━━T━━R━━O━━X━━P━━L━━A━━Y━━━━━━");
        }


       
    //CraftEvent
        
    public function OnCraftEvent(CraftItemEvent $event){
         
          foreach(
    $event->getRecipe()->getResults() as $result)
               if(
    $result->getId() === Item::BED or $result->getId() === Item::BOW){

                  
    $event->setCancelled();
                  
    $event->getPlayer()->sendTip("§4Cette item n'est pas disponible");
            break;
            }   
        }
    }

         
     
  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.