Search in sources :

Example 1 with EntityPortalExitEvent

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

the class GlowEntity method pulse.

/**
     * Called every game cycle. Subclasses should implement this to implement
     * periodic functionality e.g. mob AI.
     */
public void pulse() {
    ticksLived++;
    if (!getLocation().getChunk().isLoaded()) {
        return;
    }
    if (fireTicks > 0) {
        --fireTicks;
    }
    metadata.setBit(MetadataIndex.STATUS, StatusFlags.ON_FIRE, fireTicks > 0);
    // resend position if it's been a while, causes ItemFrames to disappear.
    if (ticksLived % (30 * 20) == 0) {
        if (!(this instanceof GlowItemFrame)) {
            teleported = true;
        }
    }
    if (this instanceof GlowLivingEntity && !isDead() && ((GlowLivingEntity) this).hasAI() && this.getLocation().getChunk().isLoaded()) {
        GlowLivingEntity entity = (GlowLivingEntity) this;
        entity.getTaskManager().pulse();
    }
    pulsePhysics();
    if (hasMoved()) {
        Block currentBlock = location.getBlock();
        if (currentBlock.getType() == Material.ENDER_PORTAL) {
            EventFactory.callEvent(new EntityPortalEnterEvent(this, currentBlock.getLocation()));
            if (server.getAllowEnd()) {
                Location previousLocation = location.clone();
                boolean success;
                if (getWorld().getEnvironment() == Environment.THE_END) {
                    success = teleportToSpawn();
                } else {
                    success = teleportToEnd();
                }
                if (success) {
                    EntityPortalExitEvent e = EventFactory.callEvent(new EntityPortalExitEvent(this, previousLocation, location.clone(), velocity.clone(), new Vector()));
                    if (!e.getAfter().equals(velocity)) {
                        setVelocity(e.getAfter());
                    }
                }
            }
        }
    }
}
Also used : EntityPortalEnterEvent(org.bukkit.event.entity.EntityPortalEnterEvent) Block(org.bukkit.block.Block) GlowItemFrame(net.glowstone.entity.objects.GlowItemFrame) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location) EntityPortalExitEvent(org.bukkit.event.entity.EntityPortalExitEvent)

Aggregations

GlowItemFrame (net.glowstone.entity.objects.GlowItemFrame)1 Location (org.bukkit.Location)1 Block (org.bukkit.block.Block)1 EntityPortalEnterEvent (org.bukkit.event.entity.EntityPortalEnterEvent)1 EntityPortalExitEvent (org.bukkit.event.entity.EntityPortalExitEvent)1 Vector (org.bukkit.util.Vector)1