diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/HeroesHook.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/HeroesHook.java index 59f1f4e1..3188a9b4 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/HeroesHook.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/comp/rpg/HeroesHook.java @@ -24,10 +24,13 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.HashMap; import java.util.Map; +import java.util.Set; public class HeroesHook implements RPGHandler, Listener, AttackHandler { private final Map damages = new HashMap<>(); @@ -42,15 +45,28 @@ public class HeroesHook implements RPGHandler, Listener, AttackHandler { damages.put(SkillType.ABILITY_PROPERTY_PROJECTILE, DamageType.PROJECTILE); } + @NotNull + private DamageType[] mapSkillTypes(Set types) { + ArrayList list = new ArrayList<>(); + for (SkillType type : types) { + final DamageType found = this.damages.get(type); + if (found != null) list.add(found); + } + + // Always, at least, the SKILL damage type + list.add(DamageType.SKILL); + + return list.toArray(new DamageType[0]); + } + @Override @Nullable public AttackMetadata getAttack(EntityDamageEvent event) { SkillUseInfo info = Heroes.getInstance().getDamageManager().getSpellTargetInfo(event.getEntity()); - if (info == null || !(info.getCharacter().getEntity() instanceof Player)) - return null; + if (info == null || !(info.getCharacter().getEntity() instanceof Player)) return null; - Player player = (Player) info.getCharacter().getEntity(); - DamageMetadata damageMeta = new DamageMetadata(event.getDamage(), info.getSkill().getTypes().stream().filter(damages::containsKey).map(damages::get).toArray(DamageType[]::new)); + final Player player = (Player) info.getCharacter().getEntity(); + final DamageMetadata damageMeta = new DamageMetadata(event.getDamage(), mapSkillTypes(info.getSkill().getTypes())); return new AttackMetadata(damageMeta, (LivingEntity) event.getEntity(), MMOPlayerData.get(player).getStatMap().cache(EquipmentSlot.MAIN_HAND)); }