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);
}
}
Aggregations