/** * Heals an entity by a specific amount. * * @param target the entity to heal * @param amount the amount of health to regain * @param reason the reason supplied to the {@link EntityRegainHealthEvent} */ public static void heal(LivingEntity target, double amount, EntityRegainHealthEvent.RegainReason reason) { if (target.isDead()) { return; // too late! } final double maxHealth = target.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); final double currentHealth = target.getHealth(); if (currentHealth >= maxHealth) { return; } EntityRegainHealthEvent event = new EntityRegainHealthEvent(target, amount, reason); EventFactory.getInstance().callEvent(event); if (!event.isCancelled()) { target.setHealth(Math.min(maxHealth, currentHealth + event.getAmount())); } }
/** * Attempt to damage target for value dmg with reason ENTITY_ATTACK with damager attacker * * @param target LivingEntity which to attempt to damage * @param damage Amount of damage to attempt to do * @param attacker Player to pass to event as damager */ @Deprecated public static void dealDamage(LivingEntity target, double damage, DamageCause cause, Entity attacker) { if (target.isDead()) { return; } target.damage(callFakeDamageEvent(attacker, target, cause, damage)); }
public static void dealNoInvulnerabilityTickDamage(LivingEntity target, double damage, Entity attacker) { if (target.isDead()) { return; } double incDmg = callFakeDamageEvent(attacker, target, DamageCause.CUSTOM, damage); double newHealth = Math.max(0, target.getHealth() - incDmg); target.setHealth(newHealth); }
@Override public boolean isDead() { LivingEntity entity = getLivingEntity(); if (entity != null) { return entity.isDead(); } // Check for automata if (isAutomaton) { return !isValid(); } return false; }
/** * Attempt to damage target for value dmg with reason ENTITY_ATTACK with damager attacker * * @param target LivingEntity which to attempt to damage * @param damage Amount of damage to attempt to do * @param attacker Player to pass to event as damager */ public static void dealDamage(LivingEntity target, double damage, Map<DamageModifier, Double> modifiers, LivingEntity attacker) { if (target.isDead()) { return; } // Aren't we applying the damage twice???? target.damage(callFakeDamageEvent(attacker, target, damage, modifiers)); }
@Override public boolean shouldStart() { if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { return false; } if (this.petEntity.passenger != null) { return false; } return this.petEntity.getRandom().nextFloat() < 0.02F; }
@Override public void run() { if (ticks >= maxTicks || entity.isDead() || entity.getPassengers().isEmpty() || player.isDead()) { cancel(); HandlerList.unregisterAll(listener); if (!entity.isDead() && !entity.getPassengers().isEmpty()) { entity.removePassenger(player); player.leaveVehicle(); } } ticks++; } }.runTaskTimer(RPGItems.plugin, 1, 1);
@Override public boolean shouldStart() { if (this.petEntity.getRandom().nextFloat() >= this.lookAtPlayerChance) { return false; } if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { return false; } if (this.petEntity.passenger != null) { return false; } this.targetPlayer = this.petEntity.world.findNearbyPlayer(this.petEntity, this.range); return this.targetPlayer != null; }
@Override public void run() { if (ticks >= maxTicks || player.getPassengers().isEmpty() || entity.isDead()) { cancel(); if (finalListener != null) { HandlerList.unregisterAll(finalListener); } if (!player.getPassengers().isEmpty() && player.getPassengers().get(0).getUniqueId().equals(entity.getUniqueId())) { player.getPassengers().get(0).leaveVehicle(); } } ticks++; } }.runTaskTimer(RPGItems.plugin, 1, 1);
@Override public boolean isValid() { if (forget) return false; if (!hasEntity) return true; Entity entity = getEntity(); if (entity == null) return false; if (!isNPC && entity instanceof Player) { Player player = (Player)entity; return player.isOnline(); } if (entity instanceof LivingEntity) { LivingEntity living = (LivingEntity)entity; return !living.isDead(); } // Automata theoretically handle themselves by sticking around for a while // And forcing themselves to be forgotten // but maybe some extra safety here would be good? return entity.isValid(); }
@Override public void progress() { final List<RaiseEarth> removal = new ArrayList<>(); for (final RaiseEarth abil : this.entities.keySet()) { if (abil.isRemoved() && abil.isStarted()) { final LivingEntity lent = this.entities.get(abil); if (!lent.isDead()) { if (lent instanceof Player && !((Player) lent).isOnline()) { continue; } lent.setVelocity(new Vector(0, this.power, 0)); } if (this.damaging) { DamageHandler.damageEntity(lent, this.damage, this); } removal.add(abil); } } for (final RaiseEarth remove : removal) { this.entities.remove(remove); } if (this.entities.isEmpty()) { this.bPlayer.addCooldown(this); this.remove(); return; } }
@Override public boolean shouldFinish() { if (controlPathfinderGoal.moveTo != null) { return true; } else if (this.petEntity.getOwner() == null) { return true; } else if (this.petEntity.f(owner) < this.stopDistance) { return true; } else if (!this.petEntity.canMove()) { return true; } else if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { return true; } return false; }
public void resetArmor() { if (!this.isMagnetized) { this.bPlayer.addCooldown(this); } if (this.targetEntity == null || !TempArmor.hasTempArmor(this.targetEntity) || this.targetEntity.isDead()) { return; } TempArmor.getVisibleTempArmor(this.targetEntity).revert(); this.dropIngots(this.targetEntity.getLocation()); this.isBeingWorn = false; }
private void giveHP(final LivingEntity livingEntity) { if (!livingEntity.isDead() && livingEntity.getHealth() < livingEntity.getMaxHealth()) { this.applyHealing(livingEntity); } else { this.healing = false; } for (final PotionEffect effect : livingEntity.getActivePotionEffects()) { if (ElementalAbility.isNegativeEffect(effect.getType())) { livingEntity.removePotionEffect(effect.getType()); } } }
@Override public boolean shouldStart() { if (!Configuration.MyPet.Sheep.CAN_REGROW_WOOL) { return false; } else if (!this.entityMySheep.getMyPet().isSheared()) { return false; } else if (entityMySheep.getRandom().nextInt(1000) != 0) { return false; } else if (this.entityMySheep.getTarget() != null && !this.entityMySheep.getTarget().isDead()) { return false; } int blockLocX = MathHelper.floor(this.entityMySheep.locX); int blockLocY = MathHelper.floor(this.entityMySheep.locY); int blockLocZ = MathHelper.floor(this.entityMySheep.locZ); return this.world.getType(blockLocX, blockLocY, blockLocZ) == Blocks.LONG_GRASS || this.world.getType(blockLocX, blockLocY - 1, blockLocZ) == Blocks.GRASS; }
public void setTarget(LivingEntity entity, TargetPriority priority) { if (entity == null || entity.isDead() || !(entity instanceof CraftLivingEntity)) { forgetTarget(); return; } if (!MyPetApi.getHookHelper().canHurt(myPet.getOwner().getPlayer(), entity)) { forgetTarget(); return; } if (priority.getPriority() > getTargetPriority().getPriority()) { target = ((CraftLivingEntity) entity).getHandle(); } }
@Override public boolean shouldStart() { if (controlPathfinderGoal == null) { if (petEntity.getPathfinder().hasGoal("Control")) { controlPathfinderGoal = (Control) petEntity.getPathfinder().getGoal("Control"); } } if (!this.petEntity.canMove()) { return false; } if (this.petEntity.getTarget() != null && !this.petEntity.getTarget().isDead()) { return false; } if (this.petEntity.getOwner() == null) { return false; } if (this.petEntity.f(owner) < this.startDistance) { return false; } if (controlPathfinderGoal != null && controlPathfinderGoal.moveTo != null) { return false; } return true; }
if (e.isDead()) { arena.getMonsterManager().removeMonster(e); arena.getMonsterManager().removeExplodingSheep(e);
if (this.target.isDead()) { this.remove(); return;
private void dragEntity(final Location location) { if (this.grabbedEntity != null && this.grabbed) { if (!this.waterArms.canDisplayActiveArm() || this.grabbedEntity.isDead()) { this.grabbed = false; GRABBED_ENTITIES.remove(this.grabbedEntity);