Solved ItemHeldEvent

Discussion in 'Plugin Development' started by legostarwarszach, May 26, 2013.

Thread Status:
Not open for further replies.
  1. For some in my EventHandler it says I need to make it not a void and stuff. Here's my code:
    Code:
            @EventHandler
            public void onPlayerItemHeld(PlayerItemHeldEvent item){
           
               
            }
    Eclipse is telling me: void is an invalid type for the variable onPlayerItemHeld
    Can you please tell me what's wrong?
    Thanks
     
  2. Offline

    Seadragon91

    Do you have that code in a method? Move it into the class body.
     
  3. Offline

    Seadragon91

    Please post your whole code then I can help you better.
     
  4. Offline

    Seadragon91

    Change this:
    Code:
    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent inter){
            Player player = inter.getPlayer();
            int handblock = player.getItemInHand().getType().getId();
            if(handblock==76){
                    Block b = player.getTargetBlock(null, 50);
                    Location lb = b.getLocation();
                    World w = player.getWorld();
                    player.performCommand("say hi!");
                    w.createExplosion(lb, 3);
                 
                 
            }
         
            @EventHandler
        public void onPlayerItemHeld(PlayerItemHeldEvent item){
     
                 
        }
    }
    to
    Code:
    @EventHandler
    public void onPlayerInteract(PlayerInteractEvent inter){
        Player player = inter.getPlayer();
        int handblock = player.getItemInHand().getType().getId();
        if(handblock==76){
                Block b = player.getTargetBlock(null, 50);
                Location lb = b.getLocation();
                World w = player.getWorld();
                player.performCommand("say hi!");
                w.createExplosion(lb, 3);
             
             
        }
    }
     
    @EventHandler
    public void onPlayerItemHeld(PlayerItemHeldEvent item){
    }
    That should work now, you have the second method in the first one.
     
    legostarwarszach likes this.
Thread Status:
Not open for further replies.

Share This Page