diff --git a/src/com/projectkorra/projectkorra/ability/Ability.java b/src/com/projectkorra/projectkorra/ability/Ability.java index a4835a53..bd710f85 100644 --- a/src/com/projectkorra/projectkorra/ability/Ability.java +++ b/src/com/projectkorra/projectkorra/ability/Ability.java @@ -1,6 +1,5 @@ package com.projectkorra.projectkorra.ability; -import com.projectkorra.projectkorra.BendingPlayer; import com.projectkorra.projectkorra.Manager; import com.projectkorra.projectkorra.ability.info.AbilityInfo; import com.projectkorra.projectkorra.ability.util.Collision; @@ -13,6 +12,8 @@ import com.projectkorra.projectkorra.configuration.configs.abilities.AbilityConf import com.projectkorra.projectkorra.event.AbilityEndEvent; import com.projectkorra.projectkorra.event.AbilityStartEvent; import com.projectkorra.projectkorra.module.ModuleManager; +import com.projectkorra.projectkorra.player.BendingPlayer; +import com.projectkorra.projectkorra.player.BendingPlayerManager; import com.projectkorra.projectkorra.util.FlightHandler; import org.apache.commons.lang3.Validate; import org.apache.commons.lang3.builder.ToStringBuilder; @@ -51,12 +52,13 @@ public abstract class Ability) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0])); protected Player player; - protected BendingPlayer bPlayer; + protected BendingPlayer bendingPlayer; protected FlightHandler flightHandler; private final Map>>> attributeModifiers = new HashMap<>(); @@ -110,7 +112,7 @@ public abstract class Ability { }); } - public boolean bindAbility(Player player, String abilityName, int slot) { - PlayerBindAbilityEvent playerBindAbilityEvent = new PlayerBindAbilityEvent(player, abilityName); - getPlugin().getServer().getPluginManager().callEvent(playerBindAbilityEvent); - - if (playerBindAbilityEvent.isCancelled()) { - String cancelMessage = playerBindAbilityEvent.getCancelMessage(); - - if (cancelMessage != null) { - GeneralMethods.sendBrandingMessage(player, cancelMessage); - } - - return false; - } - + public Result bindAbility(Player player, String abilityName, int slot) { BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player); + PlayerBindChangeEvent playerBindChangeEvent = new PlayerBindChangeEvent(player, abilityName, slot, PlayerBindChangeEvent.Reason.ADD); + getPlugin().getServer().getPluginManager().callEvent(playerBindChangeEvent); + + if (playerBindChangeEvent.isCancelled()) { + return Result.CANCELLED; + } + bendingPlayer.setAbility(slot, abilityName); runAsync(() -> { @@ -75,17 +70,22 @@ public class AbilityBindManager extends DatabaseModule { } }); - return true; + return Result.SUCCESS; } - public boolean unbindAbility(Player player, int slot) { + public Result unbindAbility(Player player, int slot) { BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player); - String abilityName = bendingPlayer.getAbility(slot); if (abilityName == null) { - player.sendMessage("No ability bound"); - return false; + return Result.ALREADY_EMPTY; + } + + PlayerBindChangeEvent playerBindChangeEvent = new PlayerBindChangeEvent(player, abilityName, slot, PlayerBindChangeEvent.Reason.REMOVE); + getPlugin().getServer().getPluginManager().callEvent(playerBindChangeEvent); + + if (playerBindChangeEvent.isCancelled()) { + return Result.CANCELLED; } bendingPlayer.setAbility(slot, null); @@ -98,12 +98,19 @@ public class AbilityBindManager extends DatabaseModule { } }); - return true; + return Result.SUCCESS; } - public void clearBinds(Player player) { + public Result clearBinds(Player player) { BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player); + PlayerBindChangeEvent playerBindChangeEvent = new PlayerBindChangeEvent(player, PlayerBindChangeEvent.Reason.REMOVE); + getPlugin().getServer().getPluginManager().callEvent(playerBindChangeEvent); + + if (playerBindChangeEvent.isCancelled()) { + return Result.CANCELLED; + } + bendingPlayer.setAbilities(new String[9]); runAsync(() -> { @@ -113,5 +120,11 @@ public class AbilityBindManager extends DatabaseModule { e.printStackTrace(); } }); + + return Result.SUCCESS; + } + + public enum Result { + SUCCESS, CANCELLED, ALREADY_EMPTY } } diff --git a/src/com/projectkorra/projectkorra/airbending/passive/AirSaturation.java b/src/com/projectkorra/projectkorra/airbending/passive/AirSaturation.java index 8d87359c..8254f4f0 100644 --- a/src/com/projectkorra/projectkorra/airbending/passive/AirSaturation.java +++ b/src/com/projectkorra/projectkorra/airbending/passive/AirSaturation.java @@ -8,8 +8,8 @@ import org.bukkit.Location; import org.bukkit.entity.Player; public class AirSaturation extends AirAbility { - public AirSaturation(final AirSaturationConfig config, final Player player) { - super(config, player); + public AirSaturation(final Player player) { + super(player); } public static double getExhaustionFactor() { diff --git a/src/com/projectkorra/projectkorra/command/BindCommand.java b/src/com/projectkorra/projectkorra/command/BindCommand.java index 05bf0501..56bf6398 100644 --- a/src/com/projectkorra/projectkorra/command/BindCommand.java +++ b/src/com/projectkorra/projectkorra/command/BindCommand.java @@ -1,6 +1,7 @@ package com.projectkorra.projectkorra.command; import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.bind.AbilityBindManager; import com.projectkorra.projectkorra.ability.info.AbilityInfo; import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.configuration.configs.commands.BindCommandConfig; @@ -100,8 +101,9 @@ public class BindCommand extends PKCommand { GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.toggledElementOff); } - this.abilityBindManager.bindAbility(player, abilityInfo.getName(), slot); - 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, 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))); + } return; } diff --git a/src/com/projectkorra/projectkorra/command/ChooseCommand.java b/src/com/projectkorra/projectkorra/command/ChooseCommand.java index 425d5360..f8256f22 100644 --- a/src/com/projectkorra/projectkorra/command/ChooseCommand.java +++ b/src/com/projectkorra/projectkorra/command/ChooseCommand.java @@ -1,25 +1,24 @@ package com.projectkorra.projectkorra.command; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import com.projectkorra.projectkorra.BendingPlayer; -import com.projectkorra.projectkorra.Element; import com.projectkorra.projectkorra.GeneralMethods; import com.projectkorra.projectkorra.ProjectKorra; import com.projectkorra.projectkorra.configuration.ConfigManager; import com.projectkorra.projectkorra.configuration.configs.commands.ChooseCommandConfig; 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; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; /** * Executor for /bending choose. Extends {@link PKCommand}. @@ -57,94 +56,100 @@ public class ChooseCommand extends PKCommand { return; } - BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(sender.getName()); - if (bPlayer == null) { - GeneralMethods.createBendingPlayer(((Player) sender).getUniqueId(), sender.getName()); - bPlayer = BendingPlayer.getBendingPlayer(sender.getName()); - } - if (bPlayer.isPermaRemoved()) { + Player player = (Player) sender; + BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player); + + if (bendingPlayer.isBendingPermanentlyRemoved()) { GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + ConfigManager.getConfig(CommandPropertiesConfig.class).BendingPermanentlyRemoved); return; } - if (!bPlayer.getElements().isEmpty() && !sender.hasPermission("bending.command.rechoose")) { + + if (!bendingPlayer.getElements().isEmpty() && !sender.hasPermission("bending.command.rechoose")) { GeneralMethods.sendBrandingMessage(sender, super.noPermissionMessage); return; } - String element = args.get(0).toLowerCase(); - if (element.equalsIgnoreCase("a")) { - element = "air"; - } else if (element.equalsIgnoreCase("e")) { - element = "earth"; - } else if (element.equalsIgnoreCase("f")) { - element = "fire"; - } else if (element.equalsIgnoreCase("w")) { - element = "water"; - } else if (element.equalsIgnoreCase("c")) { - element = "chi"; + + String elementName = args.get(0).toLowerCase(); + + if (elementName.equalsIgnoreCase("a")) { + elementName = "air"; + } else if (elementName.equalsIgnoreCase("e")) { + elementName = "earth"; + } else if (elementName.equalsIgnoreCase("f")) { + elementName = "fire"; + } else if (elementName.equalsIgnoreCase("w")) { + elementName = "water"; + } else if (elementName.equalsIgnoreCase("c")) { + elementName = "chi"; } - final Element targetElement = Element.getElement(element); - if (Arrays.asList(Element.getAllElements()).contains(targetElement)) { - if (!this.hasPermission(sender, element)) { - return; - } - if (bPlayer.isOnCooldown("ChooseElement")) { - if (sender.hasPermission("bending.choose.ignorecooldown") || sender.hasPermission("bending.admin.choose")) { - bPlayer.removeCooldown("ChooseElement"); - } else { - GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.onCooldown.replace("%cooldown%", TimeUtil.formatTime(bPlayer.getCooldown("ChooseElement") - System.currentTimeMillis()))); - return; - } - } - this.add(sender, (Player) sender, targetElement); + final Element element = this.elementManager.getElement(elementName); - if (sender.hasPermission("bending.choose.ignorecooldown") || sender.hasPermission("bending.admin.choose")) { - return; - } - - bPlayer.addCooldown("ChooseElement", this.cooldown, true); - return; - } else { + if (element == null) { GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.invalidElement); return; } + + if (!this.hasPermission(sender, elementName)) { + return; + } + if (bendingPlayer.isOnCooldown("ChooseElement")) { + if (sender.hasPermission("bending.choose.ignorecooldown") || sender.hasPermission("bending.admin.choose")) { + bendingPlayer.removeCooldown("ChooseElement"); + } else { + GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.onCooldown.replace("%cooldown%", TimeUtil.formatTime(bendingPlayer.getCooldown("ChooseElement") - System.currentTimeMillis()))); + return; + } + } + + this.add(sender, (Player) sender, element); + + if (sender.hasPermission("bending.choose.ignorecooldown") || sender.hasPermission("bending.admin.choose")) { + return; + } + + bendingPlayer.addCooldown("ChooseElement", this.cooldown, true); } else if (args.size() == 2) { if (!sender.hasPermission("bending.admin.choose")) { GeneralMethods.sendBrandingMessage(sender, super.noPermissionMessage); return; } - final Player target = ProjectKorra.plugin.getServer().getPlayer(args.get(1)); - if (target == null || !target.isOnline()) { + + final Player player = ProjectKorra.plugin.getServer().getPlayer(args.get(1)); + + if (player == null || !player.isOnline()) { GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.playerNotFound); return; } - String element = args.get(0).toLowerCase(); - if (element.equalsIgnoreCase("a")) { - element = "air"; - } else if (element.equalsIgnoreCase("e")) { - element = "earth"; - } else if (element.equalsIgnoreCase("f")) { - element = "fire"; - } else if (element.equalsIgnoreCase("w")) { - element = "water"; - } else if (element.equalsIgnoreCase("c")) { - element = "chi"; + + String elementName = args.get(0).toLowerCase(); + if (elementName.equalsIgnoreCase("a")) { + elementName = "air"; + } else if (elementName.equalsIgnoreCase("e")) { + elementName = "earth"; + } else if (elementName.equalsIgnoreCase("f")) { + elementName = "fire"; + } else if (elementName.equalsIgnoreCase("w")) { + elementName = "water"; + } else if (elementName.equalsIgnoreCase("c")) { + elementName = "chi"; } - final Element targetElement = Element.getElement(element); - if (Arrays.asList(Element.getAllElements()).contains(targetElement) && targetElement != Element.AVATAR) { - this.add(sender, target, targetElement); - if (target.hasPermission("bending.choose.ignorecooldown") || target.hasPermission("bending.admin.choose")) { - return; - } + final Element element = this.elementManager.getElement(elementName); - final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(target); - bPlayer.addCooldown("ChooseElement", this.cooldown, true); - - return; - } else { + if (element == null || element.equals(this.elementManager.getAvatar())) { GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.invalidElement); + return; } + + this.add(sender, player, element); + + if (player.hasPermission("bending.choose.ignorecooldown") || player.hasPermission("bending.admin.choose")) { + return; + } + + final BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player); + bendingPlayer.addCooldown("ChooseElement", this.cooldown, true); } } @@ -152,56 +157,51 @@ public class ChooseCommand extends PKCommand { * Adds the ability to bend the given element to the specified Player. * * @param sender The CommandSender who issued the command - * @param target The Player to add the element to + * @param player The Player to add the element to * @param element The element to add to the Player */ - private void add(final CommandSender sender, final Player target, final Element element) { - final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(target); + private void add(final CommandSender sender, final Player player, final Element element) { + final BendingPlayer bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player); - if (bPlayer == null) { + if (bendingPlayer == null) { return; } - - bPlayer.setElement(element); + + this.elementManager.setElement(player, element); final ChatColor color = element != null ? element.getColor() : ChatColor.WHITE; boolean vowel = GeneralMethods.isVowel(ChatColor.stripColor(element.getName()).charAt(0)); - if (!(sender instanceof Player) || !((Player) sender).equals(target)) { + if (!(sender instanceof Player) || !(sender).equals(player)) { if (vowel) { - GeneralMethods.sendBrandingMessage(sender, color + this.chosenOtherVowel.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", element.getName() + element.getType().getBender())); + GeneralMethods.sendBrandingMessage(sender, color + this.chosenOtherVowel.replace("{target}", ChatColor.DARK_AQUA + player.getName() + color).replace("{element}", element.getName() + element.getType().getBender())); } else { - GeneralMethods.sendBrandingMessage(sender, color + this.chosenOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", element.getName() + element.getType().getBender())); + GeneralMethods.sendBrandingMessage(sender, color + this.chosenOther.replace("{target}", ChatColor.DARK_AQUA + player.getName() + color).replace("{element}", element.getName() + element.getType().getBender())); } } else { if (vowel) { - GeneralMethods.sendBrandingMessage(target, color + this.chosenVowel.replace("{element}", element.getName() + element.getType().getBender())); + GeneralMethods.sendBrandingMessage(player, color + this.chosenVowel.replace("{element}", element.getName() + element.getType().getBender())); } else { - GeneralMethods.sendBrandingMessage(target, color + this.chosen.replace("{element}", element.getName() + element.getType().getBender())); + GeneralMethods.sendBrandingMessage(player, color + this.chosen.replace("{element}", element.getName() + element.getType().getBender())); } } - GeneralMethods.saveElement(bPlayer, element); - Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, target, element, Result.CHOOSE)); - GeneralMethods.removeUnusableAbilities(target.getName()); + Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, player, element, Result.CHOOSE)); + GeneralMethods.removeUnusableAbilities(player.getName()); } @Override protected List getTabCompletion(final CommandSender sender, final List args) { if (args.size() >= 2 || !sender.hasPermission("bending.command.choose")) { - return new ArrayList(); + return new ArrayList<>(); } final List l = new ArrayList(); if (args.size() == 0) { - - l.add("Air"); - l.add("Earth"); - l.add("Fire"); - l.add("Water"); - l.add("Chi"); - for (final Element e : Element.getAddonElements()) { - l.add(e.getName()); + for (Element element : this.elementManager.getElements()) { + if (!(element instanceof SubElement)) { + l.add(element.getName()); + } } } else { for (final Player p : Bukkit.getOnlinePlayers()) { diff --git a/src/com/projectkorra/projectkorra/command/ClearCommand.java b/src/com/projectkorra/projectkorra/command/ClearCommand.java index 892a2ef8..bdd24ba5 100644 --- a/src/com/projectkorra/projectkorra/command/ClearCommand.java +++ b/src/com/projectkorra/projectkorra/command/ClearCommand.java @@ -1,17 +1,17 @@ package com.projectkorra.projectkorra.command; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - +import com.google.common.primitives.Ints; +import com.projectkorra.projectkorra.GeneralMethods; +import com.projectkorra.projectkorra.ability.bind.AbilityBindManager; +import com.projectkorra.projectkorra.configuration.configs.commands.ClearCommandConfig; +import com.projectkorra.projectkorra.player.BendingPlayer; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; -import com.projectkorra.projectkorra.BendingPlayer; -import com.projectkorra.projectkorra.GeneralMethods; -import com.projectkorra.projectkorra.ability.util.MultiAbilityManager; -import com.projectkorra.projectkorra.configuration.configs.commands.ClearCommandConfig; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; /** * Executor for /bending clear. Extends {@link PKCommand}. @@ -38,45 +38,43 @@ public class ClearCommand extends PKCommand { public void execute(final CommandSender sender, final List args) { if (!this.hasPermission(sender) || !this.correctLength(sender, args.size(), 0, 1) || !this.isPlayer(sender)) { return; - } else if (MultiAbilityManager.hasMultiAbilityBound((Player) sender)) { - GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.cantEditBinds); + } + + Player player = (Player) sender; + + if (args.isEmpty()) { + if (this.abilityBindManager.clearBinds(player) == AbilityBindManager.Result.SUCCESS) { + GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.cleared); + } + return; } - BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(sender.getName()); - if (bPlayer == null) { - GeneralMethods.createBendingPlayer(((Player) sender).getUniqueId(), sender.getName()); - bPlayer = BendingPlayer.getBendingPlayer(sender.getName()); + Integer slot = Ints.tryParse(args.get(0)); + + if (slot == null || slot < 1 || slot > 9) { + GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.wrongNumber); + return; } - if (args.size() == 0) { - Arrays.fill(bPlayer.getAbilities(), null); - for (int i = 0; i < 9; i++) { - GeneralMethods.saveAbility(bPlayer, i, null); - } - GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.cleared); - } else if (args.size() == 1) { - try { - final int slot = Integer.parseInt(args.get(0)); - if (slot < 1 || slot > 9) { - GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.wrongNumber); - } - if (bPlayer.getAbilities()[slot - 1] != null) { - bPlayer.getAbilities()[slot - 1] = 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); - } - } catch (final NumberFormatException e) { - GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.wrongNumber); - } + + slot =- 1; + + AbilityBindManager.Result result = this.abilityBindManager.unbindAbility(player, slot); + + switch (result) { + case SUCCESS: + GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.clearedSlot.replace("{slot}", String.valueOf(slot))); + break; + case ALREADY_EMPTY: + GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.alreadyEmpty); + break; } } @Override protected List getTabCompletion(final CommandSender sender, final List args) { if (args.size() >= 1 || !sender.hasPermission("bending.command.clear")) { - return new ArrayList(); + return new ArrayList<>(); } return Arrays.asList("123456789".split("")); } diff --git a/src/com/projectkorra/projectkorra/player/BendingPlayer.java b/src/com/projectkorra/projectkorra/player/BendingPlayer.java index a63ffb9d..76a64468 100644 --- a/src/com/projectkorra/projectkorra/player/BendingPlayer.java +++ b/src/com/projectkorra/projectkorra/player/BendingPlayer.java @@ -37,7 +37,7 @@ public class BendingPlayer { private final String[] abilities; private ChiAbility stance; - private boolean bendingRemoved; + private boolean bendingPermanentlyRemoved; private boolean toggled; private boolean tremorSense; private boolean illumination; @@ -188,6 +188,14 @@ public class BendingPlayer { this.abilities[slot] = abilityName; } + public long getCooldown(Ability ability) { + return getCooldown(ability.getName()); + } + + public long getCooldown(String abilityName) { + return this.cooldownManager.getCooldown(this.player, abilityName); + } + public void addCooldown(Ability ability) { addCooldown(ability, ability.getCooldown()); } @@ -217,10 +225,10 @@ public class BendingPlayer { } public void removeCooldown(Ability ability) { - removeCoolldown(ability.getName()); + removeCooldown(ability.getName()); } - public void removeCoolldown(String abilityName) { + public void removeCooldown(String abilityName) { this.cooldownManager.removeCooldown(this.player, abilityName); } @@ -252,12 +260,12 @@ public class BendingPlayer { this.stance = stance; } - public boolean isBendingRemoved() { - return this.bendingRemoved; + public boolean isBendingPermanentlyRemoved() { + return this.bendingPermanentlyRemoved; } - protected void setBendingRemoved(boolean bendingRemoved) { - this.bendingRemoved = bendingRemoved; + protected void setBendingPermanentlyRemoved(boolean bendingPermanentlyRemoved) { + this.bendingPermanentlyRemoved = bendingPermanentlyRemoved; } public boolean isToggled() { diff --git a/src/com/projectkorra/projectkorra/player/BendingPlayerRepository.java b/src/com/projectkorra/projectkorra/player/BendingPlayerRepository.java index e59ac602..46ba2516 100644 --- a/src/com/projectkorra/projectkorra/player/BendingPlayerRepository.java +++ b/src/com/projectkorra/projectkorra/player/BendingPlayerRepository.java @@ -11,8 +11,8 @@ import java.util.UUID; public class BendingPlayerRepository extends DatabaseRepository { private static final DatabaseQuery CREATE_TABLE_BENDING_PLAYERS = DatabaseQuery.newBuilder() - .mysql("CREATE TABLE IF NOT EXISTS pk_bending_players (player_id INTEGER PRIMARY KEY AUTO_INCREMENT, uuid BINARY(16) NOT NULL, player_name VARCHAR(16) NOT NULL, first_login BIGINT NOT NULL, bending_removed BOOLEAN, INDEX uuid_index (uuid));") - .sqlite("CREATE TABLE IF NOT EXISTS pk_bending_players (player_id INTEGER PRIMARY KEY AUTOINCREMENT, uuid BINARY(16) NOT NULL, player_name VARCHAR(16) NOT NULL, first_login BIGINT NOT NULL, bending_removed BOOLEAN); CREATE INDEX uuid_index ON pk_bending_players (uuid);") + .mysql("CREATE TABLE IF NOT EXISTS pk_bending_players (player_id INTEGER PRIMARY KEY AUTO_INCREMENT, uuid BINARY(16) NOT NULL, player_name VARCHAR(16) NOT NULL, first_login BIGINT NOT NULL, bending_permanently_removed BOOLEAN, INDEX uuid_index (uuid));") + .sqlite("CREATE TABLE IF NOT EXISTS pk_bending_players (player_id INTEGER PRIMARY KEY AUTOINCREMENT, uuid BINARY(16) NOT NULL, player_name VARCHAR(16) NOT NULL, first_login BIGINT NOT NULL, bending_permanently_removed BOOLEAN); CREATE INDEX uuid_index ON pk_bending_players (uuid);") .build(); private static final DatabaseQuery SELECT_BENDING_PLAYER = DatabaseQuery.newBuilder() @@ -27,8 +27,8 @@ public class BendingPlayerRepository extends DatabaseRepository { .query("UPDATE pk_bending_players SET player_name = ? WHERE player_id = ?;") .build(); - private static final DatabaseQuery UPDATE_BENDING_REMOVED = DatabaseQuery.newBuilder() - .query("UPDATE pk_bending_players SET bending_removed = ? WHERE player_id = ?;") + private static final DatabaseQuery UPDATE_BENDING_PERMANENTLY_REMOVED = DatabaseQuery.newBuilder() + .query("UPDATE pk_bending_players SET bending_permanently_removed = ? WHERE player_id = ?;") .build(); protected void createTables() throws SQLException { @@ -56,7 +56,7 @@ public class BendingPlayerRepository extends DatabaseRepository { int playerId = rs.getInt("player_id"); String playerName = rs.getString("player_name"); long firstLogin = rs.getLong("first_login"); - boolean bendingRemoved = rs.getBoolean("bending_removed"); + boolean bendingPermanentlyRemoved = rs.getBoolean("bending_permanently_removed"); if (!player.getName().equals(playerName)) { updatePlayerName(playerId, player.getName()); @@ -64,7 +64,7 @@ public class BendingPlayerRepository extends DatabaseRepository { BendingPlayer bendingPlayer = new BendingPlayer(playerId, uuid, playerName, firstLogin); - bendingPlayer.setBendingRemoved(bendingRemoved); + bendingPlayer.setBendingPermanentlyRemoved(bendingPermanentlyRemoved); return bendingPlayer; } @@ -108,9 +108,9 @@ public class BendingPlayerRepository extends DatabaseRepository { protected void updateBendingRemoved(BendingPlayer bendingPlayer) throws SQLException { Connection connection = getDatabase().getConnection(); - try (PreparedStatement statement = connection.prepareStatement(UPDATE_BENDING_REMOVED.getQuery())) { + try (PreparedStatement statement = connection.prepareStatement(UPDATE_BENDING_PERMANENTLY_REMOVED.getQuery())) { statement.setInt(1, bendingPlayer.getId()); - statement.setBoolean(2, bendingPlayer.isBendingRemoved()); + statement.setBoolean(2, bendingPlayer.isBendingPermanentlyRemoved()); statement.executeUpdate(); }