Please Help || ClickEvent

Discussion in 'Plugin Development' started by LuFans, Aug 28, 2014.

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

    LuFans

    Hi there,
    i'd like to code a plugin which performs a command when a make a right-click with a Cake in his Inventar...
    Code:java
    1. import org.bukkit.event.EventHandler;
    2. import org.bukkit.event.Listener;
    3. import org.bukkit.event.block.Action;
    4. import org.bukkit.event.player.PlayerInteractEvent;
    5. import org.bukkit.inventory.ItemStack;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7.  
    8. public class CakeClicker extends JavaPlugin implements Listener{
    9.  
    10. public void onEnable() {
    11.  
    12. }
    13.  
    14.  
    15. @EventHandler
    16. public void onPlayerInteract(PlayerInteractEvent e) {
    17.  
    18. ItemStack b = e.getItem();
    19. Player p = e.getPlayer();
    20. if (e.getAction() == Action.LEFT_CLICK_AIR || e.getAction() == Action.LEFT_CLICK_BLOCK) {
    21. if( b.getType() == Material.CAKE) {
    22. p.performCommand("InvTP");
    23. }
    24. }
    25.  
    26.  
    27. }
    28.  
    29. }
     
  2. Is it when he has his inventory open or when he has the item in his hand.
    If it's the inventory, you use the InventoryClickEvent. Else you need to check if the item b isn't equal to null. And you check when you left click(break a block).
     
    TheMintyMate likes this.
Thread Status:
Not open for further replies.

Share This Page