Java 类org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason 实例源码

项目:Crescent    文件:FastHealA.java   
@Override
public void call(Event event) {
    if (event instanceof EntityRegainHealthEvent) {
        EntityRegainHealthEvent erhe = (EntityRegainHealthEvent) event;

        if (erhe.getRegainReason() == RegainReason.SATIATED) {
            /*
             * Player is regenerating health because their hunger is full.
             */

            final double health = profile.getPlayer().getHealth();

            if (!isAcceptable(health, erhe.getAmount())) {
                callback(true);
            }

            lastTime = System.currentTimeMillis();
        }
    }
}
项目:CraftBukkit    文件:MobEffectList.java   
public void applyInstantEffect(EntityLiving entityliving, EntityLiving entityliving1, int i, double d0, EntityPotion potion) {
    // CraftBukkit end
    int j;

    if ((this.id != HEAL.id || entityliving1.aR()) && (this.id != HARM.id || !entityliving1.aR())) {
        if (this.id == HARM.id && !entityliving1.aR() || this.id == HEAL.id && entityliving1.aR()) {
            j = (int) (d0 * (double) (6 << i) + 0.5D);
            if (entityliving == null) {
                entityliving1.damageEntity(DamageSource.MAGIC, (float) j);
            } else {
                // CraftBukkit - The "damager" needs to be the potion
                entityliving1.damageEntity(DamageSource.b(potion != null ? potion : entityliving1, entityliving), (float) j);
            }
        }
    } else {
        j = (int) (d0 * (double) (4 << i) + 0.5D);
        entityliving1.heal((float) j, RegainReason.MAGIC); // CraftBukkit
    }
}
项目:Almura-Server    文件:MobEffectList.java   
public void tick(EntityLiving entityliving, int i) {
    if (this.id == REGENERATION.id) {
        if (entityliving.getHealth() < entityliving.getMaxHealth()) {
            entityliving.heal(1.0F, RegainReason.MAGIC_REGEN); // CraftBukkit
        }
    } else if (this.id == POISON.id) {
        if (entityliving.getHealth() > 1.0F) {
            entityliving.damageEntity(CraftEventFactory.POISON, 1.0F); // CraftBukkit - DamageSource.MAGIC -> CraftEventFactory.POISON
        }
    } else if (this.id == WITHER.id) {
        entityliving.damageEntity(DamageSource.WITHER, 1.0F);
    } else if (this.id == HUNGER.id && entityliving instanceof EntityHuman) {
        ((EntityHuman) entityliving).a(0.025F * (float) (i + 1));
    } else if (this.id == SATURATION.id && entityliving instanceof EntityHuman) {
        if (!entityliving.world.isStatic) {
            ((EntityHuman) entityliving).getFoodData().eat(i + 1, 1.0F);
        }
    } else if ((this.id != HEAL.id || entityliving.aM()) && (this.id != HARM.id || !entityliving.aM())) {
        if (this.id == HARM.id && !entityliving.aM() || this.id == HEAL.id && entityliving.aM()) {
            entityliving.damageEntity(DamageSource.MAGIC, (float) (6 << i));
        }
    } else {
        entityliving.heal((float) Math.max(4 << i, 0), RegainReason.MAGIC); // CraftBukkit
    }
}
项目:Almura-Server    文件:MobEffectList.java   
public void applyInstantEffect(EntityLiving entityliving, EntityLiving entityliving1, int i, double d0, EntityPotion potion) {
    // CraftBukkit end
    int j;

    if ((this.id != HEAL.id || entityliving1.aM()) && (this.id != HARM.id || !entityliving1.aM())) {
        if (this.id == HARM.id && !entityliving1.aM() || this.id == HEAL.id && entityliving1.aM()) {
            j = (int) (d0 * (double) (6 << i) + 0.5D);
            if (entityliving == null) {
                entityliving1.damageEntity(DamageSource.MAGIC, (float) j);
            } else {
                // CraftBukkit - The "damager" needs to be the potion
                entityliving1.damageEntity(DamageSource.b(potion != null ? potion : entityliving1, entityliving), (float) j);
            }
        }
    } else {
        j = (int) (d0 * (double) (4 << i) + 0.5D);
        entityliving1.heal((float) j, RegainReason.MAGIC);
    }
}
项目:Factoid    文件:PlayerListener.java   
/**
 * On entity regain health.
 *
 * @param event the event
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEntityRegainHealth(EntityRegainHealthEvent event) {

    Entity entity = event.getEntity();
    Player player;
    IPlayerConfEntry entry;

    if(entity != null && event.getEntity() instanceof Player
            && (event.getRegainReason() == RegainReason.REGEN
            || event.getRegainReason() == RegainReason.SATIATED)
            && (entry = playerConf.get((player = (Player) event.getEntity()))) != null
            && !entry.isAdminMod()) {

        IDummyLand land = Factoid.getThisPlugin().iLands().getLandOrOutsideArea(player.getLocation());

        if (!checkPermission(land, player, PermissionList.FOOD_HEAL.getPermissionType())) {
            event.setCancelled(true);
        }
    }
}
项目:AntiCheat-COMPAT    文件:EntityListener.java   
@EventHandler
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
    if (event.getEntity() instanceof Player && event.getRegainReason() == RegainReason.SATIATED) {
        Player player = (Player) event.getEntity();
        if (getCheckManager().willCheck(player, CheckType.FAST_HEAL)) {
            CheckResult result = getBackend().checkFastHeal(player);
            if (result.failed()) {
                event.setCancelled(!silentMode());
                log(result.getMessage(), player, CheckType.FAST_HEAL);
            } else {
                decrease(player);
                getBackend().logHeal(player);
            }
        }
    }

    AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
}
项目:SpigotSource    文件:MobEffectList.java   
public void applyInstantEffect(@Nullable Entity entity, @Nullable Entity entity1, EntityLiving entityliving, int i, double d0) {
    int j;

    if ((this != MobEffects.HEAL || entityliving.bQ()) && (this != MobEffects.HARM || !entityliving.bQ())) {
        if (this == MobEffects.HARM && !entityliving.bQ() || this == MobEffects.HEAL && entityliving.bQ()) {
            j = (int) (d0 * (double) (6 << i) + 0.5D);
            if (entity == null) {
                entityliving.damageEntity(DamageSource.MAGIC, (float) j);
            } else {
                entityliving.damageEntity(DamageSource.b(entity, entity1), (float) j);
            }
        }
    } else {
        j = (int) (d0 * (double) (4 << i) + 0.5D);
        entityliving.heal((float) j, RegainReason.MAGIC); // CraftBukkit
    }

}
项目:FoodBalance    文件:RegenListener.java   
@EventHandler
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
    if (!(event.getEntity() instanceof Player)) {
        return;
    }

    if (event.getRegainReason() != RegainReason.SATIATED) {
        return;
    }

    Player player = (Player) event.getEntity();
    int proteinValue = plugin.getValueManager().getValue(FoodType.PROTEIN, player);

    Random ran = new Random();
    if (proteinValue <= -7) {
        if (ran.nextInt(2) == 0) {
            event.setCancelled(true);
        }
    } else if (proteinValue <= -6) {
        if (ran.nextInt(4) > 0) {
            event.setCancelled(true);
        }
    }

}
项目:NPlugins    文件:EnderDragonListener.java   
/**
 * Handle EnderDragon regen
 *
 * @param event an EntityRegainHealthEvent
 */
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onEnderDragonRegainHealth(final EntityRegainHealthEvent event) {
    if (event.getEntityType() == EntityType.ENDER_DRAGON && event.getRegainReason() == RegainReason.ENDER_CRYSTAL) {
        final EndWorldHandler handler = this.plugin.getHandler(StringUtil.toLowerCamelCase(event.getEntity().getLocation().getWorld().getName()));
        if (handler != null) {
            final float rate = handler.getConfig().getEcHealthRegainRate();
            if (rate < 1.0) {
                if (RANDOM.nextFloat() >= rate) {
                    event.setCancelled(true);
                }
            } else if (rate > 1.0) {
                event.setAmount((int)(rate * event.getAmount()));
            }
        }
    }
}
项目:Craft-city    文件:MobEffectList.java   
public void tick(EntityLiving entityliving, int i) {
    if (this.id == REGENERATION.id) {
        if (entityliving.getHealth() < entityliving.maxHealth) { // CraftBukkit - .getMaxHealth() -> .maxHealth
            entityliving.heal(1, RegainReason.MAGIC_REGEN); // CraftBukkit
        }
    } else if (this.id == POISON.id) {
        if (entityliving.getHealth() > 1) {
            entityliving.damageEntity(CraftEventFactory.POISON, 1); // CraftBukkit - DamageSource.MAGIC -> CraftEventFactory.POISON
        }
    } else if (this.id == WITHER.id) {
        entityliving.damageEntity(DamageSource.WITHER, 1);
    } else if (this.id == HUNGER.id && entityliving instanceof EntityHuman) {
        ((EntityHuman) entityliving).j(0.025F * (float) (i + 1));
    } else if ((this.id != HEAL.id || entityliving.bD()) && (this.id != HARM.id || !entityliving.bD())) {
        if (this.id == HARM.id && !entityliving.bD() || this.id == HEAL.id && entityliving.bD()) {
            entityliving.damageEntity(DamageSource.MAGIC, 6 << i);
        }
    } else {
        entityliving.heal(6 << i, RegainReason.MAGIC); // CraftBukkit
    }
}
项目:Craft-city    文件:MobEffectList.java   
public void applyInstantEffect(EntityLiving entityliving, EntityLiving entityliving1, int i, double d0, EntityPotion potion) {
    // CraftBukkit end
    int j;

    if ((this.id != HEAL.id || entityliving1.bD()) && (this.id != HARM.id || !entityliving1.bD())) {
        if (this.id == HARM.id && !entityliving1.bD() || this.id == HEAL.id && entityliving1.bD()) {
            j = (int) (d0 * (double) (6 << i) + 0.5D);
            if (entityliving == null) {
                entityliving1.damageEntity(DamageSource.MAGIC, j);
            } else {
                // CraftBukkit - The "damager" needs to be the potion
                entityliving1.damageEntity(DamageSource.b(potion != null ? potion : entityliving1, entityliving), j);
            }
        }
    } else {
        j = (int) (d0 * (double) (6 << i) + 0.5D);
        entityliving1.heal(j, RegainReason.MAGIC); // CraftBukkit
    }
}
项目:Essentials    文件:EssentialsEntityListener.java   
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onEntityRegainHealth(final EntityRegainHealthEvent event)
{

    if (event.getRegainReason() == RegainReason.SATIATED && event.getEntity() instanceof Player)
    {

        final ISettings settings = ess.getSettings();

        final IUser user = ess.getUserMap().getUser((Player)event.getEntity());
        if (user.getData().isAfk() && settings.getData().getCommands().getAfk().isFreezeAFKPlayers())
        {
            event.setCancelled(true);
        }
    }
}
项目:Damocles    文件:EventCanceller.java   
@EventHandler
public void healthRegen(EntityRegainHealthEvent event){
    if(event.getRegainReason().equals(RegainReason.SATIATED)){
        event.setCancelled(true);
    }
    if(event.getRegainReason().equals(RegainReason.REGEN)){
        event.setCancelled(true);
    }
}
项目:Pokkit    文件:EntityEvents.java   
@EventHandler(ignoreCancelled = false)
public void onEntityRegainHealth(cn.nukkit.event.entity.EntityRegainHealthEvent event) {
    if (canIgnore(PlayerInteractEvent.getHandlerList())) {
        return;
    }

    int reason = event.getRegainReason();
    RegainReason bukkitReason = RegainReason.EATING;

    switch (reason) {
    case cn.nukkit.event.entity.EntityRegainHealthEvent.CAUSE_MAGIC:
        bukkitReason = RegainReason.MAGIC;
        break;
    case cn.nukkit.event.entity.EntityRegainHealthEvent.CAUSE_CUSTOM:
        bukkitReason = RegainReason.CUSTOM;
        break;
    case cn.nukkit.event.entity.EntityRegainHealthEvent.CAUSE_EATING:
        bukkitReason = RegainReason.EATING;
        break;
    case cn.nukkit.event.entity.EntityRegainHealthEvent.CAUSE_REGEN:
        bukkitReason = RegainReason.REGEN;
        break;
    }

    EntityRegainHealthEvent bukkitEvent = new EntityRegainHealthEvent(PokkitEntity.toBukkit(event.getEntity()), event.getAmount(), bukkitReason);

    callCancellable(event, bukkitEvent);
}
项目:CraftBukkit    文件:MobEffectList.java   
public void tick(EntityLiving entityliving, int i) {
    if (this.id == REGENERATION.id) {
        if (entityliving.getHealth() < entityliving.getMaxHealth()) {
            entityliving.heal(1.0F, RegainReason.MAGIC_REGEN); // CraftBukkit
        }
    } else if (this.id == POISON.id) {
        if (entityliving.getHealth() > 1.0F) {
            entityliving.damageEntity(CraftEventFactory.POISON, 1.0F); // CraftBukkit - DamageSource.MAGIC -> CraftEventFactory.POISON
        }
    } else if (this.id == WITHER.id) {
        entityliving.damageEntity(DamageSource.WITHER, 1.0F);
    } else if (this.id == HUNGER.id && entityliving instanceof EntityHuman) {
        ((EntityHuman) entityliving).applyExhaustion(0.025F * (float) (i + 1));
    } else if (this.id == SATURATION.id && entityliving instanceof EntityHuman) {
        if (!entityliving.world.isStatic) {
            // CraftBukkit start
            EntityHuman entityhuman = (EntityHuman) entityliving;
            int oldFoodLevel = entityhuman.getFoodData().foodLevel;

            org.bukkit.event.entity.FoodLevelChangeEvent event = CraftEventFactory.callFoodLevelChangeEvent(entityhuman, i + 1 + oldFoodLevel);

            if (!event.isCancelled()) {
                entityhuman.getFoodData().eat(event.getFoodLevel() - oldFoodLevel, 1.0F);
            }

            ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutUpdateHealth(((EntityPlayer) entityhuman).getBukkitEntity().getScaledHealth(), entityhuman.getFoodData().foodLevel, entityhuman.getFoodData().saturationLevel));
            // CraftBukkit end
        }
    } else if ((this.id != HEAL.id || entityliving.aR()) && (this.id != HARM.id || !entityliving.aR())) {
        if (this.id == HARM.id && !entityliving.aR() || this.id == HEAL.id && entityliving.aR()) {
            entityliving.damageEntity(DamageSource.MAGIC, (float) (6 << i));
        }
    } else {
        entityliving.heal((float) Math.max(4 << i, 0), RegainReason.MAGIC); // CraftBukkit
    }
}
项目:CraftBukkit    文件:EntityHorse.java   
public void e() {
    if (this.random.nextInt(200) == 0) {
        this.cR();
    }

    super.e();
    if (!this.world.isStatic) {
        if (this.random.nextInt(900) == 0 && this.deathTicks == 0) {
            this.heal(1.0F, RegainReason.REGEN); // CraftBukkit
        }

        if (!this.cm() && this.passenger == null && this.random.nextInt(300) == 0 && this.world.getType(MathHelper.floor(this.locX), MathHelper.floor(this.locY) - 1, MathHelper.floor(this.locZ)) == Blocks.GRASS) {
            this.o(true);
        }

        if (this.cm() && ++this.bD > 50) {
            this.bD = 0;
            this.o(false);
        }

        if (this.co() && !this.cb() && !this.cm()) {
            EntityHorse entityhorse = this.a(this, 16.0D);

            if (entityhorse != null && this.f(entityhorse) > 4.0D) {
                PathEntity pathentity = this.world.findPath(this, entityhorse, 16.0F, true, false, false, true);

                this.setPathEntity(pathentity);
            }
        }
    }
}
项目:Tweakkit-Server    文件:MobEffectList.java   
public void tick(EntityLiving entityliving, int i) {
    if (this.id == REGENERATION.id) {
        if (entityliving.getHealth() < entityliving.getMaxHealth()) {
            entityliving.heal(1.0F, RegainReason.MAGIC_REGEN); // CraftBukkit
        }
    } else if (this.id == POISON.id) {
        if (entityliving.getHealth() > 1.0F) {
            entityliving.damageEntity(CraftEventFactory.POISON, 1.0F); // CraftBukkit - DamageSource.MAGIC -> CraftEventFactory.POISON
        }
    } else if (this.id == WITHER.id) {
        entityliving.damageEntity(DamageSource.WITHER, 1.0F);
    } else if (this.id == HUNGER.id && entityliving instanceof EntityHuman) {
        ((EntityHuman) entityliving).applyExhaustion(0.025F * (float) (i + 1));
    } else if (this.id == SATURATION.id && entityliving instanceof EntityHuman) {
        if (!entityliving.world.isStatic) {
            // CraftBukkit start
            EntityHuman entityhuman = (EntityHuman) entityliving;
            int oldFoodLevel = entityhuman.getFoodData().foodLevel;

            org.bukkit.event.entity.FoodLevelChangeEvent event = CraftEventFactory.callFoodLevelChangeEvent(entityhuman, i + 1 + oldFoodLevel);

            if (!event.isCancelled()) {
                entityhuman.getFoodData().eat(event.getFoodLevel() - oldFoodLevel, 1.0F);
            }

            ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutUpdateHealth(((EntityPlayer) entityhuman).getBukkitEntity().getScaledHealth(), entityhuman.getFoodData().foodLevel, entityhuman.getFoodData().saturationLevel));
            // CraftBukkit end
        }
    } else if ((this.id != HEAL.id || entityliving.aR()) && (this.id != HARM.id || !entityliving.aR())) {
        if (this.id == HARM.id && !entityliving.aR() || this.id == HEAL.id && entityliving.aR()) {
            entityliving.damageEntity(DamageSource.MAGIC, (float) (6 << i));
        }
    } else {
        entityliving.heal((float) Math.max(4 << i, 0), RegainReason.MAGIC); // CraftBukkit
    }
}
项目:Tweakkit-Server    文件:MobEffectList.java   
public void applyInstantEffect(EntityLiving entityliving, EntityLiving entityliving1, int i, double d0, EntityPotion potion) {
    // CraftBukkit end
    int j;

    // Tweakkit start
    MobEffect effectEvent = new MobEffect(id,0,i); // Need to construct the MobEffect to use in the Event
    EntityPotionEffectChangeEvent potionEvent = CraftEventFactory.callEntityPotionEffectChangeEvent(entityliving, effectEvent, EntityPotionEffectChangeEvent.Cause.POTION, entityliving1.world, entityliving1.locX, entityliving1.locY, entityliving1.locZ);
    if (potionEvent.isCancelled()) {
        return;
    }
    if ((potionEvent.getEffect().getType().getId() != HEAL.id || entityliving1.aR()) && (potionEvent.getEffect().getType().getId() != HARM.id || !entityliving1.aR())) {
        if (potionEvent.getEffect().getType().getId() == HARM.id && !entityliving1.aR() || potionEvent.getEffect().getType().getId() == HEAL.id && entityliving1.aR()) {
            j = (int) (d0 * (double) (6 << potionEvent.getEffect().getAmplifier()) + 0.5D); // CraftBukkit - Apply the amplifier of the event
            // Tweakkit end

            if (entityliving == null) {
                entityliving1.damageEntity(DamageSource.MAGIC, (float) j);
            } else {
                // CraftBukkit - The "damager" needs to be the potion
                entityliving1.damageEntity(DamageSource.b(potion != null ? potion : entityliving1, entityliving), (float) j);
            }
        }
    } else {
        // Tweakkit - Use potionEvent.getEffect().getAmplifier() instead of default i
        j = (int) (d0 * (double) (4 << potionEvent.getEffect().getAmplifier()) + 0.5D);
        entityliving1.heal((float) j, RegainReason.MAGIC); // CraftBukkit
    }
}
项目:Tweakkit-Server    文件:EntityHorse.java   
public void e() {
    if (this.random.nextInt(200) == 0) {
        this.cR();
    }

    super.e();
    if (!this.world.isStatic) {
        if (this.random.nextInt(900) == 0 && this.deathTicks == 0) {
            this.heal(1.0F, RegainReason.REGEN); // CraftBukkit
        }

        if (!this.cm() && this.passenger == null && this.random.nextInt(300) == 0 && this.world.getType(MathHelper.floor(this.locX), MathHelper.floor(this.locY) - 1, MathHelper.floor(this.locZ)) == Blocks.GRASS) {
            this.o(true);
        }

        if (this.cm() && ++this.bD > 50) {
            this.bD = 0;
            this.o(false);
        }

        if (this.co() && !this.cb() && !this.cm()) {
            EntityHorse entityhorse = this.a(this, 16.0D);

            if (entityhorse != null && this.f(entityhorse) > 4.0D) {
                PathEntity pathentity = this.world.findPath(this, entityhorse, 16.0F, true, false, false, true);

                this.setPathEntity(pathentity);
            }
        }
    }
}
项目:Cauldron    文件:Potion.java   
public void applyInstantEffect(EntityLivingBase p_76402_1_, EntityLivingBase p_76402_2_, int p_76402_3_, double p_76402_4_, EntityPotion potion)
{
    // CraftBukkit end
    int j;

    if ((this.id != heal.id || p_76402_2_.isEntityUndead()) && (this.id != harm.id || !p_76402_2_.isEntityUndead()))
    {
        if (this.id == harm.id && !p_76402_2_.isEntityUndead() || this.id == heal.id && p_76402_2_.isEntityUndead())
        {
            j = (int)(p_76402_4_ * (double)(6 << p_76402_3_) + 0.5D);

            if (p_76402_1_ == null)
            {
                p_76402_2_.attackEntityFrom(DamageSource.magic, (float)j);
            }
            else
            {
                // CraftBukkit - The "damager" needs to be the potion
                p_76402_2_.attackEntityFrom(DamageSource.causeIndirectMagicDamage(potion != null ? potion : p_76402_2_, p_76402_1_), (float)j);
            }
        }
    }
    else
    {
        j = (int)(p_76402_4_ * (double)(4 << p_76402_3_) + 0.5D);
        p_76402_2_.heal((float)j, RegainReason.MAGIC); // CraftBukkit
    }
}
项目:PV-Star    文件:PlayerEventListener.java   
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerAutoHeal(EntityRegainHealthEvent event) {
    if (event.getRegainReason() != RegainReason.REGEN &&
            event.getRegainReason() != RegainReason.MAGIC_REGEN &&
            event.getRegainReason() != RegainReason.SATIATED)
        return;

    if (!(event.getEntity() instanceof Player))
        return;

    Player p = (Player)event.getEntity();
    IArenaPlayer player = ArenaPlayer.get(p);
    if (player == null)
        return;

    IArena arena = player.getArena();
    if (arena == null)
        return;

    // get settings
    IContextSettings settings = player.getContextSettings();
    if (settings == null)
        return;

    // prevent auto heal
    if (!settings.isAutoHealEnabled()) {
        event.setCancelled(true);
    }
}
项目:SpigotSource    文件:MobEffectList.java   
public void tick(EntityLiving entityliving, int i) {
    if (this == MobEffects.REGENERATION) {
        if (entityliving.getHealth() < entityliving.getMaxHealth()) {
            entityliving.heal(1.0F, RegainReason.MAGIC_REGEN); // CraftBukkit
        }
    } else if (this == MobEffects.POISON) {
        if (entityliving.getHealth() > 1.0F) {
            entityliving.damageEntity(CraftEventFactory.POISON, 1.0F);  // CraftBukkit - DamageSource.MAGIC -> CraftEventFactory.POISON
        }
    } else if (this == MobEffects.WITHER) {
        entityliving.damageEntity(DamageSource.WITHER, 1.0F);
    } else if (this == MobEffects.HUNGER && entityliving instanceof EntityHuman) {
        ((EntityHuman) entityliving).applyExhaustion(0.025F * (float) (i + 1));
    } else if (this == MobEffects.SATURATION && entityliving instanceof EntityHuman) {
        if (!entityliving.world.isClientSide) {
            // CraftBukkit start
            EntityHuman entityhuman = (EntityHuman) entityliving;
            int oldFoodLevel = entityhuman.getFoodData().foodLevel;

            org.bukkit.event.entity.FoodLevelChangeEvent event = CraftEventFactory.callFoodLevelChangeEvent(entityhuman, i + 1 + oldFoodLevel);

            if (!event.isCancelled()) {
                entityhuman.getFoodData().eat(event.getFoodLevel() - oldFoodLevel, 1.0F);
            }

            ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutUpdateHealth(((EntityPlayer) entityhuman).getBukkitEntity().getScaledHealth(), entityhuman.getFoodData().foodLevel, entityhuman.getFoodData().saturationLevel));
            // CraftBukkit end
        }
    } else if ((this != MobEffects.HEAL || entityliving.bQ()) && (this != MobEffects.HARM || !entityliving.bQ())) {
        if (this == MobEffects.HARM && !entityliving.bQ() || this == MobEffects.HEAL && entityliving.bQ()) {
            entityliving.damageEntity(DamageSource.MAGIC, (float) (6 << i));
        }
    } else {
        entityliving.heal((float) Math.max(4 << i, 0), RegainReason.MAGIC); // CraftBukkit
    }

}
项目:SpigotSource    文件:EntityHorse.java   
public void n() {
    if (this.random.nextInt(200) == 0) {
        this.dO();
    }

    super.n();
    if (!this.world.isClientSide) {
        if (this.random.nextInt(900) == 0 && this.deathTicks == 0) {
            this.heal(1.0F, RegainReason.REGEN); // CraftBukkit
        }

        if (!this.dn() && !this.isVehicle() && this.random.nextInt(300) == 0 && this.world.getType(new BlockPosition(MathHelper.floor(this.locX), MathHelper.floor(this.locY) - 1, MathHelper.floor(this.locZ))).getBlock() == Blocks.GRASS) {
            this.u(true);
        }

        if (this.dn() && ++this.bP > 50) {
            this.bP = 0;
            this.u(false);
        }

        if (this.dp() && !this.dc() && !this.dn()) {
            EntityHorse entityhorse = this.a(this, 16.0D);

            if (entityhorse != null && this.h((Entity) entityhorse) > 4.0D) {
                this.navigation.a((Entity) entityhorse);
            }
        }

        if (this.dH() && this.bW++ >= 18000) {
            this.die();
        }
    }

}
项目:KTP    文件:UHPluginListener.java   
@EventHandler
public void onEntityRegainHealth(final EntityRegainHealthEvent ev) {
    if (ev.getRegainReason() == RegainReason.SATIATED) ev.setCancelled(true);
    if (ev.getEntity() instanceof Player) {
        Bukkit.getScheduler().runTaskLater(this.p, new BukkitRunnable() {

            @Override
            public void run() {
                p.updatePlayerListName((Player)ev.getEntity());
            }
        }, 1L);
    }
}
项目:McPlayUHC    文件:EntityRegainHealthListener.java   
@EventHandler
public void EntityRegainHealthListener(EntityRegainHealthEvent e) {
    if (e.getRegainReason() == RegainReason.EATING) {
        e.setCancelled(true);
    }
}
项目:QuestManager    文件:InnAction.java   
@Override
public void onAction() {

    //check their money
    if (player.getMoney() >= cost) {
        //they have enough money

        //blindness for 3 seconds, title saying you're now rested?
        //don't forget to restore health, hunger
        //and take out some money

        if (!player.getPlayer().isOnline()) {
            System.out.println("Very bad InnAction error!!!!!!!!!!!!!");
            return;
        }

        player.addMoney(-cost);

        Player p = player.getPlayer().getPlayer();
        double amount = p.getMaxHealth() - p.getHealth();
        EntityRegainHealthEvent e = new EntityRegainHealthEvent(p, amount, RegainReason.CUSTOM);
        Bukkit.getPluginManager().callEvent(e);
        if (!e.isCancelled()) {
            p.setHealth(p.getMaxHealth());
        }

        player.regenMP(-100);

        p.setFoodLevel(20);
        p.setExhaustion(0f);
        p.setSaturation(20f);

        p.addPotionEffect(
                new PotionEffect(PotionEffectType.BLINDNESS, 60, 5));


        new TitleObject(ChatColor.GREEN + "Sweet Dreams" + ChatColor.RESET,
                ChatColor.BLUE + "Health and hunger have been restored")
                .setFadeIn(20).setFadeOut(20).setStay(40).send(p);

        p.playSound(p.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, .5f);

    } else {
        //not enough money
        //show them a menu, sorrow

        ChatMenu menu = new SimpleChatMenu(denial.getFormattedMessage());

        menu.show(player.getPlayer().getPlayer());
    }

}
项目:Cauldron    文件:Potion.java   
public void performEffect(EntityLivingBase p_76394_1_, int p_76394_2_)
{
    if (this.id == regeneration.id)
    {
        if (p_76394_1_.getHealth() < p_76394_1_.getMaxHealth())
        {
            p_76394_1_.heal(1.0F, RegainReason.MAGIC_REGEN); // CraftBukkit
        }
    }
    else if (this.id == poison.id)
    {
        if (p_76394_1_.getHealth() > 1.0F)
        {
            p_76394_1_.attackEntityFrom(CraftEventFactory.POISON, 1.0F); // CraftBukkit - DamageSource.MAGIC -> CraftEventFactory.POISON
        }
    }
    else if (this.id == wither.id)
    {
        p_76394_1_.attackEntityFrom(DamageSource.wither, 1.0F);
    }
    else if (this.id == hunger.id && p_76394_1_ instanceof EntityPlayer)
    {
        ((EntityPlayer)p_76394_1_).addExhaustion(0.025F * (float)(p_76394_2_ + 1));
    }
    else if (this.id == field_76443_y.id && p_76394_1_ instanceof EntityPlayer)
    {
        if (!p_76394_1_.worldObj.isRemote)
        {
            ((EntityPlayer)p_76394_1_).getFoodStats().addStats(p_76394_2_ + 1, 1.0F);
        }
    }
    else if ((this.id != heal.id || p_76394_1_.isEntityUndead()) && (this.id != harm.id || !p_76394_1_.isEntityUndead()))
    {
        if (this.id == harm.id && !p_76394_1_.isEntityUndead() || this.id == heal.id && p_76394_1_.isEntityUndead())
        {
            p_76394_1_.attackEntityFrom(DamageSource.magic, (float)(6 << p_76394_2_));
        }
    }
    else
    {
        p_76394_1_.heal((float)Math.max(4 << p_76394_2_, 0), RegainReason.MAGIC); // CraftBukkit
    }
}
项目:BedrockAPI    文件:EntityRegainHealthEvent.java   
@Deprecated public EntityRegainHealthEvent(Entity entity, int amount, EntityRegainHealthEvent.RegainReason regainReason) {
}
项目:BedrockAPI    文件:EntityRegainHealthEvent.java   
public EntityRegainHealthEvent(Entity entity, double amount, EntityRegainHealthEvent.RegainReason regainReason) {
}
项目:BedrockAPI    文件:EntityRegainHealthEvent.java   
public EntityRegainHealthEvent.RegainReason getRegainReason() {
    return null;
}
项目:NoHack    文件:NoHackListener.java   
@EventHandler(ignoreCancelled = true)
public void onEntityRegainHealthEvent(EntityRegainHealthEvent event) {

    if (event.getRegainReason() == RegainReason.SATIATED) {

        if (event.getEntity() instanceof Player) {

            Player p = (Player) event.getEntity();

            long diff = 1000;
            if (this.lastHealhed.containsKey(p.getName())) {
                diff = (System.currentTimeMillis() - this.lastHealhed.get(p.getName()));
            }

            this.lastHealhed.put(p.getName(), System.currentTimeMillis());

            if (diff <= 3800) {

                if (nh.vars.issueViolation(p, CheckType.GOD_MODE)) {

                    event.setCancelled(true);

                }

            }

            p = null;

        }

    }

}