Search in sources :

Example 1 with MobPositionUpdateEvent

use of org.apollo.game.model.event.impl.MobPositionUpdateEvent in project apollo by apollo-rsps.

the class Mob method setPosition.

/**
 * Sets the {@link Position} of this mob.
 * <p>
 * This method may be intercepted using a {@link MobPositionUpdateEvent}, which can be terminated like any
 * other. Plugins that intercept this Event <strong>must</strong> be cautious, because movement will not be
 * possible (even through mechanisms such as teleporting) if the Event is terminated.
 *
 * @param position The Position.
 */
public final void setPosition(Position position) {
    if (!position.equals(this.position) && world.submit(new MobPositionUpdateEvent(this, position))) {
        Position old = this.position;
        RegionRepository repository = world.getRegionRepository();
        Region current = repository.fromPosition(old), next = repository.fromPosition(position);
        current.removeEntity(this);
        // addEntity relies on the position being updated, so do that first.
        this.position = position;
        next.addEntity(this);
    }
}
Also used : MobPositionUpdateEvent(org.apollo.game.model.event.impl.MobPositionUpdateEvent) Position(org.apollo.game.model.Position) RegionRepository(org.apollo.game.model.area.RegionRepository) Region(org.apollo.game.model.area.Region)

Aggregations

Position (org.apollo.game.model.Position)1 Region (org.apollo.game.model.area.Region)1 RegionRepository (org.apollo.game.model.area.RegionRepository)1 MobPositionUpdateEvent (org.apollo.game.model.event.impl.MobPositionUpdateEvent)1