Interface EntityMoveCallback

Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public interface EntityMoveCallback
Called when an entity moves from one location to another.

This event fires for ALL entities, including players. To check if the moving entity is a player, use entity instanceof TalePlayer.

This event is cancellable. If cancelled, the entity's movement will be reverted to the original location.

Example Usage


 // Log all entity movements
 EntityMoveCallback.EVENT.register((entity, from, to) -> {
   System.out.println(entity.getUniqueId() + " moved from " + from + " to " + to);
   return EventResult.PASS;
 });

 // Prevent entities from entering a restricted area
 EntityMoveCallback.EVENT.register(EventPriority.HIGH, (entity, from, to) -> {
   if (isRestrictedArea(to)) {
     return EventResult.CANCEL; // Block the movement
   }
   return EventResult.PASS;
 });

 // Player-specific movement handling
 EntityMoveCallback.EVENT.register((entity, from, to) -> {
   if (entity instanceof TalePlayer player) {
     // Handle player-specific movement logic
     updatePlayerChunks(player, from, to);
   }
   return EventResult.PASS;
 });
 
  • Field Details

    • EVENT

      static final Event<EntityMoveCallback> EVENT
      The event instance. Use this to register listeners and fire the event.
  • Method Details

    • onEntityMove

      EventResult onEntityMove(TaleEntity entity, Location from, Location to)
      Called when an entity moves from one location to another.
      Parameters:
      entity - the entity that is moving
      from - the location the entity is moving from
      to - the location the entity is moving to
      Returns:
      the event result - EventResult.CANCEL to prevent the movement