use of org.bukkit.event.entity.EntityTeleportEvent in project Glowstone by GlowstoneMC.
the class GlowEntity method teleport.
// //////////////////////////////////////////////////////////////////////////
// Internals
@Override
public boolean teleport(Location location) {
if (!(this instanceof GlowPlayer)) {
// TODO: Properly test when Enderman teleportation is implemented.
EntityTeleportEvent event = EventFactory.getInstance().callEvent(new EntityTeleportEvent(this, getLocation(), location));
if (event.isCancelled()) {
return false;
}
location = event.getTo();
}
checkNotNull(location, "location cannot be null");
checkNotNull(location.getWorld(), "location's world cannot be null");
worldLock.writeLock().lock();
try {
if (location.getWorld() != world) {
world.getEntityManager().unregister(this);
world = (GlowWorld) location.getWorld();
world.getEntityManager().register(this);
}
} finally {
worldLock.writeLock().unlock();
}
setRawLocation(location, false);
teleported = true;
return true;
}
Aggregations