How can i cancle Item drop/move events

I wanted to cancel a player if he trys to move or to drop items.
What events do i need and how does this work.

edit: oh sry wrong topic pls move this

Wrong section

To cancel an Item Drop you would listen for the DropItemEvent.Dispense event, and when fired do event.setCanceled(true);

To cancel an Entity Move Event, you would listen for the DisplaceEntityEvent and when fired do event.setCanceled(true);

1 Like

You may also be interested in the event documentation.

You can move the topic yourself simply by editing the main post title. There is a drop down box under the box where you edit the title.

1 Like

How can i get the Player that triggers the event?
I want to check if the Player is in an Array and if its true I wanted to cancle the event.

Use Optional<Player> optPlayer = event.getCause().first(Player.class); and cancel event if optPlayer.isPresent() is true

1 Like

You can put @First Player player in the arguments of your listener method.

Ex.

@Listener
public void onDropItem(DropItemEvent.Dispense event, @First Player player)
{
    event.setCanceled(true);
}
1 Like

It is alrady working with [quote=“simon816, post:6, topic:11605, full:true”]
Use Optional<Player> optPlayer = event.getCause().first(Player.class); and cancel event if optPlayer.isPresent() is true
[/quote]
Thank you all for so much help