InventoryClickEvent being called 3 times

Discussion in 'Plugin Development' started by tyler53, Nov 3, 2013.

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

    tyler53

    Hi there,

    So there is part of my plugin with a custom inventory that is being used as a menu, and there are certain items that do different things in the menu. The listener for InventoryClickEvent is working fine, but its called 3 times.

    Here is the code:

    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent e){
    3. Player player = e.getWhoClicked();
    4. if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.DARK_RED + "Attack Power")){
    5. e.setCancelled(true);
    6. player.sendMessage(ChatColor.AQUA + "[ShadowCraft RPG] " + ChatColor.GREEN + "Attack Power increases your physical damage.");
    7. }
    8. if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "Skill Up")){
    9. e.setCancelled(true);
    10. player.sendMessage(ChatColor.AQUA + "[ShadowCraft RPG] " + ChatColor.WHITE + "Your " + ChatColor.DARK_RED + "ATTACK POWER " + ChatColor.WHITE + "has been increased!");
    11. }
    12. }


    When they click the items, the user is sent the message 3 times each...
     
  2. Offline

    Hoolean

    tyler53

    Full code? Is there any chance it is being registered multiple times?
     
  3. Offline

    tyler53


    That was basically full code, this is the full class minus imports:
    Code:java
    1. public class InventoryListener implements Listener{
    2.  
    3. @EventHandler
    4. public void onInventoryClick(InventoryClickEvent e){
    5. Player player = (Player) e.getWhoClicked();
    6. if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.DARK_RED + "Attack Power")){
    7. e.setCancelled(true);
    8. player.sendMessage(ChatColor.AQUA + "[ShadowCraft RPG] " + ChatColor.GREEN + "Attack Power increases your physical damage.");
    9. }
    10. if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GREEN + "Skill Up")){
    11. e.setCancelled(true);
    12. player.sendMessage(ChatColor.AQUA + "[ShadowCraft RPG] " + ChatColor.WHITE + "Your " + ChatColor.DARK_RED + "ATTACK POWER " + ChatColor.WHITE + "has been increased!");
    13. }
    14. }
    15.  
    16. }


    And the listener as set up in my main file:
    Code:java
    1. Bukkit.getServer().getPluginManager().registerEvents(new InventoryListener(), this);
     
Thread Status:
Not open for further replies.

Share This Page