Solved Can't get InventoryDragEvent working. No way.

Discussion in 'Spigot Plugin Development' started by ZBLL, Jul 9, 2021.

Thread Status:
Not open for further replies.
  1. I don't want the users to drag the items out of a specific inventory. It never works.
    Code (Java):

    @EventHandler (priority = EventPriority.LOWEST)
    public void onDrag(InventoryDragEvent e) {
        if (e.getInventory().getName().equals(name) || e.getInventory().getHolder().equals(holder) || e.getInventory().getTitle().equals(name)) e.setCancelled(true);
    }
     
    I don't understand why. There's nothing that is wrong with this code.
     
  2. Have you tried removing the priority?
     
  3. Listen to the InventoryClickEvent and check if the inventory title is not equals to the clicked inventory title, then cancel. Also check if event.getClick() is a ClickType of a NUMBER_KEY and cancel if it is
     
    • Like Like x 1
    • Agree Agree x 1
  4. That's an alternative method, yes. But I want exactly InventoryDragEvent. I have cancelled it in one of my previous plugins with pretty much the same code and it worked.
     
  5. I am somewhat dumb. I just checked the code of my previous plugin and I should check holders like this:
    Code (Java):

    if (e.getInventory().getHolder() instanceof Holder)
     
    Let me test that
     
  6. Ok, I think I need to give details. Check this out:
     
  7. The term drag in vanilla item management is specifically for when you hold a button and drag over one or more slots. You can't drag items out of an inventory, it's only for inserting.
    Looks like your drag code is working fine. What's not fine is that you're not blocking non-drag click events, including gather to cursor. While gather to cursor does affect more than one slot, it is not a drag event.
     
    • Like Like x 1
  8. Drag is called whenever you pressed down the mouse button and drag your mouse by at least a pixel. As we can see in the console it is working as expected.
     
  9. I decided to just block InventoryClickEvent as suggested, but still do the intended actions.
     
Thread Status:
Not open for further replies.