From 732b3a8a952f665d3dc79a93e175e263198bfbff Mon Sep 17 00:00:00 2001
From: ShermansWorld <77093412+ShermansWorld@users.noreply.github.com>
Date: Fri, 23 Dec 2022 15:54:05 -0500
Subject: [PATCH] Fixed prefixes and inputs
Fixed annoying bugs with prefixes and war inputs.
---
AlathraWar2/pom.xml | 2 +-
AlathraWar2/resources/plugin.yml | 6 +-
AlathraWar2/resources/prefixes.yml | 1 -
.../me/ShermansWorld/AlathraWar/Main.java | 48 +---
.../java/me/ShermansWorld/AlathraWar/War.java | 268 +++++++++++-------
.../AlathraWar/commands/WarCommands.java | 122 ++++----
.../AlathraWar/data/PrefixData.java | 67 -----
.../AlathraWar/hooks/LuckPermsHook.java | 140 ---------
.../AlathraWar/hooks/TABHook.java | 16 +-
.../AlathraWar/listeners/JoinListener.java | 29 +-
10 files changed, 281 insertions(+), 418 deletions(-)
delete mode 100644 AlathraWar2/resources/prefixes.yml
delete mode 100644 AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/data/PrefixData.java
delete mode 100644 AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/hooks/LuckPermsHook.java
diff --git a/AlathraWar2/pom.xml b/AlathraWar2/pom.xml
index db083c2..4998804 100644
--- a/AlathraWar2/pom.xml
+++ b/AlathraWar2/pom.xml
@@ -3,7 +3,7 @@
me.ShermansWorld
AlathraWar
- 1.2.2
+ 1.3
jar
AlathraWar
diff --git a/AlathraWar2/resources/plugin.yml b/AlathraWar2/resources/plugin.yml
index 916d19a..deed8eb 100644
--- a/AlathraWar2/resources/plugin.yml
+++ b/AlathraWar2/resources/plugin.yml
@@ -1,14 +1,14 @@
name: AlathraWar
-version: 1.2.2
+version: 1.3
api-version: 1.19
author: ShermansWorld
main: me.ShermansWorld.AlathraWar.Main
-depend: [Vault, Towny, LuckPerms]
+depend: [Vault, Towny, TAB]
commands:
war:
description: used to create, delete, join and leave wars
- softdepend: [Vault, Towny, LuckPerms]
+ softdepend: [Vault, Towny, TAB]
siege:
description: used to start, end, and view sieges
softdepend: [Vault, Towny]
diff --git a/AlathraWar2/resources/prefixes.yml b/AlathraWar2/resources/prefixes.yml
deleted file mode 100644
index 3137d28..0000000
--- a/AlathraWar2/resources/prefixes.yml
+++ /dev/null
@@ -1 +0,0 @@
-Prefixes:
diff --git a/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/Main.java b/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/Main.java
index 5a6120b..582bceb 100644
--- a/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/Main.java
+++ b/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/Main.java
@@ -12,11 +12,9 @@
import me.ShermansWorld.AlathraWar.commands.SiegeTabCompletion;
import me.ShermansWorld.AlathraWar.commands.WarCommands;
import me.ShermansWorld.AlathraWar.commands.WarTabCompletion;
-import me.ShermansWorld.AlathraWar.data.PrefixData;
import me.ShermansWorld.AlathraWar.data.RolesData;
import me.ShermansWorld.AlathraWar.data.SiegeData;
import me.ShermansWorld.AlathraWar.data.WarData;
-import me.ShermansWorld.AlathraWar.hooks.LuckPermsHook;
import me.ShermansWorld.AlathraWar.hooks.TABHook;
import me.ShermansWorld.AlathraWar.listeners.BlockBreakListener;
import me.ShermansWorld.AlathraWar.listeners.JoinListener;
@@ -38,7 +36,6 @@ public class Main extends JavaPlugin {
public static WarData warData;
public static SiegeData siegeData;
- public static PrefixData prefixData;
public static RolesData rolesData;
public static Main instance;
public static Economy econ;
@@ -61,7 +58,7 @@ private static void initData() {
Iterator it = warsSet.iterator();
ArrayList warsTempList = new ArrayList();
while (it.hasNext()) {
- warsTempList.add(it.next().toLowerCase());
+ warsTempList.add(it.next());
}
for (int i = 0; i < warsTempList.size(); ++i) {
final War war = new War(warsTempList.get(i).toLowerCase(),
@@ -69,31 +66,21 @@ private static void initData() {
warData.getConfig().getString("Wars." + warsTempList.get(i) + ".side2"));
ArrayList side1Players = new ArrayList();
ArrayList side2Players = new ArrayList();
+ ArrayList side1Mercs = new ArrayList();
+ ArrayList side2Mercs = new ArrayList();
side1Players = (ArrayList) warData.getConfig()
.getList("Wars." + war.getName() + ".side1players");
side2Players = (ArrayList) warData.getConfig()
.getList("Wars." + war.getName() + ".side2players");
+ side1Mercs = (ArrayList) warData.getConfig()
+ .getList("Wars." + war.getName() + ".side1mercs");
+ side2Mercs = (ArrayList) warData.getConfig()
+ .getList("Wars." + war.getName() + ".side2mercs");
war.setSide1Players(side1Players);
war.setSide2Players(side2Players);
+ war.setSide1Mercs(side1Mercs);
+ war.setSide2Mercs(side2Mercs);
WarCommands.wars.add(war);
- for (final String playerName : war.getSide1Players()) {
- try {
- Bukkit.getServer().getPlayer(playerName)
- .setPlayerListName(String.valueOf(Helper.color(
- new StringBuilder("&c[").append(war.getSide1()).append("]&r").toString()))
- + playerName);
- } catch (NullPointerException ex) {
- }
- }
- for (final String playerName : war.getSide2Players()) {
- try {
- Bukkit.getServer().getPlayer(playerName)
- .setPlayerListName(String.valueOf(Helper.color(
- new StringBuilder("&9[").append(war.getSide2()).append("]&r").toString()))
- + playerName);
- } catch (NullPointerException ex2) {
- }
- }
}
} catch (NullPointerException e) {
Bukkit.getLogger().info("NULL when initializing wars");
@@ -137,21 +124,6 @@ private static void initData() {
} catch (NullPointerException e) {
Bukkit.getLogger().info("NULL when initializing sieges");
}
- try {
- Set prefixSet = (Set) prefixData.getConfig().getConfigurationSection("Prefixes")
- .getKeys(false);
- Iterator it3 = prefixSet.iterator();
- ArrayList prefixesTempList = new ArrayList();
- while (it3.hasNext()) {
- prefixesTempList.add(it3.next());
- }
- for (int i = 0; i < prefixesTempList.size(); ++i) {
- LuckPermsHook.prefixMap.put(prefixesTempList.get(i),
- prefixData.getConfig().getString("Prefixes." + prefixesTempList.get(i)));
- }
- } catch (NullPointerException e) {
- Bukkit.getLogger().info("NULL when initializing prefixes");
- }
}
@SuppressWarnings("rawtypes")
@@ -191,7 +163,6 @@ public static void initLogs() {
}
private static void initAPIs() {
- LuckPermsHook.init();
TABHook.init();
}
@@ -199,7 +170,6 @@ public void onEnable() {
instance = this;
warData = new WarData(this);
siegeData = new SiegeData(this);
- prefixData = new PrefixData(this);
new WarCommands(this);
new SiegeCommands(this);
new MercCommand(this);
diff --git a/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/War.java b/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/War.java
index 1b05a14..f3c210a 100644
--- a/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/War.java
+++ b/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/War.java
@@ -3,99 +3,177 @@
import java.util.ArrayList;
public class War {
- private String name;
- private String side1;
- private String side2;
- private ArrayList side1Players;
- private ArrayList side2Players;
-
- public War(final String name, final String side1, final String side2) {
- this.side1Players = new ArrayList();
- this.side2Players = new ArrayList();
- this.name = name;
- this.side1 = side1;
- this.side2 = side2;
- }
-
- public void addPlayerSide1(final String playerName) {
- boolean duplicate = false;
- for (int i = 0; i < this.side1Players.size(); ++i) {
- if (playerName.equalsIgnoreCase(this.side1Players.get(i))) {
- duplicate = true;
- }
- }
- if (!duplicate) {
- this.side1Players.add(playerName);
- }
- }
-
- public void removePlayerSide1(final String playerName) {
- for (int i = 0; i < this.side1Players.size(); ++i) {
- if (playerName.equalsIgnoreCase(this.side1Players.get(i))) {
- this.side1Players.remove(i);
- return;
- }
- }
- }
-
- public void addPlayerSide2(final String playerName) {
- boolean duplicate = false;
- for (int i = 0; i < this.side2Players.size(); ++i) {
- if (playerName.equalsIgnoreCase(this.side2Players.get(i))) {
- duplicate = true;
- }
- }
- if (!duplicate) {
- this.side2Players.add(playerName);
- }
- }
-
- public void removePlayerSide2(final String playerName) {
- for (int i = 0; i < this.side2Players.size(); ++i) {
- if (playerName.equalsIgnoreCase(this.side2Players.get(i))) {
- this.side2Players.remove(i);
- return;
- }
- }
- }
-
- public String getName() {
- return this.name;
- }
-
- public void setName(final String name) {
- this.name = name;
- }
-
- public String getSide1() {
- return this.side1;
- }
-
- public void setSide1(final String side1) {
- this.side1 = side1;
- }
-
- public String getSide2() {
- return this.side2;
- }
-
- public void setSide2(final String side2) {
- this.side2 = this.side1;
- }
-
- public ArrayList getSide1Players() {
- return this.side1Players;
- }
-
- public void setSide1Players(final ArrayList side1Players) {
- this.side1Players = side1Players;
- }
-
- public ArrayList getSide2Players() {
- return this.side2Players;
- }
-
- public void setSide2Players(final ArrayList side2Players) {
- this.side2Players = side2Players;
- }
+ private String name;
+ private String side1;
+ private String side2;
+ private ArrayList side1Players;
+ private ArrayList side2Players;
+ private ArrayList side1Mercs;
+ private ArrayList side2Mercs;
+
+ public War(final String name, final String side1, final String side2) {
+ side1Players = new ArrayList();
+ side2Players = new ArrayList();
+ side1Mercs = new ArrayList();
+ side2Mercs = new ArrayList();
+ this.name = name;
+ this.side1 = side1;
+ this.side2 = side2;
+ }
+
+ public void addPlayerSide1(final String playerName) {
+ boolean duplicate = false;
+ if (!side1Players.isEmpty()) {
+ for (int i = 0; i < this.side1Players.size(); ++i) {
+ if (playerName.equalsIgnoreCase(this.side1Players.get(i))) {
+ duplicate = true;
+ }
+ }
+ }
+ if (!duplicate) {
+ this.side1Players.add(playerName);
+ }
+ }
+
+ public void removePlayerSide1(final String playerName) {
+ if (!side1Players.isEmpty()) {
+ for (int i = 0; i < this.side1Players.size(); ++i) {
+ if (playerName.equalsIgnoreCase(this.side1Players.get(i))) {
+ this.side1Players.remove(i);
+ return;
+ }
+ }
+ }
+ }
+
+ public void addPlayerSide2(final String playerName) {
+ boolean duplicate = false;
+ if (!side2Players.isEmpty()) {
+ for (int i = 0; i < this.side2Players.size(); ++i) {
+ if (playerName.equalsIgnoreCase(this.side2Players.get(i))) {
+ duplicate = true;
+ }
+ }
+ }
+ if (!duplicate) {
+ this.side2Players.add(playerName);
+ }
+ }
+
+ public void removePlayerSide2(final String playerName) {
+ if (!side2Players.isEmpty()) {
+ for (int i = 0; i < this.side2Players.size(); ++i) {
+ if (playerName.equalsIgnoreCase(this.side2Players.get(i))) {
+ this.side2Players.remove(i);
+ return;
+ }
+ }
+ }
+ }
+
+ public void addMercSide1(final String playerName) {
+ boolean duplicate = false;
+ if (!side1Mercs.isEmpty()) {
+ for (int i = 0; i < side1Mercs.size(); ++i) {
+ if (playerName.equalsIgnoreCase(side1Mercs.get(i))) {
+ duplicate = true;
+ }
+ }
+ }
+ if (!duplicate) {
+ side1Mercs.add(playerName);
+ }
+ }
+
+ public void removeMercSide1(final String playerName) {
+ if (!side1Mercs.isEmpty()) {
+ for (int i = 0; i < side1Mercs.size(); ++i) {
+ if (playerName.equalsIgnoreCase(side1Mercs.get(i))) {
+ side1Mercs.remove(i);
+ return;
+ }
+ }
+ }
+ }
+
+ public void addMercSide2(final String playerName) {
+ boolean duplicate = false;
+ if (!side2Mercs.isEmpty()) {
+ for (int i = 0; i < side2Mercs.size(); ++i) {
+ if (playerName.equalsIgnoreCase(side2Mercs.get(i))) {
+ duplicate = true;
+ }
+ }
+ }
+ if (!duplicate) {
+ side2Mercs.add(playerName);
+ }
+ }
+
+ public void removeMercSide2(final String playerName) {
+ if (!side2Mercs.isEmpty()) {
+ for (int i = 0; i < side2Mercs.size(); ++i) {
+ if (playerName.equalsIgnoreCase(side2Mercs.get(i))) {
+ side2Mercs.remove(i);
+ return;
+ }
+ }
+ }
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getSide1() {
+ return this.side1;
+ }
+
+ public void setSide1(final String side1) {
+ this.side1 = side1;
+ }
+
+ public String getSide2() {
+ return this.side2;
+ }
+
+ public void setSide2(final String side2) {
+ this.side2 = this.side1;
+ }
+
+ public ArrayList getSide1Players() {
+ return this.side1Players;
+ }
+
+ public void setSide1Players(final ArrayList side1Players) {
+ this.side1Players = side1Players;
+ }
+
+ public ArrayList getSide2Players() {
+ return this.side2Players;
+ }
+
+ public void setSide2Players(final ArrayList side2Players) {
+ this.side2Players = side2Players;
+ }
+
+ public ArrayList getSide1Mercs() {
+ return this.side1Mercs;
+ }
+
+ public void setSide1Mercs(final ArrayList side1Mercs) {
+ this.side1Mercs = side1Mercs;
+ }
+
+ public ArrayList getSide2Mercs() {
+ return this.side2Mercs;
+ }
+
+ public void setSide2Mercs(final ArrayList side2Mercs) {
+ this.side2Mercs = side2Mercs;
+ }
}
diff --git a/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/commands/WarCommands.java b/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/commands/WarCommands.java
index 46733b2..af27765 100644
--- a/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/commands/WarCommands.java
+++ b/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/commands/WarCommands.java
@@ -6,7 +6,6 @@
import me.ShermansWorld.AlathraWar.Helper;
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.War;
-import me.ShermansWorld.AlathraWar.hooks.LuckPermsHook;
import me.ShermansWorld.AlathraWar.hooks.TABHook;
import me.ShermansWorld.AlathraWar.roles.Merc;
@@ -40,21 +39,29 @@ else if (args.length >= 1) {
}
if (args.length == 4) {
if (WarCommands.wars.isEmpty()) {
- final War war = new War(args[1].toLowerCase(), args[2].toLowerCase(), args[3].toLowerCase());
+ final War war = new War(args[1], args[2], args[3]);
WarCommands.wars.add(war);
final ArrayList side1Players = new ArrayList();
final ArrayList side2Players = new ArrayList();
- side1Players.add("Notch1");
- side2Players.add("Notch2");
+ final ArrayList side1Mercs = new ArrayList();
+ final ArrayList side2Mercs = new ArrayList();
+ side1Players.add("Placeholder1");
+ side2Players.add("Placeholder2");
+ side1Mercs.add("Placeholder1");
+ side2Mercs.add("Placeholder2");
war.setSide1Players(side1Players);
war.setSide2Players(side2Players);
- Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side1", (Object)args[2]);
- Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side2", (Object)args[3]);
- Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side1players", (Object)side1Players);
- Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side2players", (Object)side2Players);
+ war.setSide1Mercs(side1Mercs);
+ war.setSide2Mercs(side2Mercs);
+ Main.warData.getConfig().set("Wars." + args[1] + ".side1", (Object)args[2]);
+ Main.warData.getConfig().set("Wars." + args[1] + ".side2", (Object)args[3]);
+ Main.warData.getConfig().set("Wars." + args[1] + ".side1players", (Object)side1Players);
+ Main.warData.getConfig().set("Wars." + args[1] + ".side2players", (Object)side2Players);
+ Main.warData.getConfig().set("Wars." + args[1] + ".side1mercs", (Object)side1Mercs);
+ Main.warData.getConfig().set("Wars." + args[1] + ".side2mercs", (Object)side2Mercs);
Main.warData.saveConfig();
- p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War created with the name " + args[1].toLowerCase() + ", " + args[2] + " vs. " + args[3]);
- Main.warLogger.log(p.getName() + " created a new war with the name " + args[1].toLowerCase() + ", " + args[2] + " vs. " + args[3]);
+ p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War created with the name " + args[1] + ", " + args[2] + " vs. " + args[3]);
+ Main.warLogger.log(p.getName() + " created a new war with the name " + args[1] + ", " + args[2] + " vs. " + args[3]);
}
else {
for (int i = 0; i < WarCommands.wars.size(); ++i) {
@@ -67,17 +74,17 @@ else if (args.length >= 1) {
WarCommands.wars.add(war2);
final ArrayList side1Players2 = new ArrayList();
final ArrayList side2Players2 = new ArrayList();
- side1Players2.add("Notch1");
- side2Players2.add("Notch2");
+ side1Players2.add("Placeholder1");
+ side2Players2.add("Placeholder2");
war2.setSide1Players(side1Players2);
war2.setSide2Players(side2Players2);
- Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side1", (Object)args[2]);
- Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side2", (Object)args[3]);
- Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side1players", (Object)side1Players2);
- Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side2players", (Object)side2Players2);
+ Main.warData.getConfig().set("Wars." + args[1] + ".side1", (Object)args[2]);
+ Main.warData.getConfig().set("Wars." + args[1] + ".side2", (Object)args[3]);
+ Main.warData.getConfig().set("Wars." + args[1] + ".side1players", (Object)side1Players2);
+ Main.warData.getConfig().set("Wars." + args[1] + ".side2players", (Object)side2Players2);
Main.warData.saveConfig();
- p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War created with the name " + args[1].toLowerCase() + ", " + args[2] + " vs. " + args[3]);
- Main.warLogger.log(p.getName() + " created a new war with the name " + args[1].toLowerCase() + ", " + args[2] + " vs. " + args[3]);
+ p.sendMessage(String.valueOf(Helper.Chatlabel()) + "War created with the name " + args[1] + ", " + args[2] + " vs. " + args[3]);
+ Main.warLogger.log(p.getName() + " created a new war with the name " + args[1] + ", " + args[2] + " vs. " + args[3]);
}
}
}
@@ -86,6 +93,7 @@ else if (args.length >= 1) {
}
}
else if (args[0].equalsIgnoreCase("delete")) {
+ String deleteTarget = args[1];
if (!p.hasPermission("AlathraWar.admin")) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + Helper.color("&cYou do not have permission to do this"));
return false;
@@ -94,20 +102,17 @@ else if (args[0].equalsIgnoreCase("delete")) {
boolean found = false;
for (int j = 0; j < WarCommands.wars.size(); ++j) {
if (WarCommands.wars.get(j).getName().equalsIgnoreCase(args[1])) {
- p.sendMessage(String.valueOf(Helper.Chatlabel()) + "The war named " + args[1] + " has been deleted");
- Main.warLogger.log(p.getName() + " deleted a war named " + args[1]);
+ p.sendMessage(String.valueOf(Helper.Chatlabel()) + "The war named " + deleteTarget + " has been deleted");
+ Main.warLogger.log(p.getName() + " deleted a war named " + deleteTarget);
for (String playername : WarCommands.wars.get(j).getSide1Players()) {
TABHook.resetSuffix(playername);
- LuckPermsHook.resetPrefix(playername);
- TABHook.resetPrefix(playername);
}
for (String playername : WarCommands.wars.get(j).getSide2Players()) {
TABHook.resetSuffix(playername);
- LuckPermsHook.resetPrefix(playername);
- TABHook.resetPrefix(playername);
}
+ deleteTarget = wars.get(j).getName();
+ Main.warData.getConfig().set("Wars." + deleteTarget, (Object)null);
WarCommands.wars.remove(j);
- Main.warData.getConfig().set("Wars." + args[1].toLowerCase(), (Object)null);
Main.warData.saveConfig();
found = true;
break;
@@ -136,8 +141,9 @@ else if (args[0].equalsIgnoreCase("join")) {
boolean found = false;
boolean isMercJoining = false;
if (args.length == 3 || args.length == 4) {
-
- if (args.length == 4) {
+ String joinWarTarget = args[1];
+ String joinSideTarget = args[2];
+ if (args.length == 4 && (args[3].equalsIgnoreCase("merc") || args[3].equalsIgnoreCase("mercenary")) ) {
if (!Merc.hasMercRole(p)) {
p.sendMessage(Helper.Chatlabel() + Helper.color("&cYou must have the mercenary role to join a war as a mercenary!"));
return false;
@@ -146,28 +152,27 @@ else if (args[0].equalsIgnoreCase("join")) {
}
for (final War war2 : WarCommands.wars) {
- if (war2.getName().equalsIgnoreCase(args[1].toLowerCase())) {
- if (war2.getSide1().equalsIgnoreCase(args[2].toLowerCase())) {
+ if (war2.getName().equalsIgnoreCase(joinWarTarget)) {
+ if (war2.getSide1().equalsIgnoreCase(joinSideTarget)) {
if (war2.getSide1Players().contains(p.getName()) || war2.getSide2Players().contains(p.getName())) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have already joined this war! Type /war leave [war] to leave the war");
return false;
}
+ joinWarTarget = war2.getName();
war2.addPlayerSide1(p.getName());
- p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the war on the side of " + war2.getSide1());
- TABHook.assignSide1WarSuffix(p, war2);
- if (isMercJoining) {
- LuckPermsHook.assignSide1WarColor(p.getName(), true);
- } else {
- LuckPermsHook.assignSide1WarColor(p.getName(), false);
- }
- TABHook.removeColorPrefix(p, LuckPermsHook.getPrefix(p.getName()));
- Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side1players", (Object)war2.getSide1Players());
+ Main.warData.getConfig().set("Wars." + joinWarTarget + ".side1players", (Object)war2.getSide1Players());
Main.warData.saveConfig();
+ p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the war on the side of " + war2.getSide1());
if (isMercJoining) {
+ TABHook.assignSide1WarSuffixMerc(p, war2);
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has joined " + war2.getName() + " on the side of " + war2.getSide1() + " as a mercenary!");
Bukkit.getLogger().info("[AlathraWar] Player " + p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide1() + " as a mercenary");
Main.warLogger.log(p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide1() + " as a mercenary");
+ war2.addMercSide1(p.getName());
+ Main.warData.getConfig().set("Wars." + joinWarTarget + ".side1mercs", (Object)war2.getSide1Players());
+ Main.warData.saveConfig();
} else {
+ TABHook.assignSide1WarSuffix(p, war2);
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has joined " + war2.getName() + " on the side of " + war2.getSide1() + "!");
Bukkit.getLogger().info("[AlathraWar] Player " + p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide1());
Main.warLogger.log(p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide1());
@@ -175,29 +180,28 @@ else if (args[0].equalsIgnoreCase("join")) {
found = true;
}
else {
- if (!war2.getSide2().equalsIgnoreCase(args[2].toLowerCase())) {
+ if (!war2.getSide2().equalsIgnoreCase(args[2])) {
continue;
}
if (war2.getSide2Players().contains(p.getName()) || war2.getSide1Players().contains(p.getName())) {
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have already joined this war! Type /war leave [war] to leave the war");
return false;
}
+ joinWarTarget = war2.getName();
war2.addPlayerSide2(p.getName());
- p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the war on the side of " + war2.getSide2());
- TABHook.assignSide2WarSuffix(p, war2);
- if (isMercJoining) {
- LuckPermsHook.assignSide2WarColor(p.getName(), true);
- } else {
- LuckPermsHook.assignSide2WarColor(p.getName(), false);
- }
- TABHook.removeColorPrefix(p, LuckPermsHook.getPrefix(p.getName()));
- Main.warData.getConfig().set("Wars." + args[1].toLowerCase() + ".side2players", (Object)war2.getSide2Players());
+ Main.warData.getConfig().set("Wars." + joinWarTarget + ".side2players", (Object)war2.getSide2Players());
Main.warData.saveConfig();
+ p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have joined the war on the side of " + war2.getSide2());
if (isMercJoining) {
+ TABHook.assignSide2WarSuffixMerc(p, war2);
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has joined " + war2.getName() + " on the side of " + war2.getSide2() + " as a mercenary!");
Bukkit.getLogger().info("[AlathraWar] Player " + p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide2() + " as a mercenary");
Main.warLogger.log(p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide2() + " as a mercenary");
+ war2.addMercSide2(p.getName());
+ Main.warData.getConfig().set("Wars." + joinWarTarget + ".side2mercs", (Object)war2.getSide2Players());
+ Main.warData.saveConfig();
} else {
+ TABHook.assignSide2WarSuffix(p, war2);
Bukkit.broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has joined " + war2.getName() + " on the side of " + war2.getSide2() + "!");
Bukkit.getLogger().info("[AlathraWar] Player " + p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide2());
Main.warLogger.log(p.getName() + " has entered " + war2.getName() + " on the side of " + war2.getSide2());
@@ -218,32 +222,40 @@ else if (args[0].equalsIgnoreCase("leave")) {
if (args.length == 2) {
boolean found = false;
boolean found2 = false;
+ String leaveWarTarget = args[1];
for (final War war3 : WarCommands.wars) {
- if (war3.getName().equalsIgnoreCase(args[1])) {
+ if (war3.getName().equalsIgnoreCase(leaveWarTarget)) {
found = true;
+ leaveWarTarget = war3.getName();
if (war3.getSide1Players().contains(p.getName())) {
found2 = true;
war3.removePlayerSide1(p.getName());
- Main.warData.getConfig().set("Wars." + args[1] + ".side1players", (Object)war3.getSide1Players());
+ Main.warData.getConfig().set("Wars." + leaveWarTarget + ".side1players", (Object)war3.getSide1Players());
Main.warData.saveConfig();
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have left the war");
TABHook.resetSuffix(p);
- LuckPermsHook.resetPrefix(p.getName());
- TABHook.resetPrefix(p);
Bukkit.getServer().broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has left " + war3.getName() + ", they were on the side of " + war3.getSide1());
Main.warLogger.log(p.getName() + " has left " + war3.getName() + ", they were on the side of " + war3.getSide1());
+ if (war3.getSide1Mercs().contains(p.getName())) {
+ war3.removeMercSide1(p.getName());
+ Main.warData.getConfig().set("Wars." + leaveWarTarget + ".side1mercs", (Object)war3.getSide1Mercs());
+ Main.warData.saveConfig();
+ }
}
if (war3.getSide2Players().contains(p.getName())) {
found2 = true;
war3.removePlayerSide2(p.getName());
- Main.warData.getConfig().set("Wars." + args[1] + ".side2players", (Object)war3.getSide2Players());
+ Main.warData.getConfig().set("Wars." + leaveWarTarget + ".side2players", (Object)war3.getSide2Players());
Main.warData.saveConfig();
p.sendMessage(String.valueOf(Helper.Chatlabel()) + "You have left the war");
TABHook.resetSuffix(p);
- LuckPermsHook.resetPrefix(p.getName());
- TABHook.resetPrefix(p);
Bukkit.getServer().broadcastMessage(String.valueOf(Helper.Chatlabel()) + p.getName() + " has left " + war3.getName() + ", they were on the side of " + war3.getSide2());
Main.warLogger.log(p.getName() + " has left " + war3.getName() + ", they were on the side of " + war3.getSide2());
+ if (war3.getSide2Mercs().contains(p.getName())) {
+ war3.removeMercSide2(p.getName());
+ Main.warData.getConfig().set("Wars." + leaveWarTarget + ".side2mercs", (Object)war3.getSide2Mercs());
+ Main.warData.saveConfig();
+ }
}
}
}
diff --git a/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/data/PrefixData.java b/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/data/PrefixData.java
deleted file mode 100644
index 13e54cc..0000000
--- a/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/data/PrefixData.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package me.ShermansWorld.AlathraWar.data;
-
-import java.io.IOException;
-import java.io.InputStream;
-import org.bukkit.configuration.Configuration;
-import java.io.Reader;
-import java.io.InputStreamReader;
-import org.bukkit.configuration.file.YamlConfiguration;
-
-import me.ShermansWorld.AlathraWar.Main;
-
-import java.io.File;
-import org.bukkit.configuration.file.FileConfiguration;
-
-public class PrefixData
-{
- private Main plugin;
- private FileConfiguration dataConfig;
- private File configFile;
-
- public PrefixData(final Main plugin) {
- this.dataConfig = null;
- this.configFile = null;
- this.plugin = plugin;
- this.saveDefaultConfig();
- }
-
- public void reloadConfig() {
- if (this.configFile == null) {
- this.configFile = new File(this.plugin.getDataFolder(), "prefixes.yml");
- }
- this.dataConfig = (FileConfiguration)YamlConfiguration.loadConfiguration(this.configFile);
- final InputStream defaultStream = this.plugin.getResource("prefixes.yml");
- if (defaultStream != null) {
- final YamlConfiguration defaultConfig = YamlConfiguration.loadConfiguration((Reader)new InputStreamReader(defaultStream));
- this.dataConfig.setDefaults((Configuration)defaultConfig);
- }
- }
-
- public FileConfiguration getConfig() {
- if (this.dataConfig == null) {
- this.reloadConfig();
- }
- return this.dataConfig;
- }
-
- public void saveConfig() {
- if (this.dataConfig == null || this.configFile == null) {
- return;
- }
- try {
- this.getConfig().save(this.configFile);
- }
- catch (IOException e) {
- e.printStackTrace();
- }
- }
-
- public void saveDefaultConfig() {
- if (this.configFile == null) {
- this.configFile = new File(this.plugin.getDataFolder(), "prefixes.yml");
- }
- if (!this.configFile.exists()) {
- this.plugin.saveResource("prefixes.yml", false);
- }
- }
-}
diff --git a/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/hooks/LuckPermsHook.java b/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/hooks/LuckPermsHook.java
deleted file mode 100644
index 848de30..0000000
--- a/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/hooks/LuckPermsHook.java
+++ /dev/null
@@ -1,140 +0,0 @@
-package me.ShermansWorld.AlathraWar.hooks;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-
-import org.bukkit.Bukkit;
-import org.bukkit.OfflinePlayer;
-import org.bukkit.plugin.RegisteredServiceProvider;
-
-import me.ShermansWorld.AlathraWar.Main;
-import net.luckperms.api.LuckPerms;
-import net.luckperms.api.model.group.Group;
-import net.luckperms.api.model.user.User;
-import net.luckperms.api.model.user.UserManager;
-import net.luckperms.api.node.Node;
-import net.luckperms.api.node.NodeType;
-import net.luckperms.api.node.types.PrefixNode;
-
-public class LuckPermsHook {
- public static boolean init = false;
- public static LuckPerms lp;
- private static UserManager um;
-
- public static HashMap prefixMap = new HashMap();
-
- public static void init() {
- RegisteredServiceProvider provider = Bukkit.getServicesManager().getRegistration(LuckPerms.class);
- if (provider != null) {
- lp = provider.getProvider();
- um = lp.getUserManager();
- }
- init = true;
- }
-
- public static String getPrefix(String playername) {
- User user = um.getUser(playername);
- String prefix = user.getCachedData().getMetaData().getPrefix();
- if (prefix == null) {
- return "";
- } else {
- return prefix;
- }
- }
-
- public static void assignSide1WarColor(String playername, boolean isWarMerc) {
- String prefix = getPrefix(playername);
- boolean isGroupPrefix = false;
- if (!prefix.equals("")) {
- User user = um.getUser(playername);
- for (Group group : user.getInheritedGroups(user.getQueryOptions())) {
- String groupPrefix = group.getCachedData().getMetaData().getPrefix();
- if (groupPrefix == null) {
- groupPrefix = "";
- }
- if (groupPrefix.equals(prefix)) {
- isGroupPrefix = true;
- }
- }
- if (!isGroupPrefix) {
- prefixMap.put(playername, prefix);
- Main.prefixData.getConfig().set("Prefixes." + playername, prefix);
- Main.prefixData.saveConfig();
- }
- }
- if (isWarMerc) {
- prefix = prefix + "&a[M]&r&c";
- } else {
- prefix = prefix + "&c";
- }
- removePrefixNodes(playername);
- addPrefix(playername, prefix);
- }
-
- public static void assignSide2WarColor(String playername, boolean isWarMerc) {
- String prefix = getPrefix(playername);
- boolean isGroupPrefix = false;
- if (!prefix.equals("")) {
- User user = um.getUser(playername);
- for (Group group : user.getInheritedGroups(user.getQueryOptions())) {
- String groupPrefix = group.getCachedData().getMetaData().getPrefix();
- if (groupPrefix == null) {
- groupPrefix = "";
- }
- if (groupPrefix.equals(prefix)) {
- isGroupPrefix = true;
- }
- }
- if (!isGroupPrefix) {
- prefixMap.put(playername, prefix);
- Main.prefixData.getConfig().set("Prefixes." + playername, prefix);
- Main.prefixData.saveConfig();
- }
- }
-
- if (isWarMerc) {
- prefix = prefix + "&a[M]&r&9";
- } else {
- prefix = prefix + "&9";
- }
- removePrefixNodes(playername);
- addPrefix(playername, prefix);
- }
-
- public static void resetPrefix(String playername) {
- @SuppressWarnings("deprecation")
- OfflinePlayer op = Bukkit.getOfflinePlayer(playername);
- try {
- if (op.isOnline()) {
- removePrefixNodes(playername);
- if (prefixMap.containsKey(playername)) {
- addPrefix(playername, prefixMap.get(playername));
- }
- }
- } catch (NullPointerException e) {
- return;
- }
- }
-
- public static void removePrefixNodes(String playername) {
- ArrayList prefixNodes = new ArrayList();
- User user = um.getUser(playername);
- for (Node node : user.getNodes()) {
- if (node.getType().equals(NodeType.PREFIX)) {
- prefixNodes.add(node);
- }
- }
-
- for (int i = 0; i < prefixNodes.size(); i++) {
- user.data().remove(prefixNodes.get(i));
- }
- um.saveUser(user);
- }
-
- private static void addPrefix(String playername, String prefix) {
- User user = um.getUser(playername);
- user.data().add(PrefixNode.builder(prefix, 100).build());
- um.saveUser(user);
- }
-
-}
diff --git a/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/hooks/TABHook.java b/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/hooks/TABHook.java
index 0f8d967..535520d 100644
--- a/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/hooks/TABHook.java
+++ b/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/hooks/TABHook.java
@@ -22,13 +22,25 @@ public static void init() {
public static void assignSide1WarSuffix(Player p, War war) {
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
tabAPI.getTablistFormatManager().setSuffix(tabPlayer,
- Helper.color(new StringBuilder("&c[").append(war.getSide1()).append("]&r").toString()));
+ Helper.color("&c[") + war.getSide1() + "]&r");
}
public static void assignSide2WarSuffix(Player p, War war) {
TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
tabAPI.getTablistFormatManager().setSuffix(tabPlayer,
- Helper.color(new StringBuilder("&9[").append(war.getSide2()).append("]&r").toString()));
+ Helper.color("&9[") + war.getSide2() + "]&r");
+ }
+
+ public static void assignSide1WarSuffixMerc(Player p, War war) {
+ TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
+ tabAPI.getTablistFormatManager().setSuffix(tabPlayer,
+ Helper.color("&a[M]&c[") + war.getSide1() + "]&r");
+ }
+
+ public static void assignSide2WarSuffixMerc(Player p, War war) {
+ TabPlayer tabPlayer = tabAPI.getPlayer(p.getUniqueId());
+ tabAPI.getTablistFormatManager().setSuffix(tabPlayer,
+ Helper.color("&a[M]&9[") + war.getSide2() + "]&r");
}
public static void resetSuffix(Player p) {
diff --git a/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/listeners/JoinListener.java b/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/listeners/JoinListener.java
index ec7e977..1b4bd56 100644
--- a/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/listeners/JoinListener.java
+++ b/AlathraWar2/src/main/java/me/ShermansWorld/AlathraWar/listeners/JoinListener.java
@@ -8,7 +8,6 @@
import me.ShermansWorld.AlathraWar.Main;
import me.ShermansWorld.AlathraWar.War;
import me.ShermansWorld.AlathraWar.commands.WarCommands;
-import me.ShermansWorld.AlathraWar.hooks.LuckPermsHook;
import me.ShermansWorld.AlathraWar.hooks.TABHook;
import org.bukkit.event.Listener;
@@ -22,31 +21,31 @@ public void onPlayerJoin(final PlayerJoinEvent event) {
@Override
public void run() {
boolean inWar = false;
- boolean colorRemoved = false;
for (final War war : WarCommands.wars) {
if (war.getSide1Players() == null) {
Main.warLogger.log("ERROR: Unable to retrieve side 1 of war " + war.getName());
} else if (war.getSide1Players().contains(p.getName())) {
- TABHook.assignSide1WarSuffix(p, war);
- if (!colorRemoved) {
- TABHook.removeColorPrefix(p, LuckPermsHook.getPrefix(p.getName()));
- colorRemoved = true;
- }
+ if (war.getSide1Mercs().contains(p.getName())) {
+ TABHook.assignSide1WarSuffixMerc(p, war);
+ } else {
+ TABHook.assignSide1WarSuffix(p, war);
+ }
inWar = true;
} else if (war.getSide2Players() == null) {
Main.warLogger.log("ERROR: Unable to retrieve side 2 of war " + war.getName());
} else if (war.getSide2Players().contains(p.getName())) {
- TABHook.assignSide2WarSuffix(p, war);
- if (!colorRemoved) {
- TABHook.removeColorPrefix(p, LuckPermsHook.getPrefix(p.getName()));
- colorRemoved = true;
- }
+ if (war.getSide2Mercs().contains(p.getName())) {
+ TABHook.assignSide2WarSuffixMerc(p, war);
+ } else {
+ TABHook.assignSide2WarSuffix(p, war);
+ }
inWar = true;
}
- if (!inWar) {
- LuckPermsHook.resetPrefix(p.getName());
- }
}
+ if (!inWar) {
+ TABHook.resetPrefix(p);
+ }
+
}
}, 60L); // 20 Tick (1 Second) delay before run() is called
}