co.aikar.timings.TimingsHistory Java Examples

The following examples show how to use co.aikar.timings.TimingsHistory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Entity.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public boolean entityBaseTick(int tickDiff) {
    Timings.entityBaseTickTimer.startTiming();

    if (!this.isPlayer) {
        this.blocksAround = null;
        this.collisionBlocks = null;
    }
    this.justCreated = false;

    if (!this.isAlive()) {
        this.removeAllEffects();
        this.despawnFromAll();
        if (!this.isPlayer) {
            this.close();
        }
        Timings.entityBaseTickTimer.stopTiming();
        return false;
    }

    if (riding != null && !riding.isAlive()) {
        ((EntityVehicle) riding).mountEntity(this);
    }

    if (!this.effects.isEmpty()) {
        for (Effect effect : new ArrayList<>(this.effects.values())) {
            if (effect.canTick()) {
                effect.applyEffect(this);
            }
            effect.setDuration(effect.getDuration() - tickDiff);

            if (effect.getDuration() <= 0) {
                this.removeEffect(effect.getId());
            }
        }
    }

    boolean hasUpdate = false;

    this.checkBlockCollision();

    if (this.y <= -16 && this.isAlive()) {
        this.attack(new EntityDamageEvent(this, DamageCause.VOID, 10));
        hasUpdate = true;
    }

    if (this.fireTicks > 0) {
        if (this.fireProof) {
            this.fireTicks -= 4 * tickDiff;
            if (this.fireTicks < 0) {
                this.fireTicks = 0;
            }
        } else {
            if (!this.hasEffect(Effect.FIRE_RESISTANCE) && ((this.fireTicks % 20) == 0 || tickDiff > 20)) {
                this.attack(new EntityDamageEvent(this, DamageCause.FIRE_TICK, 1));
            }
            this.fireTicks -= tickDiff;
        }
        if (this.fireTicks <= 0) {
            this.extinguish();
        } else {
            this.setDataFlag(DATA_FLAGS, DATA_FLAG_ONFIRE, true);
            hasUpdate = true;
        }
    }

    if (this.noDamageTicks > 0) {
        this.noDamageTicks -= tickDiff;
        if (this.noDamageTicks < 0) {
            this.noDamageTicks = 0;
        }
    }

    if (this.inPortalTicks > 80) {
        EntityPortalEnterEvent ev = new EntityPortalEnterEvent(this, EntityPortalEnterEvent.TYPE_NETHER);
        getServer().getPluginManager().callEvent(ev);
    }

    this.age += tickDiff;
    this.ticksLived += tickDiff;
    TimingsHistory.activatedEntityTicks++;

    Timings.entityBaseTickTimer.stopTiming();
    return hasUpdate;
}
 
Example #2
Source File: Entity.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public boolean entityBaseTick(int tickDiff) {
    Timings.entityBaseTickTimer.startTiming();

    if (!this.isPlayer) {
        this.blocksAround = null;
        this.collisionBlocks = null;
    }
    this.justCreated = false;

    if (!this.isAlive()) {
        this.removeAllEffects();
        this.despawnFromAll();
        if (!this.isPlayer) {
            this.close();
        }
        Timings.entityBaseTickTimer.stopTiming();
        return false;
    }
    if (riding != null && !riding.isAlive() && riding instanceof EntityRideable) {
        ((EntityRideable) riding).mountEntity(this);
    }

    if (!this.effects.isEmpty()) {
        for (Effect effect : this.effects.values()) {
            if (effect.canTick()) {
                effect.applyEffect(this);
            }
            effect.setDuration(effect.getDuration() - tickDiff);

            if (effect.getDuration() <= 0) {
                this.removeEffect(effect.getId());
            }
        }
    }

    boolean hasUpdate = false;

    this.checkBlockCollision();

    if (this.y <= -16 && this.isAlive()) {
        this.attack(new EntityDamageEvent(this, DamageCause.VOID, 10));
        hasUpdate = true;
    }

    if (this.fireTicks > 0) {
        if (this.fireProof) {
            this.fireTicks -= 4 * tickDiff;
            if (this.fireTicks < 0) {
                this.fireTicks = 0;
            }
        } else {
            if (!this.hasEffect(Effect.FIRE_RESISTANCE) && ((this.fireTicks % 20) == 0 || tickDiff > 20)) {
                this.attack(new EntityDamageEvent(this, DamageCause.FIRE_TICK, 1));
            }
            this.fireTicks -= tickDiff;
        }
        if (this.fireTicks <= 0) {
            this.extinguish();
        } else {
            this.setDataFlag(DATA_FLAGS, DATA_FLAG_ONFIRE, true);
            hasUpdate = true;
        }
    }

    if (this.noDamageTicks > 0) {
        this.noDamageTicks -= tickDiff;
        if (this.noDamageTicks < 0) {
            this.noDamageTicks = 0;
        }
    }

    if (this.inPortalTicks == 80) {
        EntityPortalEnterEvent ev = new EntityPortalEnterEvent(this, PortalType.NETHER);
        getServer().getPluginManager().callEvent(ev);

        //TODO: teleport
    }

    this.age += tickDiff;
    this.ticksLived += tickDiff;
    TimingsHistory.activatedEntityTicks++;

    Timings.entityBaseTickTimer.stopTiming();
    return hasUpdate;
}