Search in sources :

Example 56 with FixedMetadataValue

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));
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue) MetadataValue(org.bukkit.metadata.MetadataValue) FixedMetadataValue(org.bukkit.metadata.FixedMetadataValue)

Aggregations

FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)56 MinorPowerPowerStance (com.magmaguy.elitemobs.powerstances.MinorPowerPowerStance)22 Entity (org.bukkit.entity.Entity)10 EventHandler (org.bukkit.event.EventHandler)9 LivingEntity (org.bukkit.entity.LivingEntity)7 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)7 Player (org.bukkit.entity.Player)6 ItemStack (org.bukkit.inventory.ItemStack)6 MajorPowerPowerStance (com.magmaguy.elitemobs.powerstances.MajorPowerPowerStance)4 Item (org.bukkit.entity.Item)4 Zombie (org.bukkit.entity.Zombie)4 Vector (org.bukkit.util.Vector)4 Location (org.bukkit.Location)3 Block (org.bukkit.block.Block)3 IronGolem (org.bukkit.entity.IronGolem)3 PotionEffect (org.bukkit.potion.PotionEffect)3 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Random (java.util.Random)2