Solved Right click current item

Discussion in 'Plugin Development' started by tombath10, Jul 14, 2013.

Thread Status:
Not open for further replies.
  1. Hi,

    I want to be able to right click on the item which I currently have in my hand, this will then send the player a message saying "Hi". How can this be done? I've tried a few ways none of which I can get working.

    Many thanks to all!

    - Tom
  2. Which ways have you tried?
    If you want a message to be sent to them when they right click with any item in their hand, listen to PlayerInteractEvent, and check that event.getAction() is Action.RIGHT_CLICK_AIR or Action.RIGHT_CLICK_BLOCK :)
    tombath10 likes this.
  3. This is the content of my entire file:
    Nothing happens when I right click with iron in my hand

    1. package me.tombath10.test;
    3. import org.bukkit.Material;
    5. import org.bukkit.event.block.Action;
    6. import org.bukkit.event.player.PlayerInteractEvent;
    7. import;
    9. public class test extends JavaPlugin{
    12. public void onPlayerInteract(PlayerInteractEvent e) {
    14. if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction().equals(Action.RIGHT_CLICK_AIR)) {
    15. if (e.getPlayer().getItemInHand().getType().equals(Material.IRON_INGOT)) {
    16. e.getPlayer().sendMessage("Hi");
    17. }}}
    18. }
  4. Ah ok, your syntax is right but you haven't registered the listener.

    Add this:
    public void onEnable()
        getServer().getPluginManager().registerEvents(this, this);
    And add @EventHandler above line 12, so you will have
    public void onInteract (PlayerInteractEvent e) {
    Make sure to read this :rolleyes:
    tombath10 likes this.

  5. OMG IT WORKS! Thanks ever so much wasted about 4 hours!!!!!! Like given!
  6. tombath10 No problem :) Mark this thread as solved if that's everything ;)
Thread Status:
Not open for further replies.

Share This Page