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)
*/
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<Element> e) {

View file

@ -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;
}
}

View file

@ -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()) {

View file

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

View file

@ -50,7 +50,7 @@ public class ClearCommand extends PKCommand<ClearCommandConfig> {
}
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<ClearCommandConfig> {
}
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);

View file

@ -222,9 +222,7 @@ public class PresetCommand extends PKCommand<PresetCommandConfig> {
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);

View file

@ -314,13 +314,13 @@ public class WhoCommand extends PKCommand<WhoCommandConfig> {
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);
}
}
}

View file

@ -470,7 +470,7 @@ public class WaterArms extends WaterAbility<WaterArmsConfig> {
}
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);
}