Need help - Right click an item frame with certain item

Discussion in 'Plugin Development' started by CraftedWarrior59, Jan 12, 2013.

Thread Status:
Not open for further replies.
  1. Hi, I'm developing a really simple plugin, that is supposed to do something when you right-click with a certain item in your hand, or right click on an item frame, that have that item inside it. The part where you right-click with an item works just fine, but I have the problem with the item frame one: it doesn't work. This is my code:
    Code:
    public class MyListener implements Listener {
        @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event) {
            Action action = event.getAction();
            Player player = event.getPlayer();
            if (action == Action.RIGHT_CLICK_BLOCK) {
                Block block = event.getClickedBlock();
                if (block.getState() instanceof ItemFrame) {
                    ItemFrame frame = (ItemFrame) block.getState();
                    ItemStack item = frame.getItem();
                    if (item.getType() == Material.SOMETHING) {
                        //do stuff
                    }
                }
            }       
        }
    }
    If anyone have an idea why, please tell me. I am new to java and plugin developing, so keep it simple. Thanks.
     
  2. Offline

    ImDeJay

    Code:
    @EventHandler
    public void blah(PlayerInteractEntityEvent event){
     
    Player player = event.getPlayer();
     
    Entity e = event.getRightClicked();
     
    if(e instanceof ItemFrame){
     
    player.sendMessage("You right clicked an item frame!");
     
    }
     
    }
    CraftedWarrior59
     
  3. Offline

    chasechocolate

    Do what DeJay said, ItemFrames are entities, not blocks.
     
  4. Thanks a lot, works now :) I was trying the same at first, but I forgot to put the @EventHandler there (because I'm dumb, and I guess it's probably important), so I did a bit of googling and saw someone handling it as blocks for some reason.
     
  5. Offline

    i4evercode

    How would you make something happen if the item frame was in a certain location?
     
Thread Status:
Not open for further replies.

Share This Page