From b2efe135755972427315fb102ae8a6426d21972e Mon Sep 17 00:00:00 2001 From: jayoevans Date: Mon, 2 Dec 2019 11:52:10 +1000 Subject: [PATCH] Fixed commands --- .../projectkorra/command/BindCommand.java | 30 ++--- .../projectkorra/command/ChooseCommand.java | 4 +- .../projectkorra/command/CopyCommand.java | 25 ++-- .../projectkorra/command/DisplayCommand.java | 107 +++++++++--------- .../projectkorra/command/HelpCommand.java | 72 ++++++------ .../projectkorra/command/PKCommand.java | 6 +- .../projectkorra/command/StatsCommand.java | 20 ++-- .../projectkorra/command/WhoCommand.java | 8 +- .../event/PlayerChangeElementEvent.java | 14 +-- 9 files changed, 140 insertions(+), 146 deletions(-) diff --git a/src/com/projectkorra/projectkorra/command/BindCommand.java b/src/com/projectkorra/projectkorra/command/BindCommand.java index d637e0d2..e15c758a 100644 --- a/src/com/projectkorra/projectkorra/command/BindCommand.java +++ b/src/com/projectkorra/projectkorra/command/BindCommand.java @@ -1,10 +1,10 @@ package com.projectkorra.projectkorra.command; import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.AbilityHandler; +import com.projectkorra.projectkorra.ability.api.ComboAbility; +import com.projectkorra.projectkorra.ability.api.PassiveAbility; import com.projectkorra.projectkorra.ability.bind.AbilityBindManager; -import com.projectkorra.projectkorra.ability.info.AbilityInfo; -import com.projectkorra.projectkorra.ability.api.ComboAbilityInfo; -import com.projectkorra.projectkorra.ability.api.PassiveAbilityInfo; import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.configuration.configs.commands.BindCommandConfig; import com.projectkorra.projectkorra.element.Element; @@ -53,9 +53,9 @@ public class BindCommand extends PKCommand { } String abilityName = args.get(0); - AbilityInfo abilityInfo = this.abilityManager.getAbilityInfo(abilityName); + AbilityHandler abilityHandler = this.abilityHandlerManager.getHandler(abilityName); - if (abilityInfo == null) { + if (abilityHandler == null) { GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.abilityDoesntExist.replace("{ability}", args.get(0))); return; } @@ -67,20 +67,20 @@ public class BindCommand extends PKCommand { // bending bind [Ability]. if (args.size() == 1) { - this.bind(sender, abilityInfo, ((Player) sender).getInventory().getHeldItemSlot() + 1); + this.bind(sender, abilityHandler, ((Player) sender).getInventory().getHeldItemSlot() + 1); } // bending bind [ability] [#]. if (args.size() == 2) { try { - this.bind(sender, abilityInfo, Integer.parseInt(args.get(1))); + this.bind(sender, abilityHandler, Integer.parseInt(args.get(1))); } catch (final NumberFormatException ex) { GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.wrongNumber); } } } - private void bind(final CommandSender sender, final AbilityInfo abilityInfo, final int slot) { + private void bind(final CommandSender sender, final AbilityHandler abilityHandler, final int slot) { if (!(sender instanceof Player)) { return; } else if (slot < 1 || slot > 9) { @@ -91,20 +91,20 @@ public class BindCommand extends PKCommand { Player player = (Player) sender; BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player); - Element element = abilityInfo.getElement(); + Element element = abilityHandler.getElement(); // if (bPlayer == null) { // GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.loadingInfo); // return; // } - if (bendingPlayer.canBind(abilityInfo)) { + if (bendingPlayer.canBind(abilityHandler)) { if (!bendingPlayer.isElementToggled(element)) { GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.toggledElementOff); } - if (this.abilityBindManager.bindAbility(player, abilityInfo.getName(), slot) == AbilityBindManager.Result.SUCCESS) { - GeneralMethods.sendBrandingMessage(player, element.getColor() + ConfigManager.getConfig(BindCommandConfig.class).SuccessfullyBoundMessage.replace("{ability}", abilityInfo.getName()).replace("{slot}", String.valueOf(slot + 1))); + if (this.abilityBindManager.bindAbility(player, abilityHandler.getName(), slot) == AbilityBindManager.Result.SUCCESS) { + GeneralMethods.sendBrandingMessage(player, element.getColor() + ConfigManager.getConfig(BindCommandConfig.class).SuccessfullyBoundMessage.replace("{ability}", abilityHandler.getName()).replace("{slot}", String.valueOf(slot + 1))); } return; } @@ -158,9 +158,9 @@ public class BindCommand extends PKCommand { Set abilitySet = new HashSet<>(); - for (AbilityInfo abilityInfo : this.abilityManager.getAbilityInfo()) { - if (!abilityInfo.isHidden() && bendingPlayer.canBind(abilityInfo) && !(abilityInfo instanceof PassiveAbilityInfo || abilityInfo instanceof ComboAbilityInfo && !abilitySet.contains(abilityInfo.getName()))) { - abilitySet.add(abilityInfo.getName()); + for (AbilityHandler abilityHandler : this.abilityHandlerManager.getHandlers()) { + if (!abilityHandler.isHidden() && bendingPlayer.canBind(abilityHandler) && !(abilityHandler instanceof PassiveAbility || abilityHandler instanceof ComboAbility && !abilitySet.contains(abilityHandler.getName()))) { + abilitySet.add(abilityHandler.getName()); } } diff --git a/src/com/projectkorra/projectkorra/command/ChooseCommand.java b/src/com/projectkorra/projectkorra/command/ChooseCommand.java index 8e74ac27..b1a7cbe2 100644 --- a/src/com/projectkorra/projectkorra/command/ChooseCommand.java +++ b/src/com/projectkorra/projectkorra/command/ChooseCommand.java @@ -7,9 +7,7 @@ import com.projectkorra.projectkorra.configuration.configs.commands.ChooseComman import com.projectkorra.projectkorra.configuration.configs.properties.CommandPropertiesConfig; import com.projectkorra.projectkorra.configuration.configs.properties.GeneralPropertiesConfig; import com.projectkorra.projectkorra.element.Element; -import com.projectkorra.projectkorra.element.SubElement; import com.projectkorra.projectkorra.event.PlayerChangeElementEvent; -import com.projectkorra.projectkorra.event.PlayerChangeElementEvent.Result; import com.projectkorra.projectkorra.player.BendingPlayer; import com.projectkorra.projectkorra.util.TimeUtil; import org.bukkit.Bukkit; @@ -186,7 +184,7 @@ public class ChooseCommand extends PKCommand { } } - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, player, element, Result.CHOOSE)); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(player, element, PlayerChangeElementEvent.Action.SET)); GeneralMethods.removeUnusableAbilities(player.getName()); } diff --git a/src/com/projectkorra/projectkorra/command/CopyCommand.java b/src/com/projectkorra/projectkorra/command/CopyCommand.java index 94e994f3..c13ede47 100644 --- a/src/com/projectkorra/projectkorra/command/CopyCommand.java +++ b/src/com/projectkorra/projectkorra/command/CopyCommand.java @@ -1,20 +1,19 @@ package com.projectkorra.projectkorra.command; -import java.util.ArrayList; -import java.util.List; - -import com.projectkorra.projectkorra.ability.info.AbilityInfo; +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ProjectKorra; +import com.projectkorra.projectkorra.ability.AbilityHandler; +import com.projectkorra.projectkorra.configuration.ConfigManager; +import com.projectkorra.projectkorra.configuration.configs.commands.CopyCommandConfig; +import com.projectkorra.projectkorra.configuration.configs.properties.CommandPropertiesConfig; import com.projectkorra.projectkorra.player.BendingPlayer; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ProjectKorra; -import com.projectkorra.projectkorra.configuration.ConfigManager; -import com.projectkorra.projectkorra.configuration.configs.commands.CopyCommandConfig; -import com.projectkorra.projectkorra.configuration.configs.properties.CommandPropertiesConfig; +import java.util.ArrayList; +import java.util.List; @SuppressWarnings("rawtypes") public class CopyCommand extends PKCommand { @@ -91,15 +90,15 @@ public class CopyCommand extends PKCommand { return false; } - List abilities = orig.getAbilities(); + String[] abilities = orig.getAbilities(); boolean boundAll = true; for (int i = 0; i < 9; i++) { - String abilityName = abilities.get(0); + String abilityName = abilities[0]; - AbilityInfo abilityInfo = this.abilityManager.getAbilityInfo(abilityName); + AbilityHandler abilityHandler = this.abilityHandlerManager.getHandler(abilityName); - if (abilityInfo == null || !target.canBind(abilityInfo)) { + if (abilityHandler == null || !target.canBind(abilityHandler)) { boundAll = false; continue; } diff --git a/src/com/projectkorra/projectkorra/command/DisplayCommand.java b/src/com/projectkorra/projectkorra/command/DisplayCommand.java index 54eaea30..a3c9e2e3 100644 --- a/src/com/projectkorra/projectkorra/command/DisplayCommand.java +++ b/src/com/projectkorra/projectkorra/command/DisplayCommand.java @@ -1,14 +1,13 @@ package com.projectkorra.projectkorra.command; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Objects; - -import com.projectkorra.projectkorra.ability.info.AbilityInfo; -import com.projectkorra.projectkorra.ability.api.AddonAbilityInfo; -import com.projectkorra.projectkorra.ability.api.ComboAbilityInfo; -import com.projectkorra.projectkorra.ability.api.PassiveAbilityInfo; +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.AbilityHandler; +import com.projectkorra.projectkorra.ability.api.AddonAbility; +import com.projectkorra.projectkorra.ability.api.ComboAbility; +import com.projectkorra.projectkorra.ability.legacy.SubAbility; +import com.projectkorra.projectkorra.configuration.ConfigManager; +import com.projectkorra.projectkorra.configuration.configs.commands.DisplayCommandConfig; +import com.projectkorra.projectkorra.configuration.configs.properties.CommandPropertiesConfig; import com.projectkorra.projectkorra.element.Element; import com.projectkorra.projectkorra.element.SubElement; import com.projectkorra.projectkorra.player.BendingPlayer; @@ -16,11 +15,11 @@ import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ability.legacy.SubAbility; -import com.projectkorra.projectkorra.configuration.ConfigManager; -import com.projectkorra.projectkorra.configuration.configs.commands.DisplayCommandConfig; -import com.projectkorra.projectkorra.configuration.configs.properties.CommandPropertiesConfig; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Objects; +import java.util.stream.Stream; /** * Executor for /bending display. Extends {@link PKCommand}. @@ -88,16 +87,16 @@ public class DisplayCommand extends PKCommand { sender.sendMessage(ChatColor.BOLD + "Combos"); for (final Element e : this.elementManager.getElements()) { - final List abilities = this.comboAbilityManager.getAbilities(e); + final List abilities = this.comboAbilityManager.getHandlers(e); - for (final ComboAbilityInfo comboAbilityInfo : abilities) { - if (!sender.hasPermission("bending.ability." + comboAbilityInfo.getName())) { + for (final AbilityHandler abilityHandler : abilities) { + if (!sender.hasPermission("bending.ability." + abilityHandler.getName())) { continue; } - String message = comboAbilityInfo.getElement().getColor() + comboAbilityInfo.getName(); + String message = abilityHandler.getElement().getColor() + abilityHandler.getName(); - if (comboAbilityInfo instanceof AddonAbilityInfo) { + if (abilityHandler instanceof AddonAbility) { message += ChatColor.WHITE + (ChatColor.BOLD + "*"); } @@ -107,7 +106,7 @@ public class DisplayCommand extends PKCommand { return; } else { final ChatColor color = element != null ? element.getColor() : null; - final List abilities = this.comboAbilityManager.getAbilities(element); + final List abilities = this.comboAbilityManager.getHandlers(element); if (abilities.isEmpty()) { GeneralMethods.sendBrandingMessage(sender, color + this.noCombosAvailable.replace("{element}", element.getName())); @@ -116,14 +115,14 @@ public class DisplayCommand extends PKCommand { sender.sendMessage(element.getColor() + (ChatColor.BOLD + element.getName()) + element.getType().getBending() + ChatColor.WHITE + (ChatColor.BOLD + " Combos")); - for (final ComboAbilityInfo comboAbilityInfo : abilities) { - if (!sender.hasPermission("bending.ability." + comboAbilityInfo.getName())) { + for (final AbilityHandler abilityHandler : abilities) { + if (!sender.hasPermission("bending.ability." + abilityHandler.getName())) { continue; } - String message = comboAbilityInfo.getElement().getColor() + comboAbilityInfo.getName(); + String message = abilityHandler.getElement().getColor() + abilityHandler.getName(); - if (comboAbilityInfo instanceof AddonAbilityInfo) { + if (abilityHandler instanceof AddonAbility) { message += ChatColor.WHITE + (ChatColor.BOLD + "*"); } @@ -137,16 +136,16 @@ public class DisplayCommand extends PKCommand { sender.sendMessage(ChatColor.BOLD + "Passives"); for (final Element e : this.elementManager.getElements()) { - final List passives = this.passiveAbilityManager.getPassives(e); + final List passives = this.passiveAbilityManager.getPassives(e); - for (final PassiveAbilityInfo passiveAbilityInfo : passives) { - if (!sender.hasPermission("bending.ability." + passiveAbilityInfo.getName())) { + for (final AbilityHandler abilityHandler : passives) { + if (!sender.hasPermission("bending.ability." + abilityHandler.getName())) { continue; } - String message = passiveAbilityInfo.getElement().getColor() + passiveAbilityInfo.getName(); + String message = abilityHandler.getElement().getColor() + abilityHandler.getName(); - if (passiveAbilityInfo instanceof AddonAbilityInfo) { + if (abilityHandler instanceof AddonAbility) { message += ChatColor.WHITE + (ChatColor.BOLD + "*"); } @@ -156,7 +155,7 @@ public class DisplayCommand extends PKCommand { return; } final ChatColor color = element != null ? element.getColor() : null; - final List passives = this.passiveAbilityManager.getPassives(element); + final List passives = this.passiveAbilityManager.getPassives(element); if (passives.isEmpty()) { GeneralMethods.sendBrandingMessage(sender, color + this.noPassivesAvailable.replace("{element}", element.getName())); @@ -165,12 +164,12 @@ public class DisplayCommand extends PKCommand { sender.sendMessage(element.getColor() + (ChatColor.BOLD + element.getName()) + element.getType().getBending() + ChatColor.WHITE + (ChatColor.BOLD + " Passives")); - for (final PassiveAbilityInfo passiveAbilityInfo : passives) { - if (!sender.hasPermission("bending.ability." + passiveAbilityInfo.getName())) { + for (final AbilityHandler abilityHandler : passives) { + if (!sender.hasPermission("bending.ability." + abilityHandler.getName())) { continue; } - sender.sendMessage(passiveAbilityInfo.getElement().getColor() + passiveAbilityInfo.getName()); + sender.sendMessage(abilityHandler.getElement().getColor() + abilityHandler.getName()); } return; } else if (element != null) { @@ -214,7 +213,7 @@ public class DisplayCommand extends PKCommand { * @param element The element to show the moves for */ private void displayElement(final CommandSender sender, final Element element) { - final List abilities = this.abilityManager.getAbilities(element); + final List abilities = this.abilityHandlerManager.getHandlers(element); if (abilities.isEmpty()) { sender.sendMessage(ChatColor.YELLOW + this.noAbilitiesAvailable.replace("{element}", element.getColor() + element.getName() + ChatColor.YELLOW)); @@ -224,19 +223,19 @@ public class DisplayCommand extends PKCommand { sender.sendMessage(element.getColor() + (ChatColor.BOLD + element.getName()) + element.getType().getBending()); final HashSet abilitiesSent = new HashSet(); // Some abilities have the same name. This prevents this from showing anything. - for (final AbilityInfo abilityInfo : abilities) { - if (abilityInfo instanceof SubAbility || abilityInfo instanceof ComboAbilityInfo || abilityInfo.isHidden() || abilitiesSent.contains(abilityInfo.getName())) { + for (final AbilityHandler abilityHandler : abilities) { + if (abilityHandler instanceof SubAbility || abilityHandler instanceof ComboAbility || abilityHandler.isHidden() || abilitiesSent.contains(abilityHandler.getName())) { continue; } - if (!(sender instanceof Player) || GeneralMethods.canView((Player) sender, abilityInfo.getName())) { - String message = abilityInfo.getElement().getColor() + abilityInfo.getName(); - if (abilityInfo instanceof AddonAbilityInfo) { + if (!(sender instanceof Player) || GeneralMethods.canView((Player) sender, abilityHandler.getName())) { + String message = abilityHandler.getElement().getColor() + abilityHandler.getName(); + if (abilityHandler instanceof AddonAbility) { message += ChatColor.WHITE + (ChatColor.BOLD + "*"); } sender.sendMessage(message); - abilitiesSent.add(abilityInfo.getName()); + abilitiesSent.add(abilityHandler.getName()); } } @@ -261,7 +260,7 @@ public class DisplayCommand extends PKCommand { * @param element The subelement to show the moves for */ private void displaySubElement(final CommandSender sender, final SubElement element) { - final List abilities = this.abilityManager.getAbilities(element);; + final List abilities = this.abilityHandlerManager.getHandlers(element);; if (abilities.isEmpty() && element != null) { sender.sendMessage(ChatColor.YELLOW + this.noAbilitiesAvailable.replace("{element}", element.getColor() + element.getName() + ChatColor.YELLOW)); @@ -271,17 +270,17 @@ public class DisplayCommand extends PKCommand { sender.sendMessage(element.getColor() + (ChatColor.BOLD + element.getName()) + element.getType().getBending()); final HashSet abilitiesSent = new HashSet(); - for (final AbilityInfo abilityInfo : abilities) { - if (abilityInfo.isHidden() || abilitiesSent.contains(abilityInfo.getName())) { + for (final AbilityHandler abilityHandler : abilities) { + if (abilityHandler.isHidden() || abilitiesSent.contains(abilityHandler.getName())) { continue; - } else if (!(sender instanceof Player) || GeneralMethods.canView((Player) sender, abilityInfo.getName())) { - String message = element.getColor() + abilityInfo.getName(); - if (abilityInfo instanceof AddonAbilityInfo) { + } else if (!(sender instanceof Player) || GeneralMethods.canView((Player) sender, abilityHandler.getName())) { + String message = element.getColor() + abilityHandler.getName(); + if (abilityHandler instanceof AddonAbility) { message += ChatColor.WHITE + (ChatColor.BOLD + "*"); } sender.sendMessage(message); - abilitiesSent.add(abilityInfo.getName()); + abilitiesSent.add(abilityHandler.getName()); } } sender.sendMessage(element.getParent().getColor() + "Passives: " + element.getColor() + "/bending display " + element.getName() + "Passives"); @@ -294,9 +293,9 @@ public class DisplayCommand extends PKCommand { */ private void displayBinds(final Player player) { BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player); - List abilities = bendingPlayer.getAbilities(); + String[] abilities = bendingPlayer.getAbilities(); - if (abilities.stream().allMatch(Objects::isNull)) { + if (Stream.of(abilities).allMatch(Objects::isNull)) { player.sendMessage(ChatColor.RED + this.noBinds); return; } @@ -304,16 +303,16 @@ public class DisplayCommand extends PKCommand { player.sendMessage(ChatColor.WHITE + (ChatColor.BOLD + "Abilities")); for (int i = 0; i < 9; i++) { - final String abilityName = abilities.get(i); - final AbilityInfo abilityInfo = this.abilityManager.getAbilityInfo(abilityName); + final String abilityName = abilities[i]; + final AbilityHandler abilityHandler = this.abilityHandlerManager.getHandler(abilityName); - if (abilityInfo == null) { + if (abilityHandler == null) { continue; } - String message = (i + 1) + ". " + abilityInfo.getElement().getColor() + abilityName; + String message = (i + 1) + ". " + abilityHandler.getElement().getColor() + abilityName; - if (abilityInfo instanceof AddonAbilityInfo) { + if (abilityHandler instanceof AddonAbility) { message += ChatColor.WHITE + (ChatColor.BOLD + "*"); } diff --git a/src/com/projectkorra/projectkorra/command/HelpCommand.java b/src/com/projectkorra/projectkorra/command/HelpCommand.java index ab304df4..e213c8e5 100644 --- a/src/com/projectkorra/projectkorra/command/HelpCommand.java +++ b/src/com/projectkorra/projectkorra/command/HelpCommand.java @@ -1,10 +1,10 @@ package com.projectkorra.projectkorra.command; import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ability.info.AbilityInfo; -import com.projectkorra.projectkorra.ability.api.AddonAbilityInfo; -import com.projectkorra.projectkorra.ability.api.ComboAbilityInfo; -import com.projectkorra.projectkorra.ability.api.PassiveAbilityInfo; +import com.projectkorra.projectkorra.ability.AbilityHandler; +import com.projectkorra.projectkorra.ability.api.AddonAbility; +import com.projectkorra.projectkorra.ability.api.ComboAbility; +import com.projectkorra.projectkorra.ability.api.PassiveAbility; import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.configuration.configs.commands.HelpCommandConfig; import com.projectkorra.projectkorra.configuration.configs.properties.*; @@ -95,7 +95,7 @@ public class HelpCommand extends PKCommand { } final String arg = args.get(0).toLowerCase(); - AbilityInfo abilityInfo = this.abilityManager.getAbilityInfo(arg); + AbilityHandler abilityHandler = this.abilityHandlerManager.getHandler(arg); if (this.isNumeric(arg)) { final List strings = new ArrayList(); @@ -125,36 +125,36 @@ public class HelpCommand extends PKCommand { sender.sendMessage(ChatColor.GOLD + this.properUsage.replace("{command1}", ChatColor.RED + "/bending display " + arg + ChatColor.GOLD).replace("{command2}", ChatColor.RED + "/bending help " + ChatColor.GOLD)); } else if (Arrays.asList(Commands.passivealiases).contains(arg)) { // bending help elementpassive. sender.sendMessage(ChatColor.GOLD + this.properUsage.replace("{command1}", ChatColor.RED + "/bending display " + arg + ChatColor.GOLD).replace("{command2}", ChatColor.RED + "/bending help " + ChatColor.RED)); - } else if (abilityInfo != null && !(abilityInfo instanceof ComboAbilityInfo) && !abilityInfo.isHidden() || abilityInfo instanceof PassiveAbilityInfo) { // bending help ability. - final ChatColor color = abilityInfo.getElement().getColor(); + } else if (abilityHandler != null && !(abilityHandler instanceof ComboAbility) && !abilityHandler.isHidden() || abilityHandler instanceof PassiveAbility) { // bending help ability. + final ChatColor color = abilityHandler.getElement().getColor(); - if (abilityInfo instanceof AddonAbilityInfo) { - if (abilityInfo instanceof PassiveAbilityInfo) { - sender.sendMessage(color + (ChatColor.BOLD + abilityInfo.getName()) + ChatColor.WHITE + " (Addon Passive)"); + if (abilityHandler instanceof AddonAbility) { + if (abilityHandler instanceof PassiveAbility) { + sender.sendMessage(color + (ChatColor.BOLD + abilityHandler.getName()) + ChatColor.WHITE + " (Addon Passive)"); } else { - sender.sendMessage(color + (ChatColor.BOLD + abilityInfo.getName()) + ChatColor.WHITE + " (Addon)"); + sender.sendMessage(color + (ChatColor.BOLD + abilityHandler.getName()) + ChatColor.WHITE + " (Addon)"); } - sender.sendMessage(color + abilityInfo.getDescription()); + sender.sendMessage(color + abilityHandler.getDescription()); - if (!abilityInfo.getInstructions().isEmpty()) { - sender.sendMessage(ChatColor.WHITE + this.usage + abilityInfo.getInstructions()); + if (!abilityHandler.getInstructions().isEmpty()) { + sender.sendMessage(ChatColor.WHITE + this.usage + abilityHandler.getInstructions()); } - final AddonAbilityInfo addonAbilityInfo = (AddonAbilityInfo) abilityInfo; + final AddonAbility addonAbilityInfo = (AddonAbility) abilityHandler; sender.sendMessage(color + "- By: " + ChatColor.WHITE + addonAbilityInfo.getAuthor()); sender.sendMessage(color + "- Version: " + ChatColor.WHITE + addonAbilityInfo.getVersion()); } else { - if (abilityInfo instanceof PassiveAbilityInfo) { - sender.sendMessage(color + (ChatColor.BOLD + abilityInfo.getName()) + ChatColor.WHITE + " (Passive)"); + if (abilityHandler instanceof PassiveAbility) { + sender.sendMessage(color + (ChatColor.BOLD + abilityHandler.getName()) + ChatColor.WHITE + " (Passive)"); } else { - sender.sendMessage(color + (ChatColor.BOLD + abilityInfo.getName())); + sender.sendMessage(color + (ChatColor.BOLD + abilityHandler.getName())); } - sender.sendMessage(color + abilityInfo.getDescription()); + sender.sendMessage(color + abilityHandler.getDescription()); - if (!abilityInfo.getInstructions().isEmpty()) { - sender.sendMessage(ChatColor.WHITE + this.usage + abilityInfo.getInstructions()); + if (!abilityHandler.getInstructions().isEmpty()) { + sender.sendMessage(ChatColor.WHITE + this.usage + abilityHandler.getInstructions()); } } } else if (Arrays.asList(Commands.airaliases).contains(arg)) { @@ -188,30 +188,30 @@ public class HelpCommand extends PKCommand { sender.sendMessage(avatar.getColor() + this.avatar.replace("/b display Avatar", avatar.getSecondaryColor() + "/b display Avatar" + avatar.getColor())); sender.sendMessage(ChatColor.YELLOW + this.learnMore + ChatColor.DARK_AQUA + "http://projectkorra.com/"); } else { - ComboAbilityInfo comboAbilityInfo = this.comboAbilityManager.getAbility(arg); + AbilityHandler abilityInfo = this.comboAbilityManager.getHandler(arg); - if (comboAbilityInfo == null) { + if (abilityInfo == null) { sender.sendMessage(ChatColor.RED + this.invalidTopic); return; } - final ChatColor color = comboAbilityInfo.getElement().getColor(); + final ChatColor color = abilityInfo.getElement().getColor(); - if (comboAbilityInfo instanceof AddonAbilityInfo) { - sender.sendMessage(color + (ChatColor.BOLD + comboAbilityInfo.getName()) + ChatColor.WHITE + " (Addon Combo)"); - sender.sendMessage(color + comboAbilityInfo.getDescription()); + if (abilityInfo instanceof AddonAbility) { + sender.sendMessage(color + (ChatColor.BOLD + abilityInfo.getName()) + ChatColor.WHITE + " (Addon Combo)"); + sender.sendMessage(color + abilityInfo.getDescription()); - if (!comboAbilityInfo.getInstructions().isEmpty()) { - sender.sendMessage(ChatColor.WHITE + this.usage + comboAbilityInfo.getInstructions()); + if (!abilityInfo.getInstructions().isEmpty()) { + sender.sendMessage(ChatColor.WHITE + this.usage + abilityInfo.getInstructions()); } - final AddonAbilityInfo addonAbilityInfo = (AddonAbilityInfo) comboAbilityInfo; + final AddonAbility addonAbilityInfo = (AddonAbility) abilityInfo; sender.sendMessage(color + "- By: " + ChatColor.WHITE + addonAbilityInfo.getAuthor()); sender.sendMessage(color + "- Version: " + ChatColor.WHITE + addonAbilityInfo.getVersion()); } else { - sender.sendMessage(color + (ChatColor.BOLD + comboAbilityInfo.getName()) + ChatColor.WHITE + " (Combo)"); - sender.sendMessage(color + comboAbilityInfo.getDescription()); - sender.sendMessage(ChatColor.WHITE + this.usage + comboAbilityInfo.getInstructions()); + sender.sendMessage(color + (ChatColor.BOLD + abilityInfo.getName()) + ChatColor.WHITE + " (Combo)"); + sender.sendMessage(color + abilityInfo.getDescription()); + sender.sendMessage(ChatColor.WHITE + this.usage + abilityInfo.getInstructions()); } } } @@ -229,9 +229,9 @@ public class HelpCommand extends PKCommand { final Set abilitySet = new HashSet<>(); - for (AbilityInfo abilityInfo : this.abilityManager.getAbilityInfo()) { - if (!abilityInfo.isHidden()) { - abilitySet.add(abilityInfo.getName()); + for (AbilityHandler abilityHandler : this.abilityHandlerManager.getHandlers()) { + if (!abilityHandler.isHidden()) { + abilitySet.add(abilityHandler.getName()); } } diff --git a/src/com/projectkorra/projectkorra/command/PKCommand.java b/src/com/projectkorra/projectkorra/command/PKCommand.java index 469efe87..b6d208aa 100644 --- a/src/com/projectkorra/projectkorra/command/PKCommand.java +++ b/src/com/projectkorra/projectkorra/command/PKCommand.java @@ -9,10 +9,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import com.projectkorra.projectkorra.ability.AbilityManager; -import com.projectkorra.projectkorra.ability.ComboAbilityManager; -import com.projectkorra.projectkorra.ability.MultiAbilityManager; -import com.projectkorra.projectkorra.ability.PassiveAbilityManager; +import com.projectkorra.projectkorra.ability.*; import com.projectkorra.projectkorra.ability.bind.AbilityBindManager; import com.projectkorra.projectkorra.element.ElementManager; import com.projectkorra.projectkorra.module.ModuleManager; @@ -37,6 +34,7 @@ public abstract class PKCommand implements SubCommand { if (!this.correctLength(sender, args.size(), 3, 4)) { return; } - final AbilityInfo abilityInfo = this.abilityManager.getAbilityInfo(args.get(1)); + final AbilityHandler abilityHandler = this.abilityHandlerManager.getHandler(args.get(1)); final Element element = this.elementManager.getElement(args.get(1)); Object object = null; - if (abilityInfo != null) { - object = abilityInfo; + if (abilityHandler != null) { + object = abilityHandler; } else if (element != null) { object = element; } @@ -118,9 +118,9 @@ public class StatsCommand extends PKCommand { } else { value = StatisticsMethods.getStatistic(target.getUniqueId(), object, statistic); } - if (object instanceof AbilityInfo) { - final AbilityInfo abilityInfo = (AbilityInfo) object; - message = message.replace("%object%", abilityInfo.getName()).replace("%player%", target.getName()).replace("%value%", String.valueOf(value)); + if (object instanceof AbilityHandler) { + final AbilityHandler abilityHandler = (AbilityHandler) object; + message = message.replace("%object%", abilityHandler.getName()).replace("%player%", target.getName()).replace("%value%", String.valueOf(value)); } else if (object instanceof Element) { final Element element = (Element) object; message = message.replace("%object%", element.getName()).replace("%player%", target.getName()).replace("%value%", String.valueOf(value)); @@ -137,9 +137,9 @@ public class StatsCommand extends PKCommand { int p = page > maxPage ? maxPage : page; p = p < 1 ? 1 : p; String title = "%object% " + statistic.getDisplayName() + " Leaderboard"; - if (object instanceof AbilityInfo) { - final AbilityInfo abilityInfo = (AbilityInfo) object; - title = title.replace("%object%", abilityInfo.getName()); + if (object instanceof AbilityHandler) { + final AbilityHandler abilityHandler = (AbilityHandler) object; + title = title.replace("%object%", abilityHandler.getName()); } else if (object instanceof Element) { final Element element = (Element) object; title = title.replace("%object%", element.getName()); diff --git a/src/com/projectkorra/projectkorra/command/WhoCommand.java b/src/com/projectkorra/projectkorra/command/WhoCommand.java index 58b3d4c0..3aa2d1cf 100644 --- a/src/com/projectkorra/projectkorra/command/WhoCommand.java +++ b/src/com/projectkorra/projectkorra/command/WhoCommand.java @@ -2,7 +2,7 @@ package com.projectkorra.projectkorra.command; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; -import com.projectkorra.projectkorra.ability.info.AbilityInfo; +import com.projectkorra.projectkorra.ability.AbilityHandler; import com.projectkorra.projectkorra.configuration.configs.commands.WhoCommandConfig; import com.projectkorra.projectkorra.element.Element; import com.projectkorra.projectkorra.element.ElementManager; @@ -315,13 +315,13 @@ public class WhoCommand extends PKCommand { sender.sendMessage("Abilities: "); for (int i = 0; i < 9; i++) { String abilityName = bendingPlayer.getAbility(i); - AbilityInfo abilityInfo = this.abilityManager.getAbilityInfo(abilityName); + AbilityHandler abilityHandler = this.abilityHandlerManager.getHandler(abilityName); - if (abilityInfo == null) { + if (abilityHandler == null) { continue; } - sender.sendMessage((i + 1) + " - " + abilityInfo.getElement().getColor() + abilityName); + sender.sendMessage((i + 1) + " - " + abilityHandler.getElement().getColor() + abilityName); } if (this.staff.containsKey(uuid.toString())) { diff --git a/src/com/projectkorra/projectkorra/event/PlayerChangeElementEvent.java b/src/com/projectkorra/projectkorra/event/PlayerChangeElementEvent.java index b28390c7..e304bce1 100644 --- a/src/com/projectkorra/projectkorra/event/PlayerChangeElementEvent.java +++ b/src/com/projectkorra/projectkorra/event/PlayerChangeElementEvent.java @@ -14,19 +14,19 @@ public class PlayerChangeElementEvent extends Event { private final Player player; private final Element element; - private final Reason reason; + private final Action action; /** * * @param player the {@link Player player} who's bending was changed * @param element the {@link Element element} that was affected - * @param reason whether the element was chosen, added, removed, or + * @param action whether the element was chosen, added, removed, or * permaremoved */ - public PlayerChangeElementEvent(final Player player, final Element element, final Reason reason) { + public PlayerChangeElementEvent(final Player player, final Element element, final Action action) { this.player = player; this.element = element; - this.reason = reason; + this.action = action; } /** @@ -49,8 +49,8 @@ public class PlayerChangeElementEvent extends Event { * * @return whether the element was chosen, added, removed, or permaremoved */ - public Reason getReason() { - return this.reason; + public Action getAction() { + return this.action; } @Override @@ -62,7 +62,7 @@ public class PlayerChangeElementEvent extends Event { return HANDLER_LIST; } - public enum Reason { + public enum Action { ADD, SET, REMOVE, CLEAR } }