1

Today I wanted to cancel the PlayerDropItemEvent but if I go into my Inventory and do 'Option + Q' the itemstack dissapears

Src Code:

@EventHandler
public void onDrop(PlayerDropItemEvent event) {
    event.setCancelled(true);
}

but if I do it like that the above mentioned problem happens. The console doesn't show something either

11
  • Did you implement Listener and register events? You can test if the event is called by printing something in the console. Use System.out.println("...");
    – user5735975
    Sep 14, 2020 at 6:01
  • @KrijnToet It detects the drop event and it gets triggered. Looks like this problem only occurs in Creative Mode
    – CronixZero
    Sep 15, 2020 at 8:42
  • It appears to be working for me just fine. Assuming 'Option + Q' is your control to drop a full stack? It's still working fine. The only way I was able to reproduce your problem is in creative mode when you open the inventory, hover over an item and then drop the item, the item disappears. Is this the problem you mean?
    – user5735975
    Sep 17, 2020 at 16:13
  • @KrijnToet yes I mean dropping a full stack in creative mode
    – CronixZero
    Sep 18, 2020 at 11:25
  • What version of Spigot are you using?
    – Lucan
    Sep 18, 2020 at 16:10

1 Answer 1

0

If you cancel an inventory-bound event, it could be possible that the player's inventory doesn't get updated. Use

new BukkitRunnable() {
    @Override
    public void run() {
        p.updateInventory();
    }
}.runTask(plugin);

(delay because you can't do 2 inventory bound actions in 1 tick).

PS: Get an instance of your plugin by using MyMain.getPlugin(MyMain.class).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.