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())) {
|
||||
return false;
|
||||
}
|
||||
if (!hasSubElement(subElement)) {
|
||||
return false;
|
||||
}
|
||||
if (GeneralMethods.hasSpirits()) {
|
||||
if (GeneralMethods.hasSpirits()) {
|
||||
SpiritPlayer sPlayer = SpiritPlayer.getSpiritPlayer(player);
|
||||
|
@ -446,6 +449,15 @@ public class BendingPlayer {
|
|||
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}.
|
||||
*
|
||||
|
@ -500,6 +512,17 @@ public class BendingPlayer {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
return CoreAbility.hasAbility(player, AvatarState.class);
|
||||
}
|
||||
|
|
|
@ -321,10 +321,21 @@ public class GeneralMethods {
|
|||
}
|
||||
}
|
||||
final ArrayList<SubElement> subelements = new ArrayList<SubElement>();
|
||||
boolean shouldSave = false;
|
||||
if (subelement != null) {
|
||||
boolean hasAddon = subelement.contains(";");
|
||||
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")) {
|
||||
subelements.add(Element.METAL);
|
||||
}
|
||||
|
@ -380,10 +391,14 @@ public class GeneralMethods {
|
|||
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));
|
||||
}
|
||||
}
|
||||
}.runTask(ProjectKorra.plugin);
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public class AddCommand extends PKCommand {
|
|||
private String alreadyHasSubElement;
|
||||
|
||||
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.invalidElement = ConfigManager.languageConfig.get().getString("Commands.Add.InvalidElement");
|
||||
|
@ -51,7 +51,7 @@ public class AddCommand extends PKCommand {
|
|||
if (!hasPermission(sender) || !isPlayer(sender)) {
|
||||
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
|
||||
if (!hasPermission(sender, "others")) {
|
||||
return;
|
||||
|
@ -61,7 +61,7 @@ public class AddCommand extends PKCommand {
|
|||
sender.sendMessage(ChatColor.RED + playerNotFound);
|
||||
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 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);
|
||||
if (bPlayer == null) {
|
||||
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"));
|
||||
return;
|
||||
}
|
||||
if (Arrays.asList(Element.getAllElements()).contains(element)) {
|
||||
if (bPlayer.hasElement(element)) {
|
||||
if (Arrays.asList(Element.getAllElements()).contains(e)) {
|
||||
if (bPlayer.hasElement(e)) {
|
||||
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
||||
sender.sendMessage(ChatColor.RED + alreadyHasElementOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + ChatColor.RED));
|
||||
} else {
|
||||
|
@ -91,19 +97,19 @@ public class AddCommand extends PKCommand {
|
|||
}
|
||||
return;
|
||||
}
|
||||
bPlayer.addElement(element);
|
||||
ChatColor color = element.getColor();
|
||||
bPlayer.addElement(e);
|
||||
ChatColor color = e.getColor();
|
||||
|
||||
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 {
|
||||
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);
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, target, element, Result.ADD));
|
||||
Bukkit.getServer().getPluginManager().callEvent(new PlayerChangeElementEvent(sender, target, e, Result.ADD));
|
||||
return;
|
||||
} else if (Arrays.asList(Element.getAllSubElements()).contains(element)) {
|
||||
SubElement sub = (SubElement) element;
|
||||
} else if (Arrays.asList(Element.getAllSubElements()).contains(e)) {
|
||||
SubElement sub = (SubElement) e;
|
||||
if (bPlayer.hasSubElement(sub)) {
|
||||
if (!(sender instanceof Player) || !((Player) sender).equals(target)) {
|
||||
sender.sendMessage(ChatColor.RED + alreadyHasSubElementOther.replace("{target}", ChatColor.DARK_AQUA + target.getName() + ChatColor.RED));
|
||||
|
@ -113,7 +119,7 @@ public class AddCommand extends PKCommand {
|
|||
return;
|
||||
}
|
||||
bPlayer.addSubElement(sub);
|
||||
ChatColor color = element.getColor();
|
||||
ChatColor color = e.getColor();
|
||||
|
||||
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()));
|
||||
|
|
|
@ -87,8 +87,10 @@ public class BendingTabComplete implements TabCompleter {
|
|||
}
|
||||
return getPossibleCompletionsForGivenArgs(args, list);
|
||||
} 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"))
|
||||
return new ArrayList<String>();
|
||||
if (args.length > 3) 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>();
|
||||
if (args.length == 2)
|
||||
{
|
||||
|
@ -100,6 +102,23 @@ public class BendingTabComplete implements TabCompleter {
|
|||
for (Element e : Element.getAddonElements()) {
|
||||
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
|
||||
{
|
||||
|
@ -197,6 +216,22 @@ public class BendingTabComplete implements TabCompleter {
|
|||
for (Element e : Element.getAddonElements()) {
|
||||
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);
|
||||
} else if (args[0].equalsIgnoreCase("who") || args[0].equalsIgnoreCase("w")) {
|
||||
|
|
|
@ -29,7 +29,7 @@ public class ChooseCommand extends PKCommand {
|
|||
private String chosenOther;
|
||||
|
||||
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.invalidElement = ConfigManager.languageConfig.get().getString("Commands.Choose.InvalidElement");
|
||||
|
@ -61,6 +61,11 @@ public class ChooseCommand extends PKCommand {
|
|||
return;
|
||||
}
|
||||
String element = args.get(0).toLowerCase();
|
||||
if (element.equalsIgnoreCase("a")) element = "air";
|
||||
else if (element.equalsIgnoreCase("e")) element = "earth";
|
||||
else if (element.equalsIgnoreCase("f")) element = "fire";
|
||||
else if (element.equalsIgnoreCase("w")) element = "water";
|
||||
else if (element.equalsIgnoreCase("c")) element = "chi";
|
||||
Element target = Element.getElement(element);
|
||||
if (Arrays.asList(Element.getAllElements()).contains(target)) {
|
||||
if (!hasPermission(sender, element)) {
|
||||
|
@ -68,12 +73,6 @@ public class ChooseCommand extends PKCommand {
|
|||
}
|
||||
add(sender, (Player) sender, target);
|
||||
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 {
|
||||
sender.sendMessage(ChatColor.RED + invalidElement);
|
||||
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));
|
||||
} else {
|
||||
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;
|
||||
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()));
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.projectkorra.projectkorra.command;
|
|||
import com.projectkorra.projectkorra.BendingPlayer;
|
||||
import com.projectkorra.projectkorra.Element;
|
||||
import com.projectkorra.projectkorra.GeneralMethods;
|
||||
import com.projectkorra.projectkorra.Element.SubElement;
|
||||
import com.projectkorra.projectkorra.configuration.ConfigManager;
|
||||
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent;
|
||||
import com.projectkorra.projectkorra.event.PlayerChangeElementEvent.Result;
|
||||
|
@ -61,6 +62,11 @@ public class RemoveCommand extends PKCommand {
|
|||
sender.sendMessage(ChatColor.RED + wrongElementSelf);
|
||||
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 {
|
||||
sender.sendMessage(ChatColor.RED + invalidElement);
|
||||
return;
|
||||
|
@ -82,8 +88,14 @@ public class RemoveCommand extends PKCommand {
|
|||
sender.sendMessage(ChatColor.DARK_RED + wrongElementTarget.replace("{target}", player.getName()));
|
||||
return;
|
||||
}
|
||||
if (e instanceof SubElement) {
|
||||
bPlayer.getSubElements().remove(e);
|
||||
GeneralMethods.saveSubElements(bPlayer);
|
||||
} else {
|
||||
bPlayer.getElements().remove(e);
|
||||
GeneralMethods.saveElements(bPlayer);
|
||||
}
|
||||
|
||||
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.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.db", "minecraft");
|
||||
config.addDefault("Storage.MySQL.user", "root");
|
||||
config.addDefault("Storage.MySQL.SubElementAdded", false);
|
||||
|
||||
config.addDefault("debug", false);
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package com.projectkorra.projectkorra.storage;
|
||||
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.SQLException;
|
||||
import com.projectkorra.projectkorra.GeneralMethods;
|
||||
import com.projectkorra.projectkorra.ProjectKorra;
|
||||
import com.projectkorra.projectkorra.configuration.ConfigManager;
|
||||
|
||||
public class DBConnection {
|
||||
|
||||
|
@ -14,7 +15,6 @@ public class DBConnection {
|
|||
public static String user;
|
||||
public static String pass;
|
||||
public static boolean isOpen = false;
|
||||
private static boolean subelement = ConfigManager.defaultConfig.get().getBoolean("Storage.MySQL.SubElementAdded");
|
||||
|
||||
public static void init() {
|
||||
if (ProjectKorra.plugin.getConfig().getString("Storage.engine").equalsIgnoreCase("mysql")) {
|
||||
|
@ -33,9 +33,19 @@ public class DBConnection {
|
|||
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);
|
||||
} else {
|
||||
if (!subelement) {
|
||||
try {
|
||||
DatabaseMetaData md = sql.connection.getMetaData();
|
||||
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);");
|
||||
ConfigManager.defaultConfig.get().set("Storage.MySQL.SubElementAdded", true);
|
||||
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));";
|
||||
sql.modifyQuery(query);
|
||||
} else {
|
||||
if (!subelement) {
|
||||
try {
|
||||
DatabaseMetaData md = sql.connection.getMetaData();
|
||||
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);");
|
||||
ConfigManager.defaultConfig.get().set("Storage.MySQL.SubElementAdded", true);
|
||||
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