diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/MythicMobSkill.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/MythicMobSkill.java index 937b4680..7d1989cd 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/MythicMobSkill.java +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/MythicMobSkill.java @@ -68,7 +68,7 @@ public class MythicMobSkill extends Skill { Optional passiveType = Enums.getIfPresent(PassiveSkillType.class, config.getString("passive-type").toUpperCase()); Validate.isTrue(passiveType.isPresent(), "Invalid passive skill type"); setPassive(); - Bukkit.getPluginManager().registerEvents(passiveType.get().getListener(this), MMOCore.plugin); + Bukkit.getPluginManager().registerEvents(passiveType.get().getHandler(this), MMOCore.plugin); } // cast = config.getBoolean("target") ? (data, info) -> new diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/PassiveMythicMobSkillHandler.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/PassiveMythicMobSkillHandler.java new file mode 100644 index 00000000..49b2c5cc --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/PassiveMythicMobSkillHandler.java @@ -0,0 +1,41 @@ +package net.Indyuce.mmocore.comp.mythicmobs.skill; + +import java.util.Arrays; + +import org.bukkit.entity.Entity; +import org.bukkit.event.Listener; + +import io.lumine.xikage.mythicmobs.MythicMobs; +import net.Indyuce.mmocore.MMOCore; +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.api.skill.SkillResult; + +public abstract class PassiveMythicMobSkillHandler implements Listener { + protected final MythicMobSkill skill; + + /** + * Core class for all passive types + */ + protected PassiveMythicMobSkillHandler(MythicMobSkill skill) { + this.skill = skill; + } + + public void castSkill(PlayerData data) { + castSkill(data, data.getPlayer()); + } + + public void castSkill(PlayerData data, Entity target) { + if (!data.getProfess().hasSkill(skill.getId())) + return; + + SkillResult cast = data.cast(data.getProfess().getSkill(skill.getId())); + if (!cast.isSuccessful()) + return; + + data.getSkillData().cacheModifiers(skill.getInternalName(), cast); + if (MMOCore.plugin.hasAntiCheat()) + MMOCore.plugin.antiCheatSupport.disableAntiCheat(data.getPlayer(), skill.getAntiCheat()); + MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), skill.getInternalName(), target, data.getPlayer().getEyeLocation(), + Arrays.asList(data.getPlayer()), null, 1); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/PassiveSkillType.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/PassiveSkillType.java index 7cb6c1e4..ac795ab5 100644 --- a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/PassiveSkillType.java +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/PassiveSkillType.java @@ -1,16 +1,33 @@ package net.Indyuce.mmocore.comp.mythicmobs.skill; -import org.bukkit.event.Listener; +import net.Indyuce.mmocore.comp.mythicmobs.skill.handlers.EntityDeathSkillHandler; +import net.Indyuce.mmocore.comp.mythicmobs.skill.handlers.PlayerAttackSkillHandler; +import net.Indyuce.mmocore.comp.mythicmobs.skill.handlers.PlayerDamageByEntitySkillHandler; +import net.Indyuce.mmocore.comp.mythicmobs.skill.handlers.PlayerDamageSkillHandler; +import net.Indyuce.mmocore.comp.mythicmobs.skill.handlers.PlayerDeathSkillHandler; +import net.Indyuce.mmocore.comp.mythicmobs.skill.handlers.ShootBowSkillHandler; public enum PassiveSkillType { PLAYER_ATTACK, - PLAYER_DAMAGE; + PLAYER_DAMAGE, + PLAYER_DAMAGE_BY_ENTITY, + PLAYER_DEATH, + PLAYER_KILL_ENTITY, + SHOOT_BOW; - public Listener getListener(MythicMobSkill skill) { + public PassiveMythicMobSkillHandler getHandler(MythicMobSkill skill) { if (this == PLAYER_ATTACK) return new PlayerAttackSkillHandler(skill); if (this == PLAYER_DAMAGE) return new PlayerDamageSkillHandler(skill); + if (this == PLAYER_KILL_ENTITY) + return new EntityDeathSkillHandler(skill); + if (this == PLAYER_DAMAGE_BY_ENTITY) + return new PlayerDamageByEntitySkillHandler(skill); + if (this == PLAYER_DEATH) + return new PlayerDeathSkillHandler(skill); + if (this == SHOOT_BOW) + return new ShootBowSkillHandler(skill); throw new NullPointerException(); } } diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/PlayerAttackSkillHandler.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/PlayerAttackSkillHandler.java deleted file mode 100644 index 5bf08fd4..00000000 --- a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/PlayerAttackSkillHandler.java +++ /dev/null @@ -1,62 +0,0 @@ -package net.Indyuce.mmocore.comp.mythicmobs.skill; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; - -import io.lumine.xikage.mythicmobs.MythicMobs; -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.api.skill.SkillResult; -import net.mmogroup.mmolib.api.event.PlayerAttackEvent; - -public class PlayerAttackSkillHandler implements Listener { - private final MythicMobSkill skill; - - /** - * Used to handle passive skills which trigger when a player attacks another - * entity - * - * @param skill - * Passive skill info - */ - public PlayerAttackSkillHandler(MythicMobSkill skill) { - this.skill = skill; - } - - @EventHandler - private void playerAttack(PlayerAttackEvent event) { - castSkill(event.getData().getMMOCore(), event.getEntity()); - } - - /** - * Has an extra parameter compared to PlayerDamageSkillHandler because the - * hit entity is added to the MythicMobs target list - * - * @param data - * Player casting the skill - * @param target - * Entity hit - */ - public void castSkill(PlayerData data, LivingEntity target) { - if (!data.getProfess().hasSkill(skill.getId())) - return; - - SkillResult cast = data.cast(data.getProfess().getSkill(skill.getId())); - if (!cast.isSuccessful()) - return; - - data.getSkillData().cacheModifiers(skill.getInternalName(), cast); - if (MMOCore.plugin.hasAntiCheat()) - MMOCore.plugin.antiCheatSupport.disableAntiCheat(data.getPlayer(), skill.getAntiCheat()); - List targets = new ArrayList<>(); - targets.add(data.getPlayer()); - targets.add(target); - MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), skill.getInternalName(), data.getPlayer(), data.getPlayer().getEyeLocation(), - targets, null, 1); - } -} \ No newline at end of file diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/PlayerDamageSkillHandler.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/PlayerDamageSkillHandler.java deleted file mode 100644 index 71fbd4eb..00000000 --- a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/PlayerDamageSkillHandler.java +++ /dev/null @@ -1,54 +0,0 @@ -package net.Indyuce.mmocore.comp.mythicmobs.skill; - -import java.util.ArrayList; -import java.util.List; - -import org.bukkit.entity.Entity; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageEvent; - -import io.lumine.xikage.mythicmobs.MythicMobs; -import net.Indyuce.mmocore.MMOCore; -import net.Indyuce.mmocore.api.player.PlayerData; -import net.Indyuce.mmocore.api.skill.SkillResult; - -public class PlayerDamageSkillHandler implements Listener { - private final MythicMobSkill skill; - - /** - * Used to handle passive skills which trigger when a player is attacked by - * another entity - * - * @param skill - * Passive skill info - */ - public PlayerDamageSkillHandler(MythicMobSkill skill) { - this.skill = skill; - } - - @EventHandler - private void playerDamage(EntityDamageEvent event) { - if (event.getEntityType() == EntityType.PLAYER) - castSkill(PlayerData.get((Player) event.getEntity())); - } - - public void castSkill(PlayerData data) { - if (!data.getProfess().hasSkill(skill.getId())) - return; - - SkillResult cast = data.cast(data.getProfess().getSkill(skill.getId())); - if (!cast.isSuccessful()) - return; - - data.getSkillData().cacheModifiers(skill.getInternalName(), cast); - if (MMOCore.plugin.hasAntiCheat()) - MMOCore.plugin.antiCheatSupport.disableAntiCheat(data.getPlayer(), skill.getAntiCheat()); - List targets = new ArrayList<>(); - targets.add(data.getPlayer()); - MythicMobs.inst().getAPIHelper().castSkill(data.getPlayer(), skill.getInternalName(), data.getPlayer(), data.getPlayer().getEyeLocation(), - targets, null, 1); - } -} diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/EntityDeathSkillHandler.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/EntityDeathSkillHandler.java new file mode 100644 index 00000000..ed513b72 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/EntityDeathSkillHandler.java @@ -0,0 +1,26 @@ +package net.Indyuce.mmocore.comp.mythicmobs.skill.handlers; + +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; + +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill; +import net.Indyuce.mmocore.comp.mythicmobs.skill.PassiveMythicMobSkillHandler; +import net.mmogroup.mmolib.api.event.EntityKillEntityEvent; + +public class EntityDeathSkillHandler extends PassiveMythicMobSkillHandler { + /** + * Used to handle passive skills which trigger when a player kills + * another entity + */ + public EntityDeathSkillHandler(MythicMobSkill skill) { + super(skill); + } + + @EventHandler + private void event(EntityKillEntityEvent e) { + if (e.getEntity().getType() == EntityType.PLAYER) + castSkill(PlayerData.get((Player) e.getEntity()), e.getTarget()); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/PlayerAttackSkillHandler.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/PlayerAttackSkillHandler.java new file mode 100644 index 00000000..5462c3ae --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/PlayerAttackSkillHandler.java @@ -0,0 +1,22 @@ +package net.Indyuce.mmocore.comp.mythicmobs.skill.handlers; + +import org.bukkit.event.EventHandler; + +import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill; +import net.Indyuce.mmocore.comp.mythicmobs.skill.PassiveMythicMobSkillHandler; +import net.mmogroup.mmolib.api.event.PlayerAttackEvent; + +public class PlayerAttackSkillHandler extends PassiveMythicMobSkillHandler { + /** + * Used to handle passive skills which trigger when a player attacks another + * entity + */ + public PlayerAttackSkillHandler(MythicMobSkill skill) { + super(skill); + } + + @EventHandler + private void event(PlayerAttackEvent e) { + castSkill(e.getData().getMMOCore(), e.getEntity()); + } +} \ No newline at end of file diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/PlayerDamageByEntitySkillHandler.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/PlayerDamageByEntitySkillHandler.java new file mode 100644 index 00000000..2ca66ee0 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/PlayerDamageByEntitySkillHandler.java @@ -0,0 +1,26 @@ +package net.Indyuce.mmocore.comp.mythicmobs.skill.handlers; + +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageByEntityEvent; + +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill; +import net.Indyuce.mmocore.comp.mythicmobs.skill.PassiveMythicMobSkillHandler; + +public class PlayerDamageByEntitySkillHandler extends PassiveMythicMobSkillHandler { + /** + * Used to handle passive skills which trigger when a player takes damage + * from another entity + */ + public PlayerDamageByEntitySkillHandler(MythicMobSkill skill) { + super(skill); + } + + @EventHandler + private void event(EntityDamageByEntityEvent e) { + if (e.getEntity().getType() == EntityType.PLAYER) + castSkill(PlayerData.get((Player) e.getEntity()), e.getDamager()); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/PlayerDamageSkillHandler.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/PlayerDamageSkillHandler.java new file mode 100644 index 00000000..58704467 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/PlayerDamageSkillHandler.java @@ -0,0 +1,25 @@ +package net.Indyuce.mmocore.comp.mythicmobs.skill.handlers; + +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent; + +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill; +import net.Indyuce.mmocore.comp.mythicmobs.skill.PassiveMythicMobSkillHandler; + +public class PlayerDamageSkillHandler extends PassiveMythicMobSkillHandler { + /** + * Used to handle passive skills which trigger when a player takes damage + */ + public PlayerDamageSkillHandler(MythicMobSkill skill) { + super(skill); + } + + @EventHandler + private void event(EntityDamageEvent e) { + if (e.getEntityType() == EntityType.PLAYER) + castSkill(PlayerData.get((Player) e.getEntity())); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/PlayerDeathSkillHandler.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/PlayerDeathSkillHandler.java new file mode 100644 index 00000000..f0bd425f --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/PlayerDeathSkillHandler.java @@ -0,0 +1,25 @@ +package net.Indyuce.mmocore.comp.mythicmobs.skill.handlers; + +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDeathEvent; + +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill; +import net.Indyuce.mmocore.comp.mythicmobs.skill.PassiveMythicMobSkillHandler; + +public class PlayerDeathSkillHandler extends PassiveMythicMobSkillHandler { + /** + * Used to handle passive skills which trigger when a player dies + */ + public PlayerDeathSkillHandler(MythicMobSkill skill) { + super(skill); + } + + @EventHandler + private void event(EntityDeathEvent e) { + if (e.getEntityType() == EntityType.PLAYER) + castSkill(PlayerData.get((Player) e.getEntity())); + } +} diff --git a/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/ShootBowSkillHandler.java b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/ShootBowSkillHandler.java new file mode 100644 index 00000000..4508dbe8 --- /dev/null +++ b/src/main/java/net/Indyuce/mmocore/comp/mythicmobs/skill/handlers/ShootBowSkillHandler.java @@ -0,0 +1,25 @@ +package net.Indyuce.mmocore.comp.mythicmobs.skill.handlers; + +import org.bukkit.entity.EntityType; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityShootBowEvent; + +import net.Indyuce.mmocore.api.player.PlayerData; +import net.Indyuce.mmocore.comp.mythicmobs.skill.MythicMobSkill; +import net.Indyuce.mmocore.comp.mythicmobs.skill.PassiveMythicMobSkillHandler; + +public class ShootBowSkillHandler extends PassiveMythicMobSkillHandler { + /** + * Used to handle passive skills which trigger when a player shoots a bow + */ + public ShootBowSkillHandler(MythicMobSkill skill) { + super(skill); + } + + @EventHandler + private void event(EntityShootBowEvent e) { + if(e.getEntity().getType() == EntityType.PLAYER) + castSkill(PlayerData.get((Player) e.getEntity()), e.getProjectile()); + } +}