Solved InventoryClickEvent Help

Discussion in 'Plugin Development' started by HelGod, Nov 1, 2013.

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

    HelGod

    I have this event, but when I click it the first time the message is sent once, when it I click it the next time the message it sent twice, when I click it again the message it sent three times and continuing. Does anyone know why this is happening?
    Code:java
    1. @EventHandler
    2. public void onInventoryClick(InventoryClickEvent event) {
    3. if(!event.getInventory().getName().equalsIgnoreCase(inv.getName())) return;
    4. if(event.getCurrentItem().getItemMeta() == null) return;
    5.  
    6. Player player = (Player) event.getWhoClicked();
    7. ItemStack item = event.getCurrentItem();
    8. String iname = item.getItemMeta().getDisplayName();
    9.  
    10. event.setCancelled(true);
    11.  
    12. if(iname.contains("Test")) {
    13. player.closeInventory();
    14. player.sendMessage(prefix + "§bYou selected the Test Kit");
    15. }
    16. }
     
  2. Offline

    Doamax

    Try if(event.getAction != InventoryAction.??????) ????? can be COLLECT_TO_CURSOR
     
  3. Offline

    HelGod

    Doamax
    What does that do?
     
  4. Offline

    Doamax

    Code:java
    1. if(event.getAction() == InventoryAction.COLLECT_TO_CURSOR){
    2. event.setCancelled(true);
    3. //code
    4. }else{
    5. event.setCancelled(true);
    6. return;
    7. }

    This way, it would cancel events, but only if they clicked it once would it send a message. Like if the action was InventoryAction.DROP_ALL_CURSOR, it would cancel it but not send the message.
     
  5. Offline

    HelGod

    Nope, that didn't work :( Anyone else want to try to help?

    Fixed, it turns out I was registering the event multiple times

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  6. Offline

    Doamax

    How does that explain that it was different each time?
     
Thread Status:
Not open for further replies.

Share This Page