use of cn.nukkit.event.entity.EntityRegainHealthEvent in project Nukkit by Nukkit.
the class Potion method applyPotion.
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);
}
}
use of cn.nukkit.event.entity.EntityRegainHealthEvent in project Nukkit by Nukkit.
the class PlayerFood method update.
public void update(int tickDiff) {
if (!this.getPlayer().isFoodEnabled())
return;
if (this.getPlayer().isAlive()) {
int diff = Server.getInstance().getDifficulty();
if (this.getLevel() > 17) {
this.foodTickTimer += tickDiff;
if (this.foodTickTimer >= 80) {
if (this.getPlayer().getHealth() < this.getPlayer().getMaxHealth()) {
EntityRegainHealthEvent ev = new EntityRegainHealthEvent(this.getPlayer(), 1, EntityRegainHealthEvent.CAUSE_EATING);
this.getPlayer().heal(ev);
// this.updateFoodExpLevel(3);
}
this.foodTickTimer = 0;
}
} else if (this.getLevel() == 0) {
this.foodTickTimer += tickDiff;
if (this.foodTickTimer >= 80) {
EntityDamageEvent ev = new EntityDamageEvent(this.getPlayer(), DamageCause.VOID, 1);
float now = this.getPlayer().getHealth();
if (diff == 1) {
if (now > 10)
this.getPlayer().attack(ev);
} else if (diff == 2) {
if (now > 1)
this.getPlayer().attack(ev);
} else {
this.getPlayer().attack(ev);
}
this.foodTickTimer = 0;
}
}
if (this.getPlayer().hasEffect(Effect.HUNGER)) {
this.updateFoodExpLevel(0.025);
}
}
}
Aggregations