
PlayerInteractEvent handlers are changing results incorrectly
lexiccn opened this issue ยท 0 comments
What steps will reproduce the problem?
PlayerInteractEvent#setUseItemInHand(PlayerInteractEvent.Result.DENY)
in another plugin on LOW priority- Try to use item in game
- Towny will remove the DENY if item use test passes
- Item will be usable ingame
This is caused by poor design in the Spigot API, not Towny, where:
- PlayerInteractEvent is only considered cancelled if both results are DENY
- PlayerInteractEvent changes both item use and and block interaction results when set to not be cancelled
This is different behaviour to every other event where ignoring cancelled, then setting cancelled to false would have zero effect.
What is the expected output?
The item should not be usable in game.
The ideal solution:
- Towny checks
useItemInHand
oruseInteractedBlock
is DENY where relevant and returns, as well as using ignoreCancelled - Towny sets
setUseItemInHand
orsetUseInteractedBlock
to DENY where relevant instead of callingsetCancelled
- This should also only be called if the result is being set to DENY to avoid this behaviour
This will actually improve handling in many cases as Towny will no longer cancel a block interaction if item use is denied - For example if Towny denies Ender Pearl use, players can now open doors with a pearl in their hand
This may not be available in all versions Towny supports, in which case;
The less ideal solution:
- Towny only uses
setCancelled
if it is explicitly setting it to false
Towny version
0.99.5.2
Server version
Paper 1.20.1 #83
Please use Pastebin.com to link the following files
- Your full server startup from the logs\latest.log: N/A
- Your Towny config.yml: N/A
- Your townyperms.yml: N/A
- Your log's error: N/A