Solved InventoryClickEvent not working

Discussion in 'Plugin Development' started by jbeck18, Jul 4, 2014.

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

    jbeck18

    I have created an inventory, then have two different players open it at the same time. However, only one player actually triggers the event when they click in it. I changed the code to cancel the event on any inventory click, and it still ignored it and didnt call the event. Here is the code to the click event.

    Code:
    @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            if(!ChatColor.stripColor(event.getInventory().getTitle()).equalsIgnoreCase("Barter Window")) {
                return;
            }
            else {
                Player player = (Player) event.getWhoClicked();
                event.setCancelled(true);
           
                if(event.getCurrentItem() == null || event.getCurrentItem().getType() == Material.AIR || !event.getCurrentItem().hasItemMeta()) {
                    return;
                }
     
  2. Offline

    FabeGabeMC

    Did you register your events?
     
  3. Offline

    jbeck18

    Yes, and it works for one of the players that i have opening the inventory but not the other one

    Ok I just figured it out, apparently you have to schedule a delayed task before opening the inventory or the event wont trigger.

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

    CynutsBR

    First you need to check if the item is null, then check the type or if the item have metadata
    Code:java
    1. if(event.getCurrentItem() == null{
    2. if(event.getCurrentItem().getType() == Material.POOP){
    3. }
    4. }
     
  5. Offline

    Phasesaber

    jbeck18 I don't know how you're using it, but I make Inventories all the time, and I've never had to do that. :confused:
     
Thread Status:
Not open for further replies.

Share This Page