mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2024-12-23 00:15:05 +00:00
Update Subelement Lingo
• Updated all commands to treat subelements as elements in certain circumstances (add, remove, etc) • Updated tabbing with bug fixes • Database will now update player's subs when they log in for the first time (post update) • Removed "SubElementAdded" field from config • Fixed /b choose not taking aliases
This commit is contained in:
parent
73834e3762
commit
3c216cebad
8 changed files with 154 additions and 37 deletions
|
@ -254,6 +254,9 @@ public class BendingPlayer {
|
||||||
if (!hasElement(subElement.getParentElement())) {
|
if (!hasElement(subElement.getParentElement())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (!hasSubElement(subElement)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (GeneralMethods.hasSpirits()) {
|
if (GeneralMethods.hasSpirits()) {
|
||||||
if (GeneralMethods.hasSpirits()) {
|
if (GeneralMethods.hasSpirits()) {
|
||||||
SpiritPlayer sPlayer = SpiritPlayer.getSpiritPlayer(player);
|
SpiritPlayer sPlayer = SpiritPlayer.getSpiritPlayer(player);
|
||||||
|
@ -446,6 +449,15 @@ public class BendingPlayer {
|
||||||
return stance;
|
return stance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the list of subelements the {@link BendingPlayer} knows.
|
||||||
|
*
|
||||||
|
* @return a list of subelements
|
||||||
|
*/
|
||||||
|
public List<SubElement> getSubElements() {
|
||||||
|
return this.subelements;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the unique identifier of the {@link BendingPlayer}.
|
* Gets the unique identifier of the {@link BendingPlayer}.
|
||||||
*
|
*
|
||||||
|
@ -499,6 +511,17 @@ public class BendingPlayer {
|
||||||
return this.subelements.contains(sub);
|
return this.subelements.contains(sub);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the player has permission to bend the subelement
|
||||||
|
* @param sub The SubElement
|
||||||
|
*/
|
||||||
|
public boolean hasSubElementPermission(SubElement sub) {
|
||||||
|
if (sub == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return player.hasPermission("bending." + sub.getParentElement().getName().toLowerCase() + "." + sub.getName().toLowerCase() + sub.getType().getBending());
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isAvatarState() {
|
public boolean isAvatarState() {
|
||||||
return CoreAbility.hasAbility(player, AvatarState.class);
|
return CoreAbility.hasAbility(player, AvatarState.class);
|
||||||
|
|
|
@ -321,10 +321,21 @@ public class GeneralMethods {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final ArrayList<SubElement> subelements = new ArrayList<SubElement>();
|
final ArrayList<SubElement> subelements = new ArrayList<SubElement>();
|
||||||
|
boolean shouldSave = false;
|
||||||
if (subelement != null) {
|
if (subelement != null) {
|
||||||
boolean hasAddon = subelement.contains(";");
|
boolean hasAddon = subelement.contains(";");
|
||||||
String[] split = subelement.split(";");
|
String[] split = subelement.split(";");
|
||||||
if (split[0] != null) {
|
if (subelement.equals("-")) {
|
||||||
|
Player playero = Bukkit.getPlayer(uuid);
|
||||||
|
for (SubElement sub : Element.getAllSubElements()) {
|
||||||
|
if (playero.hasPermission("bending." + sub.getParentElement().getName().toLowerCase() + "." + sub.getName().toLowerCase()
|
||||||
|
+ sub.getType().getBending()) && elements.contains(sub.getParentElement())) {
|
||||||
|
subelements.add(sub);
|
||||||
|
shouldSave = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (split[0] != null) {
|
||||||
if (split[0].contains("m")) {
|
if (split[0].contains("m")) {
|
||||||
subelements.add(Element.METAL);
|
subelements.add(Element.METAL);
|
||||||
}
|
}
|
||||||
|
@ -380,10 +391,14 @@ public class GeneralMethods {
|
||||||
p = (permaremoved != null && (permaremoved.equals("true")));
|
p = (permaremoved != null && (permaremoved.equals("true")));
|
||||||
|
|
||||||
final boolean boolean_p = p;
|
final boolean boolean_p = p;
|
||||||
|
final boolean shouldSave_ = shouldSave;
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
new BendingPlayer(uuid, player, elements, subelements, abilities, boolean_p);
|
new BendingPlayer(uuid, player, elements, subelements, abilities, boolean_p);
|
||||||
|
if (shouldSave_) {
|
||||||
|
saveSubElements(BendingPlayer.getBendingPlayer(player));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.runTask(ProjectKorra.plugin);
|
}.runTask(ProjectKorra.plugin);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ public class AddCommand extends PKCommand {
|
||||||
private String alreadyHasSubElement;
|
private String alreadyHasSubElement;
|
||||||
|
|
||||||
public AddCommand() {
|
public AddCommand() {
|
||||||
super("add", "/bending add <Element> [Player]", ConfigManager.languageConfig.get().getString("Commands.Add.Description"), new String[] { "add", "a" });
|
super("add", "/bending add <Element/SubElement> [Player]", ConfigManager.languageConfig.get().getString("Commands.Add.Description"), new String[] { "add", "a" });
|
||||||
|
|
||||||
this.playerNotFound = ConfigManager.languageConfig.get().getString("Commands.Add.PlayerNotFound");
|
this.playerNotFound = ConfigManager.languageConfig.get().getString("Commands.Add.PlayerNotFound");
|
||||||
this.invalidElement = ConfigManager.languageConfig.get().getString("Commands.Add.InvalidElement");
|
this.invalidElement = ConfigManager.languageConfig.get().getString("Commands.Add.InvalidElement");
|
||||||
|
@ -51,7 +51,7 @@ public class AddCommand extends PKCommand {
|
||||||
if (!hasPermission(sender) || !isPlayer(sender)) {
|
if (!hasPermission(sender) || !isPlayer(sender)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
add(sender, (Player) sender, Element.fromString(args.get(0).toLowerCase()));
|
add(sender, (Player) sender, args.get(0).toLowerCase());
|
||||||
} else if (args.size() == 2) { //bending add element combo
|
} else if (args.size() == 2) { //bending add element combo
|
||||||
if (!hasPermission(sender, "others")) {
|
if (!hasPermission(sender, "others")) {
|
||||||
return;
|
return;
|
||||||
|
@ -61,7 +61,7 @@ public class AddCommand extends PKCommand {
|
||||||
sender.sendMessage(ChatColor.RED + playerNotFound);
|
sender.sendMessage(ChatColor.RED + playerNotFound);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
add(sender, player, Element.fromString(args.get(0).toLowerCase()));
|
add(sender, player, args.get(0).toLowerCase());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,13 @@ public class AddCommand extends PKCommand {
|
||||||
* @param target The player to add the element to
|
* @param target The player to add the element to
|
||||||
* @param element The element to add
|
* @param element The element to add
|
||||||
*/
|
*/
|
||||||
private void add(CommandSender sender, Player target, Element element) {
|
private void add(CommandSender sender, Player target, String element) {
|
||||||
|
|
||||||
|
Element e = Element.fromString(element);
|
||||||
|
if (e == null) {
|
||||||
|
e = SubElement.fromString(element);
|
||||||
|
}
|
||||||
|
|
||||||
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(target);
|
BendingPlayer bPlayer = BendingPlayer.getBendingPlayer(target);
|
||||||
if (bPlayer == null) {
|
if (bPlayer == null) {
|
||||||
GeneralMethods.createBendingPlayer(target.getUniqueId(), target.getName());
|
GeneralMethods.createBendingPlayer(target.getUniqueId(), target.getName());
|
||||||
|
@ -82,8 +88,8 @@ public class AddCommand extends PKCommand {
|
||||||
sender.sendMessage(ChatColor.RED + ConfigManager.languageConfig.get().getString("Commands.Preset.Other.BendingPermanentlyRemoved"));
|
sender.sendMessage(ChatColor.RED + ConfigManager.languageConfig.get().getString("Commands.Preset.Other.BendingPermanentlyRemoved"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Arrays.asList(Element.getAllElements()).contains(element)) {
|
if (Arrays.asList(Element.getAllElements()).contains(e)) {
|
||||||
if (bPlayer.hasElement(element)) {
|
if (bPlayer.hasElement(e)) {
|
||||||
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
||||||
sender.sendMessage(ChatColor.RED + alreadyHasElementOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + ChatColor.RED));
|
sender.sendMessage(ChatColor.RED + alreadyHasElementOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + ChatColor.RED));
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,19 +97,19 @@ public class AddCommand extends PKCommand {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bPlayer.addElement(element);
|
bPlayer.addElement(e);
|
||||||
ChatColor color = element.getColor();
|
ChatColor color = e.getColor();
|
||||||
|
|
||||||
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
||||||
sender.sendMessage(color + addedOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", element.getName() + element.getType().getBender()));
|
sender.sendMessage(color + addedOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", e.getName() + e.getType().getBender()));
|
||||||
} else {
|
} else {
|
||||||
target.sendMessage(color + added.replace("{element}", element.getName() + element.getType().getBender()));
|
target.sendMessage(color + added.replace("{element}", e.getName() + e.getType().getBender()));
|
||||||
}
|
}
|
||||||
GeneralMethods.saveElements(bPlayer);
|
GeneralMethods.saveElements(bPlayer);
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, target, element, Result.ADD));
|
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, target, e, Result.ADD));
|
||||||
return;
|
return;
|
||||||
} else if (Arrays.asList(Element.getAllSubElements()).contains(element)) {
|
} else if (Arrays.asList(Element.getAllSubElements()).contains(e)) {
|
||||||
SubElement sub = (SubElement) element;
|
SubElement sub = (SubElement) e;
|
||||||
if (bPlayer.hasSubElement(sub)) {
|
if (bPlayer.hasSubElement(sub)) {
|
||||||
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
||||||
sender.sendMessage(ChatColor.RED + alreadyHasSubElementOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + ChatColor.RED));
|
sender.sendMessage(ChatColor.RED + alreadyHasSubElementOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + ChatColor.RED));
|
||||||
|
@ -113,7 +119,7 @@ public class AddCommand extends PKCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bPlayer.addSubElement(sub);
|
bPlayer.addSubElement(sub);
|
||||||
ChatColor color = element.getColor();
|
ChatColor color = e.getColor();
|
||||||
|
|
||||||
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
||||||
sender.sendMessage(color + addedOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", sub.getName() + sub.getType().getBender()));
|
sender.sendMessage(color + addedOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", sub.getName() + sub.getType().getBender()));
|
||||||
|
|
|
@ -87,8 +87,10 @@ public class BendingTabComplete implements TabCompleter {
|
||||||
}
|
}
|
||||||
return getPossibleCompletionsForGivenArgs(args, list);
|
return getPossibleCompletionsForGivenArgs(args, list);
|
||||||
} else if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("a") || args[0].equalsIgnoreCase("choose") || args[0].equalsIgnoreCase("ch")) {
|
} else if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("a") || args[0].equalsIgnoreCase("choose") || args[0].equalsIgnoreCase("ch")) {
|
||||||
if (args.length > 3 || !sender.hasPermission("bending.command.add"))
|
if (args.length > 3) return new ArrayList<String>();
|
||||||
return new ArrayList<String>();
|
if ((args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("a")) && !sender.hasPermission("bending.command.add")) return new ArrayList<String>();
|
||||||
|
if ((args[0].equalsIgnoreCase("choose") || args[0].equalsIgnoreCase("ch")) && !sender.hasPermission("bending.command.choose")) return new ArrayList<String>();
|
||||||
|
|
||||||
List<String> l = new ArrayList<String>();
|
List<String> l = new ArrayList<String>();
|
||||||
if (args.length == 2)
|
if (args.length == 2)
|
||||||
{
|
{
|
||||||
|
@ -100,6 +102,23 @@ public class BendingTabComplete implements TabCompleter {
|
||||||
for (Element e : Element.getAddonElements()) {
|
for (Element e : Element.getAddonElements()) {
|
||||||
l.add(e.getName());
|
l.add(e.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("a")) {
|
||||||
|
l.add("Blood");
|
||||||
|
l.add("Combustion");
|
||||||
|
l.add("Flight");
|
||||||
|
l.add("Healing");
|
||||||
|
l.add("Ice");
|
||||||
|
l.add("Lava");
|
||||||
|
l.add("Lightning");
|
||||||
|
l.add("Metal");
|
||||||
|
l.add("Plant");
|
||||||
|
l.add("Sand");
|
||||||
|
l.add("Spiritual");
|
||||||
|
for (SubElement e : Element.getAddonSubElements()) {
|
||||||
|
l.add(e.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -197,6 +216,22 @@ public class BendingTabComplete implements TabCompleter {
|
||||||
for (Element e : Element.getAddonElements()) {
|
for (Element e : Element.getAddonElements()) {
|
||||||
l.add(e.getName());
|
l.add(e.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
l.add("Blood");
|
||||||
|
l.add("Combustion");
|
||||||
|
l.add("Flight");
|
||||||
|
l.add("Healing");
|
||||||
|
l.add("Ice");
|
||||||
|
l.add("Lava");
|
||||||
|
l.add("Lightning");
|
||||||
|
l.add("Metal");
|
||||||
|
l.add("Plant");
|
||||||
|
l.add("Sand");
|
||||||
|
l.add("Spiritual");
|
||||||
|
|
||||||
|
for (SubElement e : Element.getAddonSubElements()) {
|
||||||
|
l.add(e.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return getPossibleCompletionsForGivenArgs(args, l);
|
return getPossibleCompletionsForGivenArgs(args, l);
|
||||||
} else if (args[0].equalsIgnoreCase("who") || args[0].equalsIgnoreCase("w")) {
|
} else if (args[0].equalsIgnoreCase("who") || args[0].equalsIgnoreCase("w")) {
|
||||||
|
|
|
@ -29,7 +29,7 @@ public class ChooseCommand extends PKCommand {
|
||||||
private String chosenOther;
|
private String chosenOther;
|
||||||
|
|
||||||
public ChooseCommand() {
|
public ChooseCommand() {
|
||||||
super("choose", "/bending choose <Element/SubElement> [Player]", ConfigManager.languageConfig.get().getString("Commands.Choose.Description"), new String[] { "choose", "ch" });
|
super("choose", "/bending choose <Element> [Player]", ConfigManager.languageConfig.get().getString("Commands.Choose.Description"), new String[] { "choose", "ch" });
|
||||||
|
|
||||||
this.playerNotFound = ConfigManager.languageConfig.get().getString("Commands.Choose.PlayerNotFound");
|
this.playerNotFound = ConfigManager.languageConfig.get().getString("Commands.Choose.PlayerNotFound");
|
||||||
this.invalidElement = ConfigManager.languageConfig.get().getString("Commands.Choose.InvalidElement");
|
this.invalidElement = ConfigManager.languageConfig.get().getString("Commands.Choose.InvalidElement");
|
||||||
|
@ -61,6 +61,11 @@ public class ChooseCommand extends PKCommand {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String element = args.get(0).toLowerCase();
|
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";
|
||||||
Element target = Element.getElement(element);
|
Element target = Element.getElement(element);
|
||||||
if (Arrays.asList(Element.getAllElements()).contains(target)) {
|
if (Arrays.asList(Element.getAllElements()).contains(target)) {
|
||||||
if (!hasPermission(sender, element)) {
|
if (!hasPermission(sender, element)) {
|
||||||
|
@ -68,12 +73,6 @@ public class ChooseCommand extends PKCommand {
|
||||||
}
|
}
|
||||||
add(sender, (Player) sender, target);
|
add(sender, (Player) sender, target);
|
||||||
return;
|
return;
|
||||||
} else if (Arrays.asList(Element.getAllSubElements()).contains(target)) {
|
|
||||||
SubElement sub = (SubElement) target;
|
|
||||||
if (!hasPermission(sender, sub.getName())) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
add(sender, (Player) sender, sub);
|
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(ChatColor.RED + invalidElement);
|
sender.sendMessage(ChatColor.RED + invalidElement);
|
||||||
return;
|
return;
|
||||||
|
@ -125,6 +124,13 @@ public class ChooseCommand extends PKCommand {
|
||||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeSubElementEvent(sender, target, sub, com.projectkorra.projectkorra.event.PlayerChangeSubElementEvent.Result.CHOOSE));
|
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeSubElementEvent(sender, target, sub, com.projectkorra.projectkorra.event.PlayerChangeSubElementEvent.Result.CHOOSE));
|
||||||
} else {
|
} else {
|
||||||
bPlayer.setElement(element);
|
bPlayer.setElement(element);
|
||||||
|
|
||||||
|
for (SubElement sub : Element.getAllSubElements()) {
|
||||||
|
if (sub.getParentElement() == element && bPlayer.hasSubElementPermission(sub)) {
|
||||||
|
bPlayer.addSubElement(sub);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ChatColor color = element != null ? element.getColor() : ChatColor.WHITE;
|
ChatColor color = element != null ? element.getColor() : ChatColor.WHITE;
|
||||||
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
||||||
sender.sendMessage(color + chosenOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", element.getName() + element.getType().getBender()));
|
sender.sendMessage(color + chosenOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + color).replace("{element}", element.getName() + element.getType().getBender()));
|
||||||
|
|
|
@ -3,6 +3,7 @@ package com.projectkorra.projectkorra.command;
|
||||||
import com.projectkorra.projectkorra.BendingPlayer;
|
import com.projectkorra.projectkorra.BendingPlayer;
|
||||||
import com.projectkorra.projectkorra.Element;
|
import com.projectkorra.projectkorra.Element;
|
||||||
import com.projectkorra.projectkorra.GeneralMethods;
|
import com.projectkorra.projectkorra.GeneralMethods;
|
||||||
|
import com.projectkorra.projectkorra.Element.SubElement;
|
||||||
import com.projectkorra.projectkorra.configuration.ConfigManager;
|
import com.projectkorra.projectkorra.configuration.ConfigManager;
|
||||||
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent;
|
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent;
|
||||||
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent.Result;
|
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent.Result;
|
||||||
|
@ -61,6 +62,11 @@ public class RemoveCommand extends PKCommand {
|
||||||
sender.sendMessage(ChatColor.RED + wrongElementSelf);
|
sender.sendMessage(ChatColor.RED + wrongElementSelf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else if (SubElement.fromString(args.get(0)) != null) {
|
||||||
|
SubElement sub = (SubElement) SubElement.fromString(args.get(0));
|
||||||
|
if (senderBPlayer.hasSubElement(sub)) {
|
||||||
|
senderBPlayer.getSubElements().remove(sub);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(ChatColor.RED + invalidElement);
|
sender.sendMessage(ChatColor.RED + invalidElement);
|
||||||
return;
|
return;
|
||||||
|
@ -82,8 +88,14 @@ public class RemoveCommand extends PKCommand {
|
||||||
sender.sendMessage(ChatColor.DARK_RED + wrongElementTarget.replace("{target}", player.getName()));
|
sender.sendMessage(ChatColor.DARK_RED + wrongElementTarget.replace("{target}", player.getName()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bPlayer.getElements().remove(e);
|
if (e instanceof SubElement) {
|
||||||
GeneralMethods.saveElements(bPlayer);
|
bPlayer.getSubElements().remove(e);
|
||||||
|
GeneralMethods.saveSubElements(bPlayer);
|
||||||
|
} else {
|
||||||
|
bPlayer.getElements().remove(e);
|
||||||
|
GeneralMethods.saveElements(bPlayer);
|
||||||
|
}
|
||||||
|
|
||||||
GeneralMethods.removeUnusableAbilities(player.getName());
|
GeneralMethods.removeUnusableAbilities(player.getName());
|
||||||
sender.sendMessage(e.getColor() + this.succesfullyRemovedElementTargetConfirm.replace("{element}", e.getName() + e.getType().getBending()).replace("{sender}", ChatColor.DARK_AQUA + player.getName() + e.getColor()));
|
sender.sendMessage(e.getColor() + this.succesfullyRemovedElementTargetConfirm.replace("{element}", e.getName() + e.getType().getBending()).replace("{sender}", ChatColor.DARK_AQUA + player.getName() + e.getColor()));
|
||||||
sender.sendMessage(e.getColor() + this.succesfullyRemovedElementTarget.replace("{element}" , e.getName() + e.getType().getBending()).replace("{sender}", ChatColor.DARK_AQUA + sender.getName() + e.getColor()));
|
sender.sendMessage(e.getColor() + this.succesfullyRemovedElementTarget.replace("{element}" , e.getName() + e.getType().getBending()).replace("{sender}", ChatColor.DARK_AQUA + sender.getName() + e.getColor()));
|
||||||
|
|
|
@ -1102,7 +1102,6 @@ public class ConfigManager {
|
||||||
config.addDefault("Storage.MySQL.pass", "");
|
config.addDefault("Storage.MySQL.pass", "");
|
||||||
config.addDefault("Storage.MySQL.db", "minecraft");
|
config.addDefault("Storage.MySQL.db", "minecraft");
|
||||||
config.addDefault("Storage.MySQL.user", "root");
|
config.addDefault("Storage.MySQL.user", "root");
|
||||||
config.addDefault("Storage.MySQL.SubElementAdded", false);
|
|
||||||
|
|
||||||
config.addDefault("debug", false);
|
config.addDefault("debug", false);
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package com.projectkorra.projectkorra.storage;
|
package com.projectkorra.projectkorra.storage;
|
||||||
|
|
||||||
|
import java.sql.DatabaseMetaData;
|
||||||
|
import java.sql.SQLException;
|
||||||
import com.projectkorra.projectkorra.GeneralMethods;
|
import com.projectkorra.projectkorra.GeneralMethods;
|
||||||
import com.projectkorra.projectkorra.ProjectKorra;
|
import com.projectkorra.projectkorra.ProjectKorra;
|
||||||
import com.projectkorra.projectkorra.configuration.ConfigManager;
|
|
||||||
|
|
||||||
public class DBConnection {
|
public class DBConnection {
|
||||||
|
|
||||||
|
@ -14,8 +15,7 @@ public class DBConnection {
|
||||||
public static String user;
|
public static String user;
|
||||||
public static String pass;
|
public static String pass;
|
||||||
public static boolean isOpen = false;
|
public static boolean isOpen = false;
|
||||||
private static boolean subelement = ConfigManager.defaultConfig.get().getBoolean("Storage.MySQL.SubElementAdded");
|
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
if (ProjectKorra.plugin.getConfig().getString("Storage.engine").equalsIgnoreCase("mysql")) {
|
if (ProjectKorra.plugin.getConfig().getString("Storage.engine").equalsIgnoreCase("mysql")) {
|
||||||
sql = new MySQL(ProjectKorra.log, "Establishing MySQL Connection...", host, port, user, pass, db);
|
sql = new MySQL(ProjectKorra.log, "Establishing MySQL Connection...", host, port, user, pass, db);
|
||||||
|
@ -32,10 +32,20 @@ public class DBConnection {
|
||||||
ProjectKorra.log.info("Creating pk_players table");
|
ProjectKorra.log.info("Creating pk_players table");
|
||||||
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));";
|
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));";
|
||||||
sql.modifyQuery(query);
|
sql.modifyQuery(query);
|
||||||
} else {
|
} else {
|
||||||
if (!subelement) {
|
try {
|
||||||
sql.modifyQuery("ALTER TABLE `pk_players` ADD subelement varchar(255);");
|
DatabaseMetaData md = sql.connection.getMetaData();
|
||||||
ConfigManager.defaultConfig.get().set("Storage.MySQL.SubElementAdded", true);
|
if (!md.getColumns(null, null, "pk_players", "subelement").next()) {
|
||||||
|
ProjectKorra.log.info("Updating Database with subelements...");
|
||||||
|
sql.getConnection().setAutoCommit(false);
|
||||||
|
sql.modifyQuery("ALTER TABLE `pk_players` ADD subelement varchar(255);");
|
||||||
|
sql.getConnection().commit();
|
||||||
|
sql.modifyQuery("UPDATE pk_players SET subelement = '-';");
|
||||||
|
sql.getConnection().setAutoCommit(true);
|
||||||
|
ProjectKorra.log.info("Database Updated.");
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,9 +68,20 @@ public class DBConnection {
|
||||||
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));";
|
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));";
|
||||||
sql.modifyQuery(query);
|
sql.modifyQuery(query);
|
||||||
} else {
|
} else {
|
||||||
if (!subelement) {
|
try {
|
||||||
sql.modifyQuery("ALTER TABLE `pk_players` ADD subelement TEXT(255);");
|
DatabaseMetaData md = sql.connection.getMetaData();
|
||||||
ConfigManager.defaultConfig.get().set("Storage.MySQL.SubElementAdded", true);
|
if (!md.getColumns(null, null, "pk_players", "subelement").next()) {
|
||||||
|
ProjectKorra.log.info("Updating Database with subelements...");
|
||||||
|
sql.getConnection().setAutoCommit(false);
|
||||||
|
sql.modifyQuery("ALTER TABLE `pk_players` ADD subelement TEXT(255);");
|
||||||
|
sql.getConnection().commit();
|
||||||
|
sql.modifyQuery("UPDATE pk_players SET subelement = '-';");
|
||||||
|
sql.getConnection().setAutoCommit(true);
|
||||||
|
ProjectKorra.log.info("Database Updated.");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue