Updated Choose and Clear commands

This commit is contained in:
jayoevans 2019-10-29 15:18:00 +10:00
parent 9c15e20924
commit ad72ad026c
10 changed files with 228 additions and 195 deletions

View file

@ -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<Info extends AbilityInfo, Config extends AbilityCo
private static int idCounter;
protected final BendingPlayerManager bendingPlayerManager = ModuleManager.getModule(BendingPlayerManager.class);
protected final AbilityManager manager = ModuleManager.getModule(AbilityManager.class);
protected final Info info = (Info) this.manager.getAbilityInfo(getClass());
protected final Config config = ConfigManager.getConfig(((Class<Config>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]));
protected Player player;
protected BendingPlayer bPlayer;
protected BendingPlayer bendingPlayer;
protected FlightHandler flightHandler;
private final Map<String, Map<AttributePriority, Set<Pair<Number, AttributeModifier>>>> attributeModifiers = new HashMap<>();
@ -110,7 +112,7 @@ public abstract class Ability<Info extends AbilityInfo, Config extends AbilityCo
}
this.player = player;
this.bPlayer = BendingPlayer.getBendingPlayer(player);
this.bendingPlayer = this.bendingPlayerManager.getBendingPlayer(player);
this.flightHandler = Manager.getManager(FlightHandler.class);
this.startTime = System.currentTimeMillis();
this.started = false;
@ -201,7 +203,7 @@ public abstract class Ability<Info extends AbilityInfo, Config extends AbilityCo
}
public BendingPlayer getBendingPlayer() {
return this.bPlayer;
return this.bendingPlayer;
}
public int getId() {

View file

@ -1,6 +1,7 @@
package com.projectkorra.projectkorra.ability;
import com.projectkorra.projectkorra.ability.api.PlayerBindAbilityEvent;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ability.api.PlayerBindChangeEvent;
import com.projectkorra.projectkorra.ability.info.AbilityInfo;
import com.projectkorra.projectkorra.ability.info.MultiAbilityInfo;
import com.projectkorra.projectkorra.event.AbilityEndEvent;
@ -128,13 +129,13 @@ public class MultiAbilityManager extends Module {
}
@EventHandler
public void onPlayerBindAbility(PlayerBindAbilityEvent event) {
public void onPlayerBindAbility(PlayerBindChangeEvent event) {
if (!this.playerAbilities.containsKey(event.getPlayer().getUniqueId())) {
return;
}
event.setCancelled(true);
event.setCancelMessage(ChatColor.RED + "You can't edit your binds right now!");
GeneralMethods.sendBrandingMessage(event.getPlayer(), ChatColor.RED + "You can't edit your binds right now!");
}
public class MultiAbility {

View file

@ -5,20 +5,27 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
public class PlayerBindAbilityEvent extends PlayerEvent implements Cancellable
public class PlayerBindChangeEvent extends PlayerEvent implements Cancellable
{
private static final HandlerList HANDLER_LIST = new HandlerList();
private final String abilityName;
private final int slot;
private final Reason reason;
private boolean cancelled;
private String cancelMessage;
public PlayerBindAbilityEvent(Player player, String abilityName)
public PlayerBindChangeEvent(Player player, Reason reason) {
this(player, null, -1, reason);
}
public PlayerBindChangeEvent(Player player, String abilityName, int slot, Reason reason)
{
super(player);
this.abilityName = abilityName;
this.slot = slot;
this.reason = reason;
}
public String getAbilityName()
@ -26,6 +33,14 @@ public class PlayerBindAbilityEvent extends PlayerEvent implements Cancellable
return this.abilityName;
}
public int getSlot() {
return this.slot;
}
public Reason getReason() {
return this.reason;
}
@Override
public boolean isCancelled()
{
@ -38,16 +53,6 @@ public class PlayerBindAbilityEvent extends PlayerEvent implements Cancellable
this.cancelled = cancelled;
}
public String getCancelMessage()
{
return this.cancelMessage;
}
public void setCancelMessage(String cancelMessage)
{
this.cancelMessage = cancelMessage;
}
@Override
public HandlerList getHandlers()
{
@ -58,4 +63,8 @@ public class PlayerBindAbilityEvent extends PlayerEvent implements Cancellable
{
return HANDLER_LIST;
}
public enum Reason {
ADD, REMOVE, CLEAR
}
}

View file

@ -1,7 +1,8 @@
package com.projectkorra.projectkorra.ability.bind;
import com.projectkorra.projectkorra.GeneralMethods;
import com.projectkorra.projectkorra.ability.api.PlayerBindAbilityEvent;
import com.projectkorra.projectkorra.ability.api.PlayerBindChangeEvent;
import com.projectkorra.projectkorra.event.PlayerCooldownChangeEvent;
import com.projectkorra.projectkorra.module.DatabaseModule;
import com.projectkorra.projectkorra.module.ModuleManager;
import com.projectkorra.projectkorra.player.BendingPlayer;
@ -49,22 +50,16 @@ public class AbilityBindManager extends DatabaseModule<AbilityBindRepository> {
});
}
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<AbilityBindRepository> {
}
});
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<AbilityBindRepository> {
}
});
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<AbilityBindRepository> {
e.printStackTrace();
}
});
return Result.SUCCESS;
}
public enum Result {
SUCCESS, CANCELLED, ALREADY_EMPTY
}
}

View file

@ -8,8 +8,8 @@ import org.bukkit.Location;
import org.bukkit.entity.Player;
public class AirSaturation extends AirAbility<AirSaturationInfo, AirSaturationConfig> {
public AirSaturation(final AirSaturationConfig config, final Player player) {
super(config, player);
public AirSaturation(final Player player) {
super(player);
}
public static double getExhaustionFactor() {

View file

@ -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<BindCommandConfig> {
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.toggledElementOff);
}
this.abilityBindManager.bindAbility(player, abilityInfo.getName(), slot);
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;
}

View file

@ -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<ChooseCommandConfig> {
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";
}
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;
}
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";
}
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";
}
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;
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 BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(target);
bPlayer.addCooldown("ChooseElement", this.cooldown, true);
final Element element = this.elementManager.getElement(elementName);
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<ChooseCommandConfig> {
* 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<String> getTabCompletion(final CommandSender sender, final List<String> args) {
if (args.size() >= 2 || !sender.hasPermission("bending.command.choose")) {
return new ArrayList<String>();
return new ArrayList<>();
}
final List<String> l = new ArrayList<String>();
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()) {

View file

@ -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<ClearCommandConfig> {
public void execute(final CommandSender sender, final List<String> 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());
}
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) {
Integer slot = Ints.tryParse(args.get(0));
if (slot == null || slot < 1 || slot > 9) {
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.wrongNumber);
return;
}
if (bPlayer.getAbilities()[slot - 1] != null) {
bPlayer.getAbilities()[slot - 1] = null;
GeneralMethods.saveAbility(bPlayer, slot - 1, null);
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)));
} else {
break;
case ALREADY_EMPTY:
GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.alreadyEmpty);
}
} catch (final NumberFormatException e) {
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.wrongNumber);
}
break;
}
}
@Override
protected List<String> getTabCompletion(final CommandSender sender, final List<String> args) {
if (args.size() >= 1 || !sender.hasPermission("bending.command.clear")) {
return new ArrayList<String>();
return new ArrayList<>();
}
return Arrays.asList("123456789".split(""));
}

View file

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

View file

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