Solved PlayerInteractEntityEvent

Discussion in 'Plugin Development' started by playmaker247, Aug 24, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    playmaker247

    Im trying to create a plugin which gives the player a certain item when they right click an animal with a specific item in hand. The problem is the InteractWithEntitiyEvent is never being called.

    Im just starting with right clicking sheep but it says im not interacting with anything at all

    Code:
        @EventHandler(priority=EventPriority.HIGHEST)
        public void onInteractWithEntity(PlayerInteractEntityEvent event){
           
            Player p = event.getPlayer();
           
                   
                if(event.getRightClicked().getType().equals(EntityType.SHEEP)|| event.getRightClicked() instanceof Sheep){
                   
                    p.getInventory().addItem(new ItemStack(Material.WOOL));
                   
                }
               
               
               
               
               
           
           
        }
     
  2. Offline

    N00BHUN73R

    @playmaker247
    Are you registering your events? Try adding a Debug message outside of the If statement to see if it's even being called.
     
  3. Offline

    playmaker247

    @N00BHUN73R
    Yeah i had forgotten to register the events, thanks for that. But now its being called twice.
     
    Last edited: Aug 24, 2016
  4. Offline

    Zombie_Striker

    @playmaker247
    There are three possibilities to why this is happening.
    1. You are registering the class twice.
    2. Have to instances of the same event
    3. Have duplicate methods.
    Since you did not post your main class/ have not posted an updated class, I cannot say which you have done.
     
  5. Offline

    playmaker247

    I solved it i just had to add: if(event.getHand() == EquipmentSlot.HAND)
     
    Last edited: Aug 24, 2016
Thread Status:
Not open for further replies.

Share This Page