Solved RightClickEntity not working

Discussion in 'Plugin Development' started by MordorKing78, May 16, 2015.

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

    MordorKing78

    I'm trying to detect when a player right clicks a entity with a compass in it, this is my code:

    Code:
    if(e instanceof ItemFrame){
                Entity entity = e.getRightClicked();
                if(entity.getType().equals(Material.COMPASS)){
                    Bukkit.getServer().dispatchCommand(p, "return");
                    e.setCancelled(true);
                }
            }
     
  2. Offline

    Reynergodoy

    i think is because youre putting if the entity is with the compass, not the player :)
    and thats not if(entity.getType().equals(Material.COMPASS)){
    thats getItemInHand
    by doing if(entity.getType().equals(Material.COMPASS)){ i think that youre setting that the entity you want to click in a compass
     
    Last edited by a moderator: May 16, 2015
  3. Offline

    MordorKing78

    @Reynergodoy Sohh how would I fix it? Cuz p.getType will not work..
     
  4. Offline

    Ungemonstert

    @MordorKing78 I think you must search for the right clicked block.

    Entity entity = e.getRightClickedBlock();

    Don't know if it works. Just try it ;)
     
  5. Offline

    MordorKing78

  6. Offline

    nverdier

    1) #getRightClickedBlock() isn't anything
    2) It would return a Block
    3) An Entity isn't a Block
    4) So that's invalid code

    <3
     
  7. Offline

    Ungemonstert

    Oh okay, I thought it could be but when i'm think about it, it was a stupid idea ._.
     
  8. Offline

    SrNicks_

    try to check if it is with a compass in hand
     
  9. Offline

    Reynergodoy

    you have to do:
    p.getItemInHand == Material.COMPASS
     
  10. Offline

    I Al Istannen

    @Reynergodoy p.getItemInHand returns an ItemStack not an Material. Use p.getItemInHand.getType instead
     
  11. Offline

    MordorKing78

    @I Al Istannen I want to do if a player right clicks a item in a item frame not in his hand
     
  12. Offline

    I Al Istannen

    @MordorKing78 Like this?

    Code:
    @EventHandler
    public void onInteract(PlayerInteractEntityEvent event) {
      if(event.getRightClicked().getType() == EntityType.ITEM_FRAME) {
        Player p = event.getPlayer();
        p.sendMessage("Item frame");
        
        ItemFrame frame = (ItemFrame) event.getRightClicked();
        ItemStack itemInFrame = frame.getItem();
        p.sendMessage(itemInFrame.getType().toString());
      }
    }
    
     
  13. Offline

    Reynergodoy

    that was just an example '-'
     
  14. Offline

    MordorKing78

  15. Offline

    I Al Istannen

Thread Status:
Not open for further replies.

Share This Page