mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-02-11 03:30:10 +00:00
Improve element/subelement storing and loading and improve in-memory storage of bound slots
This commit is contained in:
parent
9661611945
commit
6e07e3b4d9
21 changed files with 346 additions and 532 deletions
|
@ -2,8 +2,7 @@ package com.projectkorra.projectkorra;
|
|||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -61,9 +60,9 @@ public class BendingPlayer {
|
|||
private final String name;
|
||||
private ChiAbility stance;
|
||||
private final DBCooldownManager cooldownManager;
|
||||
private final ArrayList<Element> elements;
|
||||
private final ArrayList<SubElement> subelements;
|
||||
private HashMap<Integer, String> abilities;
|
||||
private final List<Element> elements;
|
||||
private final List<SubElement> subelements;
|
||||
private final String[] abilities;
|
||||
private final Map<String, Cooldown> cooldowns;
|
||||
private final Map<Element, Boolean> toggledElements;
|
||||
|
||||
|
@ -76,12 +75,13 @@ public class BendingPlayer {
|
|||
* @param abilities The known abilities
|
||||
* @param permaRemoved The permanent removed status
|
||||
*/
|
||||
public BendingPlayer(final UUID uuid, final String playerName, final ArrayList<Element> elements, final ArrayList<SubElement> subelements, final HashMap<Integer, String> abilities, final boolean permaRemoved) {
|
||||
public BendingPlayer(final UUID uuid, final String playerName, final List<Element> elements, final List<SubElement> subelements, final String[] abilities, final boolean permaRemoved) {
|
||||
this.uuid = uuid;
|
||||
this.name = playerName;
|
||||
this.cooldownManager = Manager.getManager(DBCooldownManager.class);
|
||||
this.elements = elements;
|
||||
this.subelements = subelements;
|
||||
this.abilities = new String[9];
|
||||
this.setAbilities(abilities);
|
||||
this.permaRemoved = permaRemoved;
|
||||
this.player = Bukkit.getPlayer(uuid);
|
||||
|
@ -493,7 +493,7 @@ public class BendingPlayer {
|
|||
*
|
||||
* @return map of abilities
|
||||
*/
|
||||
public HashMap<Integer, String> getAbilities() {
|
||||
public String[] getAbilities() {
|
||||
return this.abilities;
|
||||
}
|
||||
|
||||
|
@ -545,8 +545,8 @@ public class BendingPlayer {
|
|||
* @return The Ability name bounded to the slot
|
||||
*/
|
||||
public String getBoundAbilityName() {
|
||||
final int slot = this.player.getInventory().getHeldItemSlot() + 1;
|
||||
final String name = this.getAbilities().get(slot);
|
||||
final int slot = this.player.getInventory().getHeldItemSlot();
|
||||
final String name = this.getAbilities()[slot];
|
||||
|
||||
return name != null ? name : "";
|
||||
}
|
||||
|
@ -823,11 +823,14 @@ public class BendingPlayer {
|
|||
*
|
||||
* @param abilities The abilities to set/save
|
||||
*/
|
||||
public void setAbilities(final HashMap<Integer, String> abilities) {
|
||||
this.abilities = abilities;
|
||||
public void setAbilities(final String[] abilities) {
|
||||
if (abilities.length < this.abilities.length) {
|
||||
Arrays.fill(abilities, null);
|
||||
}
|
||||
System.arraycopy(abilities, 0, this.abilities, 0, abilities.length);
|
||||
|
||||
for (int i = 1; i <= 9; i++) {
|
||||
DBConnection.sql.modifyQuery("UPDATE pk_players SET slot" + i + " = '" + abilities.get(i) + "' WHERE uuid = '" + this.uuid + "'");
|
||||
for (int i = 0; i < 9; i++) {
|
||||
DBConnection.sql.modifyQuery("UPDATE pk_players SET slot" + (i + 1) + " = '" + this.abilities[i] + "' WHERE uuid = '" + this.uuid + "'");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
|
@ -41,7 +42,7 @@ public class Element {
|
|||
}
|
||||
}
|
||||
|
||||
private static final HashMap<String, Element> ALL_ELEMENTS = new HashMap<>(); // Must be initialized first.
|
||||
private static final Map<String, Element> ALL_ELEMENTS = new HashMap<>(); // Must be initialized first.
|
||||
|
||||
public static final Element AIR = new Element("Air", () -> ConfigManager.getConfig(ChatPropertiesConfig.class).AirPrefix, () -> ConfigManager.getConfig(ChatPropertiesConfig.class).AirColor, () -> ConfigManager.getConfig(ChatPropertiesConfig.class).AirSubColor);
|
||||
public static final Element WATER = new Element("Water", () -> ConfigManager.getConfig(ChatPropertiesConfig.class).WaterPrefix, () -> ConfigManager.getConfig(ChatPropertiesConfig.class).WaterColor, () -> ConfigManager.getConfig(ChatPropertiesConfig.class).WaterSubColor);
|
||||
|
|
|
@ -23,13 +23,11 @@ import java.util.Arrays;
|
|||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
|
@ -214,7 +212,7 @@ public class GeneralMethods {
|
|||
if (bPlayer == null) {
|
||||
return;
|
||||
}
|
||||
bPlayer.getAbilities().put(slot, ability);
|
||||
bPlayer.getAbilities()[slot - 1] = ability;
|
||||
|
||||
if (coreAbil != null) {
|
||||
GeneralMethods.sendBrandingMessage(player, coreAbil.getElement().getColor() + ConfigManager.getConfig(BindCommandConfig.class).SuccessfullyBoundMessage.replace("{ability}", ability).replace("{slot}", String.valueOf(slot)));
|
||||
|
@ -338,206 +336,61 @@ public class GeneralMethods {
|
|||
}
|
||||
|
||||
private static void createBendingPlayerAsynchronously(final UUID uuid, final String player) {
|
||||
final ResultSet rs2 = DBConnection.sql.readQuery("SELECT * FROM pk_players WHERE uuid = '" + uuid.toString() + "'");
|
||||
try {
|
||||
if (!rs2.next()) { // Data doesn't exist, we want a completely new player.
|
||||
try (ResultSet rs = DBConnection.sql.readQuery("SELECT * FROM pk_players WHERE uuid = '" + uuid.toString() + "'")) {
|
||||
if (!rs.next()) { // Data doesn't exist, we want a completely new player.
|
||||
DBConnection.sql.modifyQuery("INSERT INTO pk_players (uuid, player, slot1, slot2, slot3, slot4, slot5, slot6, slot7, slot8, slot9) VALUES ('" + uuid.toString() + "', '" + player + "', 'null', 'null', 'null', 'null', 'null', 'null', 'null', 'null', 'null')");
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new BendingPlayer(uuid, player, new ArrayList<Element>(), new ArrayList<SubElement>(), new HashMap<Integer, String>(), false);
|
||||
new BendingPlayer(uuid, player, new ArrayList<>(), new ArrayList<>(), new String[9], false);
|
||||
ProjectKorra.log.info("Created new BendingPlayer for " + player);
|
||||
}
|
||||
}.runTask(ProjectKorra.plugin);
|
||||
} else {
|
||||
// The player has at least played before.
|
||||
final String player2 = rs2.getString("player");
|
||||
final String player2 = rs.getString("player");
|
||||
if (!player.equalsIgnoreCase(player2)) {
|
||||
DBConnection.sql.modifyQuery("UPDATE pk_players SET player = '" + player + "' WHERE uuid = '" + uuid.toString() + "'");
|
||||
// They have changed names.
|
||||
ProjectKorra.log.info("Updating Player Name for " + player);
|
||||
}
|
||||
final String subelement = rs2.getString("subelement");
|
||||
final String element = rs2.getString("element");
|
||||
final String permaremoved = rs2.getString("permaremoved");
|
||||
boolean p = false;
|
||||
final ArrayList<Element> elements = new ArrayList<Element>();
|
||||
if (element != null && !element.equals("NULL")) {
|
||||
final boolean hasAddon = element.contains(";");
|
||||
final String[] split = element.split(";");
|
||||
if (split[0] != null) { // Player has an element.
|
||||
if (split[0].contains("a")) {
|
||||
elements.add(Element.AIR);
|
||||
}
|
||||
if (split[0].contains("w")) {
|
||||
elements.add(Element.WATER);
|
||||
}
|
||||
if (split[0].contains("e")) {
|
||||
elements.add(Element.EARTH);
|
||||
}
|
||||
if (split[0].contains("f")) {
|
||||
elements.add(Element.FIRE);
|
||||
}
|
||||
if (split[0].contains("c")) {
|
||||
elements.add(Element.CHI);
|
||||
}
|
||||
if (hasAddon) {
|
||||
/*
|
||||
* Because plugins which depend on ProjectKorra
|
||||
* would be loaded after ProjectKorra, addon
|
||||
* elements would = null. To work around this, we
|
||||
* keep trying to load in the elements from the
|
||||
* database until it successfully loads everything
|
||||
* in, or it times out.
|
||||
*/
|
||||
final CopyOnWriteArrayList<String> addonClone = new CopyOnWriteArrayList<String>(Arrays.asList(split[split.length - 1].split(",")));
|
||||
final long startTime = System.currentTimeMillis();
|
||||
final long timeoutLength = 30000; // How long until it should time out attempting to load addons in.
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (addonClone.isEmpty()) {
|
||||
ProjectKorra.log.info("Successfully loaded in all addon elements!");
|
||||
this.cancel();
|
||||
} else if (System.currentTimeMillis() - startTime > timeoutLength) {
|
||||
ProjectKorra.log.severe("ProjectKorra has timed out after attempting to load in the following addon elements: " + addonClone.toString());
|
||||
ProjectKorra.log.severe("These elements have taken too long to load in, resulting in users having lost these element.");
|
||||
this.cancel();
|
||||
} else {
|
||||
ProjectKorra.log.info("Attempting to load in the following addon elements... " + addonClone.toString());
|
||||
for (final String addon : addonClone) {
|
||||
if (Element.getElement(addon) != null) {
|
||||
elements.add(Element.getElement(addon));
|
||||
addonClone.remove(addon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(ProjectKorra.plugin, 0, 20);
|
||||
}
|
||||
final String permarem = rs.getString("permaremoved");
|
||||
boolean permaremoved = permarem != null && permarem.equals("true");
|
||||
final List<Element> elements = new ArrayList<>();
|
||||
final List<SubElement> subelements = new ArrayList<>();
|
||||
final String[] abilities = new String[9];
|
||||
|
||||
for (int i = 0; i < 9; i++) {
|
||||
final String ability = rs.getString("slot" + (i + 1));
|
||||
if (CoreAbility.getAbility(ability) != null && CoreAbility.getAbility(ability).isEnabled()) {
|
||||
abilities[i] = ability;
|
||||
}
|
||||
}
|
||||
final ArrayList<SubElement> subelements = new ArrayList<SubElement>();
|
||||
boolean shouldSave = false;
|
||||
if (subelement != null && !subelement.equals("NULL")) {
|
||||
final boolean hasAddon = subelement.contains(";");
|
||||
final String[] split = subelement.split(";");
|
||||
if (subelement.equals("-")) {
|
||||
final Player playero = Bukkit.getPlayer(uuid);
|
||||
for (final SubElement sub : Element.getAllSubElements()) {
|
||||
if ((playero != null && playero.hasPermission("bending." + sub.getParentElement().getName().toLowerCase() + "." + sub.getName().toLowerCase() + sub.getType().getBending())) && elements.contains(sub.getParentElement())) {
|
||||
subelements.add(sub);
|
||||
shouldSave = true && playero != null;
|
||||
}
|
||||
|
||||
try (ResultSet rs2 = DBConnection.sql.readQuery("SELECT * FROM pk_player_elements WHERE uuid = '" + uuid.toString() + "';")) {
|
||||
while (rs2.next()) {
|
||||
String elementName = rs2.getString("element");
|
||||
String subElement = rs2.getString("sub_element");
|
||||
boolean isSub = subElement != null && subElement.equals("true");
|
||||
|
||||
Element element = Element.fromString(elementName);
|
||||
|
||||
if (element == null) {
|
||||
continue;
|
||||
}
|
||||
} else if (split[0] != null) {
|
||||
if (split[0].contains("m")) {
|
||||
subelements.add(Element.METAL);
|
||||
}
|
||||
if (split[0].contains("v")) {
|
||||
subelements.add(Element.LAVA);
|
||||
}
|
||||
if (split[0].contains("s")) {
|
||||
subelements.add(Element.SAND);
|
||||
}
|
||||
if (split[0].contains("c")) {
|
||||
subelements.add(Element.COMBUSTION);
|
||||
}
|
||||
if (split[0].contains("l")) {
|
||||
subelements.add(Element.LIGHTNING);
|
||||
}
|
||||
if (split[0].contains("t")) {
|
||||
subelements.add(Element.SPIRITUAL);
|
||||
}
|
||||
if (split[0].contains("f")) {
|
||||
subelements.add(Element.FLIGHT);
|
||||
}
|
||||
if (split[0].contains("i")) {
|
||||
subelements.add(Element.ICE);
|
||||
}
|
||||
if (split[0].contains("h")) {
|
||||
subelements.add(Element.HEALING);
|
||||
}
|
||||
if (split[0].contains("b")) {
|
||||
subelements.add(Element.BLOOD);
|
||||
}
|
||||
if (split[0].contains("p")) {
|
||||
subelements.add(Element.PLANT);
|
||||
}
|
||||
if (hasAddon) {
|
||||
final CopyOnWriteArrayList<String> addonClone = new CopyOnWriteArrayList<String>(Arrays.asList(split[split.length - 1].split(",")));
|
||||
final long startTime = System.currentTimeMillis();
|
||||
final long timeoutLength = 30000; // How long until it should time out attempting to load addons in.
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (addonClone.isEmpty()) {
|
||||
ProjectKorra.log.info("Successfully loaded in all addon subelements!");
|
||||
this.cancel();
|
||||
} else if (System.currentTimeMillis() - startTime > timeoutLength) {
|
||||
ProjectKorra.log.severe("ProjectKorra has timed out after attempting to load in the following addon subelements: " + addonClone.toString());
|
||||
ProjectKorra.log.severe("These subelements have taken too long to load in, resulting in users having lost these subelement.");
|
||||
this.cancel();
|
||||
} else {
|
||||
ProjectKorra.log.info("Attempting to load in the following addon subelements... " + addonClone.toString());
|
||||
for (final String addon : addonClone) {
|
||||
if (Element.getElement(addon) != null && Element.getElement(addon) instanceof SubElement) {
|
||||
subelements.add((SubElement) Element.getElement(addon));
|
||||
addonClone.remove(addon);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(ProjectKorra.plugin, 0, 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final HashMap<Integer, String> abilities = new HashMap<Integer, String>();
|
||||
final ConcurrentHashMap<Integer, String> abilitiesClone = new ConcurrentHashMap<Integer, String>(abilities);
|
||||
for (int i = 1; i <= 9; i++) {
|
||||
final String ability = rs2.getString("slot" + i);
|
||||
abilitiesClone.put(i, ability);
|
||||
}
|
||||
final long startTime = System.currentTimeMillis();
|
||||
final long timeoutLength = 30000; // How long until it should time out attempting to load addons in.
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (abilitiesClone.isEmpty()) {
|
||||
// All abilities loaded.
|
||||
this.cancel();
|
||||
} else if (System.currentTimeMillis() - startTime > timeoutLength) {
|
||||
ProjectKorra.log.severe("ProjectKorra has timed out after attempting to load in the following external abilities: " + abilitiesClone.values().toString());
|
||||
ProjectKorra.log.severe("These abilities have taken too long to load in, resulting in users having lost them if bound.");
|
||||
this.cancel();
|
||||
|
||||
if (isSub) {
|
||||
subelements.add((SubElement)element);
|
||||
} else {
|
||||
for (final int slot : abilitiesClone.keySet()) {
|
||||
final String ability = abilitiesClone.get(slot);
|
||||
if (ability.equalsIgnoreCase("null")) {
|
||||
abilitiesClone.remove(slot);
|
||||
continue;
|
||||
} else if (CoreAbility.getAbility(ability) != null && CoreAbility.getAbility(ability).isEnabled()) {
|
||||
abilities.put(slot, ability);
|
||||
abilitiesClone.remove(slot);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
elements.add(element);
|
||||
}
|
||||
}
|
||||
}.runTaskTimer(ProjectKorra.plugin, 0, 20);
|
||||
}
|
||||
|
||||
p = (permaremoved != null && (permaremoved.equals("true")));
|
||||
|
||||
final boolean boolean_p = p;
|
||||
final boolean shouldSave_ = shouldSave;
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new BendingPlayer(uuid, player, elements, subelements, abilities, boolean_p);
|
||||
if (shouldSave_) {
|
||||
saveSubElements(BendingPlayer.getBendingPlayer(player));
|
||||
}
|
||||
new BendingPlayer(uuid, player, elements, subelements, abilities, permaremoved);
|
||||
}
|
||||
}.runTask(ProjectKorra.plugin);
|
||||
}
|
||||
|
@ -659,7 +512,7 @@ public class GeneralMethods {
|
|||
if (bPlayer == null) {
|
||||
return;
|
||||
}
|
||||
String displayedMessage = bPlayer.getAbilities().get(slot);
|
||||
String displayedMessage = bPlayer.getAbilities()[slot - 1];
|
||||
final CoreAbility ability = CoreAbility.getAbility(displayedMessage);
|
||||
|
||||
if (ability != null && bPlayer != null) {
|
||||
|
@ -1681,8 +1534,8 @@ public class GeneralMethods {
|
|||
|
||||
// Handle the AirSpout/WaterSpout login glitches.
|
||||
if (player.getGameMode() != GameMode.CREATIVE) {
|
||||
final HashMap<Integer, String> bound = bPlayer.getAbilities();
|
||||
for (final String str : bound.values()) {
|
||||
final String[] bound = bPlayer.getAbilities();
|
||||
for (final String str : bound) {
|
||||
if (str.equalsIgnoreCase("AirSpout") || str.equalsIgnoreCase("WaterSpout") || str.equalsIgnoreCase("SandSpout")) {
|
||||
final Player fplayer = player;
|
||||
new BukkitRunnable() {
|
||||
|
@ -1786,12 +1639,12 @@ public class GeneralMethods {
|
|||
}
|
||||
|
||||
// Remove all bound abilities that will become unusable.
|
||||
final HashMap<Integer, String> slots = bPlayer.getAbilities();
|
||||
final HashMap<Integer, String> finalAbilities = new HashMap<Integer, String>();
|
||||
for (final int i : slots.keySet()) {
|
||||
if (bPlayer.canBind(CoreAbility.getAbility(slots.get(i)))) {
|
||||
String[] currentAbilities = bPlayer.getAbilities();
|
||||
String[] finalAbilities = new String[9];
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (bPlayer.canBind(CoreAbility.getAbility(currentAbilities[i]))) {
|
||||
// The player will still be able to use this given Ability, do not remove it from their binds.
|
||||
finalAbilities.put(i, slots.get(i));
|
||||
finalAbilities[i] = currentAbilities[i];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1988,107 +1841,62 @@ public class GeneralMethods {
|
|||
if (MultiAbilityManager.playerAbilities.containsKey(Bukkit.getPlayer(bPlayer.getUUID()))) {
|
||||
return;
|
||||
}
|
||||
final HashMap<Integer, String> abilities = bPlayer.getAbilities();
|
||||
final String[] abilities = bPlayer.getAbilities();
|
||||
|
||||
DBConnection.sql.modifyQuery("UPDATE pk_players SET slot" + slot + " = '" + (abilities.get(slot) == null ? null : abilities.get(slot)) + "' WHERE uuid = '" + uuid + "'");
|
||||
DBConnection.sql.modifyQuery("UPDATE pk_players SET slot" + slot + " = '" + (abilities[slot - 1] == null ? null : abilities[slot - 1]) + "' WHERE uuid = '" + uuid + "'");
|
||||
}
|
||||
|
||||
public static void saveElements(final BendingPlayer bPlayer) {
|
||||
public static void saveElementsNew(final BendingPlayer bPlayer, List<Element> e) {
|
||||
if (bPlayer == null) {
|
||||
return;
|
||||
}
|
||||
final String uuid = bPlayer.getUUIDString();
|
||||
|
||||
final StringBuilder elements = new StringBuilder();
|
||||
if (bPlayer.hasElement(Element.AIR)) {
|
||||
elements.append("a");
|
||||
}
|
||||
if (bPlayer.hasElement(Element.WATER)) {
|
||||
elements.append("w");
|
||||
}
|
||||
if (bPlayer.hasElement(Element.EARTH)) {
|
||||
elements.append("e");
|
||||
}
|
||||
if (bPlayer.hasElement(Element.FIRE)) {
|
||||
elements.append("f");
|
||||
}
|
||||
if (bPlayer.hasElement(Element.CHI)) {
|
||||
elements.append("c");
|
||||
}
|
||||
boolean hasAddon = false;
|
||||
for (final Element element : bPlayer.getElements()) {
|
||||
if (Arrays.asList(Element.getAddonElements()).contains(element)) {
|
||||
if (!hasAddon) {
|
||||
hasAddon = true;
|
||||
elements.append(";");
|
||||
}
|
||||
elements.append(element.getName() + ",");
|
||||
}
|
||||
}
|
||||
|
||||
if (elements.length() == 0) {
|
||||
elements.append("NULL");
|
||||
}
|
||||
|
||||
DBConnection.sql.modifyQuery("UPDATE pk_players SET element = '" + elements.toString() + "' WHERE uuid = '" + uuid + "'");
|
||||
StringBuilder queryBuilder = new StringBuilder();
|
||||
e.forEach(element -> {
|
||||
queryBuilder.append("INSERT INTO pk_player_elements (uuid, element, sub_element) VALUES ('" + uuid + "', '" + element.getName().toLowerCase() + "', '" + String.valueOf(e instanceof SubElement) + "');");
|
||||
});
|
||||
final String query = queryBuilder.toString();
|
||||
|
||||
DBConnection.sql.modifyQuery(query);
|
||||
}
|
||||
|
||||
public static void saveSubElements(final BendingPlayer bPlayer) {
|
||||
|
||||
public static void saveElement(final BendingPlayer bPlayer, Element e) {
|
||||
if (bPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String uuid = bPlayer.getUUIDString();
|
||||
final String element = e.getName().toLowerCase();
|
||||
final boolean subElement = e instanceof SubElement;
|
||||
|
||||
DBConnection.sql.modifyQuery("INSERT INTO pk_player_elements (uuid, element, sub_element) VALUES ('" + uuid + "', '" + element + "', '" + String.valueOf(subElement) + "');");
|
||||
}
|
||||
|
||||
public static void deleteElements(final BendingPlayer bPlayer, List<Element> e) {
|
||||
if (bPlayer == null) {
|
||||
return;
|
||||
}
|
||||
final String uuid = bPlayer.getUUIDString();
|
||||
|
||||
final StringBuilder subs = new StringBuilder();
|
||||
if (bPlayer.hasSubElement(Element.METAL)) {
|
||||
subs.append("m");
|
||||
StringBuilder queryBuilder = new StringBuilder();
|
||||
e.forEach(element -> {
|
||||
queryBuilder.append("DELETE FROM pk_player_elements WHERE uuid='" + uuid + "' AND element='" + element.getName().toLowerCase() + "';");
|
||||
});
|
||||
final String query = queryBuilder.toString();
|
||||
|
||||
DBConnection.sql.modifyQuery(query);
|
||||
}
|
||||
|
||||
public static void deleteElement(final BendingPlayer bPlayer, Element e) {
|
||||
if (bPlayer == null) {
|
||||
return;
|
||||
}
|
||||
if (bPlayer.hasSubElement(Element.LAVA)) {
|
||||
subs.append("v");
|
||||
}
|
||||
if (bPlayer.hasSubElement(Element.SAND)) {
|
||||
subs.append("s");
|
||||
}
|
||||
if (bPlayer.hasSubElement(Element.COMBUSTION)) {
|
||||
subs.append("c");
|
||||
}
|
||||
if (bPlayer.hasSubElement(Element.LIGHTNING)) {
|
||||
subs.append("l");
|
||||
}
|
||||
if (bPlayer.hasSubElement(Element.SPIRITUAL)) {
|
||||
subs.append("t");
|
||||
}
|
||||
if (bPlayer.hasSubElement(Element.FLIGHT)) {
|
||||
subs.append("f");
|
||||
}
|
||||
if (bPlayer.hasSubElement(Element.ICE)) {
|
||||
subs.append("i");
|
||||
}
|
||||
if (bPlayer.hasSubElement(Element.HEALING)) {
|
||||
subs.append("h");
|
||||
}
|
||||
if (bPlayer.hasSubElement(Element.BLOOD)) {
|
||||
subs.append("b");
|
||||
}
|
||||
if (bPlayer.hasSubElement(Element.PLANT)) {
|
||||
subs.append("p");
|
||||
}
|
||||
boolean hasAddon = false;
|
||||
for (final Element element : bPlayer.getSubElements()) {
|
||||
if (Arrays.asList(Element.getAddonSubElements()).contains(element)) {
|
||||
if (!hasAddon) {
|
||||
hasAddon = true;
|
||||
subs.append(";");
|
||||
}
|
||||
subs.append(element.getName() + ",");
|
||||
}
|
||||
}
|
||||
|
||||
if (subs.length() == 0) {
|
||||
subs.append("NULL");
|
||||
}
|
||||
|
||||
DBConnection.sql.modifyQuery("UPDATE pk_players SET subelement = '" + subs.toString() + "' WHERE uuid = '" + uuid + "'");
|
||||
|
||||
final String uuid = bPlayer.getUUIDString();
|
||||
final String element = e.getName().toLowerCase();
|
||||
|
||||
DBConnection.sql.modifyQuery("DELETE FROM pk_player_elements WHERE uuid='" + uuid + "' AND element='" + element + "';");
|
||||
}
|
||||
|
||||
public static void savePermaRemoved(final BendingPlayer bPlayer) {
|
||||
|
@ -2097,7 +1905,7 @@ public class GeneralMethods {
|
|||
}
|
||||
final String uuid = bPlayer.getUUIDString();
|
||||
final boolean permaRemoved = bPlayer.isPermaRemoved();
|
||||
DBConnection.sql.modifyQuery("UPDATE pk_players SET permaremoved = '" + (permaRemoved ? "true" : "false") + "' WHERE uuid = '" + uuid + "'");
|
||||
DBConnection.sql.modifyQuery("UPDATE pk_players SET permaremoved = '" + String.valueOf(permaRemoved) + "' WHERE uuid = '" + uuid + "'");
|
||||
}
|
||||
|
||||
public static void setVelocity(final Entity entity, final Vector velocity) {
|
||||
|
@ -2298,4 +2106,10 @@ public class GeneralMethods {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isVowel(char c) {
|
||||
String vowels = "aeiou";
|
||||
|
||||
return vowels.indexOf(Character.toLowerCase(c)) != -1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package com.projectkorra.projectkorra.ability.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
@ -19,7 +19,7 @@ import com.projectkorra.projectkorra.event.PlayerBindChangeEvent;
|
|||
|
||||
public class MultiAbilityManager {
|
||||
|
||||
public static Map<Player, HashMap<Integer, String>> playerAbilities = new ConcurrentHashMap<>();
|
||||
public static Map<Player, String[]> playerAbilities = new ConcurrentHashMap<>();
|
||||
public static Map<Player, Integer> playerSlot = new ConcurrentHashMap<>();
|
||||
public static Map<Player, String> playerBoundAbility = new ConcurrentHashMap<>();
|
||||
public static ArrayList<MultiAbilityInfo> multiAbilityList = new ArrayList<MultiAbilityInfo>();
|
||||
|
@ -55,20 +55,18 @@ public class MultiAbilityManager {
|
|||
playerSlot.put(player, player.getInventory().getHeldItemSlot());
|
||||
playerBoundAbility.put(player, multiAbility);
|
||||
final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
|
||||
final HashMap<Integer, String> currAbilities = new HashMap<Integer, String>();
|
||||
for (final int i : bPlayer.getAbilities().keySet()) {
|
||||
currAbilities.put(i, bPlayer.getAbilities().get(i));
|
||||
}
|
||||
final String[] currAbilities = new String[9];
|
||||
System.arraycopy(bPlayer.getAbilities(), 0, currAbilities, 0, bPlayer.getAbilities().length);
|
||||
playerAbilities.put(player, currAbilities);
|
||||
|
||||
final List<MultiAbilityInfoSub> modes = getMultiAbility(multiAbility).getAbilities();
|
||||
|
||||
bPlayer.getAbilities().clear();
|
||||
Arrays.fill(bPlayer.getAbilities(), null);
|
||||
for (int i = 0; i < modes.size(); i++) {
|
||||
if (!player.hasPermission("bending.ability." + multiAbility + "." + modes.get(i).getName())) {
|
||||
bPlayer.getAbilities().put(i + 1, new StringBuilder().append(modes.get(i).getAbilityColor()).append(ChatColor.STRIKETHROUGH).append(modes.get(i).getName()).toString());
|
||||
bPlayer.getAbilities()[i] = new StringBuilder().append(modes.get(i).getAbilityColor()).append(ChatColor.STRIKETHROUGH).append(modes.get(i).getName()).toString();
|
||||
} else {
|
||||
bPlayer.getAbilities().put(i + 1, modes.get(i).getAbilityColor() + modes.get(i).getName());
|
||||
bPlayer.getAbilities()[i] = modes.get(i).getAbilityColor() + modes.get(i).getName();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,21 +202,21 @@ public class MultiAbilityManager {
|
|||
*/
|
||||
public static void unbindMultiAbility(final Player player) {
|
||||
if (playerAbilities.containsKey(player)) {
|
||||
final HashMap<Integer, String> prevBinds = playerAbilities.get(player);
|
||||
final String[] prevBinds = playerAbilities.get(player);
|
||||
final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(player);
|
||||
if (bPlayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
System.arraycopy(prevBinds, 0, bPlayer.getAbilities(), 0, prevBinds.length);
|
||||
int lastNonNull = -1;
|
||||
for (int i = 1; i < 10; i++) {
|
||||
if (prevBinds.get(i) != null) {
|
||||
for (int i = 0; i < 9; i++) {
|
||||
if (prevBinds[i] != null) {
|
||||
lastNonNull = i;
|
||||
}
|
||||
bPlayer.getAbilities().put(i, prevBinds.get(i));
|
||||
}
|
||||
if (lastNonNull > -1) {
|
||||
GeneralMethods.saveAbility(bPlayer, lastNonNull, prevBinds.get(lastNonNull));
|
||||
GeneralMethods.saveAbility(bPlayer, lastNonNull + 1, prevBinds[lastNonNull]);
|
||||
}
|
||||
|
||||
if (player.isOnline()) {
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.projectkorra.projectkorra.command;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -12,10 +13,10 @@ import org.bukkit.entity.Player;
|
|||
import com.projectkorra.projectkorra.BendingPlayer;
|
||||
import com.projectkorra.projectkorra.Element;
|
||||
import com.projectkorra.projectkorra.Element.SubElement;
|
||||
import com.projectkorra.projectkorra.GeneralMethods;
|
||||
import com.projectkorra.projectkorra.configuration.ConfigManager;
|
||||
import com.projectkorra.projectkorra.configuration.configs.commands.AddCommandConfig;
|
||||
import com.projectkorra.projectkorra.configuration.configs.properties.CommandPropertiesConfig;
|
||||
import com.projectkorra.projectkorra.GeneralMethods;
|
||||
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent;
|
||||
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent.Result;
|
||||
import com.projectkorra.projectkorra.event.PlayerChangeSubElementEvent;
|
||||
|
@ -27,10 +28,10 @@ public class AddCommand extends PKCommand<AddCommandConfig> {
|
|||
|
||||
private final String playerNotFound;
|
||||
private final String invalidElement;
|
||||
private final String addedOtherCFW;
|
||||
private final String addedOtherAE;
|
||||
private final String addedCFW;
|
||||
private final String addedAE;
|
||||
private final String addedOther;
|
||||
private final String addedOtherVowel;
|
||||
private final String added;
|
||||
private final String addedVowel;
|
||||
private final String alreadyHasElementOther;
|
||||
private final String alreadyHasElement;
|
||||
private final String alreadyHasSubElementOther;
|
||||
|
@ -45,10 +46,10 @@ public class AddCommand extends PKCommand<AddCommandConfig> {
|
|||
|
||||
this.playerNotFound = config.PlayerNotFound;
|
||||
this.invalidElement = config.InvalidElement;
|
||||
this.addedOtherCFW = config.SuccessfullyAddedCFW_Other;
|
||||
this.addedOtherAE = config.SuccessfullyAddedAE_Other;
|
||||
this.addedCFW = config.SuccessfullyAddedCFW;
|
||||
this.addedAE = config.SuccessfullyAddedAE;
|
||||
this.addedOther = config.SuccessfullyAdded_Other;
|
||||
this.addedOtherVowel = config.SuccessfullyAddedVowel_Other;
|
||||
this.added = config.SuccessfullyAdded;
|
||||
this.addedVowel = config.SuccessfullyAddedVowel;
|
||||
this.addedOtherAll = config.SuccessfullyAddedAll_Other;
|
||||
this.addedAll = config.SuccessfullyAddedAll;
|
||||
this.alreadyHasElementOther = config.AlreadyHasElement_Other;
|
||||
|
@ -95,37 +96,30 @@ public class AddCommand extends PKCommand<AddCommandConfig> {
|
|||
if (bPlayer == null) {
|
||||
GeneralMethods.createBendingPlayer(target.getUniqueId(), target.getName());
|
||||
bPlayer = BendingPlayer.getBendingPlayer(target);
|
||||
} else if (bPlayer.isPermaRemoved()) { // ignore permabanned users.
|
||||
} else if (bPlayer.isPermaRemoved()) { // ignore permaremoved users.
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + ConfigManager.getConfig(CommandPropertiesConfig.class).BendingPermanentlyRemoved_Other);
|
||||
return;
|
||||
}
|
||||
|
||||
if (element.toLowerCase().equals("all")) {
|
||||
final StringBuilder elements = new StringBuilder("");
|
||||
boolean elementFound = false;
|
||||
List<Element> added = new LinkedList<>();
|
||||
for (final Element e : Element.getAllElements()) {
|
||||
if (!bPlayer.hasElement(e) && e != Element.AVATAR) {
|
||||
elementFound = true;
|
||||
bPlayer.addElement(e);
|
||||
added.add(e);
|
||||
|
||||
if (elements.length() > 1) {
|
||||
elements.append(ChatColor.YELLOW + ", ");
|
||||
}
|
||||
elements.append(e.getColor() + e.getName());
|
||||
|
||||
bPlayer.getSubElements().clear();
|
||||
for (final SubElement sub : Element.getAllSubElements()) {
|
||||
if (bPlayer.hasElement(sub.getParentElement()) && bPlayer.hasSubElementPermission(sub)) {
|
||||
bPlayer.addSubElement(sub);
|
||||
}
|
||||
}
|
||||
|
||||
GeneralMethods.saveElements(bPlayer);
|
||||
GeneralMethods.saveSubElements(bPlayer);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, target, e, Result.ADD));
|
||||
}
|
||||
}
|
||||
if (elementFound) {
|
||||
if (added.size() > 0) {
|
||||
GeneralMethods.saveElementsNew(bPlayer, added);
|
||||
|
||||
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.addedOtherAll.replace("{target}", ChatColor.DARK_AQUA + target.getName() + ChatColor.YELLOW) + elements);
|
||||
GeneralMethods.sendBrandingMessage(target, ChatColor.YELLOW + this.addedAll + elements);
|
||||
|
@ -144,110 +138,108 @@ public class AddCommand extends PKCommand<AddCommandConfig> {
|
|||
|
||||
// get the [sub]element.
|
||||
Element e = Element.fromString(element);
|
||||
|
||||
if (e == null) {
|
||||
e = Element.fromString(element);
|
||||
}
|
||||
|
||||
if (e == Element.AVATAR) {
|
||||
this.add(sender, target, Element.AIR.getName());
|
||||
this.add(sender, target, Element.EARTH.getName());
|
||||
this.add(sender, target, Element.FIRE.getName());
|
||||
this.add(sender, target, Element.WATER.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
List<Element> adding = new LinkedList<>();
|
||||
adding.add(e);
|
||||
|
||||
// if it's an element:
|
||||
if (Arrays.asList(Element.getAllElements()).contains(e)) {
|
||||
if (bPlayer.hasElement(e)) { // if already had, determine who to send the error message to.
|
||||
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
||||
if (e == Element.AVATAR) {
|
||||
adding.clear();
|
||||
adding.add(Element.AIR);
|
||||
adding.add(Element.EARTH);
|
||||
adding.add(Element.FIRE);
|
||||
adding.add(Element.WATER);
|
||||
}
|
||||
|
||||
List<Element> added = new LinkedList<>();
|
||||
|
||||
for (Element elem : adding) {
|
||||
// if it's an element:
|
||||
if (Arrays.asList(Element.getAllElements()).contains(elem)) {
|
||||
if (bPlayer.hasElement(elem)) { // if already had, determine who to send the error message to.
|
||||
continue;
|
||||
}
|
||||
|
||||
// add all allowed subelements.
|
||||
bPlayer.addElement(elem);
|
||||
added.add(elem);
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, target, e, Result.ADD));
|
||||
return;
|
||||
|
||||
// if it's a sub element:
|
||||
} else if (Arrays.asList(Element.getAllSubElements()).contains(e)) {
|
||||
final SubElement sub = (SubElement) e;
|
||||
|
||||
if (bPlayer.hasSubElement(sub)) { // if already had, determine who to send the error message to.
|
||||
continue;
|
||||
}
|
||||
|
||||
bPlayer.addSubElement(sub);
|
||||
added.add(elem);
|
||||
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeSubElementEvent(sender, target, sub, PlayerChangeSubElementEvent.Result.ADD));
|
||||
return;
|
||||
|
||||
} else { // bad element.
|
||||
sender.sendMessage(ChatColor.RED + this.invalidElement);
|
||||
}
|
||||
}
|
||||
|
||||
if (added.isEmpty()) {
|
||||
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
||||
if (adding.size() == 1 && adding.get(0) instanceof SubElement) {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.alreadyHasSubElementOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + ChatColor.RED));
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.alreadyHasElementOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + ChatColor.RED));
|
||||
}
|
||||
} else {
|
||||
if (adding.size() == 1 && adding.get(0) instanceof SubElement) {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.alreadyHasSubElement);
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.alreadyHasElement);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// add all allowed subelements.
|
||||
bPlayer.addElement(e);
|
||||
bPlayer.getSubElements().clear();
|
||||
for (final SubElement sub : Element.getAllSubElements()) {
|
||||
if (bPlayer.hasElement(sub.getParentElement()) && bPlayer.hasSubElementPermission(sub)) {
|
||||
bPlayer.addSubElement(sub);
|
||||
}
|
||||
}
|
||||
|
||||
// send the message.
|
||||
final ChatColor color = e.getColor();
|
||||
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
||||
if (e != Element.AIR && e != Element.EARTH) {
|
||||
GeneralMethods.sendBrandingMessage(sender, color + this.addedOtherCFW.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", e.getName() + e.getType().getBender()));
|
||||
GeneralMethods.sendBrandingMessage(target, color + this.addedCFW.replace("{element}", e.getName() + e.getType().getBender()));
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(sender, color + this.addedOtherAE.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", e.getName() + e.getType().getBender()));
|
||||
GeneralMethods.sendBrandingMessage(target, color + this.addedAE.replace("{element}", e.getName() + e.getType().getBender()));
|
||||
}
|
||||
} else {
|
||||
if (e != Element.AIR && e != Element.EARTH) {
|
||||
GeneralMethods.sendBrandingMessage(target, color + this.addedCFW.replace("{element}", e.getName() + e.getType().getBender()));
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(target, color + this.addedAE.replace("{element}", e.getName() + e.getType().getBender()));
|
||||
}
|
||||
|
||||
}
|
||||
GeneralMethods.saveElements(bPlayer);
|
||||
GeneralMethods.saveSubElements(bPlayer);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, target, e, Result.ADD));
|
||||
|
||||
return;
|
||||
|
||||
// if it's a sub element:
|
||||
} else if (Arrays.asList(Element.getAllSubElements()).contains(e)) {
|
||||
final SubElement sub = (SubElement) e;
|
||||
if (bPlayer.hasSubElement(sub)) { // if already had, determine who to send the error message to.
|
||||
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.alreadyHasSubElementOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + ChatColor.RED));
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.alreadyHasSubElement);
|
||||
}
|
||||
return;
|
||||
}
|
||||
bPlayer.addSubElement(sub);
|
||||
final ChatColor color = e.getColor();
|
||||
|
||||
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
||||
if (e != Element.AIR && e != Element.EARTH) {
|
||||
GeneralMethods.sendBrandingMessage(sender, color + this.addedOtherCFW.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", sub.getName() + sub.getType().getBender()));
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(sender, color + this.addedOtherAE.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", sub.getName() + sub.getType().getBender()));
|
||||
}
|
||||
|
||||
} else {
|
||||
if (e != Element.AIR && e != Element.EARTH) {
|
||||
GeneralMethods.sendBrandingMessage(target, color + this.addedCFW.replace("{element}", sub.getName() + sub.getType().getBender()));
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(target, color + this.addedAE.replace("{element}", sub.getName() + sub.getType().getBender()));
|
||||
}
|
||||
}
|
||||
GeneralMethods.saveSubElements(bPlayer);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeSubElementEvent(sender, target, sub, com.projectkorra.projectkorra.event.PlayerChangeSubElementEvent.Result.ADD));
|
||||
return;
|
||||
|
||||
} else { // bad element.
|
||||
sender.sendMessage(ChatColor.RED + this.invalidElement);
|
||||
}
|
||||
|
||||
|
||||
if (added.size() == 1) {
|
||||
GeneralMethods.saveElement(bPlayer, added.get(0));
|
||||
} else {
|
||||
GeneralMethods.saveElementsNew(bPlayer, added);
|
||||
}
|
||||
|
||||
for (Element elem : added) {
|
||||
ChatColor color = elem.getColor();
|
||||
boolean vowel = GeneralMethods.isVowel(ChatColor.stripColor(elem.getName()).charAt(0));
|
||||
|
||||
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
||||
if (vowel) {
|
||||
GeneralMethods.sendBrandingMessage(sender, color + this.addedOtherVowel.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", elem.getName() + elem.getType().getBender()));
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(sender, color + this.addedOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", elem.getName() + elem.getType().getBender()));
|
||||
}
|
||||
} else {
|
||||
if (vowel) {
|
||||
GeneralMethods.sendBrandingMessage(target, color + this.addedVowel.replace("{element}", elem.getName() + elem.getType().getBender()));
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(target, color + this.added.replace("{element}", elem.getName() + elem.getType().getBender()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isVowel(final char c) {
|
||||
return "AEIOUaeiou".indexOf(c) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> getTabCompletion(final CommandSender sender, final List<String> args) {
|
||||
if (args.size() >= 2 || !sender.hasPermission("bending.command.add")) {
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
final List<String> l = new ArrayList<String>();
|
||||
final List<String> l = new ArrayList<>();
|
||||
if (args.size() == 0) {
|
||||
|
||||
l.add("Air");
|
||||
|
|
|
@ -29,8 +29,9 @@ public class BindCommand extends PKCommand<BindCommandConfig> {
|
|||
private final String loadingInfo;
|
||||
private final String toggledElementOff;
|
||||
private final String noElement;
|
||||
private final String noElementAE;
|
||||
private final String noElementVowel;
|
||||
private final String noSubElement;
|
||||
private final String noSubElementVowel;
|
||||
private final String unbindable;
|
||||
|
||||
public BindCommand(final BindCommandConfig config) {
|
||||
|
@ -41,8 +42,9 @@ public class BindCommand extends PKCommand<BindCommandConfig> {
|
|||
this.loadingInfo = config.LoadingInfoMessage;
|
||||
this.toggledElementOff = config.ElementToggledOffMessage;
|
||||
this.noElement = config.NoElementMessage;
|
||||
this.noElementAE = config.NoElementMessageAE;
|
||||
this.noElementVowel = config.NoElementMessageVowel;
|
||||
this.noSubElement = config.NoSubElementMessage;
|
||||
this.noSubElementVowel = config.NoSubElementMessageVowel;
|
||||
this.unbindable = config.UnbindableMessage;
|
||||
}
|
||||
|
||||
|
@ -94,12 +96,24 @@ public class BindCommand extends PKCommand<BindCommandConfig> {
|
|||
if (coreAbil.getElement() instanceof SubElement) {
|
||||
final SubElement sub = (SubElement) coreAbil.getElement();
|
||||
if (!bPlayer.hasElement(sub.getParentElement())) {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + ("AEIOUaeiou".indexOf(sub.getParentElement().getName().charAt(0)) > -1 ? this.noElementAE : this.noElement).replace("{element}", sub.getParentElement().getName() + sub.getParentElement().getType().getBender()));
|
||||
if (GeneralMethods.isVowel(ChatColor.stripColor(sub.getParentElement().getName()).charAt(0))) {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.noElementVowel.replace("{element}", sub.getParentElement().getName() + sub.getParentElement().getType().getBender()));
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.noElement.replace("{element}", sub.getParentElement().getName() + sub.getParentElement().getType().getBender()));
|
||||
}
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.noSubElement.replace("{subelement}", coreAbil.getElement().getName() + coreAbil.getElement().getType().getBending()));
|
||||
if (GeneralMethods.isVowel(ChatColor.stripColor(sub.getName()).charAt(0))) {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.noSubElementVowel.replace("{subelement}", coreAbil.getElement().getName() + coreAbil.getElement().getType().getBending()));
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.noSubElement.replace("{subelement}", coreAbil.getElement().getName() + coreAbil.getElement().getType().getBending()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + ("AEIOUaeiou".indexOf(coreAbil.getElement().getName().charAt(0)) > -1 ? this.noElementAE : this.noElement).replace("{element}", coreAbil.getElement().getName() + coreAbil.getElement().getType().getBender()));
|
||||
if (GeneralMethods.isVowel(ChatColor.stripColor(coreAbil.getElement().getName()).charAt(0))) {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.noElementVowel.replace("{element}", coreAbil.getElement().getName() + coreAbil.getElement().getType().getBender()));
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.noElement.replace("{element}", coreAbil.getElement().getName() + coreAbil.getElement().getType().getBender()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + super.noPermissionMessage);
|
||||
|
@ -119,7 +133,7 @@ public class BindCommand extends PKCommand<BindCommandConfig> {
|
|||
return new ArrayList<String>();
|
||||
}
|
||||
|
||||
List<String> abilities = new ArrayList<String>();
|
||||
List<String> abilities = new ArrayList<>();
|
||||
final BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(sender.getName());
|
||||
if (args.size() == 0) {
|
||||
if (bPlayer != null) {
|
||||
|
|
|
@ -11,16 +11,14 @@ import org.bukkit.entity.Player;
|
|||
|
||||
import com.projectkorra.projectkorra.BendingPlayer;
|
||||
import com.projectkorra.projectkorra.Element;
|
||||
import com.projectkorra.projectkorra.Element.SubElement;
|
||||
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.GeneralMethods;
|
||||
import com.projectkorra.projectkorra.ProjectKorra;
|
||||
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent;
|
||||
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent.Result;
|
||||
import com.projectkorra.projectkorra.event.PlayerChangeSubElementEvent;
|
||||
import com.projectkorra.projectkorra.util.TimeUtil;
|
||||
|
||||
/**
|
||||
|
@ -31,10 +29,10 @@ public class ChooseCommand extends PKCommand<ChooseCommandConfig> {
|
|||
private final String invalidElement;
|
||||
private final String playerNotFound;
|
||||
private final String onCooldown;
|
||||
private final String chosenCFW;
|
||||
private final String chosenAE;
|
||||
private final String chosenOtherCFW;
|
||||
private final String chosenOtherAE;
|
||||
private final String chosen;
|
||||
private final String chosenVowel;
|
||||
private final String chosenOther;
|
||||
private final String chosenOtherVowel;
|
||||
private final long cooldown;
|
||||
|
||||
public ChooseCommand(final ChooseCommandConfig config) {
|
||||
|
@ -43,10 +41,10 @@ public class ChooseCommand extends PKCommand<ChooseCommandConfig> {
|
|||
this.playerNotFound = config.PlayerNotFound;
|
||||
this.invalidElement = config.InvalidElement;
|
||||
this.onCooldown = config.OnCooldown;
|
||||
this.chosenCFW = config.SuccessfullyChosenCFW;
|
||||
this.chosenAE = config.SuccessfullyChosenAE;
|
||||
this.chosenOtherCFW = config.SuccessfullyChosenCFW_Other;
|
||||
this.chosenOtherAE = config.SuccessfullyChosenAE_Other;
|
||||
this.chosen = config.SuccessfullyChosen;
|
||||
this.chosenVowel = config.SuccessfullyChosenVowel;
|
||||
this.chosenOther = config.SuccessfullyChosen_Other;
|
||||
this.chosenOtherVowel = config.SuccessfullyChosenVowel_Other;
|
||||
this.cooldown = ConfigManager.getConfig(GeneralPropertiesConfig.class).ChooseCooldown;
|
||||
}
|
||||
|
||||
|
@ -163,51 +161,29 @@ public class ChooseCommand extends PKCommand<ChooseCommandConfig> {
|
|||
if (bPlayer == null) {
|
||||
return;
|
||||
}
|
||||
if (element instanceof SubElement) {
|
||||
final SubElement sub = (SubElement) element;
|
||||
bPlayer.addSubElement(sub);
|
||||
final ChatColor color = sub != null ? sub.getColor() : ChatColor.WHITE;
|
||||
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
||||
GeneralMethods.sendBrandingMessage(sender, color + this.chosenOtherCFW.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", sub.getName() + sub.getType().getBender()));
|
||||
|
||||
bPlayer.setElement(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 (vowel) {
|
||||
GeneralMethods.sendBrandingMessage(sender, color + this.chosenOtherVowel.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", element.getName() + element.getType().getBender()));
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(target, color + this.chosenCFW.replace("{element}", sub.getName() + sub.getType().getBender()));
|
||||
GeneralMethods.sendBrandingMessage(sender, color + this.chosenOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", element.getName() + element.getType().getBender()));
|
||||
}
|
||||
GeneralMethods.saveSubElements(bPlayer);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeSubElementEvent(sender, target, sub, com.projectkorra.projectkorra.event.PlayerChangeSubElementEvent.Result.CHOOSE));
|
||||
} else {
|
||||
bPlayer.setElement(element);
|
||||
bPlayer.getSubElements().clear();
|
||||
for (final SubElement sub : Element.getAllSubElements()) {
|
||||
if (bPlayer.hasElement(sub.getParentElement()) && bPlayer.hasSubElementPermission(sub)) {
|
||||
bPlayer.addSubElement(sub);
|
||||
}
|
||||
}
|
||||
|
||||
final ChatColor color = element != null ? element.getColor() : ChatColor.WHITE;
|
||||
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
||||
if (element != Element.AIR && element != Element.EARTH) {
|
||||
GeneralMethods.sendBrandingMessage(sender, color + this.chosenOtherCFW.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", element.getName() + element.getType().getBender()));
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(sender, color + this.chosenOtherAE.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", element.getName() + element.getType().getBender()));
|
||||
}
|
||||
if (vowel) {
|
||||
GeneralMethods.sendBrandingMessage(target, color + this.chosenVowel.replace("{element}", element.getName() + element.getType().getBender()));
|
||||
} else {
|
||||
if (element != Element.AIR && element != Element.EARTH) {
|
||||
GeneralMethods.sendBrandingMessage(target, color + this.chosenCFW.replace("{element}", element.getName() + element.getType().getBender()));
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(target, color + this.chosenAE.replace("{element}", element.getName() + element.getType().getBender()));
|
||||
}
|
||||
GeneralMethods.sendBrandingMessage(target, color + this.chosen.replace("{element}", element.getName() + element.getType().getBender()));
|
||||
}
|
||||
GeneralMethods.saveElements(bPlayer);
|
||||
GeneralMethods.saveSubElements(bPlayer);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, target, element, Result.CHOOSE));
|
||||
}
|
||||
|
||||
|
||||
GeneralMethods.saveElement(bPlayer, element);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, target, element, Result.CHOOSE));
|
||||
GeneralMethods.removeUnusableAbilities(target.getName());
|
||||
|
||||
}
|
||||
|
||||
public static boolean isVowel(final char c) {
|
||||
return "AEIOUaeiou".indexOf(c) != -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -49,7 +49,7 @@ public class ClearCommand extends PKCommand<ClearCommandConfig> {
|
|||
bPlayer = BendingPlayer.getBendingPlayer(sender.getName());
|
||||
}
|
||||
if (args.size() == 0) {
|
||||
bPlayer.getAbilities().clear();
|
||||
Arrays.fill(bPlayer.getAbilities(), null);
|
||||
for (int i = 1; i <= 9; i++) {
|
||||
GeneralMethods.saveAbility(bPlayer, i, null);
|
||||
}
|
||||
|
@ -60,8 +60,8 @@ public class ClearCommand extends PKCommand<ClearCommandConfig> {
|
|||
if (slot < 1 || slot > 9) {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.wrongNumber);
|
||||
}
|
||||
if (bPlayer.getAbilities().get(slot) != null) {
|
||||
bPlayer.getAbilities().remove(slot);
|
||||
if (bPlayer.getAbilities()[slot - 1] != null) {
|
||||
bPlayer.getAbilities()[slot - 1] = null;
|
||||
GeneralMethods.saveAbility(bPlayer, slot, null);
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.clearedSlot.replace("{slot}", String.valueOf(slot)));
|
||||
} else {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.projectkorra.projectkorra.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -17,7 +16,7 @@ import com.projectkorra.projectkorra.configuration.ConfigManager;
|
|||
import com.projectkorra.projectkorra.configuration.configs.commands.CopyCommandConfig;
|
||||
import com.projectkorra.projectkorra.configuration.configs.properties.CommandPropertiesConfig;
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@SuppressWarnings("rawtypes")
|
||||
public class CopyCommand extends PKCommand<CopyCommandConfig> {
|
||||
|
||||
private final String playerNotFound;
|
||||
|
@ -100,15 +99,16 @@ public class CopyCommand extends PKCommand<CopyCommandConfig> {
|
|||
return false;
|
||||
}
|
||||
|
||||
final HashMap<Integer, String> abilities = (HashMap<Integer, String>) orig.getAbilities().clone();
|
||||
final String[] abilities = orig.getAbilities().clone();
|
||||
boolean boundAll = true;
|
||||
for (int i = 1; i <= 9; i++) {
|
||||
final CoreAbility coreAbil = CoreAbility.getAbility(abilities.get(i));
|
||||
for (int i = 0; i < 9; i++) {
|
||||
final CoreAbility coreAbil = CoreAbility.getAbility(abilities[i]);
|
||||
if (coreAbil != null && !target.canBind(coreAbil)) {
|
||||
abilities.remove(i);
|
||||
abilities[i] = null;
|
||||
boundAll = false;
|
||||
}
|
||||
}
|
||||
|
||||
target.setAbilities(abilities);
|
||||
return boundAll;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
package com.projectkorra.projectkorra.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -322,9 +323,9 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
|
|||
GeneralMethods.createBendingPlayer(((Player) sender).getUniqueId(), sender.getName());
|
||||
bPlayer = BendingPlayer.getBendingPlayer(sender.getName());
|
||||
}
|
||||
final HashMap<Integer, String> abilities = bPlayer.getAbilities();
|
||||
final String[] abilities = bPlayer.getAbilities();
|
||||
|
||||
if (abilities.isEmpty()) {
|
||||
if (Stream.of(abilities).allMatch(Objects::isNull)) {
|
||||
sender.sendMessage(ChatColor.RED + this.noBinds);
|
||||
return;
|
||||
}
|
||||
|
@ -332,7 +333,7 @@ public class DisplayCommand extends PKCommand<DisplayCommandConfig> {
|
|||
sender.sendMessage(ChatColor.WHITE + (ChatColor.BOLD + "Abilities"));
|
||||
|
||||
for (int i = 1; i <= 9; i++) {
|
||||
final String ability = abilities.get(i);
|
||||
final String ability = abilities[i - 1];
|
||||
final CoreAbility coreAbil = CoreAbility.getAbility(ability);
|
||||
if (coreAbil != null && !ability.equalsIgnoreCase("null")) {
|
||||
String message = i + ". " + coreAbil.getElement().getColor() + ability;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.projectkorra.projectkorra.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -9,6 +10,7 @@ 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.configuration.configs.commands.PermaremoveCommandConfig;
|
||||
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent;
|
||||
|
@ -75,8 +77,12 @@ public class PermaremoveCommand extends PKCommand<PermaremoveCommandConfig> {
|
|||
GeneralMethods.sendBrandingMessage(sender, ChatColor.GREEN + this.restoredConfirm.replace("{target}", ChatColor.DARK_AQUA + player.getName() + ChatColor.GREEN));
|
||||
}
|
||||
} else {
|
||||
List<Element> removed = new LinkedList<>();
|
||||
removed.addAll(bPlayer.getElements());
|
||||
removed.addAll(bPlayer.getSubElements());
|
||||
bPlayer.getElements().clear();
|
||||
GeneralMethods.saveElements(bPlayer);
|
||||
bPlayer.getSubElements().clear();
|
||||
GeneralMethods.deleteElements(bPlayer, removed);
|
||||
bPlayer.setPermaRemoved(true);
|
||||
GeneralMethods.savePermaRemoved(bPlayer);
|
||||
GeneralMethods.removeUnusableAbilities(player.getName());
|
||||
|
|
|
@ -223,9 +223,7 @@ public class PresetCommand extends PKCommand<PresetCommandConfig> {
|
|||
}
|
||||
String[] abilities = new String[9];
|
||||
for (int slot = 0; slot < 9; slot++) {
|
||||
if (bPlayer.getAbilities().containsKey(slot + 1)) {
|
||||
abilities[slot] = bPlayer.getAbilities().get(slot + 1);
|
||||
}
|
||||
abilities[slot] = bPlayer.getAbilities()[slot];
|
||||
}
|
||||
|
||||
final Preset preset = new Preset(player.getUniqueId(), name, abilities);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.projectkorra.projectkorra.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
@ -55,10 +56,10 @@ public class RemoveCommand extends PKCommand<RemoveCommandConfig> {
|
|||
if (e instanceof SubElement) {
|
||||
if (senderBPlayer.hasElement(e)) {
|
||||
senderBPlayer.getSubElements().remove(e);
|
||||
GeneralMethods.saveSubElements(senderBPlayer);
|
||||
GeneralMethods.deleteElement(senderBPlayer, e);
|
||||
GeneralMethods.removeUnusableAbilities(sender.getName());
|
||||
GeneralMethods.sendBrandingMessage(sender, e.getColor() + this.succesfullyRemovedElementSelf.replace("{element}", e.getName() + e.getType().getBending()).replace("{sender}", ChatColor.DARK_AQUA + sender.getName() + e.getColor()));
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeSubElementEvent(sender, player, (SubElement) e, com.projectkorra.projectkorra.event.PlayerChangeSubElementEvent.Result.REMOVE));
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeSubElementEvent(sender, player, (SubElement) e, PlayerChangeSubElementEvent.Result.REMOVE));
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.wrongElementSelf);
|
||||
}
|
||||
|
@ -66,11 +67,7 @@ public class RemoveCommand extends PKCommand<RemoveCommandConfig> {
|
|||
} else if (e instanceof Element) {
|
||||
if (senderBPlayer.hasElement(e)) {
|
||||
senderBPlayer.getElements().remove(e);
|
||||
for (final SubElement sub : Element.getSubElements(e)) {
|
||||
senderBPlayer.getSubElements().remove(sub);
|
||||
}
|
||||
GeneralMethods.saveElements(senderBPlayer);
|
||||
GeneralMethods.saveSubElements(senderBPlayer);
|
||||
GeneralMethods.deleteElement(senderBPlayer, e);
|
||||
GeneralMethods.removeUnusableAbilities(sender.getName());
|
||||
|
||||
GeneralMethods.sendBrandingMessage(sender, e.getColor() + this.succesfullyRemovedElementSelf.replace("{element}", e.getName() + e.getType().getBending()));
|
||||
|
@ -79,16 +76,12 @@ public class RemoveCommand extends PKCommand<RemoveCommandConfig> {
|
|||
} else {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.wrongElementSelf);
|
||||
}
|
||||
{
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.invalidElement);
|
||||
}
|
||||
{
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.RED + this.playerOffline);
|
||||
return;
|
||||
|
@ -112,15 +105,10 @@ public class RemoveCommand extends PKCommand<RemoveCommandConfig> {
|
|||
}
|
||||
if (e instanceof SubElement) {
|
||||
bPlayer.getSubElements().remove(e);
|
||||
GeneralMethods.saveSubElements(bPlayer);
|
||||
} else {
|
||||
bPlayer.getElements().remove(e);
|
||||
for (final SubElement sub : Element.getSubElements(e)) {
|
||||
bPlayer.getSubElements().remove(sub);
|
||||
}
|
||||
GeneralMethods.saveElements(bPlayer);
|
||||
GeneralMethods.saveSubElements(bPlayer);
|
||||
}
|
||||
GeneralMethods.deleteElement(bPlayer, e);
|
||||
|
||||
GeneralMethods.removeUnusableAbilities(player.getName());
|
||||
GeneralMethods.sendBrandingMessage(player, e.getColor() + this.succesfullyRemovedElementTarget.replace("{element}", e.getName() + e.getType().getBending()).replace("{sender}", ChatColor.DARK_AQUA + sender.getName() + e.getColor()));
|
||||
|
@ -129,10 +117,14 @@ public class RemoveCommand extends PKCommand<RemoveCommandConfig> {
|
|||
return;
|
||||
}
|
||||
} else if (args.size() == 1) {
|
||||
List<Element> removed = new LinkedList<>();
|
||||
removed.addAll(bPlayer.getElements());
|
||||
removed.addAll(bPlayer.getSubElements());
|
||||
|
||||
bPlayer.getElements().clear();
|
||||
bPlayer.getSubElements().clear();
|
||||
GeneralMethods.saveElements(bPlayer);
|
||||
GeneralMethods.saveSubElements(bPlayer);
|
||||
|
||||
GeneralMethods.deleteElements(bPlayer, removed);
|
||||
GeneralMethods.removeUnusableAbilities(player.getName());
|
||||
if (!player.getName().equalsIgnoreCase(sender.getName())) {
|
||||
GeneralMethods.sendBrandingMessage(sender, ChatColor.YELLOW + this.succesfullyRemovedAllElementsTargetConfirm.replace("{target}", ChatColor.DARK_AQUA + player.getName() + ChatColor.YELLOW));
|
||||
|
|
|
@ -315,7 +315,7 @@ public class WhoCommand extends PKCommand<WhoCommandConfig> {
|
|||
if (bPlayer != null) {
|
||||
sender.sendMessage("Abilities: ");
|
||||
for (int i = 1; i <= 9; i++) {
|
||||
final String ability = bPlayer.getAbilities().get(i);
|
||||
final String ability = bPlayer.getAbilities()[i - 1];
|
||||
final CoreAbility coreAbil = CoreAbility.getAbility(ability);
|
||||
if (coreAbil == null) {
|
||||
continue;
|
||||
|
|
|
@ -4,10 +4,10 @@ public class AddCommandConfig extends CommandConfig {
|
|||
|
||||
public final String PlayerNotFound = "";
|
||||
public final String InvalidElement = "";
|
||||
public final String SuccessfullyAddedCFW_Other = "";
|
||||
public final String SuccessfullyAddedCFW = "";
|
||||
public final String SuccessfullyAddedAE_Other = "";
|
||||
public final String SuccessfullyAddedAE = "";
|
||||
public final String SuccessfullyAdded_Other = "";
|
||||
public final String SuccessfullyAdded = "";
|
||||
public final String SuccessfullyAddedVowel_Other = "";
|
||||
public final String SuccessfullyAddedVowel = "";
|
||||
public final String SuccessfullyAddedAll_Other = "";
|
||||
public final String SuccessfullyAddedAll = "";
|
||||
public final String AlreadyHasElement_Other = "";
|
||||
|
|
|
@ -8,8 +8,9 @@ public class BindCommandConfig extends CommandConfig {
|
|||
public final String LoadingInfoMessage = "";
|
||||
public final String ElementToggledOffMessage = "";
|
||||
public final String NoElementMessage = "";
|
||||
public final String NoElementMessageAE = "";
|
||||
public final String NoElementMessageVowel = "";
|
||||
public final String NoSubElementMessage = "";
|
||||
public final String NoSubElementMessageVowel = "";
|
||||
public final String UnbindableMessage = "";
|
||||
|
||||
public BindCommandConfig() {
|
||||
|
|
|
@ -5,10 +5,10 @@ public class ChooseCommandConfig extends CommandConfig {
|
|||
public final String PlayerNotFound = "";
|
||||
public final String InvalidElement = "";
|
||||
public final String OnCooldown = "";
|
||||
public final String SuccessfullyChosenCFW_Other = "";
|
||||
public final String SuccessfullyChosenCFW = "";
|
||||
public final String SuccessfullyChosenAE_Other = "";
|
||||
public final String SuccessfullyChosenAE = "";
|
||||
public final String SuccessfullyChosen_Other = "";
|
||||
public final String SuccessfullyChosen = "";
|
||||
public final String SuccessfullyChosenVowel_Other = "";
|
||||
public final String SuccessfullyChosenVowel = "";
|
||||
|
||||
public ChooseCommandConfig() {
|
||||
super("");
|
||||
|
|
|
@ -31,7 +31,7 @@ public class PlaceholderAPIHook extends PlaceholderExpansion {
|
|||
}
|
||||
|
||||
if (params.startsWith("slot")) {
|
||||
final String ability = bPlayer.getAbilities().get(Integer.parseInt(params.substring(params.length() - 1)));
|
||||
final String ability = bPlayer.getAbilities()[Integer.parseInt(params.substring(params.length() - 1)) - 1];
|
||||
final CoreAbility coreAbil = CoreAbility.getAbility(ability);
|
||||
if (coreAbil == null) {
|
||||
return "";
|
||||
|
|
|
@ -162,17 +162,14 @@ public class Preset {
|
|||
|
||||
String[] abilities = preset.getAbilities();
|
||||
boolean boundAll = true;
|
||||
HashMap<Integer, String> bindings = new HashMap<>();
|
||||
for (int i = 0; i < abilities.length; i++) {
|
||||
final CoreAbility coreAbil = CoreAbility.getAbility(abilities[i]);
|
||||
if (coreAbil != null && !bPlayer.canBind(coreAbil)) {
|
||||
abilities[i] = null;
|
||||
boundAll = false;
|
||||
} else {
|
||||
bindings.put(i + 1, abilities[i]);
|
||||
}
|
||||
}
|
||||
bPlayer.setAbilities(bindings);
|
||||
bPlayer.setAbilities(abilities);
|
||||
return boundAll;
|
||||
}
|
||||
|
||||
|
|
|
@ -37,17 +37,23 @@ public class DBConnection {
|
|||
ProjectKorra.log.info("Database connection established.");
|
||||
if (!sql.tableExists("pk_players")) {
|
||||
ProjectKorra.log.info("Creating pk_players table");
|
||||
final String query = "CREATE TABLE `pk_players` (" + "`uuid` varchar(36) NOT NULL," + "`player` varchar(16) NOT NULL," + "`element` varchar(255)," + "`subelement` varchar(255)," + "`permaremoved` varchar(5)," + "`slot1` varchar(255)," + "`slot2` varchar(255)," + "`slot3` varchar(255)," + "`slot4` varchar(255)," + "`slot5` varchar(255)," + "`slot6` varchar(255)," + "`slot7` varchar(255)," + "`slot8` varchar(255)," + "`slot9` varchar(255)," + " PRIMARY KEY (uuid));";
|
||||
final String query = "CREATE TABLE `pk_players` (`uuid` varchar(36) NOT NULL, `player` varchar(16) NOT NULL, `permaremoved` varchar(5), `slot1` varchar(255), `slot2` varchar(255), `slot3` varchar(255), `slot4` varchar(255), `slot5` varchar(255), `slot6` varchar(255), `slot7` varchar(255), `slot8` varchar(255), `slot9` varchar(255), PRIMARY KEY (uuid));";
|
||||
sql.modifyQuery(query, false);
|
||||
} else {
|
||||
try {
|
||||
final DatabaseMetaData md = sql.connection.getMetaData();
|
||||
if (!md.getColumns(null, null, "pk_players", "subelement").next()) {
|
||||
ProjectKorra.log.info("Updating Database with subelements...");
|
||||
boolean elementColumn = md.getColumns(null, null, "pk_players", "element").next();
|
||||
boolean subElementColumn = md.getColumns(null, null, "pk_players", "subelement").next();
|
||||
if (elementColumn || subElementColumn) {
|
||||
ProjectKorra.log.info("Updating Database...");
|
||||
sql.getConnection().setAutoCommit(false);
|
||||
sql.modifyQuery("ALTER TABLE `pk_players` ADD subelement varchar(255);", false);
|
||||
if (elementColumn) {
|
||||
sql.modifyQuery("ALTER TABLE `pk_players` DROP element;", false);
|
||||
}
|
||||
if (subElementColumn) {
|
||||
sql.modifyQuery("ALTER TABLE `pk_players` DROP subelement;", false);
|
||||
}
|
||||
sql.getConnection().commit();
|
||||
sql.modifyQuery("UPDATE pk_players SET subelement = '-';", false);
|
||||
sql.getConnection().setAutoCommit(true);
|
||||
ProjectKorra.log.info("Database Updated.");
|
||||
}
|
||||
|
@ -55,9 +61,14 @@ public class DBConnection {
|
|||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (!sql.tableExists("pk_player_elements")) {
|
||||
ProjectKorra.log.info("Creating pk_player_elements table");
|
||||
final String query = "CREATE TABLE `pk_player_elements` (`uuid` varchar(36) NOT NULL, `element` varchar(36) NOT NULL, `sub_element` varchar(5) NOT NULL, PRIMARY KEY (`uuid`, `element`));";
|
||||
sql.modifyQuery(query, false);
|
||||
}
|
||||
if (!sql.tableExists("pk_presets")) {
|
||||
ProjectKorra.log.info("Creating pk_presets table");
|
||||
final String query = "CREATE TABLE `pk_presets` (" + "`uuid` varchar(36) NOT NULL," + "`name` varchar(255) NOT NULL," + "`slot1` varchar(255)," + "`slot2` varchar(255)," + "`slot3` varchar(255)," + "`slot4` varchar(255)," + "`slot5` varchar(255)," + "`slot6` varchar(255)," + "`slot7` varchar(255)," + "`slot8` varchar(255)," + "`slot9` varchar(255)," + " PRIMARY KEY (uuid, name));";
|
||||
final String query = "CREATE TABLE `pk_presets` (`uuid` varchar(36) NOT NULL, `name` varchar(255) NOT NULL, `slot1` varchar(255), `slot2` varchar(255), `slot3` varchar(255), `slot4` varchar(255), `slot5` varchar(255), `slot6` varchar(255), `slot7` varchar(255), `slot8` varchar(255), `slot9` varchar(255), PRIMARY KEY (uuid, name));";
|
||||
sql.modifyQuery(query, false);
|
||||
}
|
||||
if (!sql.tableExists("pk_cooldown_ids")) {
|
||||
|
@ -80,28 +91,38 @@ public class DBConnection {
|
|||
isOpen = true;
|
||||
if (!sql.tableExists("pk_players")) {
|
||||
ProjectKorra.log.info("Creating pk_players table.");
|
||||
final String query = "CREATE TABLE `pk_players` (" + "`uuid` TEXT(36) PRIMARY KEY," + "`player` TEXT(16)," + "`element` TEXT(255)," + "`subelement` TEXT(255)," + "`permaremoved` TEXT(5)," + "`slot1` TEXT(255)," + "`slot2` TEXT(255)," + "`slot3` TEXT(255)," + "`slot4` TEXT(255)," + "`slot5` TEXT(255)," + "`slot6` TEXT(255)," + "`slot7` TEXT(255)," + "`slot8` TEXT(255)," + "`slot9` TEXT(255));";
|
||||
final String query = "CREATE TABLE `pk_players` (`uuid` TEXT(36) PRIMARY KEY, `player` TEXT(16), `permaremoved` TEXT(5), `slot1` TEXT(255), `slot2` TEXT(255), `slot3` TEXT(255), `slot4` TEXT(255), `slot5` TEXT(255), `slot6` TEXT(255), `slot7` TEXT(255), `slot8` TEXT(255), `slot9` TEXT(255));";
|
||||
sql.modifyQuery(query, false);
|
||||
} else {
|
||||
try {
|
||||
final DatabaseMetaData md = sql.connection.getMetaData();
|
||||
if (!md.getColumns(null, null, "pk_players", "subelement").next()) {
|
||||
ProjectKorra.log.info("Updating Database with subelements...");
|
||||
boolean elementColumn = md.getColumns(null, null, "pk_players", "element").next();
|
||||
boolean subElementColumn = md.getColumns(null, null, "pk_players", "subelement").next();
|
||||
if (elementColumn || subElementColumn) {
|
||||
ProjectKorra.log.info("Updating Database...");
|
||||
sql.getConnection().setAutoCommit(false);
|
||||
sql.modifyQuery("ALTER TABLE `pk_players` ADD subelement TEXT(255);", false);
|
||||
if (elementColumn) {
|
||||
sql.modifyQuery("ALTER TABLE `pk_players` DROP element;", false);
|
||||
}
|
||||
if (subElementColumn) {
|
||||
sql.modifyQuery("ALTER TABLE `pk_players` DROP subelement;", false);
|
||||
}
|
||||
sql.getConnection().commit();
|
||||
sql.modifyQuery("UPDATE pk_players SET subelement = '-';", false);
|
||||
sql.getConnection().setAutoCommit(true);
|
||||
ProjectKorra.log.info("Database Updated.");
|
||||
}
|
||||
|
||||
} catch (final SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (!sql.tableExists("pk_player_elements")) {
|
||||
ProjectKorra.log.info("Creating pk_player_elements table");
|
||||
final String query = "CREATE TABLE `pk_player_elements` (`uuid` TEXT(36) NOT NULL, `element` TEXT(36) NOT NULL, `sub_element` TEXT(5) NOT NULL, PRIMARY KEY (`uuid`, `element`));";
|
||||
sql.modifyQuery(query, false);
|
||||
}
|
||||
if (!sql.tableExists("pk_presets")) {
|
||||
ProjectKorra.log.info("Creating pk_presets table");
|
||||
final String query = "CREATE TABLE `pk_presets` (" + "`uuid` TEXT(36)," + "`name` TEXT(255)," + "`slot1` TEXT(255)," + "`slot2` TEXT(255)," + "`slot3` TEXT(255)," + "`slot4` TEXT(255)," + "`slot5` TEXT(255)," + "`slot6` TEXT(255)," + "`slot7` TEXT(255)," + "`slot8` TEXT(255)," + "`slot9` TEXT(255)," + "PRIMARY KEY (uuid, name));";
|
||||
final String query = "CREATE TABLE `pk_presets` (`uuid` TEXT(36), `name` TEXT(255), `slot1` TEXT(255), `slot2` TEXT(255), `slot3` TEXT(255), `slot4` TEXT(255), `slot5` TEXT(255), `slot6` TEXT(255), `slot7` TEXT(255), `slot8` TEXT(255), `slot9` TEXT(255), PRIMARY KEY (uuid, name));";
|
||||
sql.modifyQuery(query, false);
|
||||
}
|
||||
if (!sql.tableExists("pk_cooldown_ids")) {
|
||||
|
|
|
@ -470,7 +470,7 @@ public class WaterArms extends WaterAbility<WaterArmsConfig> {
|
|||
}
|
||||
|
||||
public void displayBoundMsg(final int slot) {
|
||||
final String name = this.bPlayer.getAbilities().get(slot);
|
||||
final String name = this.bPlayer.getAbilities()[slot - 1];
|
||||
if (name != null) {
|
||||
this.player.sendMessage(this.getElement().getColor() + this.sneakMsg + " " + name);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue