本文整理汇总了Java中cn.nukkit.event.entity.EntityRegainHealthEvent类的典型用法代码示例。如果您正苦于以下问题:Java EntityRegainHealthEvent类的具体用法?Java EntityRegainHealthEvent怎么用?Java EntityRegainHealthEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EntityRegainHealthEvent类属于cn.nukkit.event.entity包,在下文中一共展示了EntityRegainHealthEvent类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyEffect
import cn.nukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
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;
}
}
示例2: heal
import cn.nukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
@Override
public void heal(EntityRegainHealthEvent source) {
super.heal(source);
if (source.isCancelled()) {
return;
}
this.attackTime = 0;
}
示例3: heal
import cn.nukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
public void heal(EntityRegainHealthEvent source) {
this.server.getPluginManager().callEvent(source);
if (source.isCancelled()) {
return;
}
this.setHealth(this.getHealth() + source.getAmount());
}
示例4: applyPotion
import cn.nukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
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);
}
}
示例5: applyPotion
import cn.nukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
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, EntityDamageEvent.CAUSE_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);
}
}
示例6: applyPotion
import cn.nukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
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);
}
}
示例7: applyPotion
import cn.nukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
public void applyPotion(Entity entity) {
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:
entity.heal(new EntityRegainHealthEvent(entity, 4, EntityRegainHealthEvent.CAUSE_EATING));
break;
case INSTANT_HEALTH_II:
entity.heal(new EntityRegainHealthEvent(entity, 8, EntityRegainHealthEvent.CAUSE_EATING));
break;
case HARMING:
entity.attack(new EntityDamageEvent(entity, EntityDamageEvent.CAUSE_MAGIC, 6));
break;
case HARMING_II:
entity.attack(new EntityDamageEvent(entity, EntityDamageEvent.CAUSE_MAGIC, 12));
break;
default:
entity.addEffect(applyEffect);
}
}
示例8: onEntityRegainHealth
import cn.nukkit.event.entity.EntityRegainHealthEvent; //导入依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
if (event.getRegainReason() == EntityRegainHealthEvent.CAUSE_REGEN) {
event.setCancelled(!api.isNaturalRegeneration(event.getEntity().getLevel()));
}
}