Better reflect storage of bindings in array throughout API methods

This commit is contained in:
Alexander Meech 2019-08-19 15:58:14 -04:00
parent 8530c75ba6
commit 715429c343
8 changed files with 17 additions and 19 deletions

View file

@ -188,7 +188,7 @@ public class GeneralMethods {
* @see #bindAbility(Player, String, int) * @see #bindAbility(Player, String, int)
*/ */
public static void bindAbility(final Player player, final String ability) { 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); bindAbility(player, ability, slot);
} }
@ -212,10 +212,10 @@ public class GeneralMethods {
if (bPlayer == null) { if (bPlayer == null) {
return; return;
} }
bPlayer.getAbilities()[slot - 1] = ability; bPlayer.getAbilities()[slot] = ability;
if (coreAbil != null) { 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); saveAbility(bPlayer, slot, ability);
} }
@ -498,7 +498,7 @@ public class GeneralMethods {
} }
public static void displayMovePreview(final Player player) { 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) { public static void displayMovePreview(final Player player, final int slot) {
@ -510,7 +510,7 @@ public class GeneralMethods {
if (bPlayer == null) { if (bPlayer == null) {
return; return;
} }
String displayedMessage = bPlayer.getAbilities()[slot - 1]; String displayedMessage = bPlayer.getAbilities()[slot];
final CoreAbility ability = CoreAbility.getAbility(displayedMessage); final CoreAbility ability = CoreAbility.getAbility(displayedMessage);
if (ability != null && bPlayer != null) { if (ability != null && bPlayer != null) {
@ -1841,7 +1841,7 @@ public class GeneralMethods {
} }
final String[] abilities = bPlayer.getAbilities(); 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<Element> e) { public static void saveElements(final BendingPlayer bPlayer, List<Element> e) {

View file

@ -1589,13 +1589,13 @@ public class PKListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerSlotChange(final PlayerItemHeldEvent event) { public void onPlayerSlotChange(final PlayerItemHeldEvent event) {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final int slot = event.getNewSlot() + 1; final int slot = event.getNewSlot();
GeneralMethods.displayMovePreview(player, slot); GeneralMethods.displayMovePreview(player, slot);
if (!ConfigManager.getConfig(GeneralPropertiesConfig.class).BendingPreview) { if (!ConfigManager.getConfig(GeneralPropertiesConfig.class).BendingPreview) {
final WaterArms waterArms = CoreAbility.getAbility(player, WaterArms.class); final WaterArms waterArms = CoreAbility.getAbility(player, WaterArms.class);
if (waterArms != null) { if (waterArms != null) {
waterArms.displayBoundMsg(event.getNewSlot() + 1); waterArms.displayBoundMsg(event.getNewSlot());
return; return;
} }
} }

View file

@ -216,7 +216,7 @@ public class MultiAbilityManager {
} }
} }
if (lastNonNull > -1) { if (lastNonNull > -1) {
GeneralMethods.saveAbility(bPlayer, lastNonNull + 1, prevBinds[lastNonNull]); GeneralMethods.saveAbility(bPlayer, lastNonNull, prevBinds[lastNonNull]);
} }
if (player.isOnline()) { if (player.isOnline()) {

View file

@ -124,7 +124,7 @@ public class BindCommand extends PKCommand<BindCommandConfig> {
} }
final String name = coreAbil != null ? coreAbil.getName() : null; final String name = coreAbil != null ? coreAbil.getName() : null;
GeneralMethods.bindAbility((Player) sender, name, slot); GeneralMethods.bindAbility((Player) sender, name, slot - 1);
} }
@Override @Override

View file

@ -50,7 +50,7 @@ public class ClearCommand extends PKCommand<ClearCommandConfig> {
} }
if (args.size() == 0) { if (args.size() == 0) {
Arrays.fill(bPlayer.getAbilities(), null); 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.saveAbility(bPlayer, i, null);
} }
GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.cleared); GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.cleared);
@ -62,7 +62,7 @@ public class ClearCommand extends PKCommand<ClearCommandConfig> {
} }
if (bPlayer.getAbilities()[slot - 1] != null) { if (bPlayer.getAbilities()[slot - 1] != null) {
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))); GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.clearedSlot.replace("{slot}", String.valueOf(slot)));
} else { } else {
GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.alreadyEmpty); GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.alreadyEmpty);

View file

@ -222,9 +222,7 @@ public class PresetCommand extends PKCommand<PresetCommandConfig> {
return; return;
} }
String[] abilities = new String[9]; String[] abilities = new String[9];
for (int slot = 0; slot < 9; slot++) { System.arraycopy(bPlayer.getAbilities(), 0, abilities, 0, bPlayer.getAbilities().length);
abilities[slot] = bPlayer.getAbilities()[slot];
}
final Preset preset = new Preset(player.getUniqueId(), name, abilities); final Preset preset = new Preset(player.getUniqueId(), name, abilities);
preset.save(player); preset.save(player);

View file

@ -314,13 +314,13 @@ public class WhoCommand extends PKCommand<WhoCommandConfig> {
final UUID uuid = player.getUniqueId(); final UUID uuid = player.getUniqueId();
if (bPlayer != null) { if (bPlayer != null) {
sender.sendMessage("Abilities: "); sender.sendMessage("Abilities: ");
for (int i = 1; i <= 9; i++) { for (int i = 0; i < 9; i++) {
final String ability = bPlayer.getAbilities()[i - 1]; final String ability = bPlayer.getAbilities()[i];
final CoreAbility coreAbil = CoreAbility.getAbility(ability); final CoreAbility coreAbil = CoreAbility.getAbility(ability);
if (coreAbil == null) { if (coreAbil == null) {
continue; continue;
} else { } else {
sender.sendMessage(i + " - " + coreAbil.getElement().getColor() + ability); sender.sendMessage((i + 1) + " - " + coreAbil.getElement().getColor() + ability);
} }
} }
} }

View file

@ -470,7 +470,7 @@ public class WaterArms extends WaterAbility<WaterArmsConfig> {
} }
public void displayBoundMsg(final int slot) { public void displayBoundMsg(final int slot) {
final String name = this.bPlayer.getAbilities()[slot - 1]; final String name = this.bPlayer.getAbilities()[slot];
if (name != null) { if (name != null) {
this.player.sendMessage(this.getElement().getColor() + this.sneakMsg + " " + name); this.player.sendMessage(this.getElement().getColor() + this.sneakMsg + " " + name);
} }