playerInventoryClick event triggers only when item is taken out

Discussion in 'Plugin Development' started by doredstone, Feb 5, 2021.

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

    doredstone

    my code:

    Code:
    public class recipes implements Listener {
    
    
    
    
    EatingChildren plugin; public recipes(EatingChildren plugin) {
    this.plugin = plugin;}
    
    
    @EventHandlerpublic void onPlayerClick(InventoryClickEvent event) {
    
    new BukkitRunnable(){
    
    @Override
    public void run(){
    
     if (event.getInventory().getItem(11).getItemMeta().getDisplayName().endsWith("'s raw meat")){
    
    
    player.sendMessage("plssssssssss");}
    
    }
    
    }.runTaskLater(plugin,2);
    }

    the if is triggers only when i take items out of the inventory i have in my code more uses of the event and they work fine like:
    Code:
            ItemStack itemStack = new ItemStack(event.getCurrentItem());
    
    if (itemStack.getItemMeta().getLore() == null && !itemStack.getType().equals(Material.COAL)){
                    event.setCancelled(true);
    
                    return;
    
                }
    do some1 know what the problom is?


    sorry for my bad english
     
  2. Offline

    Kars

    What is your problem?
    The if doesn't trigger when you release an item?
     
  3. Offline

    doredstone

  4. Offline

    Newdel

    Are you trying to trigger it with the item at index 11 or with another? Because if you do, the item you are clicking is null because at the time the event triggers, it's still on the cursor and not in the inventory
     
  5. Offline

    doredstone

    the runnable is delaying it i think
     
  6. Offline

    Newdel

    Well, it is, but the event stays the same. It has the same variables for clicked item, cursor and event inventory. Now and X ticks later.
    I think it would be possible to get the item from the player's inventory in the runnable but don't do that. Just use InventoryClickEvent#getCursor() instead.

    If your runnable only does something when a certain if is true, move the if out of the runnable so it does not even get started.
     
Thread Status:
Not open for further replies.

Share This Page