Search in sources :

Example 1 with EntityPortalEvent

use of org.bukkit.event.entity.EntityPortalEvent in project Glowstone by GlowstoneMC.

the class GlowEntity method teleportToSpawn.

/**
     * Teleport this entity to the spawn point of the main world.
     * This is used to teleport out of the End.
     *
     * @return {@code true} if the teleport was successful.
     */
protected boolean teleportToSpawn() {
    Location target = server.getWorlds().get(0).getSpawnLocation();
    EntityPortalEvent event = EventFactory.callEvent(new EntityPortalEvent(this, location.clone(), target, null));
    if (event.isCancelled()) {
        return false;
    }
    target = event.getTo();
    teleport(target);
    return true;
}
Also used : EntityPortalEvent(org.bukkit.event.entity.EntityPortalEvent) Location(org.bukkit.Location)

Example 2 with EntityPortalEvent

use of org.bukkit.event.entity.EntityPortalEvent in project Glowstone by GlowstoneMC.

the class GlowEntity method teleportToEnd.

/**
     * Teleport this entity to the End.
     * If no End world is loaded this does nothing.
     *
     * @return {@code true} if the teleport was successful.
     */
protected boolean teleportToEnd() {
    if (!server.getAllowEnd()) {
        return false;
    }
    Location target = null;
    for (World world : server.getWorlds()) {
        if (world.getEnvironment() == Environment.THE_END) {
            target = world.getSpawnLocation();
            break;
        }
    }
    if (target == null) {
        return false;
    }
    EntityPortalEvent event = EventFactory.callEvent(new EntityPortalEvent(this, location.clone(), target, null));
    if (event.isCancelled()) {
        return false;
    }
    target = event.getTo();
    teleport(target);
    return true;
}
Also used : EntityPortalEvent(org.bukkit.event.entity.EntityPortalEvent) World(org.bukkit.World) GlowWorld(net.glowstone.GlowWorld) Location(org.bukkit.Location)

Aggregations

Location (org.bukkit.Location)2 EntityPortalEvent (org.bukkit.event.entity.EntityPortalEvent)2 GlowWorld (net.glowstone.GlowWorld)1 World (org.bukkit.World)1