use of org.bukkit.metadata.FixedMetadataValue in project MyPet by xXKeyleXx.
the class MyPetExperience method addDamageToEntity.
@SuppressWarnings("unchecked")
public static void addDamageToEntity(LivingEntity damager, LivingEntity victim, double damage) {
Map<Entity, Double> damageMap;
if (victim.hasMetadata("DamageCount")) {
for (MetadataValue value : victim.getMetadata("DamageCount")) {
if (value.getOwningPlugin().getName().equals("MyPet")) {
damageMap = (Map<Entity, Double>) value.value();
if (damageMap.containsKey(damager)) {
double oldDamage = damageMap.get(damager);
damageMap.put(damager, victim.getHealth() < damage ? victim.getHealth() + oldDamage : damage + oldDamage);
} else {
damageMap.put(damager, victim.getHealth() < damage ? victim.getHealth() : damage);
}
break;
}
}
} else {
damageMap = new WeakHashMap<>();
damageMap.put(damager, victim.getHealth() < damage ? victim.getHealth() : damage);
victim.setMetadata("DamageCount", new FixedMetadataValue(MyPetApi.getPlugin(), damageMap));
}
}
Aggregations