From 861705f717dfda19039cb1ddf6ab45aa2f26f562 Mon Sep 17 00:00:00 2001 From: AMinecraftDev Date: Sun, 18 Nov 2018 16:56:06 +0800 Subject: [PATCH] 1.0.0-SNAPSHOT-U59 + Finalised the Skill system --- .../epicbosses/events/BossSkillEvent.java | 16 +++++- .../listeners/during/BossSkillListener.java | 57 +++++++------------ .../epicbosses/managers/BossSkillManager.java | 42 ++++++++++++-- .../epicbosses/utils/MessageUtils.java | 5 +- pom.xml | 2 +- 5 files changed, 75 insertions(+), 47 deletions(-) diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/events/BossSkillEvent.java b/plugin-modules/Core/src/com/songoda/epicbosses/events/BossSkillEvent.java index f2c1259..1dd948e 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/events/BossSkillEvent.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/events/BossSkillEvent.java @@ -1,6 +1,8 @@ package com.songoda.epicbosses.events; import com.songoda.epicbosses.holder.ActiveBossHolder; +import com.songoda.epicbosses.skills.ISkillHandler; +import com.songoda.epicbosses.skills.Skill; import lombok.Getter; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; @@ -15,9 +17,21 @@ public class BossSkillEvent extends Event { private static final HandlerList handlers = new HandlerList(); @Getter private ActiveBossHolder activeBossHolder; + @Getter private ISkillHandler skillHandler; + @Getter private Skill skill; + + public BossSkillEvent(ActiveBossHolder activeBossHolder, ISkillHandler skillHandler, Skill skill) { + this.activeBossHolder = activeBossHolder; + this.skillHandler = skillHandler; + this.skill = skill; + } @Override public HandlerList getHandlers() { - return null; + return handlers; + } + + public static HandlerList getHandlerList() { + return handlers; } } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/listeners/during/BossSkillListener.java b/plugin-modules/Core/src/com/songoda/epicbosses/listeners/during/BossSkillListener.java index 746874e..24da141 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/listeners/during/BossSkillListener.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/listeners/during/BossSkillListener.java @@ -3,17 +3,20 @@ package com.songoda.epicbosses.listeners.during; import com.songoda.epicbosses.CustomBosses; import com.songoda.epicbosses.api.BossAPI; import com.songoda.epicbosses.entity.BossEntity; +import com.songoda.epicbosses.events.BossSkillEvent; import com.songoda.epicbosses.events.PreBossSkillEvent; import com.songoda.epicbosses.holder.ActiveBossHolder; import com.songoda.epicbosses.managers.BossEntityManager; import com.songoda.epicbosses.managers.BossSkillManager; import com.songoda.epicbosses.managers.files.SkillsFileManager; +import com.songoda.epicbosses.skills.ISkillHandler; import com.songoda.epicbosses.skills.Skill; import com.songoda.epicbosses.skills.types.CommandSkillElement; import com.songoda.epicbosses.skills.types.CustomSkillElement; import com.songoda.epicbosses.skills.types.GroupSkillElement; import com.songoda.epicbosses.skills.types.PotionSkillElement; import com.songoda.epicbosses.utils.Debug; +import com.songoda.epicbosses.utils.MessageUtils; import com.songoda.epicbosses.utils.RandomUtils; import com.songoda.epicbosses.utils.ServerUtils; import org.bukkit.Bukkit; @@ -26,10 +29,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageByEntityEvent; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.util.*; /** * @author Charles Cullen @@ -65,11 +65,11 @@ public class BossSkillListener implements Listener { if(bossEntity.getSkills() == null || bossEntity.getSkills().getOverallChance() == null) return; -// if(RandomUtils.get().canPreformAction(bossEntity.getSkills().getOverallChance())) { + if(RandomUtils.get().canPreformAction(bossEntity.getSkills().getOverallChance())) { PreBossSkillEvent preBossSkillEvent = new PreBossSkillEvent(activeBossHolder, livingEntity, (LivingEntity) entityDamaging); ServerUtils.get().callEvent(preBossSkillEvent); -// } + } } @EventHandler @@ -95,56 +95,39 @@ public class BossSkillListener implements Listener { return; } - List targettedEntities = getTargetedEntities(activeBossHolder, skill, activeBossHolder.getLivingEntity().getLocation(), damagingEntity); + List targettedEntities = this.bossSkillManager.getTargetedEntities(activeBossHolder, skill, activeBossHolder.getLivingEntity().getLocation(), damagingEntity); + String bossDisplayName = activeBossHolder.getName(); + String skillDisplayName = skill.getDisplayName(); + ISkillHandler skillHandler; if(skill.getType().equalsIgnoreCase("POTION")) { PotionSkillElement potionSkillElement = this.bossSkillManager.getPotionSkillElement(skill); potionSkillElement.castSkill(skill, potionSkillElement, activeBossHolder, targettedEntities); - System.out.println("#1"); + skillHandler = potionSkillElement; } else if(skill.getType().equalsIgnoreCase("COMMAND")) { CommandSkillElement commandSkillElement = this.bossSkillManager.getCommandSkillElement(skill); commandSkillElement.castSkill(skill, commandSkillElement, activeBossHolder, targettedEntities); - System.out.println("#2"); + skillHandler = commandSkillElement; } else if(skill.getType().equalsIgnoreCase("GROUP")) { GroupSkillElement groupSkillElement = this.bossSkillManager.getGroupSkillElement(skill); groupSkillElement.castSkill(skill, groupSkillElement, activeBossHolder, targettedEntities); - System.out.println("#3"); + skillHandler = groupSkillElement; } else if(skill.getType().equalsIgnoreCase("CUSTOM")) { CustomSkillElement customSkillElement = this.bossSkillManager.getCustomSkillElement(skill); - this.bossSkillManager.handleCustomSkillCasting(skill, customSkillElement, activeBossHolder, targettedEntities); - System.out.println("#4"); - } - } - - private List getTargetedEntities(ActiveBossHolder activeBossHolder, Skill skill, Location center, LivingEntity damager) { - double radiusSqr = skill.getRadius() * skill.getRadius(); - List targetedList = new ArrayList<>(); - String mode = skill.getMode(); - - if(mode.equalsIgnoreCase("ONE")) { - return Arrays.asList(damager); - } else if(mode.equalsIgnoreCase("BOSS")) { - targetedList.addAll(activeBossHolder.getLivingEntityMap().values()); + skillHandler = this.bossSkillManager.handleCustomSkillCasting(skill, customSkillElement, activeBossHolder, targettedEntities); } else { - for(Player player : Bukkit.getOnlinePlayers()) { - if(!player.getWorld().equals(center.getWorld())) continue; - if(center.distanceSquared(player.getLocation()) > radiusSqr) continue; - - if(mode.equalsIgnoreCase("ALL")) { - targetedList.add(player); - } else if(mode.equalsIgnoreCase("RANDOM")) { - if(RandomUtils.get().preformRandomAction()) { - targetedList.add(player); - } - } - } + return; } - return targetedList; + masterMessage.replaceAll(s -> s.replace("{boss}", bossDisplayName).replace("{skill}", skillDisplayName)); + targettedEntities.forEach(livingEntity -> MessageUtils.get().sendMessage(livingEntity, masterMessage)); + + BossSkillEvent bossSkillEvent = new BossSkillEvent(activeBossHolder, skillHandler, skill); + ServerUtils.get().callEvent(bossSkillEvent); } } diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossSkillManager.java b/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossSkillManager.java index ede55d3..17de218 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossSkillManager.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/managers/BossSkillManager.java @@ -11,11 +11,13 @@ import com.songoda.epicbosses.skills.types.PotionSkillElement; import com.songoda.epicbosses.utils.BossesGson; import com.songoda.epicbosses.utils.Debug; import com.songoda.epicbosses.utils.ILoadable; +import com.songoda.epicbosses.utils.RandomUtils; +import org.bukkit.Bukkit; +import org.bukkit.Location; import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; /** * @author Charles Cullen @@ -40,16 +42,17 @@ public class BossSkillManager implements ILoadable { registerCustomSkill(new Warp()); } - public void handleCustomSkillCasting(Skill skill, CustomSkillElement customSkillElement, ActiveBossHolder activeBossHolder, List nearbyEntities) { + public CustomSkillHandler handleCustomSkillCasting(Skill skill, CustomSkillElement customSkillElement, ActiveBossHolder activeBossHolder, List nearbyEntities) { String type = customSkillElement.getCustom().getType(); CustomSkillHandler customSkillHandler = getCustomSkillHandler(type); if(customSkillHandler == null) { Debug.FAILED_TO_OBTAIN_THE_SKILL_HANDLER.debug(type); - return; + return null; } customSkillHandler.castSkill(skill, customSkillElement, activeBossHolder, nearbyEntities); + return customSkillHandler; } public PotionSkillElement getPotionSkillElement(Skill skill) { @@ -97,7 +100,34 @@ public class BossSkillManager implements ILoadable { SKILLS.remove(customSkillHandler); } - public CustomSkillHandler getCustomSkillHandler(String name) { + public List getTargetedEntities(ActiveBossHolder activeBossHolder, Skill skill, Location center, LivingEntity damager) { + double radiusSqr = skill.getRadius() * skill.getRadius(); + List targetedList = new ArrayList<>(); + String mode = skill.getMode(); + + if(mode.equalsIgnoreCase("ONE")) { + return Arrays.asList(damager); + } else if(mode.equalsIgnoreCase("BOSS")) { + targetedList.addAll(activeBossHolder.getLivingEntityMap().values()); + } else { + for(Player player : Bukkit.getOnlinePlayers()) { + if(!player.getWorld().equals(center.getWorld())) continue; + if(center.distanceSquared(player.getLocation()) > radiusSqr) continue; + + if(mode.equalsIgnoreCase("ALL")) { + targetedList.add(player); + } else if(mode.equalsIgnoreCase("RANDOM")) { + if(RandomUtils.get().preformRandomAction()) { + targetedList.add(player); + } + } + } + } + + return targetedList; + } + + private CustomSkillHandler getCustomSkillHandler(String name) { for(CustomSkillHandler customSkillHandler : new HashSet<>(SKILLS)) { String skillName = customSkillHandler.getClass().getSimpleName(); diff --git a/plugin-modules/Core/src/com/songoda/epicbosses/utils/MessageUtils.java b/plugin-modules/Core/src/com/songoda/epicbosses/utils/MessageUtils.java index 8e75a6e..351a3fc 100644 --- a/plugin-modules/Core/src/com/songoda/epicbosses/utils/MessageUtils.java +++ b/plugin-modules/Core/src/com/songoda/epicbosses/utils/MessageUtils.java @@ -2,6 +2,7 @@ package com.songoda.epicbosses.utils; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import java.util.Arrays; @@ -16,11 +17,11 @@ public class MessageUtils { private static MessageUtils INSTANCE = new MessageUtils(); - public void sendMessage(Player player, String... messages) { + public void sendMessage(LivingEntity player, String... messages) { sendMessage(player, Arrays.asList(messages)); } - public void sendMessage(Player player, List messages) { + public void sendMessage(LivingEntity player, List messages) { for(String s : messages) { player.sendMessage(StringUtils.get().translateColor(s)); } diff --git a/pom.xml b/pom.xml index 946b5a3..98f14a6 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ - 1.0.0-SNAPSHOT-U58 + 1.0.0-SNAPSHOT-U59 EpicBosses com.songoda.epicbosses.CustomBosses AMinecraftDev