HELP! Inventory click event cancellation?

Discussion in 'Plugin Development' started by MrSiborg4, Aug 10, 2013.

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

    MrSiborg4

    So I've been coding a shop plugin, and for some reason, whenever I attempt to set the InventoryClickEvent cancellation when someone clicks on an item in the shop inventory, so they can't take the item out. I still can. Here's my command code:

    Code:java
    1. if(cmd.getName().equalsIgnoreCase("shop")){
    2. p.openInventory(shopInventory);
    3. shopInventory.clear();
    4. shopInventory.addItem(new ItemStack(Material.ANVIL));
    5. }




    here's my event code:
    Code:
    @EventHandler
            public void onInventoryClick(InventoryClickEvent event) {
              if(event.getInventory().getName().equals("shopInventory")){
                    if(event.getCurrentItem().getType() == (Material.ANVIL)){
                        event.setCancelled(true);
                        event.getWhoClicked().getInventory().addItem(new ItemStack(Material.APPLE));
                    }
            }
     
  2. Offline

    Seadragon91

    Do you have register the event?
     
  3. Offline

    MrSiborg4

    It's in the same class. Do I still have to register it even if it's in the same class?
     
  4. Offline

    chris4315

    Register the event. Your code is fine.
     
  5. Offline

    MrSiborg4

    It worked! thank you so much :D
     
Thread Status:
Not open for further replies.

Share This Page