Fixed commands

This commit is contained in:
jayoevans 2019-12-02 11:52:10 +10:00
parent 03844d5bab
commit b2efe13575
9 changed files with 140 additions and 146 deletions

View file

@ -1,10 +1,10 @@
package com.projectkorra.projectkorra.command; package com.projectkorra.projectkorra.command;
import com.projectkorra.projectkorra.GeneralMethods; 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.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.ConfigManager;
import com.projectkorra.projectkorra.configuration.configs.commands.BindCommandConfig; import com.projectkorra.projectkorra.configuration.configs.commands.BindCommandConfig;
import com.projectkorra.projectkorra.element.Element; import com.projectkorra.projectkorra.element.Element;
@ -53,9 +53,9 @@ public class BindCommand extends PKCommand<BindCommandConfig> {
} }
String abilityName = args.get(0); 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))); GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.abilityDoesntExist.replace("{ability}", args.get(0)));
return; return;
} }
@ -67,20 +67,20 @@ public class BindCommand extends PKCommand<BindCommandConfig> {
// bending bind [Ability]. // bending bind [Ability].
if (args.size() == 1) { 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] [#]. // bending bind [ability] [#].
if (args.size() == 2) { if (args.size() == 2) {
try { try {
this.bind(sender, abilityInfo, Integer.parseInt(args.get(1))); this.bind(sender, abilityHandler, Integer.parseInt(args.get(1)));
} catch (final NumberFormatException ex) { } catch (final NumberFormatException ex) {
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.wrongNumber); 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)) { if (!(sender instanceof Player)) {
return; return;
} else if (slot < 1 || slot > 9) { } else if (slot < 1 || slot > 9) {
@ -91,20 +91,20 @@ public class BindCommand extends PKCommand<BindCommandConfig> {
Player player = (Player) sender; Player player = (Player) sender;
BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player); BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player);
Element element = abilityInfo.getElement(); Element element = abilityHandler.getElement();
// if (bPlayer == null) { // if (bPlayer == null) {
// GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.loadingInfo); // GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.loadingInfo);
// return; // return;
// } // }
if (bendingPlayer.canBind(abilityInfo)) { if (bendingPlayer.canBind(abilityHandler)) {
if (!bendingPlayer.isElementToggled(element)) { if (!bendingPlayer.isElementToggled(element)) {
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.toggledElementOff); GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.toggledElementOff);
} }
if (this.abilityBindManager.bindAbility(player, abilityInfo.getName(), slot) == AbilityBindManager.Result.SUCCESS) { if (this.abilityBindManager.bindAbility(player, abilityHandler.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))); GeneralMethods.sendBrandingMessage(player, element.getColor() + ConfigManager.getConfig(BindCommandConfig.class).SuccessfullyBoundMessage.replace("{ability}", abilityHandler.getName()).replace("{slot}", String.valueOf(slot + 1)));
} }
return; return;
} }
@ -158,9 +158,9 @@ public class BindCommand extends PKCommand<BindCommandConfig> {
Set<String> abilitySet = new HashSet<>(); Set<String> abilitySet = new HashSet<>();
for (AbilityInfo abilityInfo : this.abilityManager.getAbilityInfo()) { for (AbilityHandler abilityHandler : this.abilityHandlerManager.getHandlers()) {
if (!abilityInfo.isHidden() && bendingPlayer.canBind(abilityInfo) && !(abilityInfo instanceof PassiveAbilityInfo || abilityInfo instanceof ComboAbilityInfo && !abilitySet.contains(abilityInfo.getName()))) { if (!abilityHandler.isHidden() && bendingPlayer.canBind(abilityHandler) && !(abilityHandler instanceof PassiveAbility || abilityHandler instanceof ComboAbility && !abilitySet.contains(abilityHandler.getName()))) {
abilitySet.add(abilityInfo.getName()); abilitySet.add(abilityHandler.getName());
} }
} }

View file

@ -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.CommandPropertiesConfig;
import com.projectkorra.projectkorra.configuration.configs.properties.GeneralPropertiesConfig; import com.projectkorra.projectkorra.configuration.configs.properties.GeneralPropertiesConfig;
import com.projectkorra.projectkorra.element.Element; import com.projectkorra.projectkorra.element.Element;
import com.projectkorra.projectkorra.element.SubElement;
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent; import com.projectkorra.projectkorra.event.PlayerChangeElementEvent;
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent.Result;
import com.projectkorra.projectkorra.player.BendingPlayer; import com.projectkorra.projectkorra.player.BendingPlayer;
import com.projectkorra.projectkorra.util.TimeUtil; import com.projectkorra.projectkorra.util.TimeUtil;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -186,7 +184,7 @@ public class ChooseCommand extends PKCommand<ChooseCommandConfig> {
} }
} }
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()); GeneralMethods.removeUnusableAbilities(player.getName());
} }

View file

@ -1,20 +1,19 @@
package com.projectkorra.projectkorra.command; package com.projectkorra.projectkorra.command;
import java.util.ArrayList; import com.projectkorra.projectkorra.GeneralMethods;
import java.util.List; import com.projectkorra.projectkorra.ProjectKorra;
import com.projectkorra.projectkorra.ability.AbilityHandler;
import com.projectkorra.projectkorra.ability.info.AbilityInfo; 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 com.projectkorra.projectkorra.player.BendingPlayer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.projectkorra.projectkorra.GeneralMethods; import java.util.ArrayList;
import com.projectkorra.projectkorra.ProjectKorra; import java.util.List;
import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.configuration.configs.commands.CopyCommandConfig;
import com.projectkorra.projectkorra.configuration.configs.properties.CommandPropertiesConfig;
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
public class CopyCommand extends PKCommand<CopyCommandConfig> { public class CopyCommand extends PKCommand<CopyCommandConfig> {
@ -91,15 +90,15 @@ public class CopyCommand extends PKCommand<CopyCommandConfig> {
return false; return false;
} }
List<String> abilities = orig.getAbilities(); String[] abilities = orig.getAbilities();
boolean boundAll = true; boolean boundAll = true;
for (int i = 0; i < 9; i++) { 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; boundAll = false;
continue; continue;
} }

View file

@ -1,14 +1,13 @@
package com.projectkorra.projectkorra.command; package com.projectkorra.projectkorra.command;
import java.util.ArrayList; import com.projectkorra.projectkorra.GeneralMethods;
import java.util.HashSet; import com.projectkorra.projectkorra.ability.AbilityHandler;
import java.util.List; import com.projectkorra.projectkorra.ability.api.AddonAbility;
import java.util.Objects; import com.projectkorra.projectkorra.ability.api.ComboAbility;
import com.projectkorra.projectkorra.ability.legacy.SubAbility;
import com.projectkorra.projectkorra.ability.info.AbilityInfo; import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.ability.api.AddonAbilityInfo; import com.projectkorra.projectkorra.configuration.configs.commands.DisplayCommandConfig;
import com.projectkorra.projectkorra.ability.api.ComboAbilityInfo; import com.projectkorra.projectkorra.configuration.configs.properties.CommandPropertiesConfig;
import com.projectkorra.projectkorra.ability.api.PassiveAbilityInfo;
import com.projectkorra.projectkorra.element.Element; import com.projectkorra.projectkorra.element.Element;
import com.projectkorra.projectkorra.element.SubElement; import com.projectkorra.projectkorra.element.SubElement;
import com.projectkorra.projectkorra.player.BendingPlayer; import com.projectkorra.projectkorra.player.BendingPlayer;
@ -16,11 +15,11 @@ import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import com.projectkorra.projectkorra.GeneralMethods; import java.util.ArrayList;
import com.projectkorra.projectkorra.ability.legacy.SubAbility; import java.util.HashSet;
import com.projectkorra.projectkorra.configuration.ConfigManager; import java.util.List;
import com.projectkorra.projectkorra.configuration.configs.commands.DisplayCommandConfig; import java.util.Objects;
import com.projectkorra.projectkorra.configuration.configs.properties.CommandPropertiesConfig; import java.util.stream.Stream;
/** /**
* Executor for /bending display. Extends {@link PKCommand}. * Executor for /bending display. Extends {@link PKCommand}.
@ -88,16 +87,16 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
sender.sendMessage(ChatColor.BOLD + "Combos"); sender.sendMessage(ChatColor.BOLD + "Combos");
for (final Element e : this.elementManager.getElements()) { for (final Element e : this.elementManager.getElements()) {
final List<ComboAbilityInfo> abilities = this.comboAbilityManager.getAbilities(e); final List<AbilityHandler> abilities = this.comboAbilityManager.getHandlers(e);
for (final ComboAbilityInfo comboAbilityInfo : abilities) { for (final AbilityHandler abilityHandler : abilities) {
if (!sender.hasPermission("bending.ability." + comboAbilityInfo.getName())) { if (!sender.hasPermission("bending.ability." + abilityHandler.getName())) {
continue; 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 + "*"); message += ChatColor.WHITE + (ChatColor.BOLD + "*");
} }
@ -107,7 +106,7 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
return; return;
} else { } else {
final ChatColor color = element != null ? element.getColor() : null; final ChatColor color = element != null ? element.getColor() : null;
final List<ComboAbilityInfo> abilities = this.comboAbilityManager.getAbilities(element); final List<AbilityHandler> abilities = this.comboAbilityManager.getHandlers(element);
if (abilities.isEmpty()) { if (abilities.isEmpty()) {
GeneralMethods.sendBrandingMessage(sender, color + this.noCombosAvailable.replace("{element}", element.getName())); GeneralMethods.sendBrandingMessage(sender, color + this.noCombosAvailable.replace("{element}", element.getName()));
@ -116,14 +115,14 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
sender.sendMessage(element.getColor() + (ChatColor.BOLD + element.getName()) + element.getType().getBending() + ChatColor.WHITE + (ChatColor.BOLD + " Combos")); sender.sendMessage(element.getColor() + (ChatColor.BOLD + element.getName()) + element.getType().getBending() + ChatColor.WHITE + (ChatColor.BOLD + " Combos"));
for (final ComboAbilityInfo comboAbilityInfo : abilities) { for (final AbilityHandler abilityHandler : abilities) {
if (!sender.hasPermission("bending.ability." + comboAbilityInfo.getName())) { if (!sender.hasPermission("bending.ability." + abilityHandler.getName())) {
continue; 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 + "*"); message += ChatColor.WHITE + (ChatColor.BOLD + "*");
} }
@ -137,16 +136,16 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
sender.sendMessage(ChatColor.BOLD + "Passives"); sender.sendMessage(ChatColor.BOLD + "Passives");
for (final Element e : this.elementManager.getElements()) { for (final Element e : this.elementManager.getElements()) {
final List<PassiveAbilityInfo> passives = this.passiveAbilityManager.getPassives(e); final List<AbilityHandler> passives = this.passiveAbilityManager.getPassives(e);
for (final PassiveAbilityInfo passiveAbilityInfo : passives) { for (final AbilityHandler abilityHandler : passives) {
if (!sender.hasPermission("bending.ability." + passiveAbilityInfo.getName())) { if (!sender.hasPermission("bending.ability." + abilityHandler.getName())) {
continue; 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 + "*"); message += ChatColor.WHITE + (ChatColor.BOLD + "*");
} }
@ -156,7 +155,7 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
return; return;
} }
final ChatColor color = element != null ? element.getColor() : null; final ChatColor color = element != null ? element.getColor() : null;
final List<PassiveAbilityInfo> passives = this.passiveAbilityManager.getPassives(element); final List<AbilityHandler> passives = this.passiveAbilityManager.getPassives(element);
if (passives.isEmpty()) { if (passives.isEmpty()) {
GeneralMethods.sendBrandingMessage(sender, color + this.noPassivesAvailable.replace("{element}", element.getName())); GeneralMethods.sendBrandingMessage(sender, color + this.noPassivesAvailable.replace("{element}", element.getName()));
@ -165,12 +164,12 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
sender.sendMessage(element.getColor() + (ChatColor.BOLD + element.getName()) + element.getType().getBending() + ChatColor.WHITE + (ChatColor.BOLD + " Passives")); sender.sendMessage(element.getColor() + (ChatColor.BOLD + element.getName()) + element.getType().getBending() + ChatColor.WHITE + (ChatColor.BOLD + " Passives"));
for (final PassiveAbilityInfo passiveAbilityInfo : passives) { for (final AbilityHandler abilityHandler : passives) {
if (!sender.hasPermission("bending.ability." + passiveAbilityInfo.getName())) { if (!sender.hasPermission("bending.ability." + abilityHandler.getName())) {
continue; continue;
} }
sender.sendMessage(passiveAbilityInfo.getElement().getColor() + passiveAbilityInfo.getName()); sender.sendMessage(abilityHandler.getElement().getColor() + abilityHandler.getName());
} }
return; return;
} else if (element != null) { } else if (element != null) {
@ -214,7 +213,7 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
* @param element The element to show the moves for * @param element The element to show the moves for
*/ */
private void displayElement(final CommandSender sender, final Element element) { private void displayElement(final CommandSender sender, final Element element) {
final List<AbilityInfo> abilities = this.abilityManager.getAbilities(element); final List<AbilityHandler> abilities = this.abilityHandlerManager.getHandlers(element);
if (abilities.isEmpty()) { if (abilities.isEmpty()) {
sender.sendMessage(ChatColor.YELLOW + this.noAbilitiesAvailable.replace("{element}", element.getColor() + element.getName() + ChatColor.YELLOW)); sender.sendMessage(ChatColor.YELLOW + this.noAbilitiesAvailable.replace("{element}", element.getColor() + element.getName() + ChatColor.YELLOW));
@ -224,19 +223,19 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
sender.sendMessage(element.getColor() + (ChatColor.BOLD + element.getName()) + element.getType().getBending()); sender.sendMessage(element.getColor() + (ChatColor.BOLD + element.getName()) + element.getType().getBending());
final HashSet<String> abilitiesSent = new HashSet<String>(); // Some abilities have the same name. This prevents this from showing anything. final HashSet<String> abilitiesSent = new HashSet<String>(); // Some abilities have the same name. This prevents this from showing anything.
for (final AbilityInfo abilityInfo : abilities) { for (final AbilityHandler abilityHandler : abilities) {
if (abilityInfo instanceof SubAbility || abilityInfo instanceof ComboAbilityInfo || abilityInfo.isHidden() || abilitiesSent.contains(abilityInfo.getName())) { if (abilityHandler instanceof SubAbility || abilityHandler instanceof ComboAbility || abilityHandler.isHidden() || abilitiesSent.contains(abilityHandler.getName())) {
continue; continue;
} }
if (!(sender instanceof Player) || GeneralMethods.canView((Player) sender, abilityInfo.getName())) { if (!(sender instanceof Player) || GeneralMethods.canView((Player) sender, abilityHandler.getName())) {
String message = abilityInfo.getElement().getColor() + abilityInfo.getName(); String message = abilityHandler.getElement().getColor() + abilityHandler.getName();
if (abilityInfo instanceof AddonAbilityInfo) { if (abilityHandler instanceof AddonAbility) {
message += ChatColor.WHITE + (ChatColor.BOLD + "*"); message += ChatColor.WHITE + (ChatColor.BOLD + "*");
} }
sender.sendMessage(message); sender.sendMessage(message);
abilitiesSent.add(abilityInfo.getName()); abilitiesSent.add(abilityHandler.getName());
} }
} }
@ -261,7 +260,7 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
* @param element The subelement to show the moves for * @param element The subelement to show the moves for
*/ */
private void displaySubElement(final CommandSender sender, final SubElement element) { private void displaySubElement(final CommandSender sender, final SubElement element) {
final List<AbilityInfo> abilities = this.abilityManager.getAbilities(element);; final List<AbilityHandler> abilities = this.abilityHandlerManager.getHandlers(element);;
if (abilities.isEmpty() && element != null) { if (abilities.isEmpty() && element != null) {
sender.sendMessage(ChatColor.YELLOW + this.noAbilitiesAvailable.replace("{element}", element.getColor() + element.getName() + ChatColor.YELLOW)); sender.sendMessage(ChatColor.YELLOW + this.noAbilitiesAvailable.replace("{element}", element.getColor() + element.getName() + ChatColor.YELLOW));
@ -271,17 +270,17 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
sender.sendMessage(element.getColor() + (ChatColor.BOLD + element.getName()) + element.getType().getBending()); sender.sendMessage(element.getColor() + (ChatColor.BOLD + element.getName()) + element.getType().getBending());
final HashSet<String> abilitiesSent = new HashSet<String>(); final HashSet<String> abilitiesSent = new HashSet<String>();
for (final AbilityInfo abilityInfo : abilities) { for (final AbilityHandler abilityHandler : abilities) {
if (abilityInfo.isHidden() || abilitiesSent.contains(abilityInfo.getName())) { if (abilityHandler.isHidden() || abilitiesSent.contains(abilityHandler.getName())) {
continue; continue;
} else if (!(sender instanceof Player) || GeneralMethods.canView((Player) sender, abilityInfo.getName())) { } else if (!(sender instanceof Player) || GeneralMethods.canView((Player) sender, abilityHandler.getName())) {
String message = element.getColor() + abilityInfo.getName(); String message = element.getColor() + abilityHandler.getName();
if (abilityInfo instanceof AddonAbilityInfo) { if (abilityHandler instanceof AddonAbility) {
message += ChatColor.WHITE + (ChatColor.BOLD + "*"); message += ChatColor.WHITE + (ChatColor.BOLD + "*");
} }
sender.sendMessage(message); sender.sendMessage(message);
abilitiesSent.add(abilityInfo.getName()); abilitiesSent.add(abilityHandler.getName());
} }
} }
sender.sendMessage(element.getParent().getColor() + "Passives: " + element.getColor() + "/bending display " + element.getName() + "Passives"); sender.sendMessage(element.getParent().getColor() + "Passives: " + element.getColor() + "/bending display " + element.getName() + "Passives");
@ -294,9 +293,9 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
*/ */
private void displayBinds(final Player player) { private void displayBinds(final Player player) {
BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player); BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player);
List<String> 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); player.sendMessage(ChatColor.RED + this.noBinds);
return; return;
} }
@ -304,16 +303,16 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
player.sendMessage(ChatColor.WHITE + (ChatColor.BOLD + "Abilities")); player.sendMessage(ChatColor.WHITE + (ChatColor.BOLD + "Abilities"));
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
final String abilityName = abilities.get(i); final String abilityName = abilities[i];
final AbilityInfo abilityInfo = this.abilityManager.getAbilityInfo(abilityName); final AbilityHandler abilityHandler = this.abilityHandlerManager.getHandler(abilityName);
if (abilityInfo == null) { if (abilityHandler == null) {
continue; 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 + "*"); message += ChatColor.WHITE + (ChatColor.BOLD + "*");
} }

View file

@ -1,10 +1,10 @@
package com.projectkorra.projectkorra.command; package com.projectkorra.projectkorra.command;
import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ability.info.AbilityInfo; import com.projectkorra.projectkorra.ability.AbilityHandler;
import com.projectkorra.projectkorra.ability.api.AddonAbilityInfo; import com.projectkorra.projectkorra.ability.api.AddonAbility;
import com.projectkorra.projectkorra.ability.api.ComboAbilityInfo; import com.projectkorra.projectkorra.ability.api.ComboAbility;
import com.projectkorra.projectkorra.ability.api.PassiveAbilityInfo; import com.projectkorra.projectkorra.ability.api.PassiveAbility;
import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.configuration.ConfigManager;
import com.projectkorra.projectkorra.configuration.configs.commands.HelpCommandConfig; import com.projectkorra.projectkorra.configuration.configs.commands.HelpCommandConfig;
import com.projectkorra.projectkorra.configuration.configs.properties.*; import com.projectkorra.projectkorra.configuration.configs.properties.*;
@ -95,7 +95,7 @@ public class HelpCommand extends PKCommand<HelpCommandConfig> {
} }
final String arg = args.get(0).toLowerCase(); final String arg = args.get(0).toLowerCase();
AbilityInfo abilityInfo = this.abilityManager.getAbilityInfo(arg); AbilityHandler abilityHandler = this.abilityHandlerManager.getHandler(arg);
if (this.isNumeric(arg)) { if (this.isNumeric(arg)) {
final List<String> strings = new ArrayList<String>(); final List<String> strings = new ArrayList<String>();
@ -125,36 +125,36 @@ public class HelpCommand extends PKCommand<HelpCommandConfig> {
sender.sendMessage(ChatColor.GOLD + this.properUsage.replace("{command1}", ChatColor.RED + "/bending display " + arg + ChatColor.GOLD).replace("{command2}", ChatColor.RED + "/bending help <Combo Name>" + ChatColor.GOLD)); sender.sendMessage(ChatColor.GOLD + this.properUsage.replace("{command1}", ChatColor.RED + "/bending display " + arg + ChatColor.GOLD).replace("{command2}", ChatColor.RED + "/bending help <Combo Name>" + ChatColor.GOLD));
} else if (Arrays.asList(Commands.passivealiases).contains(arg)) { // bending help elementpassive. } 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 <Passive Name>" + ChatColor.RED)); sender.sendMessage(ChatColor.GOLD + this.properUsage.replace("{command1}", ChatColor.RED + "/bending display " + arg + ChatColor.GOLD).replace("{command2}", ChatColor.RED + "/bending help <Passive Name>" + ChatColor.RED));
} else if (abilityInfo != null && !(abilityInfo instanceof ComboAbilityInfo) && !abilityInfo.isHidden() || abilityInfo instanceof PassiveAbilityInfo) { // bending help ability. } else if (abilityHandler != null && !(abilityHandler instanceof ComboAbility) && !abilityHandler.isHidden() || abilityHandler instanceof PassiveAbility) { // bending help ability.
final ChatColor color = abilityInfo.getElement().getColor(); final ChatColor color = abilityHandler.getElement().getColor();
if (abilityInfo instanceof AddonAbilityInfo) { if (abilityHandler instanceof AddonAbility) {
if (abilityInfo instanceof PassiveAbilityInfo) { if (abilityHandler instanceof PassiveAbility) {
sender.sendMessage(color + (ChatColor.BOLD + abilityInfo.getName()) + ChatColor.WHITE + " (Addon Passive)"); sender.sendMessage(color + (ChatColor.BOLD + abilityHandler.getName()) + ChatColor.WHITE + " (Addon Passive)");
} else { } 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()) { if (!abilityHandler.getInstructions().isEmpty()) {
sender.sendMessage(ChatColor.WHITE + this.usage + abilityInfo.getInstructions()); 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 + "- By: " + ChatColor.WHITE + addonAbilityInfo.getAuthor());
sender.sendMessage(color + "- Version: " + ChatColor.WHITE + addonAbilityInfo.getVersion()); sender.sendMessage(color + "- Version: " + ChatColor.WHITE + addonAbilityInfo.getVersion());
} else { } else {
if (abilityInfo instanceof PassiveAbilityInfo) { if (abilityHandler instanceof PassiveAbility) {
sender.sendMessage(color + (ChatColor.BOLD + abilityInfo.getName()) + ChatColor.WHITE + " (Passive)"); sender.sendMessage(color + (ChatColor.BOLD + abilityHandler.getName()) + ChatColor.WHITE + " (Passive)");
} else { } 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()) { if (!abilityHandler.getInstructions().isEmpty()) {
sender.sendMessage(ChatColor.WHITE + this.usage + abilityInfo.getInstructions()); sender.sendMessage(ChatColor.WHITE + this.usage + abilityHandler.getInstructions());
} }
} }
} else if (Arrays.asList(Commands.airaliases).contains(arg)) { } else if (Arrays.asList(Commands.airaliases).contains(arg)) {
@ -188,30 +188,30 @@ public class HelpCommand extends PKCommand<HelpCommandConfig> {
sender.sendMessage(avatar.getColor() + this.avatar.replace("/b display Avatar", avatar.getSecondaryColor() + "/b display Avatar" + avatar.getColor())); 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/"); sender.sendMessage(ChatColor.YELLOW + this.learnMore + ChatColor.DARK_AQUA + "http://projectkorra.com/");
} else { } 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); sender.sendMessage(ChatColor.RED + this.invalidTopic);
return; return;
} }
final ChatColor color = comboAbilityInfo.getElement().getColor(); final ChatColor color = abilityInfo.getElement().getColor();
if (comboAbilityInfo instanceof AddonAbilityInfo) { if (abilityInfo instanceof AddonAbility) {
sender.sendMessage(color + (ChatColor.BOLD + comboAbilityInfo.getName()) + ChatColor.WHITE + " (Addon Combo)"); sender.sendMessage(color + (ChatColor.BOLD + abilityInfo.getName()) + ChatColor.WHITE + " (Addon Combo)");
sender.sendMessage(color + comboAbilityInfo.getDescription()); sender.sendMessage(color + abilityInfo.getDescription());
if (!comboAbilityInfo.getInstructions().isEmpty()) { if (!abilityInfo.getInstructions().isEmpty()) {
sender.sendMessage(ChatColor.WHITE + this.usage + comboAbilityInfo.getInstructions()); 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 + "- By: " + ChatColor.WHITE + addonAbilityInfo.getAuthor());
sender.sendMessage(color + "- Version: " + ChatColor.WHITE + addonAbilityInfo.getVersion()); sender.sendMessage(color + "- Version: " + ChatColor.WHITE + addonAbilityInfo.getVersion());
} else { } else {
sender.sendMessage(color + (ChatColor.BOLD + comboAbilityInfo.getName()) + ChatColor.WHITE + " (Combo)"); sender.sendMessage(color + (ChatColor.BOLD + abilityInfo.getName()) + ChatColor.WHITE + " (Combo)");
sender.sendMessage(color + comboAbilityInfo.getDescription()); sender.sendMessage(color + abilityInfo.getDescription());
sender.sendMessage(ChatColor.WHITE + this.usage + comboAbilityInfo.getInstructions()); sender.sendMessage(ChatColor.WHITE + this.usage + abilityInfo.getInstructions());
} }
} }
} }
@ -229,9 +229,9 @@ public class HelpCommand extends PKCommand<HelpCommandConfig> {
final Set<String> abilitySet = new HashSet<>(); final Set<String> abilitySet = new HashSet<>();
for (AbilityInfo abilityInfo : this.abilityManager.getAbilityInfo()) { for (AbilityHandler abilityHandler : this.abilityHandlerManager.getHandlers()) {
if (!abilityInfo.isHidden()) { if (!abilityHandler.isHidden()) {
abilitySet.add(abilityInfo.getName()); abilitySet.add(abilityHandler.getName());
} }
} }

View file

@ -9,10 +9,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.projectkorra.projectkorra.ability.AbilityManager; import com.projectkorra.projectkorra.ability.*;
import com.projectkorra.projectkorra.ability.ComboAbilityManager;
import com.projectkorra.projectkorra.ability.MultiAbilityManager;
import com.projectkorra.projectkorra.ability.PassiveAbilityManager;
import com.projectkorra.projectkorra.ability.bind.AbilityBindManager; import com.projectkorra.projectkorra.ability.bind.AbilityBindManager;
import com.projectkorra.projectkorra.element.ElementManager; import com.projectkorra.projectkorra.element.ElementManager;
import com.projectkorra.projectkorra.module.ModuleManager; import com.projectkorra.projectkorra.module.ModuleManager;
@ -37,6 +34,7 @@ public abstract class PKCommand<C extends CommandConfig> implements SubCommand<C
protected final BendingPlayerManager bendingPlayerManager = ModuleManager.getModule(BendingPlayerManager.class); protected final BendingPlayerManager bendingPlayerManager = ModuleManager.getModule(BendingPlayerManager.class);
protected final ElementManager elementManager = ModuleManager.getModule(ElementManager.class); protected final ElementManager elementManager = ModuleManager.getModule(ElementManager.class);
protected final AbilityManager abilityManager = ModuleManager.getModule(AbilityManager.class); protected final AbilityManager abilityManager = ModuleManager.getModule(AbilityManager.class);
protected final AbilityHandlerManager abilityHandlerManager = ModuleManager.getModule(AbilityHandlerManager.class);
protected final ComboAbilityManager comboAbilityManager = ModuleManager.getModule(ComboAbilityManager.class); protected final ComboAbilityManager comboAbilityManager = ModuleManager.getModule(ComboAbilityManager.class);
protected final MultiAbilityManager multiAbilityManager = ModuleManager.getModule(MultiAbilityManager.class); protected final MultiAbilityManager multiAbilityManager = ModuleManager.getModule(MultiAbilityManager.class);
protected final PassiveAbilityManager passiveAbilityManager = ModuleManager.getModule(PassiveAbilityManager.class); protected final PassiveAbilityManager passiveAbilityManager = ModuleManager.getModule(PassiveAbilityManager.class);

View file

@ -2,7 +2,7 @@ package com.projectkorra.projectkorra.command;
import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ProjectKorra; 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.StatsCommandConfig; import com.projectkorra.projectkorra.configuration.configs.commands.StatsCommandConfig;
import com.projectkorra.projectkorra.element.Element; import com.projectkorra.projectkorra.element.Element;
import com.projectkorra.projectkorra.storage.DBConnection; import com.projectkorra.projectkorra.storage.DBConnection;
@ -43,11 +43,11 @@ public class StatsCommand extends PKCommand<StatsCommandConfig> {
if (!this.correctLength(sender, args.size(), 3, 4)) { if (!this.correctLength(sender, args.size(), 3, 4)) {
return; 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)); final Element element = this.elementManager.getElement(args.get(1));
Object object = null; Object object = null;
if (abilityInfo != null) { if (abilityHandler != null) {
object = abilityInfo; object = abilityHandler;
} else if (element != null) { } else if (element != null) {
object = element; object = element;
} }
@ -118,9 +118,9 @@ public class StatsCommand extends PKCommand<StatsCommandConfig> {
} else { } else {
value = StatisticsMethods.getStatistic(target.getUniqueId(), object, statistic); value = StatisticsMethods.getStatistic(target.getUniqueId(), object, statistic);
} }
if (object instanceof AbilityInfo) { if (object instanceof AbilityHandler) {
final AbilityInfo abilityInfo = (AbilityInfo) object; final AbilityHandler abilityHandler = (AbilityHandler) object;
message = message.replace("%object%", abilityInfo.getName()).replace("%player%", target.getName()).replace("%value%", String.valueOf(value)); message = message.replace("%object%", abilityHandler.getName()).replace("%player%", target.getName()).replace("%value%", String.valueOf(value));
} else if (object instanceof Element) { } else if (object instanceof Element) {
final Element element = (Element) object; final Element element = (Element) object;
message = message.replace("%object%", element.getName()).replace("%player%", target.getName()).replace("%value%", String.valueOf(value)); message = message.replace("%object%", element.getName()).replace("%player%", target.getName()).replace("%value%", String.valueOf(value));
@ -137,9 +137,9 @@ public class StatsCommand extends PKCommand<StatsCommandConfig> {
int p = page > maxPage ? maxPage : page; int p = page > maxPage ? maxPage : page;
p = p < 1 ? 1 : p; p = p < 1 ? 1 : p;
String title = "%object% " + statistic.getDisplayName() + " Leaderboard"; String title = "%object% " + statistic.getDisplayName() + " Leaderboard";
if (object instanceof AbilityInfo) { if (object instanceof AbilityHandler) {
final AbilityInfo abilityInfo = (AbilityInfo) object; final AbilityHandler abilityHandler = (AbilityHandler) object;
title = title.replace("%object%", abilityInfo.getName()); title = title.replace("%object%", abilityHandler.getName());
} else if (object instanceof Element) { } else if (object instanceof Element) {
final Element element = (Element) object; final Element element = (Element) object;
title = title.replace("%object%", element.getName()); title = title.replace("%object%", element.getName());

View file

@ -2,7 +2,7 @@ package com.projectkorra.projectkorra.command;
import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ProjectKorra; 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.configuration.configs.commands.WhoCommandConfig;
import com.projectkorra.projectkorra.element.Element; import com.projectkorra.projectkorra.element.Element;
import com.projectkorra.projectkorra.element.ElementManager; import com.projectkorra.projectkorra.element.ElementManager;
@ -315,13 +315,13 @@ public class WhoCommand extends PKCommand<WhoCommandConfig> {
sender.sendMessage("Abilities: "); sender.sendMessage("Abilities: ");
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
String abilityName = bendingPlayer.getAbility(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; continue;
} }
sender.sendMessage((i + 1) + " - " + abilityInfo.getElement().getColor() + abilityName); sender.sendMessage((i + 1) + " - " + abilityHandler.getElement().getColor() + abilityName);
} }
if (this.staff.containsKey(uuid.toString())) { if (this.staff.containsKey(uuid.toString())) {

View file

@ -14,19 +14,19 @@ public class PlayerChangeElementEvent extends Event {
private final Player player; private final Player player;
private final Element element; private final Element element;
private final Reason reason; private final Action action;
/** /**
* *
* @param player the {@link Player player} who's bending was changed * @param player the {@link Player player} who's bending was changed
* @param element the {@link Element element} that was affected * @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 * 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.player = player;
this.element = element; 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 * @return whether the element was chosen, added, removed, or permaremoved
*/ */
public Reason getReason() { public Action getAction() {
return this.reason; return this.action;
} }
@Override @Override
@ -62,7 +62,7 @@ public class PlayerChangeElementEvent extends Event {
return HANDLER_LIST; return HANDLER_LIST;
} }
public enum Reason { public enum Action {
ADD, SET, REMOVE, CLEAR ADD, SET, REMOVE, CLEAR
} }
} }