Hi, I have a dilemma! EntityDisplaceEvent.Move is called when an entity is moving. EntityDisplaceEvent.Teleport is called when an entity is being teleported.
But in my plugin, I’m listening to EntityDisplaceEvent.Move and sometime I need to teleport the moving entity.
I have multiple possibilities:
Should I :
Cancel the event and teleport the entity
Cancel the event and teleport the entity on the next tick
Do not cancel the event and teleport the entity
Do not cancel the event and call the setToTransform method of the event
Another idea ?
For me, the problem is caused by the separation of EntityDisplaceEvent in two different objects
A single EntityDisplaceEvent with a mutable DisplaceType could be nice.
I need the opinion of Sponge’s devs and plugins’s devs to know what is the best solution.
I’d go with the first one there, as it is the easiest at the current time. There really should be a method that accepts a cause, that way you can specify your plugin as a cause. (In fact, there may already be such a method).
I have a plugin where I can setup custom portals, when a player walk through a portal, he is teleported far away, even sometime in another world. Here is the problem, It start with a simple movement caused by the player but it’s ending with a teleportation caused by the plugin.
Imagine there is an other plugin, an anticheat, which listen to DisplaceEntityEvent.Move.TargetPlayer, he check the distance between getFromTransform and getToTransform, and he ban the player if the distance is too high, because it’s not natural as it should be (unlike DisplaceEntityEvent.Teleport.TargetPlayer).
The anticheat was an example, I know there is no real issues.
For me, it’s just a theoretical problem that EntityDisplaceEvent.Move can end with a huge displacement like a teleportation.
Well, it’s not really important to debate about that, I will keep using setToTransform method ^^. Thank!