Towny Classic

Towny Classic

3.2k Downloads

PlayerInteractEvent handlers are changing results incorrectly

lexiccn opened this issue ยท 0 comments

commented

What steps will reproduce the problem?

  1. PlayerInteractEvent#setUseItemInHand(PlayerInteractEvent.Result.DENY) in another plugin on LOW priority
  2. Try to use item in game
  3. Towny will remove the DENY if item use test passes
  4. 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 or useInteractedBlock is DENY where relevant and returns, as well as using ignoreCancelled
  • Towny sets setUseItemInHand or setUseInteractedBlock to DENY where relevant instead of calling setCancelled
    • 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

  1. Your full server startup from the logs\latest.log: N/A
  2. Your Towny config.yml: N/A
  3. Your townyperms.yml: N/A
  4. Your log's error: N/A