EntityDisplaceEvent.Move or .Teleport : The Dilemma

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).

You should never ever cancel this event and do your own movement as that will, in turn, go ahead and trigger ANOTHER event.

Simply use the setTransform in the event.

setToTransform is currently what i’m using and it work fine, but if I “move” the entity far away during the event, the DisplaceEntityEvent.Move is no longer a simple movement but a real teleportation.

You are confusing Teleport.

Teleport is for when something teleports you away. The way you are setting this is fine.

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).

Real portal support will be coming to 1.8.9 in the next day or two (API to be implemented).

As for your anticheat thing, they would listen to the move event at the lowest priority which will be before other plugins would make adjustments. No issues there.

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!