Search in sources :

Example 6 with EntityTeleportEvent

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;
}
Also used : EntityTeleportEvent(org.bukkit.event.entity.EntityTeleportEvent)

Aggregations

EntityTeleportEvent (org.bukkit.event.entity.EntityTeleportEvent)6 Location (org.bukkit.Location)2 List (java.util.List)1 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)1 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)1 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)1 Player (org.bukkit.entity.Player)1 PlayerTeleportEvent (org.bukkit.event.player.PlayerTeleportEvent)1