use of org.bukkit.attribute.AttributeInstance in project Glowstone by GlowstoneMC.
the class EntityUtils method heal.
/**
* 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}
* @return whether any health was regained this way
* @throws IllegalArgumentException if the specified target has no {@link Attribute#GENERIC_MAX_HEALTH}
*/
public static boolean heal(@NotNull LivingEntity target, double amount, EntityRegainHealthEvent.RegainReason reason) {
if (target.isDead() || amount <= 0) {
return false;
}
final AttributeInstance attribute = target.getAttribute(Attribute.GENERIC_MAX_HEALTH);
if (attribute == null) {
throw new IllegalArgumentException("The specified LivingEntity has no " + Attribute.GENERIC_MAX_HEALTH + " attribute");
}
final double maxHealth = attribute.getValue();
final double currentHealth = target.getHealth();
if (currentHealth >= maxHealth) {
// already max health
return false;
}
EntityRegainHealthEvent event = new EntityRegainHealthEvent(target, amount, reason);
EventFactory.getInstance().callEvent(event);
if (event.isCancelled() || event.getAmount() <= 0) {
return false;
}
target.setHealth(Math.min(maxHealth, currentHealth + event.getAmount()));
return true;
}
use of org.bukkit.attribute.AttributeInstance in project Prism-Bukkit by prism.
the class AbstractHorseSerializer method serializer.
@Override
protected void serializer(Entity entity) {
final AbstractHorse h = (AbstractHorse) entity;
// TODO: Cleanup
if (entity.getType() == EntityType.HORSE) {
Horse horse = (Horse) h;
horseColor = horse.getColor().name();
style = horse.getStyle().name();
saddle = ItemUtils.smallString(horse.getInventory().getSaddle());
armor = ItemUtils.smallString(horse.getInventory().getArmor());
} else if (entity.getType() == EntityType.LLAMA) {
Llama llama = (Llama) h;
horseColor = llama.getColor().name();
saddle = ItemUtils.smallString(llama.getInventory().getDecor());
} else if (entity.getType() == EntityType.MULE || entity.getType() == EntityType.DONKEY || entity.getType() == EntityType.ZOMBIE_HORSE || entity.getType() == EntityType.SKELETON_HORSE) {
// Actually a saddle
saddle = ItemUtils.smallString(h.getInventory().getItem(0));
}
if (entity instanceof ChestedHorse) {
chest = ((ChestedHorse) entity).isCarryingChest();
}
dom = h.getDomestication();
maxDom = h.getMaxDomestication();
jump = h.getJumpStrength();
maxHealth = h.getAttribute(Attribute.GENERIC_MAX_HEALTH).getBaseValue();
AttributeInstance attributeInstance = h.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
if (attributeInstance != null) {
movementSpeed = attributeInstance.getBaseValue();
}
}
use of org.bukkit.attribute.AttributeInstance in project NoCheatPlus by NoCheatPlus.
the class BukkitAttributeAccess method getSprintAttributeMultiplier.
@Override
public double getSprintAttributeMultiplier(final Player player) {
final AttributeInstance attrInst = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
final AttributeModifier mod = getModifier(attrInst, AttribUtil.ID_SPRINT_BOOST);
return mod == null ? 1.0 : getMultiplier(mod);
}
use of org.bukkit.attribute.AttributeInstance in project NoCheatPlus by NoCheatPlus.
the class BukkitAttributeAccess method getSpeedAttributeMultiplier.
@Override
public double getSpeedAttributeMultiplier(final Player player) {
final AttributeInstance attrInst = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
final double val = attrInst.getValue() / attrInst.getBaseValue();
final AttributeModifier mod = getModifier(attrInst, AttribUtil.ID_SPRINT_BOOST);
return mod == null ? val : (val / getMultiplier(mod));
}
use of org.bukkit.attribute.AttributeInstance in project Denizen-For-Bukkit by DenizenScript.
the class EntityAttributeModifiers method getAttributes.
@Deprecated
public ListTag getAttributes() {
ListTag list = new ListTag();
for (Attribute attribute : Attribute.values()) {
AttributeInstance instance = getAttributable().getAttribute(attribute);
if (instance == null) {
continue;
}
StringBuilder modifiers = new StringBuilder();
for (AttributeModifier modifier : instance.getModifiers()) {
modifiers.append("/").append(stringify(modifier));
}
list.add(EscapeTagBase.escape(attribute.name()) + "/" + instance.getBaseValue() + modifiers.toString());
}
return list;
}
Aggregations