Solved Right click current item

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

  1. Offline

    tombath10

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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. Offline

    Chinwe

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    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. Offline

    tombath10

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    This is the content of my entire file:
    Nothing happens when I right click with iron in my hand


    Code:java
    1. package me.tombath10.test;
    2.  
    3. import org.bukkit.Material;
    4.  
    5. import org.bukkit.event.block.Action;
    6. import org.bukkit.event.player.PlayerInteractEvent;
    7. import org.bukkit.plugin.java.JavaPlugin;
    8.  
    9. public class test extends JavaPlugin{
    10.  
    11.  
    12. public void onPlayerInteract(PlayerInteractEvent e) {
    13.  
    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. }

    This post has been edited 1 time. It was last edited by tombath10 Jul 14, 2013.
  4. Offline

    Chinwe

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Ah ok, your syntax is right but you haven't registered the listener.

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

    tombath10

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME


    OMG IT WORKS! Thanks ever so much wasted about 4 hours!!!!!! Like given!
  6. Offline

    Chinwe

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    @tombath10 No problem :) Mark this thread as solved if that's everything ;)

Share This Page