InventoryClickEvent not fired

Discussion in 'Plugin Development' started by stirante, Apr 28, 2013.

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

    stirante

    My click listener:
    Code:
        @EventHandler
        public void onClick(InventoryClickEvent e) {
            System.out.println("event fired");
            if (Menu.getInstance().isInMenu(e.getWhoClicked(), e.getInventory().getName()) && e.getSlot() < e.getInventory().getSize()) {
                Menu.getInstance().onClick(e.getInventory().getName(), e.getSlot(), e.getWhoClicked());
                e.setResult(Result.DENY);
                e.setCursor(null);
                e.setCancelled(true);
            }
        }
    It triggers this code:
    Code:
        public void onClick(String inventoryName, int slot, HumanEntity player) {
            if (inventoryName.equalsIgnoreCase("Spells")) {
                handleSpellsClick(slot, player);
            }
            else if (inventoryName.equalsIgnoreCase("Spells - Destruction")) {
                handleDestructionClick(slot, player);
            }
        }
        
        private void handleDestructionClick(int slot, HumanEntity player) {
            switch (slot) {
                case 0:
                    MagicWorld.getInstance().getPlayer(player.getName()).setActiveSpellName("fireball");
                    break;
            }
        }
        
        private void handleSpellsClick(int slot, HumanEntity player) {
            player.closeInventory();
            if (!playersInMenu.contains(player.getName())) playersInMenu.add(player.getName());
            switch (slot) {
                case 0:
                    player.openInventory(destruction);
                    break;
                case 1:
                    
                    break;
            }
        }
    When I open first inventory 'spells' event is fired well and 'destruction' inventory is opened. But when I try to click on item in destruction inventory it don't get fired.

    Help?
     
  2. Offline

    DSH105

    stirante
    Are you sure you have named the inventory correctly? I can't think of anything else at the moment.
     
  3. Offline

    stuntguy3000

    Is it registered in onEnable?
     
  4. Offline

    DSH105

    stuntguy3000
    One of his inventories works and the other doesn't, if I read his post correctly.
     
  5. Offline

    stuntguy3000

    From what i read System.out.println("event fired"); doesn't fire.
     
  6. Offline

    stirante

    Name doesn't matter, event is not fired.
    Yes, when I click in first inventory it's fired, but not when i click on second.
    Click event in one inventory works and in other don't.
    It's fired only the first time.
     
  7. stirante
    It's probably a sync issue or something... try removing closeInventory() and see if openInventory() overwrites the inventory and re-test the clicks.

    Or open the destruction inventory with some delay (extreme, like 1 second) and see if then it registers clicks.
     
  8. Offline

    stirante

    I added closeInventory becouse i thought that this may cause this error.

    But i'll try to add delay.
     
  9. Offline

    stirante

    I delayed it by 1 tick and it worked :D Thanks!
     
Thread Status:
Not open for further replies.

Share This Page