From 715429c343d9c6887bc413255e5f34897e8104e8 Mon Sep 17 00:00:00 2001 From: Alexander Meech Date: Mon, 19 Aug 2019 15:58:14 -0400 Subject: [PATCH] Better reflect storage of bindings in array throughout API methods --- .../projectkorra/projectkorra/GeneralMethods.java | 12 ++++++------ src/com/projectkorra/projectkorra/PKListener.java | 4 ++-- .../ability/util/MultiAbilityManager.java | 2 +- .../projectkorra/command/BindCommand.java | 2 +- .../projectkorra/command/ClearCommand.java | 4 ++-- .../projectkorra/command/PresetCommand.java | 4 +--- .../projectkorra/command/WhoCommand.java | 6 +++--- .../waterbending/multiabilities/WaterArms.java | 2 +- 8 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/com/projectkorra/projectkorra/GeneralMethods.java b/src/com/projectkorra/projectkorra/GeneralMethods.java index e6f71329..ee20c206 100644 --- a/src/com/projectkorra/projectkorra/GeneralMethods.java +++ b/src/com/projectkorra/projectkorra/GeneralMethods.java @@ -188,7 +188,7 @@ public class GeneralMethods { * @see #bindAbility(Player, String, int) */ public static void bindAbility(final Player player, final String ability) { - final int slot = player.getInventory().getHeldItemSlot() + 1; + final int slot = player.getInventory().getHeldItemSlot(); bindAbility(player, ability, slot); } @@ -212,10 +212,10 @@ public class GeneralMethods { if (bPlayer == null) { return; } - bPlayer.getAbilities()[slot - 1] = ability; + bPlayer.getAbilities()[slot] = ability; if (coreAbil != null) { - GeneralMethods.sendBrandingMessage(player, coreAbil.getElement().getColor() + ConfigManager.getConfig(BindCommandConfig.class).SuccessfullyBoundMessage.replace("{ability}", ability).replace("{slot}", String.valueOf(slot))); + GeneralMethods.sendBrandingMessage(player, coreAbil.getElement().getColor() + ConfigManager.getConfig(BindCommandConfig.class).SuccessfullyBoundMessage.replace("{ability}", ability).replace("{slot}", String.valueOf(slot + 1))); } saveAbility(bPlayer, slot, ability); } @@ -498,7 +498,7 @@ public class GeneralMethods { } public static void displayMovePreview(final Player player) { - displayMovePreview(player, player.getInventory().getHeldItemSlot() + 1); + displayMovePreview(player, player.getInventory().getHeldItemSlot()); } public static void displayMovePreview(final Player player, final int slot) { @@ -510,7 +510,7 @@ public class GeneralMethods { if (bPlayer == null) { return; } - String displayedMessage = bPlayer.getAbilities()[slot - 1]; + String displayedMessage = bPlayer.getAbilities()[slot]; final CoreAbility ability = CoreAbility.getAbility(displayedMessage); if (ability != null && bPlayer != null) { @@ -1841,7 +1841,7 @@ public class GeneralMethods { } final String[] abilities = bPlayer.getAbilities(); - DBConnection.sql.modifyQuery("UPDATE pk_players SET slot" + slot + " = '" + (abilities[slot - 1] == null ? null : abilities[slot - 1]) + "' WHERE uuid = '" + uuid + "'"); + DBConnection.sql.modifyQuery("UPDATE pk_players SET slot" + (slot + 1) + " = '" + (abilities[slot] == null ? null : abilities[slot - 1]) + "' WHERE uuid = '" + uuid + "'"); } public static void saveElements(final BendingPlayer bPlayer, List e) { diff --git a/src/com/projectkorra/projectkorra/PKListener.java b/src/com/projectkorra/projectkorra/PKListener.java index c9baba45..d98db3d4 100644 --- a/src/com/projectkorra/projectkorra/PKListener.java +++ b/src/com/projectkorra/projectkorra/PKListener.java @@ -1589,13 +1589,13 @@ public class PKListener implements Listener { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void onPlayerSlotChange(final PlayerItemHeldEvent event) { final Player player = event.getPlayer(); - final int slot = event.getNewSlot() + 1; + final int slot = event.getNewSlot(); GeneralMethods.displayMovePreview(player, slot); if (!ConfigManager.getConfig(GeneralPropertiesConfig.class).BendingPreview) { final WaterArms waterArms = CoreAbility.getAbility(player, WaterArms.class); if (waterArms != null) { - waterArms.displayBoundMsg(event.getNewSlot() + 1); + waterArms.displayBoundMsg(event.getNewSlot()); return; } } diff --git a/src/com/projectkorra/projectkorra/ability/util/MultiAbilityManager.java b/src/com/projectkorra/projectkorra/ability/util/MultiAbilityManager.java index 17640de3..1317c01c 100644 --- a/src/com/projectkorra/projectkorra/ability/util/MultiAbilityManager.java +++ b/src/com/projectkorra/projectkorra/ability/util/MultiAbilityManager.java @@ -216,7 +216,7 @@ public class MultiAbilityManager { } } if (lastNonNull > -1) { - GeneralMethods.saveAbility(bPlayer, lastNonNull + 1, prevBinds[lastNonNull]); + GeneralMethods.saveAbility(bPlayer, lastNonNull, prevBinds[lastNonNull]); } if (player.isOnline()) { diff --git a/src/com/projectkorra/projectkorra/command/BindCommand.java b/src/com/projectkorra/projectkorra/command/BindCommand.java index a5177d80..da3ab46a 100644 --- a/src/com/projectkorra/projectkorra/command/BindCommand.java +++ b/src/com/projectkorra/projectkorra/command/BindCommand.java @@ -124,7 +124,7 @@ public class BindCommand extends PKCommand { } final String name = coreAbil != null ? coreAbil.getName() : null; - GeneralMethods.bindAbility((Player) sender, name, slot); + GeneralMethods.bindAbility((Player) sender, name, slot - 1); } @Override diff --git a/src/com/projectkorra/projectkorra/command/ClearCommand.java b/src/com/projectkorra/projectkorra/command/ClearCommand.java index 39dcf549..892a2ef8 100644 --- a/src/com/projectkorra/projectkorra/command/ClearCommand.java +++ b/src/com/projectkorra/projectkorra/command/ClearCommand.java @@ -50,7 +50,7 @@ public class ClearCommand extends PKCommand { } if (args.size() == 0) { Arrays.fill(bPlayer.getAbilities(), null); - for (int i = 1; i <= 9; i++) { + for (int i = 0; i < 9; i++) { GeneralMethods.saveAbility(bPlayer, i, null); } GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.cleared); @@ -62,7 +62,7 @@ public class ClearCommand extends PKCommand { } if (bPlayer.getAbilities()[slot - 1] != null) { bPlayer.getAbilities()[slot - 1] = null; - GeneralMethods.saveAbility(bPlayer, slot, null); + GeneralMethods.saveAbility(bPlayer, slot - 1, null); GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.clearedSlot.replace("{slot}", String.valueOf(slot))); } else { GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.alreadyEmpty); diff --git a/src/com/projectkorra/projectkorra/command/PresetCommand.java b/src/com/projectkorra/projectkorra/command/PresetCommand.java index f2484ca3..9eac68ea 100644 --- a/src/com/projectkorra/projectkorra/command/PresetCommand.java +++ b/src/com/projectkorra/projectkorra/command/PresetCommand.java @@ -222,9 +222,7 @@ public class PresetCommand extends PKCommand { return; } String[] abilities = new String[9]; - for (int slot = 0; slot < 9; slot++) { - abilities[slot] = bPlayer.getAbilities()[slot]; - } + System.arraycopy(bPlayer.getAbilities(), 0, abilities, 0, bPlayer.getAbilities().length); final Preset preset = new Preset(player.getUniqueId(), name, abilities); preset.save(player); diff --git a/src/com/projectkorra/projectkorra/command/WhoCommand.java b/src/com/projectkorra/projectkorra/command/WhoCommand.java index c595d031..043ca3a5 100644 --- a/src/com/projectkorra/projectkorra/command/WhoCommand.java +++ b/src/com/projectkorra/projectkorra/command/WhoCommand.java @@ -314,13 +314,13 @@ public class WhoCommand extends PKCommand { final UUID uuid = player.getUniqueId(); if (bPlayer != null) { sender.sendMessage("Abilities: "); - for (int i = 1; i <= 9; i++) { - final String ability = bPlayer.getAbilities()[i - 1]; + for (int i = 0; i < 9; i++) { + final String ability = bPlayer.getAbilities()[i]; final CoreAbility coreAbil = CoreAbility.getAbility(ability); if (coreAbil == null) { continue; } else { - sender.sendMessage(i + " - " + coreAbil.getElement().getColor() + ability); + sender.sendMessage((i + 1) + " - " + coreAbil.getElement().getColor() + ability); } } } diff --git a/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArms.java b/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArms.java index d6a36b2c..3fb24ee2 100644 --- a/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArms.java +++ b/src/com/projectkorra/projectkorra/waterbending/multiabilities/WaterArms.java @@ -470,7 +470,7 @@ public class WaterArms extends WaterAbility { } public void displayBoundMsg(final int slot) { - final String name = this.bPlayer.getAbilities()[slot - 1]; + final String name = this.bPlayer.getAbilities()[slot]; if (name != null) { this.player.sendMessage(this.getElement().getColor() + this.sneakMsg + " " + name); }