cn.nukkit.event.entity.EntityRegainHealthEvent Java Examples

The following examples show how to use cn.nukkit.event.entity.EntityRegainHealthEvent. 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: Effect.java    From Nukkit with GNU General Public License v3.0 6 votes vote down vote up
public void applyEffect(Entity entity) {
    switch (this.id) {
        case Effect.POISON: //POISON
            if (entity.getHealth() > 1) {
                entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, 1));
            }
            break;
        case Effect.WITHER: //WITHER
            entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, 1));
            break;
        case Effect.REGENERATION: //REGENERATION
            if (entity.getHealth() < entity.getMaxHealth()) {
                entity.heal(new EntityRegainHealthEvent(entity, 1, EntityRegainHealthEvent.CAUSE_MAGIC));
            }
            break;
    }
}
 
Example #2
Source File: EntityLiving.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void heal(EntityRegainHealthEvent source) {
    super.heal(source);
    if (source.isCancelled()) {
        return;
    }

    this.attackTime = 0;
}
 
Example #3
Source File: Entity.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void heal(EntityRegainHealthEvent source) {
    this.server.getPluginManager().callEvent(source);
    if (source.isCancelled()) {
        return;
    }
    this.setHealth(this.getHealth() + source.getAmount());
}
 
Example #4
Source File: Effect.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void applyEffect(Entity entity) {
    switch (this.id) {
        case Effect.POISON: //POISON
            if (entity.getHealth() > 1) {
                entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, 1));
            }
            break;
        case Effect.WITHER: //WITHER
            entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, 1));
            break;
        case Effect.REGENERATION: //REGENERATION
            if (entity.getHealth() < entity.getMaxHealth()) {
                entity.heal(new EntityRegainHealthEvent(entity, 1, EntityRegainHealthEvent.CAUSE_MAGIC));
            }
            break;
        case Effect.SPEED:
            if (entity instanceof Player) {
                ((Player) entity).setMovementSpeed((float) (((this.amplifier + 1) * 0.2 + 1) * 0.1));
            }
            break;
        case Effect.SLOWNESS:
            if (entity instanceof Player) {
                ((Player) entity).setMovementSpeed((float) (((this.amplifier + 1) * -0.15 + 1) * 0.1));
            }
            break;
    }
}
 
Example #5
Source File: Potion.java    From Jupiter with GNU General Public License v3.0 5 votes vote down vote up
public void applyPotion(Entity entity, double health) {
    if (!(entity instanceof EntityLiving)) {
        return;
    }

    Effect applyEffect = getEffect(this.getId(), this.isSplash());

    if (applyEffect == null) {
        return;
    }

    if (entity instanceof Player) {
        if (!((Player) entity).isSurvival() && applyEffect.isBad()) {
            return;
        }
    }

    PotionApplyEvent event = new PotionApplyEvent(this, entity);

    entity.getServer().getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }

    switch (this.getId()) {
        case INSTANT_HEALTH:
        case INSTANT_HEALTH_II:
            entity.heal(new EntityRegainHealthEvent(entity, (float) (health * (double) (4 << (applyEffect.getAmplifier() + 1))), EntityRegainHealthEvent.CAUSE_EATING));
            break;
        case HARMING:
        case HARMING_II:
            entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, (float) (health * (double) (6 << (applyEffect.getAmplifier() + 1)))));
            break;
        default:
            int duration = (int) ((isSplash() ? health : 1) * (double) applyEffect.getDuration() + 0.5);
            applyEffect.setDuration(duration);
            entity.addEffect(applyEffect);
    }
}
 
Example #6
Source File: Effect.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
public void applyEffect(Entity entity) {
    switch (this.id) {
        case Effect.POISON: //POISON
            if (entity.getHealth() > 1) {
                entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, 1));
            }
            break;
        case Effect.WITHER: //WITHER
            entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, 1));
            break;
        case Effect.REGENERATION: //REGENERATION
            if (entity.getHealth() < entity.getMaxHealth()) {
                entity.heal(new EntityRegainHealthEvent(entity, 1, EntityRegainHealthEvent.CAUSE_MAGIC));
            }
            break;
        case Effect.SPEED:
            if (entity instanceof Player) {
                ((Player) entity).setMovementSpeed((float) (((this.amplifier + 1) * 0.2 + 1) * 0.1));
            }
            break;
        case Effect.SLOWNESS:
            if (entity instanceof Player) {
                ((Player) entity).setMovementSpeed((float) (((this.amplifier + 1) * -0.15 + 1) * 0.1));
            }
            break;
    }
}
 
Example #7
Source File: Entity.java    From Jupiter with GNU General Public License v3.0 4 votes vote down vote up
public void heal(float amount) {
    this.heal(new EntityRegainHealthEvent(this, amount, EntityRegainHealthEvent.CAUSE_REGEN));
}
 
Example #8
Source File: Potion.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void applyPotion(Entity entity, double health) {
    if (!(entity instanceof EntityLiving)) {
        return;
    }

    Effect applyEffect = getEffect(this.getId(), this.isSplash());

    if (applyEffect == null) {
        return;
    }

    if (entity instanceof Player) {
        if (!((Player) entity).isSurvival() && !((Player) entity).isAdventure() && applyEffect.isBad()) {
            return;
        }
    }

    PotionApplyEvent event = new PotionApplyEvent(this, applyEffect, entity);

    entity.getServer().getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }

    applyEffect = event.getApplyEffect();

    switch (this.getId()) {
        case INSTANT_HEALTH:
        case INSTANT_HEALTH_II:
            entity.heal(new EntityRegainHealthEvent(entity, (float) (health * (double) (4 << (applyEffect.getAmplifier() + 1))), EntityRegainHealthEvent.CAUSE_MAGIC));
            break;
        case HARMING:
        case HARMING_II:
            entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, (float) (health * (double) (6 << (applyEffect.getAmplifier() + 1)))));
            break;
        default:
            int duration = (int) ((isSplash() ? health : 1) * (double) applyEffect.getDuration() + 0.5);
            applyEffect.setDuration(duration);
            entity.addEffect(applyEffect);
    }
}
 
Example #9
Source File: Potion.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void applyPotion(Entity entity, double health) {
    if (!(entity instanceof EntityLiving)) {
        return;
    }

    Effect applyEffect = getEffect(this.getId(), this.isSplash());

    if (applyEffect == null) {
        return;
    }

    if (entity instanceof Player) {
        if (!((Player) entity).isSurvival() && applyEffect.isBad()) {
            return;
        }
    }

    PotionApplyEvent event = new PotionApplyEvent(this, applyEffect, entity);

    entity.getServer().getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }

    applyEffect = event.getApplyEffect();

    switch (this.getId()) {
        case INSTANT_HEALTH:
        case INSTANT_HEALTH_II:
            entity.heal(new EntityRegainHealthEvent(entity, (float) (health * (double) (4 << (applyEffect.getAmplifier() + 1))), EntityRegainHealthEvent.CAUSE_EATING));
            break;
        case HARMING:
        case HARMING_II:
            entity.attack(new EntityDamageEvent(entity, DamageCause.MAGIC, (float) (health * (double) (6 << (applyEffect.getAmplifier() + 1)))));
            break;
        default:
            int duration = (int) ((isSplash() ? health : 1) * (double) applyEffect.getDuration() + 0.5);
            applyEffect.setDuration(duration);
            entity.addEffect(applyEffect);
    }
}