PocketMine-MP
PocketMine-MP copied to clipboard
PlayerInteractEvent: added APIs to independently control reaction of item and block
Introduction
this allows, for example, banning the usage of spawn eggs, without preventing opening of doors, without the need for item ID whitelists.
It also allows customizing the behaviour of item and block interactions when sneaking - it's now possible to force spawn eggs to work when sneaking, or force containers to open.
Finally, this also allows preventing any interaction at all without preventing block placement (by setting both to false). Since cancelling the event will typically prevent placement too (which might not be desired).
The naming of the functions is up for discussion, but the feature itself is stolen from Spigot and is much needed.
Relevant issues
- Fixes #3267
Changes
API changes
- Added the following new API methods:
PlayerInteractEvent->useBlock()- returns whether the clicked block'sonInteract()will be calledPlayerInteractEvent->useItem()- returns whether the held item'sonInteractBlock()will be calledPlayerInteractEvent->setUseBlock()PlayerInteractEvent->setUseItem()Note that setting these both to false does NOT cancel the event; rather, it makes the action behave as if the player was sneaking.
Behavioural changes
Backwards compatibility
Backwards compatible, but could cause unexpected results for plugins not aware of these features - e.g. a plugin may assume that chests are never opened if the player was sneaking, which this change would violate.
Tests
This has not yet been tested.
This causes some buggy behaviour when using setUseItem(false) and setUseBlock(true) when using a lava bucket on a door: a ghost lava block is placed (unexpected) and the door is opened (expected). The lava doesn't exist on the server side, so it doesn't burn or spread.
Would it help if I also test with this so the PR can get merged, or are you currently busy with the work on next-major?