Solved i need to find a way to check if the player is right-clicking with a certain item in hand

Discussion in 'Plugin Development' started by StarFruitYT, Nov 9, 2019.

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

    StarFruitYT

    Im trying to make a kit selector for my kitpvp server, could you guys help. I have been coding for roughly 1.5 years, and i havnt tried to do this before, im good with making gui(s) and stuff like that i just need to know how to check if the player is right-clicking with a certain item in hand
     
  2. Offline

    DerDonut

  3. Offline

    knokko

    One thing to notice is that you should not add (ignoreCancelled=true) to the @EventHandler annotation because Bukkit automatically cancels the RIGHT_CLICK_AIR action.
     
  4. Offline

    StarFruitYT

    Thank you, that works perfectly!
    here's what i did:
    Code:
    @EventHandler
        public void onKitSelect(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            if(p.getInventory().getItemInMainHand().getType() == Material.FEATHER) {
                if(e.getAction().equals(Action.RIGHT_CLICK_AIR) || e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
                    p.sendMessage("" + ChatColor.GREEN + ChatColor.BOLD + "Opening Kit Selector!");
                }
            }
        }
    
     
    Last edited: Dec 10, 2019
  5. Offline

    KarimAKL

    @StarFruitYT
    1. Remember to set the title prefix to solved.
    2. You can format the code so it's better for the eyes. (Use [Code]Code here[/Code] )

    EDIT by Moderator: Added plain tags
     
Thread Status:
Not open for further replies.

Share This Page