From 3a97a7428b0fa4e76241bde179479640aad5dd7a Mon Sep 17 00:00:00 2001
From: speed <43330808+speedxx@users.noreply.github.com>
Date: Wed, 25 Nov 2020 11:50:53 -0500
Subject: [PATCH 01/41] =?UTF-8?q?=F0=9F=98=8A=F0=9F=98=8A=F0=9F=98=8A?=
=?UTF-8?q?=F0=9F=98=8A=F0=9F=98=8A=F0=9F=98=8A=F0=9F=98=8A=F0=9F=98=8A?=
=?UTF-8?q?=F0=9F=98=8A=F0=9F=98=8A=F0=9F=98=8A=F0=9F=98=8A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
no player uuids đđđđđđđđ¤
---
.idea/TFGuilds.iml | 110 ++++++++++++++++++
.idea/vcs.xml | 2 +-
pom.xml | 2 +-
.../tfguilds/command/GuildCommand.java | 5 +-
.../tfguilds/command/HelpSubcommand.java | 1 +
.../tfguilds/command/SetMemberSubcommand.java | 54 +++++++++
6 files changed, 171 insertions(+), 3 deletions(-)
create mode 100644 .idea/TFGuilds.iml
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/SetMemberSubcommand.java
diff --git a/.idea/TFGuilds.iml b/.idea/TFGuilds.iml
new file mode 100644
index 0000000..d0c8bd9
--- /dev/null
+++ b/.idea/TFGuilds.iml
@@ -0,0 +1,110 @@
+
+
+
+
+
+
+ SPIGOT
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 94a25f7..35eb1dd 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 23a21e0..eb5071b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.totalfreedom
TFGuilds
- 0.2.16
+ 0.2.17
jar
TFGuilds
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
index 294b329..e66fb69 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
@@ -72,6 +72,8 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
return new ToggleTagsSubcommand().onCommand(sender, command, label, args);
case "toggletag":
return new ToggleTagSubcommand().onCommand(sender, command, label, args);
+ case "setmember":
+ return new SetMemberSubcommand().onCommand(sender, command, label, args);
}
sender.sendMessage(tl(PREFIX + "Unknown command - Run /g help if you need help"));
return true;
@@ -89,7 +91,7 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
"deleterank", "disband", "help", "home", "info", "invite",
"join", "kick", "leave", "list", "motd", "removemod", "rename",
"roster", "setowner", "setrank", "setstate", "tag", "tp", "setdefaultrank",
- "toggletags", "toggletag");
+ "toggletags", "toggletag", "setmember");
}
else if (args.length == 2)
{
@@ -103,6 +105,7 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
case "info":
case "join":
case "roster":
+ case "setmember":
{
return Guild.getGuildList();
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/HelpSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/HelpSubcommand.java
index a2918b3..3071fca 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/HelpSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/HelpSubcommand.java
@@ -37,6 +37,7 @@ public class HelpSubcommand extends Common implements CommandExecutor
sender.sendMessage(tl("%s% - %p%setdefaultrank "));
sender.sendMessage(tl("%s% - %p%toggletags"));
sender.sendMessage(tl("%s% - %p%toggletag [player]"));
+ sender.sendMessage(tl("%s% - %p%setmember "));
return true;
}
}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetMemberSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetMemberSubcommand.java
new file mode 100644
index 0000000..89051c4
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetMemberSubcommand.java
@@ -0,0 +1,54 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class SetMemberSubcommand extends Common implements CommandExecutor
+{
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
+ {
+ if (args.length == 1 || args.length == 2 || args.length > 3)
+ {
+ sender.sendMessage(tl(PREFIX + "Proper usage: /g setmember "));
+ return true;
+ }
+
+ if (!plugin.bridge.isAdmin(sender))
+ {
+ sender.sendMessage(NO_PERMS);
+ return true;
+ }
+
+ Guild guild = Guild.getGuild(args[1]);
+ if (guild == null)
+ {
+ sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
+ return true;
+ }
+
+ Player player = Bukkit.getPlayer(args[2]);
+ if (player == null)
+ {
+ sender.sendMessage(PNF);
+ return true;
+ }
+
+ if (Guild.getGuild(player) != null)
+ {
+ sender.sendMessage(ChatColor.RED + "This player is already in another guild!");
+ return true;
+ }
+
+ guild.addMember(player.getName());
+ guild.broadcast(tl("%s%" + player.getName() + " %p%has joined the guild."));
+ guild.save();
+ return true;
+ }
+}
\ No newline at end of file
From e2017b3fd2f129cab650bdaf71058eb66ce475fe Mon Sep 17 00:00:00 2001
From: speed <43330808+speedxx@users.noreply.github.com>
Date: Sun, 29 Nov 2020 20:46:21 -0500
Subject: [PATCH 02/41] page /g list
---
.idea/TFGuilds.iml | 19 ++----
pom.xml | 6 +-
.../tfguilds/command/ListSubcommand.java | 42 +++++++++++-
.../tfguilds/util/PaginationList.java | 66 +++++++++++++++++++
4 files changed, 112 insertions(+), 21 deletions(-)
create mode 100644 src/main/java/me/totalfreedom/tfguilds/util/PaginationList.java
diff --git a/.idea/TFGuilds.iml b/.idea/TFGuilds.iml
index d0c8bd9..4742ffe 100644
--- a/.idea/TFGuilds.iml
+++ b/.idea/TFGuilds.iml
@@ -25,20 +25,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -68,6 +55,7 @@
+
@@ -87,6 +75,7 @@
+
@@ -105,6 +94,6 @@
-
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index eb5071b..645f53b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.totalfreedom
TFGuilds
- 0.2.17
+ 0.2.18
jar
TFGuilds
@@ -83,13 +83,13 @@
me.totalfreedom
TotalFreedomMod
- 2020.9
+ 2020.11.5
provided
org.projectlombok
lombok
- 1.18.14
+ 1.18.16
provided
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ListSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ListSubcommand.java
index 463b765..c400888 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/ListSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/ListSubcommand.java
@@ -3,7 +3,7 @@ package me.totalfreedom.tfguilds.command;
import java.util.List;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
-import org.apache.commons.lang.StringUtils;
+import me.totalfreedom.tfguilds.util.PaginationList;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -14,7 +14,14 @@ public class ListSubcommand extends Common implements CommandExecutor
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
+ if (args.length > 2)
+ {
+ sender.sendMessage(tl(PREFIX + "Proper usage: /g list [page]"));
+ return true;
+ }
+
List guilds = Guild.getGuildList();
+ PaginationList paged = new PaginationList<>(10);
if (guilds.isEmpty())
{
@@ -22,8 +29,37 @@ public class ListSubcommand extends Common implements CommandExecutor
return true;
}
- sender.sendMessage(tl(PREFIX + "%s%Guild List (%p%" + guilds.size() + " total%s%)"));
- sender.sendMessage(tl("%s%- %p%" + StringUtils.join(guilds, "\n%s%- %p%")));
+ paged.addAll(guilds);
+
+ int pageIndex = 1;
+
+ if (args.length >= 2)
+ {
+ try
+ {
+ pageIndex = Integer.parseInt(args[1]);
+ }
+ catch (NumberFormatException e)
+ {
+ sender.sendMessage(ChatColor.RED + "Invalid number");
+ }
+ }
+
+ if (pageIndex > paged.getPageCount() || pageIndex + 1 < paged.getPageCount())
+ {
+ sender.sendMessage(ChatColor.RED + "Not a valid page number");
+ return true;
+ }
+
+ paged.getPage(pageIndex);
+ List page = paged.getPage(pageIndex);
+
+ sender.sendMessage(tl(PREFIX + "%s%Guild List (%p%" + guilds.size() + " total%s%) [%p%Page " + pageIndex + "%s%/%p%" + paged.getPageCount() + "%s%]"));
+
+ for (String guild : page)
+ {
+ sender.sendMessage(tl("%s%- %p%" + guild));
+ }
return true;
}
}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/util/PaginationList.java b/src/main/java/me/totalfreedom/tfguilds/util/PaginationList.java
new file mode 100644
index 0000000..1060caa
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/util/PaginationList.java
@@ -0,0 +1,66 @@
+package me.totalfreedom.tfguilds.util;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+public class PaginationList extends ArrayList
+{
+ private final int epp;
+
+ /**
+ * Defines a new Pagination List.
+ * @param epp Elements per page - how many elements will be included on a page of the list.
+ */
+ public PaginationList(int epp)
+ {
+ super();
+ this.epp = epp;
+ }
+
+ /**
+ * Defines a new Pagination List.
+ * @param epp Elements per page - how many elements will be included on a page of the list.
+ * @param elements Elements to add to the list immediately.
+ */
+ @SafeVarargs
+ public PaginationList(int epp, T... elements)
+ {
+ super(Arrays.asList(elements));
+ this.epp = epp;
+ }
+
+ /**
+ * @return The number of pages this list holds.
+ */
+ public int getPageCount()
+ {
+ return (int) Math.ceil((double) size() / (double) epp);
+ }
+
+ /**
+ * Get a page from the list.
+ * @param page Page you want to access.
+ * @return A sublist of only the elements from that page.
+ */
+ public List getPage(int page)
+ {
+ if (page < 1 || page > getPageCount()) return null;
+ int startIndex = (page - 1) * epp;
+ int endIndex = Math.min(startIndex + (epp - 1), this.size() - 1);
+ return subList(startIndex, endIndex + 1);
+ }
+
+ /*@Override
+ public String toString()
+ {
+ StringBuilder res = new StringBuilder();
+ for (int i = 1; i <= getPageCount(); i++)
+ {
+ res.append("Page ").append(i).append(": ").append("\n");
+ for (T element : getPage(i))
+ res.append(" - ").append(element).append("\n");
+ }
+ return res.toString();
+ }*/
+}
\ No newline at end of file
From 1cf0d856a7083929f6309c976e3a93d92e6c0313 Mon Sep 17 00:00:00 2001
From: speed <43330808+speedxx@users.noreply.github.com>
Date: Mon, 30 Nov 2020 17:26:23 -0500
Subject: [PATCH 03/41] fix check
---
.../java/me/totalfreedom/tfguilds/command/ListSubcommand.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ListSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ListSubcommand.java
index c400888..50b68e3 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/ListSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/ListSubcommand.java
@@ -45,7 +45,7 @@ public class ListSubcommand extends Common implements CommandExecutor
}
}
- if (pageIndex > paged.getPageCount() || pageIndex + 1 < paged.getPageCount())
+ if (pageIndex < 1 || pageIndex > paged.getPageCount())
{
sender.sendMessage(ChatColor.RED + "Not a valid page number");
return true;
From 3a6a8b6e11a05fdb21db2f2ebca0d49762e03e2a Mon Sep 17 00:00:00 2001
From: Ryan
Date: Tue, 1 Dec 2020 19:56:14 +0000
Subject: [PATCH 04/41] Create codeql-analysis.yml
---
.github/workflows/codeql-analysis.yml | 67 +++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
create mode 100644 .github/workflows/codeql-analysis.yml
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
new file mode 100644
index 0000000..a80c844
--- /dev/null
+++ b/.github/workflows/codeql-analysis.yml
@@ -0,0 +1,67 @@
+# For most projects, this workflow file will not need changing; you simply need
+# to commit it to your repository.
+#
+# You may wish to alter this file to override the set of languages analyzed,
+# or to provide custom queries or build logic.
+#
+# ******** NOTE ********
+# We have attempted to detect the languages in your repository. Please check
+# the `language` matrix defined below to confirm you have the correct set of
+# supported CodeQL languages.
+#
+name: "CodeQL"
+
+on:
+ push:
+ branches: [ master ]
+ pull_request:
+ # The branches below must be a subset of the branches above
+ branches: [ master ]
+ schedule:
+ - cron: '35 8 * * 0'
+
+jobs:
+ analyze:
+ name: Analyze
+ runs-on: ubuntu-latest
+
+ strategy:
+ fail-fast: false
+ matrix:
+ language: [ 'java' ]
+ # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
+ # Learn more:
+ # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
+
+ steps:
+ - name: Checkout repository
+ uses: actions/checkout@v2
+
+ # Initializes the CodeQL tools for scanning.
+ - name: Initialize CodeQL
+ uses: github/codeql-action/init@v1
+ with:
+ languages: ${{ matrix.language }}
+ # If you wish to specify custom queries, you can do so here or in a config file.
+ # By default, queries listed here will override any specified in a config file.
+ # Prefix the list here with "+" to use these queries and those in the config file.
+ # queries: ./path/to/local/query, your-org/your-repo/queries@main
+
+ # Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
+ # If this step fails, then you should remove it and run the build manually (see below)
+ - name: Autobuild
+ uses: github/codeql-action/autobuild@v1
+
+ # âšī¸ Command-line programs to run using the OS shell.
+ # đ https://git.io/JvXDl
+
+ # âī¸ If the Autobuild fails above, remove it and uncomment the following three lines
+ # and modify them (or add more) to build your code if your project
+ # uses a compiled language
+
+ #- run: |
+ # make bootstrap
+ # make release
+
+ - name: Perform CodeQL Analysis
+ uses: github/codeql-action/analyze@v1
From dd1a740252417988a491002e8c7d037d17a28d8f Mon Sep 17 00:00:00 2001
From: super
Date: Thu, 3 Dec 2020 01:36:57 -0500
Subject: [PATCH 05/41] move player and guild data to a SQL database
---
.../me/totalfreedom/tfguilds/TFGuilds.java | 23 +-
.../tfguilds/bridge/TFMBridge.java | 12 +-
.../tfguilds/command/AddModSubcommand.java | 16 +-
.../command/CreateRankSubcommand.java | 2 +-
.../tfguilds/command/CreateSubcommand.java | 3 +-
.../command/DeleteRankSubcommand.java | 2 +-
.../tfguilds/command/DisbandSubcommand.java | 6 +-
.../tfguilds/command/GuildCommand.java | 36 ++-
.../tfguilds/command/HomeSubcommand.java | 2 +-
.../tfguilds/command/JoinSubcommand.java | 2 +-
.../tfguilds/command/KickSubcommand.java | 14 +-
.../tfguilds/command/LeaveSubcommand.java | 6 +-
.../tfguilds/command/MOTDSubcommand.java | 2 +-
.../tfguilds/command/RemoveModSubcommand.java | 23 +-
.../tfguilds/command/RenameSubcommand.java | 8 +-
.../command/SetDefaultRankSubcommand.java | 2 +-
.../tfguilds/command/SetMemberSubcommand.java | 2 +-
.../tfguilds/command/SetOwnerSubcommand.java | 16 +-
.../tfguilds/command/SetRankSubcommand.java | 11 +-
.../tfguilds/command/SetStateSubcommand.java | 2 +-
.../tfguilds/command/TFGuildsCommand.java | 2 -
.../tfguilds/command/TPSubcommand.java | 2 +-
.../tfguilds/command/TagSubcommand.java | 2 +-
.../tfguilds/command/ToggleTagSubcommand.java | 34 +--
.../me/totalfreedom/tfguilds/guild/Guild.java | 209 ++++++----------
.../tfguilds/guild/GuildRank.java | 42 +++-
.../tfguilds/listener/ChatListener.java | 14 +-
.../tfguilds/sql/SQLDatabase.java | 81 +++++++
.../tfguilds/sql/SQLGuildData.java | 223 ++++++++++++++++++
.../tfguilds/sql/SQLRankData.java | 142 +++++++++++
.../tfguilds/sql/SQLUserData.java | 156 ++++++++++++
.../tfguilds/sql/SQLWorldData.java | 116 +++++++++
.../me/totalfreedom/tfguilds/user/User.java | 27 +++
src/main/resources/database.db | 0
src/main/resources/guilds.yml | 3 -
src/main/resources/players.yml | 3 -
36 files changed, 976 insertions(+), 270 deletions(-)
create mode 100644 src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/user/User.java
create mode 100644 src/main/resources/database.db
delete mode 100644 src/main/resources/guilds.yml
delete mode 100644 src/main/resources/players.yml
diff --git a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
index dbe9225..5d014fd 100644
--- a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
+++ b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
@@ -8,7 +8,14 @@ import me.totalfreedom.tfguilds.command.TFGuildsCommand;
import me.totalfreedom.tfguilds.config.Config;
import me.totalfreedom.tfguilds.listener.ChatListener;
import me.totalfreedom.tfguilds.listener.JoinListener;
+import me.totalfreedom.tfguilds.sql.SQLDatabase;
+import me.totalfreedom.tfguilds.sql.SQLGuildData;
+import me.totalfreedom.tfguilds.sql.SQLRankData;
+import me.totalfreedom.tfguilds.sql.SQLUserData;
+import me.totalfreedom.tfguilds.sql.SQLWorldData;
import me.totalfreedom.tfguilds.util.GLog;
+import org.bukkit.Bukkit;
+import org.bukkit.World;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
@@ -22,18 +29,24 @@ public final class TFGuilds extends JavaPlugin
}
public Config config;
- public Config guilds;
- public Config players;
public TFMBridge bridge;
+ public SQLDatabase sql;
+ public SQLGuildData guildData;
+ public SQLRankData rankData;
+ public SQLWorldData worldData;
+ public SQLUserData userData;
@Override
public void onEnable()
{
plugin = this;
config = new Config("config.yml");
- guilds = new Config("guilds.yml");
- players = new Config("players.yml");
bridge = new TFMBridge();
+ sql = new SQLDatabase();
+ guildData = new SQLGuildData();
+ rankData = new SQLRankData();
+ worldData = new SQLWorldData();
+ userData = new SQLUserData();
loadCommands();
loadListeners();
GLog.info("Enabled " + this.getDescription().getFullName());
@@ -44,8 +57,6 @@ public final class TFGuilds extends JavaPlugin
{
plugin = null;
config.save();
- guilds.save();
- players.save();
GLog.info("Disabled " + this.getDescription().getFullName());
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/bridge/TFMBridge.java b/src/main/java/me/totalfreedom/tfguilds/bridge/TFMBridge.java
index b74fa67..dff8a05 100644
--- a/src/main/java/me/totalfreedom/tfguilds/bridge/TFMBridge.java
+++ b/src/main/java/me/totalfreedom/tfguilds/bridge/TFMBridge.java
@@ -46,7 +46,7 @@ public class TFMBridge
return player.isOp();
}
- return getTFM().sl.isStaff(player);
+ return getTFM().al.isAdmin(player);
}
public boolean isAdmin(CommandSender sender)
@@ -57,11 +57,17 @@ public class TFMBridge
return sender.isOp();
}
- return getTFM().sl.isStaff(sender);
+ return getTFM().al.isAdmin(sender);
}
public boolean isVanished(Player player)
{
- return getTFM().sl.isVanished(player.getName());
+ if (getTFM() == null)
+ {
+ GLog.warn("TFM not detected on the server.");
+ return false;
+ }
+
+ return getTFM().al.isVanished(player.getName());
}
}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/AddModSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/AddModSubcommand.java
index 40282de..eeb681b 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/AddModSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/AddModSubcommand.java
@@ -44,7 +44,7 @@ public class AddModSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.hasMember(player.getName()))
+ if (!guild.hasMember(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
return true;
@@ -56,13 +56,13 @@ public class AddModSubcommand extends Common implements CommandExecutor
return true;
}
- if (guild.hasModerator(player.getName()))
+ if (guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This member is already a moderator for this guild!");
return true;
}
- guild.addModerator(player.getName());
+ guild.addModerator(player.getUniqueId());
sender.sendMessage(tl(PREFIX + "Added %s%" + player.getName() + "%p% as a moderator for %s%" + GUtil.colorize(guild.getName()) + "%p%."));
guild.broadcast(tl("%s%" + player.getName() + " %p%has been made a moderator of your guild."));
guild.save();
@@ -83,7 +83,7 @@ public class AddModSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.getOwner().equals(player.getName()))
+ if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't change who is a moderator in your guild!");
return true;
@@ -96,25 +96,25 @@ public class AddModSubcommand extends Common implements CommandExecutor
return true;
}
- if (guild.getOwner().equals(n.getName()))
+ if (guild.getOwner().equals(n.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "No need to make yourself a moderator!");
return true;
}
- if (!guild.hasMember(n.getName()))
+ if (!guild.hasMember(n.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
return true;
}
- if (guild.hasModerator(n.getName()))
+ if (guild.hasModerator(n.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This member is already a moderator for your guild!");
return true;
}
- guild.addModerator(n.getName());
+ guild.addModerator(n.getUniqueId());
sender.sendMessage(tl(PREFIX + "Added %s%" + n.getName() + "%p% as a moderator for your guild."));
guild.broadcast(tl("%s%" + n.getName() + " %p%has been made a moderator of your guild."));
guild.save();
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubcommand.java
index f30e273..c39988e 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubcommand.java
@@ -38,7 +38,7 @@ public class CreateRankSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.getOwner().equals(player.getName()))
+ if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't create ranks for your guild!");
return true;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/CreateSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/CreateSubcommand.java
index 7e41555..df4b932 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/CreateSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/CreateSubcommand.java
@@ -32,7 +32,7 @@ public class CreateSubcommand extends Common implements CommandExecutor
return true;
}
- Player player = (Player)sender;
+ Player player = (Player) sender;
String name = StringUtils.join(args, " ", 1, args.length);
String identifier = GUtil.flatten(name);
@@ -76,7 +76,6 @@ public class CreateSubcommand extends Common implements CommandExecutor
}
Guild.createGuild(identifier, name, player);
- plugin.players.set(player.getName() + ".tag", true);
sender.sendMessage(tl(PREFIX + "Created a guild named \"" + GUtil.colorize(name) + "%p%\"!"));
broadcast(GUtil.colorize(tl("%p%" + sender.getName() + " has created guild %p%&l" + name)));
return true;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubcommand.java
index 113525d..a29a55e 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubcommand.java
@@ -35,7 +35,7 @@ public class DeleteRankSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.getOwner().equals(player.getName()))
+ if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't delete ranks from your guild!");
return true;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubcommand.java
index ddde390..e52f52a 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubcommand.java
@@ -40,7 +40,7 @@ public class DisbandSubcommand extends Common implements CommandExecutor
}
String n = guild.getName();
- GLog.info("Removing guilds.yml data for " + n);
+ GLog.info("Removing guild data for " + n);
guild.disband();
GLog.info(sender.getName() + " deleted guild " + guild.getName());
sender.sendMessage(tl(PREFIX + "Disbanded \"" + GUtil.colorize(n) + "%p%\"."));
@@ -62,13 +62,13 @@ public class DisbandSubcommand extends Common implements CommandExecutor
}
Guild guild = Guild.getGuild(player);
- if (!guild.getOwner().equals(player.getName()))
+ if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You are not the owner of this guild!");
return true;
}
- GLog.info("Removing guilds.yml data for " + guild.getName());
+ GLog.info("Removing guild data for " + guild.getName());
guild.disband();
GLog.info(player.getName() + " deleted guild " + guild.getName());
sender.sendMessage(tl(PREFIX + "You have disbanded your guild!"));
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
index e66fb69..daa23d0 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
@@ -10,6 +10,7 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
+import org.bukkit.entity.Player;
public class GuildCommand extends Common implements CommandExecutor, TabCompleter
{
@@ -84,7 +85,6 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
@Override
public List onTabComplete(CommandSender sender, Command command, String label, String[] args)
{
- Guild guild = Guild.getGuild(sender);
if (args.length == 1)
{
return Arrays.asList("addmod", "chat", "createrank", "create",
@@ -139,15 +139,25 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
case "deleterank":
case "setdefaultrank":
{
- if (guild.getOwner().equals(sender.getName()))
+ if (sender instanceof Player)
{
- return guild.getRankNames();
+ Player player = (Player) sender;
+ Guild guild = Guild.getGuild(player);
+ if (guild.getOwner().equals(player.getUniqueId()))
+ {
+ return guild.getRankNames();
+ }
}
}
case "tp":
{
- return guild.getMembers();
+ if (sender instanceof Player)
+ {
+ Player player = (Player) sender;
+ Guild guild = Guild.getGuild(player);
+ return guild.getOnlyMembers();
+ }
}
case "disband":
@@ -162,9 +172,14 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
case "kick":
{
- if (guild.hasModerator(sender.getName()))
+ if (sender instanceof Player)
{
- return guild.getOnlyMembers();
+ Player player = (Player) sender;
+ Guild guild = Guild.getGuild(player);
+ if (guild.hasModerator(player.getUniqueId()))
+ {
+ return guild.getOnlyMembers();
+ }
}
}
@@ -172,9 +187,14 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
case "addmod":
case "setowner":
{
- if (guild.getOwner().equals(sender.getName()))
+ if (sender instanceof Player)
{
- return guild.getMembers();
+ Player player = (Player) sender;
+ Guild guild = Guild.getGuild(player);
+ if (guild.getOwner().equals(player.getUniqueId()))
+ {
+ return guild.getOnlyMembers();
+ }
}
}
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/HomeSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/HomeSubcommand.java
index d0b0e8f..663d5f7 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/HomeSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/HomeSubcommand.java
@@ -38,7 +38,7 @@ public class HomeSubcommand extends Common implements CommandExecutor
{
if (args[1].equalsIgnoreCase("set"))
{
- if (!guild.hasModerator(player.getName()))
+ if (!guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't modify your guild's home!");
return true;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/JoinSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/JoinSubcommand.java
index 5047735..56a38a2 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/JoinSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/JoinSubcommand.java
@@ -59,7 +59,7 @@ public class JoinSubcommand extends Common implements CommandExecutor
INVITES.remove(player);
}
- guild.addMember(player.getName());
+ guild.addMember(player.getUniqueId());
guild.broadcast(tl("%s%" + player.getName() + " %p%has joined the guild."));
guild.save();
return true;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/KickSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/KickSubcommand.java
index 7729b99..7aefd6e 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/KickSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/KickSubcommand.java
@@ -44,19 +44,19 @@ public class KickSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.hasMember(player.getName()))
+ if (!guild.hasMember(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
return true;
}
- if (guild.getOwner().equals(player.getName()) || guild.hasModerator(player.getName()))
+ if (guild.getOwner().equals(player.getUniqueId()) || guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You cannot kick the owner/moderator(s) of a guild!");
return true;
}
- guild.removeMember(player.getName());
+ guild.removeMember(player.getUniqueId());
sender.sendMessage(tl(PREFIX + "Kicked %s%" + player.getName() + "%p% from %s%" + GUtil.colorize(guild.getName()) + "%p%."));
player.sendMessage(tl("%s%You have been kicked from your guild."));
guild.broadcast(tl("%s%" + player.getName() + " %p%has been kicked from your guild."));
@@ -78,7 +78,7 @@ public class KickSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.hasModerator(player.getName()))
+ if (!guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't kick people from your guild!");
return true;
@@ -91,19 +91,19 @@ public class KickSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.hasMember(n.getName()))
+ if (!guild.hasMember(n.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
return true;
}
- if (guild.getOwner().equals(n.getName()) || guild.hasModerator(n.getName()) && !guild.getOwner().equals(player.getName()))
+ if (guild.getOwner().equals(n.getUniqueId()) || guild.hasModerator(n.getUniqueId()) && !guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You cannot kick the owner/moderator(s) of a guild!");
return true;
}
- guild.removeMember(n.getName());
+ guild.removeMember(n.getUniqueId());
sender.sendMessage(tl(PREFIX + "Kicked %s%" + n.getName() + "%p% from your guild."));
n.sendMessage(tl("%s%You have been kicked from your guild."));
guild.broadcast(tl("%s%" + n.getName() + " %p%has been kicked from your guild."));
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/LeaveSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/LeaveSubcommand.java
index 2d1f5cb..ab1a023 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/LeaveSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/LeaveSubcommand.java
@@ -34,14 +34,14 @@ public class LeaveSubcommand extends Common implements CommandExecutor
return true;
}
- if (guild.getOwner().equals(player.getName()))
+ if (guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You cannot leave as you are the owner!");
return true;
}
- guild.removeModerator(player.getName());
- guild.removeMember(player.getName());
+ guild.removeModerator(player.getUniqueId());
+ guild.removeMember(player.getUniqueId());
guild.save();
sender.sendMessage(tl("%p%You left your guild."));
guild.broadcast(tl("%s%" + sender.getName() + " %p%left the guild."));
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/MOTDSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/MOTDSubcommand.java
index ec88d9c..3d58ae2 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/MOTDSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/MOTDSubcommand.java
@@ -36,7 +36,7 @@ public class MOTDSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.hasModerator(player.getName()))
+ if (!guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't modify your guild's MOTD!");
return true;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/RemoveModSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/RemoveModSubcommand.java
index 27c7326..bd389e1 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/RemoveModSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/RemoveModSubcommand.java
@@ -44,25 +44,28 @@ public class RemoveModSubcommand extends Common implements CommandExecutor
return true;
}
- if (guild.getModerators().contains(sender.getName()))
+ if (sender instanceof Player)
{
- sender.sendMessage(ChatColor.RED + "You may not demote yourself.");
- return true;
+ if (guild.getModerators().contains(((Player) sender).getUniqueId()))
+ {
+ sender.sendMessage(ChatColor.RED + "You may not demote yourself.");
+ return true;
+ }
}
- if (!guild.hasMember(player.getName()))
+ if (!guild.hasMember(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
return true;
}
- if (!guild.hasModerator(player.getName()))
+ if (!guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This member is not a moderator for this guild!");
return true;
}
- guild.removeModerator(player.getName());
+ guild.removeModerator(player.getUniqueId());
sender.sendMessage(tl(PREFIX + "Removed %s%" + player.getName() + "%p% as a moderator for %s%" + GUtil.colorize(guild.getName()) + "%p%."));
guild.broadcast(tl("%s%" + player.getName() + " %p%has been made a member of your guild."));
guild.save();
@@ -83,7 +86,7 @@ public class RemoveModSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.getOwner().equals(player.getName()))
+ if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't change who is a moderator in your guild!");
return true;
@@ -102,19 +105,19 @@ public class RemoveModSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.hasMember(n.getName()))
+ if (!guild.hasMember(n.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
return true;
}
- if (!guild.hasModerator(n.getName()))
+ if (!guild.hasModerator(n.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This member is not a moderator for your guild!");
return true;
}
- guild.removeModerator(n.getName());
+ guild.removeModerator(n.getUniqueId());
sender.sendMessage(tl(PREFIX + "Removed %s%" + n.getName() + "%p% as a moderator for your guild."));
guild.broadcast(tl("%s%" + n.getName() + " %p%has been made a member of your guild."));
guild.save();
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/RenameSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/RenameSubcommand.java
index 29137b8..e062734 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/RenameSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/RenameSubcommand.java
@@ -41,7 +41,7 @@ public class RenameSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.getOwner().equals(player.getName()))
+ if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't change the name of your guild!");
return true;
@@ -80,11 +80,7 @@ public class RenameSubcommand extends Common implements CommandExecutor
}
}
- guild.disband();
- guild.setIdentifier(GUtil.flatten(newName));
- guild.setName(newName);
- guild.updateRankIdentifiers();
- guild.setTag(GUtil.colorize("&8[&7" + newName + "&8]"));
+ guild.rename(newName);
sender.sendMessage(tl(PREFIX + "Set %s%" + GUtil.colorize(newName) + "%p% as the new name of your guild%p%."));
guild.broadcast(tl("%p%Your guild has been renamed to " + GUtil.colorize(newName) + "%p%."));
guild.save();
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubcommand.java
index 070918a..0d5d570 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubcommand.java
@@ -35,7 +35,7 @@ public class SetDefaultRankSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.getOwner().equals(player.getName()))
+ if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You do not have permissions to manage ranks in your guild!");
return true;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetMemberSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetMemberSubcommand.java
index 89051c4..ae95a01 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetMemberSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetMemberSubcommand.java
@@ -46,7 +46,7 @@ public class SetMemberSubcommand extends Common implements CommandExecutor
return true;
}
- guild.addMember(player.getName());
+ guild.addMember(player.getUniqueId());
guild.broadcast(tl("%s%" + player.getName() + " %p%has joined the guild."));
guild.save();
return true;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetOwnerSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetOwnerSubcommand.java
index 0648176..7b9b3bb 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetOwnerSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetOwnerSubcommand.java
@@ -44,20 +44,20 @@ public class SetOwnerSubcommand extends Common implements CommandExecutor
return true;
}
- if (guild.getOwner().contains(player.getName()))
+ if (guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is already the owner of that guild!");
return true;
}
- if (!guild.hasMember(player.getName()))
+ if (!guild.hasMember(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
return true;
}
- guild.removeModerator(player.getName());
- guild.setOwner(player.getName());
+ guild.removeModerator(player.getUniqueId());
+ guild.setOwner(player.getUniqueId());
sender.sendMessage(tl(PREFIX + "Ownership has been transferred to %s%" + player.getName() + "%p% in %s%" + GUtil.colorize(guild.getName()) + "%p%."));
guild.broadcast(tl("%s%" + player.getName() + " %p%has been made the owner of your guild."));
guild.save();
@@ -78,7 +78,7 @@ public class SetOwnerSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.getOwner().equals(player.getName()))
+ if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't change who is the owner of your guild!");
return true;
@@ -97,14 +97,14 @@ public class SetOwnerSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.hasMember(n.getName()))
+ if (!guild.hasMember(n.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
return true;
}
- guild.removeModerator(n.getName());
- guild.setOwner(n.getName());
+ guild.removeModerator(n.getUniqueId());
+ guild.setOwner(n.getUniqueId());
sender.sendMessage(tl(PREFIX + "Ownership has been transferred to %s%" + n.getName() + "%p% in your guild."));
guild.broadcast(tl("%s%" + n.getName() + " %p%has been made the owner of your guild."));
guild.save();
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
index dee3546..2a55be5 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
@@ -37,7 +37,7 @@ public class SetRankSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.hasModerator(player.getName()))
+ if (!guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't change the ranks of your guild members!");
return true;
@@ -50,7 +50,7 @@ public class SetRankSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.hasMember(r.getName()))
+ if (!guild.hasMember(r.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
return true;
@@ -61,7 +61,7 @@ public class SetRankSubcommand extends Common implements CommandExecutor
{
for (GuildRank gr : guild.getRanks())
{
- gr.getMembers().remove(r.getName());
+ gr.getMembers().remove(r.getUniqueId());
}
sender.sendMessage(tl(PREFIX + "Removed the rank of %s%" + r.getName() + "%p% in your guild."));
@@ -79,10 +79,11 @@ public class SetRankSubcommand extends Common implements CommandExecutor
for (GuildRank gr : guild.getRanks())
{
- gr.getMembers().remove(r.getName());
+ gr.getMembers().remove(r.getUniqueId());
}
- rank.getMembers().add(r.getName());
+ rank.getMembers().add(r.getUniqueId());
+ rank.save();
sender.sendMessage(tl(PREFIX + "Set the rank of %s%" + r.getName() + "%p% in your guild to %s%" + rank.getName() + "%p%."));
r.sendMessage(tl("%p%Your rank in your guild has been set to %s%" + rank.getName() + "%p%."));
guild.save();
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetStateSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetStateSubcommand.java
index 42da3cd..b95857e 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetStateSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetStateSubcommand.java
@@ -65,7 +65,7 @@ public class SetStateSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.hasModerator(player.getName()))
+ if (!guild.hasModerator(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't change the state of the guild!");
return true;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/TFGuildsCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/TFGuildsCommand.java
index 131f3c2..295db80 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/TFGuildsCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/TFGuildsCommand.java
@@ -32,8 +32,6 @@ public class TFGuildsCommand extends Common implements CommandExecutor
try
{
plugin.config.load();
- plugin.guilds.load();
- plugin.players.load();
GLog.info("All configs reloaded successfully");
sender.sendMessage(tl(PREFIX + "All configuration files have been reloaded successfully."));
return true;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/TPSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/TPSubcommand.java
index b0d7649..d2f33ed 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/TPSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/TPSubcommand.java
@@ -42,7 +42,7 @@ public class TPSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.getMembers().contains(to.getName()))
+ if (!guild.getMembers().contains(to.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "That player is not in your guild.");
return true;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/TagSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/TagSubcommand.java
index 4d97ec2..0657f60 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/TagSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/TagSubcommand.java
@@ -36,7 +36,7 @@ public class TagSubcommand extends Common implements CommandExecutor
return true;
}
- if (!guild.getOwner().equals(player.getName()))
+ if (!guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You can't modify your guild's tag!");
return true;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubcommand.java
index 222352a..b582601 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubcommand.java
@@ -2,6 +2,7 @@ package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
+import me.totalfreedom.tfguilds.user.User;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -36,19 +37,10 @@ public class ToggleTagSubcommand extends Common implements CommandExecutor
sender.sendMessage(PNF);
return true;
}
-
- boolean enabled = plugin.players.getBoolean(player.getName() + ".tag");
- if (!plugin.players.contains(player.getName()) || enabled)
- {
- plugin.players.set(player.getName() + ".tag", false);
- plugin.players.save();
- sender.sendMessage(tl(PREFIX + "Disabled personal guild tag for " + player.getName() + "."));
- return true;
- }
-
- plugin.players.set(player.getName() + ".tag", true);
- plugin.players.save();
- sender.sendMessage(tl(PREFIX + "Enabled personal guild tag for " + player.getName() + "."));
+ User user = plugin.userData.get(player.getUniqueId());
+ user.setTag(!user.isTag());
+ user.save();
+ sender.sendMessage(tl(PREFIX + (user.isTag() ? "Enabled" : "Disabled") + " personal guild tag for " + player.getName() + "."));
return true;
}
@@ -66,18 +58,10 @@ public class ToggleTagSubcommand extends Common implements CommandExecutor
return true;
}
- boolean enabled = plugin.players.getBoolean(player.getName() + ".tag");
- if (!plugin.players.contains(player.getName()) || enabled)
- {
- plugin.players.set(player.getName() + ".tag", false);
- plugin.players.save();
- sender.sendMessage(tl(PREFIX + "Disabled personal guild tag."));
- return true;
- }
-
- plugin.players.set(player.getName() + ".tag", true);
- plugin.players.save();
- sender.sendMessage(tl(PREFIX + "Enabled personal guild tag."));
+ User user = plugin.userData.get(player.getUniqueId());
+ user.setTag(!user.isTag());
+ user.save();
+ sender.sendMessage(tl(PREFIX + (user.isTag() ? "Enabled" : "Disabled") + " personal guild tag."));
return true;
}
}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
index ee89a20..d2e2b11 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
@@ -1,8 +1,8 @@
package me.totalfreedom.tfguilds.guild;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
+import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
import me.totalfreedom.tfguilds.TFGuilds;
@@ -14,8 +14,7 @@ import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
-import org.bukkit.command.CommandSender;
-import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
public class Guild
@@ -32,13 +31,13 @@ public class Guild
@Getter
@Setter
- private String owner;
+ private UUID owner;
@Getter
- private final List moderators;
+ private final List moderators;
@Getter
- private final List members;
+ private final List members;
@Getter
@Setter
@@ -68,9 +67,9 @@ public class Guild
public Guild(String identifier,
String name,
- String owner,
- List members,
- List moderators,
+ UUID owner,
+ List members,
+ List moderators,
String tag,
GuildState state,
List ranks,
@@ -95,77 +94,63 @@ public class Guild
public void save()
{
- plugin.guilds.set(identifier + ".name", name);
- plugin.guilds.set(identifier + ".owner", owner);
- plugin.guilds.set(identifier + ".members", members);
- plugin.guilds.set(identifier + ".moderators", moderators);
- plugin.guilds.set(identifier + ".tag", tag);
- plugin.guilds.set(identifier + ".state", state.name());
- for (GuildRank rank : ranks)
- {
- rank.set();
- }
- plugin.guilds.set(identifier + ".motd", motd);
- plugin.guilds.set(identifier + ".home", home);
- plugin.guilds.set(identifier + ".creation", creation);
- plugin.guilds.set(identifier + ".defaultrank", defaultRank);
- plugin.guilds.save();
+ plugin.guildData.save(this);
}
- public void addMember(String name)
+ public void addMember(UUID uuid)
{
if (hasDefaultRank())
{
- getRank(defaultRank).getMembers().add(name);
+ getRank(defaultRank).getMembers().add(uuid);
}
- members.add(name);
+ members.add(uuid);
}
- public void removeMember(String name)
+ public void removeMember(UUID uuid)
{
- Player player = Bukkit.getPlayer(name);
+ Player player = Bukkit.getPlayer(uuid);
if (player != null)
{
Common.IN_GUILD_CHAT.remove(player);
}
- members.remove(name);
+ members.remove(uuid);
for (GuildRank gr : getRanks())
{
- getRank(gr.getName()).getMembers().remove(name);
+ getRank(gr.getName()).getMembers().remove(uuid);
}
- moderators.remove(name);
+ moderators.remove(uuid);
}
- public boolean hasMember(String name)
+ public boolean hasMember(UUID uuid)
{
- return members.contains(name);
+ return members.contains(uuid);
}
- public void addModerator(String name)
+ public void addModerator(UUID uuid)
{
- moderators.add(name);
+ moderators.add(uuid);
}
- public void removeModerator(String name)
+ public void removeModerator(UUID uuid)
{
- moderators.remove(name);
+ moderators.remove(uuid);
}
- public boolean hasModerator(String name)
+ public boolean hasModerator(UUID uuid)
{
- if (owner.equals(name))
+ if (owner.equals(uuid))
{
return true;
}
- return moderators.contains(name);
+ return moderators.contains(uuid);
}
public void addRank(String name)
{
- ranks.add(new GuildRank(identifier, GUtil.flatten(name), name, new ArrayList<>()));
+ ranks.add(GuildRank.createGuildRank(identifier, GUtil.flatten(name), name));
}
public void removeRank(String name)
@@ -236,23 +221,37 @@ public class Guild
{
for (Player player : Bukkit.getOnlinePlayers())
{
- if (members.contains(player.getName()))
+ if (members.contains(player.getUniqueId()))
{
player.sendMessage(message);
}
}
}
+ public List getModeratorNames()
+ {
+ List only = new ArrayList<>();
+ for (UUID moderator : moderators)
+ {
+ if (moderator.equals(owner))
+ continue;
+ OfflinePlayer player = Bukkit.getOfflinePlayer(moderator);
+ only.add(player.getName());
+ }
+ return only;
+ }
+
public List getOnlyMembers()
{
List only = new ArrayList<>();
- for (String member : members)
+ for (UUID member : members)
{
if (member.equals(owner) || moderators.contains(member))
{
continue;
}
- only.add(member);
+ OfflinePlayer player = Bukkit.getOfflinePlayer(member);
+ only.add(player.getName());
}
return only;
}
@@ -270,14 +269,14 @@ public class Guild
public String getRoster()
{
StringBuilder list = new StringBuilder(Common.PREFIX + "Guild Roster for " + name + "\n" +
- "%s%Owner%p% - " + owner + "\n" +
- "%s%Moderators%p% - " + StringUtils.join(moderators, ", ") + "\n");
+ "%s%Owner%p% - " + Bukkit.getOfflinePlayer(owner).getName() + "\n" +
+ "%s%Moderators%p% - " + StringUtils.join(getModeratorNames(), ", ") + "\n");
for (GuildRank rank : ranks)
{
list.append("%s%")
.append(rank.getName()).append("%p% - ")
- .append(StringUtils.join(rank.getMembers(), ", "))
+ .append(StringUtils.join(rank.getMemberNames(), ", "))
.append("\n");
}
@@ -288,11 +287,8 @@ public class Guild
public static List getGuildList()
{
List g = new ArrayList<>();
- for (String key : plugin.guilds.getKeys(false))
- {
- Guild guild = getGuild(key);
+ for (Guild guild : plugin.guildData.getAll())
g.add(guild.getName());
- }
return g;
}
@@ -300,8 +296,8 @@ public class Guild
{
return Common.tl(Common.PREFIX + "Guild Information\n" +
"%s%Name%p%: " + name + "\n" +
- "%s%Owner%p%: " + owner + "\n" +
- "%s%Moderators%p%: " + StringUtils.join(moderators, ", ") + "\n" +
+ "%s%Owner%p%: " + Bukkit.getOfflinePlayer(owner).getName() + "\n" +
+ "%s%Moderators%p%: " + StringUtils.join(getModeratorNames(), ", ") + "\n" +
"%s%Members%p%: " + StringUtils.join(getOnlyMembers(), ", ") + "\n" +
"%s%Tag%p%: " + (tag == null ? "None" : GUtil.colorize(tag)) + "\n" +
"%s%State%p%: " + state.getDisplay() + "\n" +
@@ -339,17 +335,23 @@ public class Guild
public void disband()
{
- for (String member : members)
+ for (UUID member : members)
{
Player player = Bukkit.getPlayer(member);
if (player == null)
- {
continue;
- }
Common.IN_GUILD_CHAT.remove(player);
}
- plugin.guilds.set(identifier, null);
- plugin.guilds.save();
+ plugin.guildData.delete(this);
+ }
+
+ public void rename(String name)
+ {
+ this.identifier = GUtil.flatten(name);
+ updateRankIdentifiers();
+ this.name = name;
+ this.tag = GUtil.colorize("&8[&7" + name + "&8]");
+ this.save();
}
public void updateRankIdentifiers()
@@ -357,111 +359,38 @@ public class Guild
for (GuildRank rank : ranks)
{
rank.delete();
- rank.setIguild(identifier);
- rank.set();
- plugin.guilds.save();
+ rank.updateGuildIdentifier(identifier);
+ rank.save();
}
}
public static Guild createGuild(String identifier, String name, Player owner)
{
- if (plugin.guilds.contains(identifier))
- {
+ if (plugin.guildData.exists(identifier))
return getGuild(identifier);
- }
- Guild guild = new Guild(identifier,
- name,
- owner.getName(),
- Collections.singletonList(owner.getName()),
- new ArrayList<>(),
- ChatColor.DARK_GRAY + "[" + ChatColor.GRAY + name + ChatColor.DARK_GRAY + "]",
- GuildState.INVITE_ONLY,
- new ArrayList<>(),
- null,
- null,
- System.currentTimeMillis(),
- null);
- guild.save();
+ Guild guild = plugin.guildData.create(identifier, name, owner);
GLog.info(owner.getName() + " has created guild " + name);
return guild;
}
public static Guild getGuild(String identifier)
{
- if (!plugin.guilds.contains(identifier))
- {
- return null;
- }
-
- List ranks = new ArrayList<>();
- ConfigurationSection rankcs = plugin.guilds.getConfigurationSection(identifier + ".ranks");
- if (rankcs != null)
- {
- for (String key : rankcs.getKeys(false))
- {
- ranks.add(new GuildRank(identifier, key, plugin.guilds.getString(identifier + ".ranks." + key + ".name"),
- plugin.guilds.getStringList(identifier + ".ranks." + key + ".members")));
- }
- }
-
- return new Guild(identifier,
- plugin.guilds.getString(identifier + ".name"),
- plugin.guilds.getString(identifier + ".owner"),
- plugin.guilds.getStringList(identifier + ".members"),
- plugin.guilds.getStringList(identifier + ".moderators"),
- plugin.guilds.getString(identifier + ".tag"),
- GuildState.findState(plugin.guilds.getString(identifier + ".state")),
- ranks,
- plugin.guilds.getString(identifier + ".motd"),
- plugin.guilds.getLocation(identifier + ".home"),
- plugin.guilds.getLong(identifier + ".creation"),
- plugin.guilds.getString(identifier + ".defaultrank"));
+ return plugin.guildData.get(identifier);
}
public static Guild getGuild(Player player)
{
- Guild guild = null;
- for (String key : plugin.guilds.getKeys(false))
- {
- Guild kg = getGuild(key);
- if (kg.getMembers().contains(player.getName()))
- {
- guild = kg;
- }
- }
- return guild;
- }
-
- public static Guild getGuild(CommandSender sender)
- {
- Guild guild = null;
- for (String key : plugin.guilds.getKeys(false))
- {
- Guild kg = getGuild(key);
- if (kg.getMembers().contains(sender.getName()))
- {
- guild = kg;
- }
- }
- return guild;
+ return plugin.guildData.get(player);
}
public static boolean guildExists(String identifier)
{
- return plugin.guilds.contains(identifier);
+ return plugin.guildData.exists(identifier);
}
public static boolean isInGuild(Player player)
{
- for (String key : plugin.guilds.getKeys(false))
- {
- Guild guild = getGuild(key);
- if (guild.getMembers().contains(player.getName()))
- {
- return true;
- }
- }
- return false;
+ return getGuild(player) != null;
}
}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/GuildRank.java b/src/main/java/me/totalfreedom/tfguilds/guild/GuildRank.java
index f2e539b..f14af20 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/GuildRank.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/GuildRank.java
@@ -1,16 +1,19 @@
package me.totalfreedom.tfguilds.guild;
+import java.util.ArrayList;
import java.util.List;
+import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
import me.totalfreedom.tfguilds.TFGuilds;
+import org.bukkit.Bukkit;
+import org.bukkit.OfflinePlayer;
public class GuildRank
{
private static TFGuilds plugin = TFGuilds.getPlugin();
- // owning guild's identifier
- @Setter
+ @Getter
private String iguild;
// identifier
@@ -23,24 +26,45 @@ public class GuildRank
// members of this rank
@Getter
- private List members;
+ private List members;
- public GuildRank(String iguild, String identifier, String name, List members)
+ public GuildRank(String iguild, String identifier, String name, List members)
{
- this.identifier = identifier;
this.iguild = iguild;
+ this.identifier = identifier;
this.name = name;
this.members = members;
}
- public void set()
+ public List getMemberNames()
{
- plugin.guilds.set(iguild + ".ranks." + identifier + ".name", name);
- plugin.guilds.set(iguild + ".ranks." + identifier + ".members", members);
+ List only = new ArrayList<>();
+ for (UUID member : members)
+ {
+ OfflinePlayer player = Bukkit.getOfflinePlayer(member);
+ only.add(player.getName());
+ }
+ return only;
+ }
+
+ public static GuildRank createGuildRank(String guildIdentifier, String identifier, String name)
+ {
+ return plugin.rankData.create(guildIdentifier, identifier, name);
+ }
+
+ public void save()
+ {
+ plugin.rankData.save(this);
+ }
+
+ public void updateGuildIdentifier(String newIdentifier)
+ {
+ plugin.rankData.updateGuildIdentifier(this, newIdentifier);
+ this.iguild = newIdentifier;
}
public void delete()
{
- plugin.guilds.set(iguild + ".ranks." + identifier, null);
+ plugin.rankData.delete(this);
}
}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
index bcae284..62f1794 100644
--- a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
+++ b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
@@ -5,6 +5,7 @@ import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.config.ConfigEntry;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildRank;
+import me.totalfreedom.tfguilds.user.User;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@@ -46,11 +47,11 @@ public class ChatListener implements Listener
String display;
if (rank == null)
{
- if (guild.getOwner().equals(player.getName()))
+ if (guild.getOwner().equals(player.getUniqueId()))
{
display = "Guild Owner";
}
- else if (guild.hasModerator(player.getName()))
+ else if (guild.hasModerator(player.getUniqueId()))
{
display = "Guild Moderator";
}
@@ -69,13 +70,8 @@ public class ChatListener implements Listener
return;
}
- if (plugin.players.contains(player.getName()))
- {
- if (!plugin.players.getBoolean(player.getName() + ".tag"))
- {
- return;
- }
- }
+ User user = plugin.userData.get(player.getUniqueId());
+ if (!user.isTag()) return;
if (guild.hasTag())
{
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
new file mode 100644
index 0000000..db9d772
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
@@ -0,0 +1,81 @@
+package me.totalfreedom.tfguilds.sql;
+
+import java.io.File;
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import me.totalfreedom.tfguilds.TFGuilds;
+
+public class SQLDatabase
+{
+ private static final String DATABASE_FILENAME = "database.db";
+ private static final TFGuilds plugin = TFGuilds.getPlugin();
+
+ private File file;
+ private Connection connection;
+
+ public SQLDatabase()
+ {
+ File file = new File(plugin.getDataFolder(), DATABASE_FILENAME);
+ if (!file.exists())
+ {
+ try
+ {
+ file.createNewFile();
+ plugin.saveResource(DATABASE_FILENAME, false);
+ }
+ catch (IOException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ this.file = file;
+ }
+
+ public Connection getConnection()
+ {
+ try
+ {
+ Connection connection = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath());
+ connection.prepareStatement("CREATE TABLE IF NOT EXISTS `users` (\n" +
+ "\t`id` INT,\n" +
+ "\t`uuid` TINYTEXT,\n" +
+ "\t`tag` BOOL\n" +
+ ");").execute();
+ connection.prepareStatement("CREATE TABLE IF NOT EXISTS `worlds` (\n" +
+ "\t`id` SMALLINT,\n" +
+ "\t`name` TINYTEXT\n" +
+ ");").execute();
+ connection.prepareStatement("CREATE TABLE IF NOT EXISTS `ranks` (\n" +
+ "\t`guild_identifier` TEXT,\n" +
+ "\t`identifier` TEXT,\n" +
+ "\t`name` TEXT,\n" +
+ "\t`members` TEXT\n" +
+ ");").execute();
+ connection.prepareStatement("CREATE TABLE IF NOT EXISTS `guilds` (\n" +
+ "\t`identifier` TEXT,\n" +
+ "\t`name` TEXT,\n" +
+ "\t`owner` INT,\n" +
+ "\t`moderators` TEXT,\n" +
+ "\t`members` TEXT,\n" +
+ "\t`tag` TEXT,\n" +
+ "\t`state` TINYINT,\n" +
+ "\t`ranks` TEXT,\n" +
+ "\t`motd` TEXT,\n" +
+ "\t`x` DOUBLE,\n" +
+ "\t`y` DOUBLE,\n" +
+ "\t`z` DOUBLE,\n" +
+ "\t`world` SMALLINT,\n" +
+ "\t`default_rank` TEXT,\n" +
+ "\t`creation` BIGINT\n" +
+ ");").execute();
+ return connection;
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
new file mode 100644
index 0000000..07cddef
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
@@ -0,0 +1,223 @@
+package me.totalfreedom.tfguilds.sql;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+import me.totalfreedom.tfguilds.TFGuilds;
+import me.totalfreedom.tfguilds.guild.Guild;
+import me.totalfreedom.tfguilds.guild.GuildRank;
+import me.totalfreedom.tfguilds.guild.GuildState;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+
+public class SQLGuildData
+{
+ private static final TFGuilds plugin = TFGuilds.getPlugin();
+ private static final String TABLE_NAME = "guilds";
+
+ private final String SELECT = "SELECT * FROM `" + TABLE_NAME + "` WHERE identifier=?";
+ private final String SELECT_MEMBER = "SELECT * FROM `" + TABLE_NAME + "` WHERE members LIKE ?";
+ private final String SELECT_ALL = "SELECT * FROM `" + TABLE_NAME + "`";
+ private final String UPDATE = "UPDATE `" + TABLE_NAME + "` SET name=?, owner=?, members=?, moderators=?, tag=?, state=?, ranks=?, motd=?, x=?, y=?, z=?, world=?, default_rank=? WHERE identifier=?";
+ private final String DELETE = "DELETE FROM `" + TABLE_NAME + "` WHERE identifier=?";
+ private final String INSERT = "INSERT INTO `" + TABLE_NAME + "` (`identifier`, `name`, `owner`, `members`, " +
+ "`moderators`, `tag`, `state`, `ranks`, `motd`, `x`, `y`, `z`, `world`, `default_rank`, `creation`) " +
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
+
+ public boolean exists(String identifier)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(SELECT);
+ statement.setString(1, identifier);
+ ResultSet set = statement.executeQuery();
+ return set.next();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return false;
+ }
+
+ public Guild get(String identifier)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(SELECT);
+ statement.setString(1, identifier);
+ ResultSet set = statement.executeQuery();
+ boolean next = set.next();
+ if (!next) return null;
+ String name = set.getString("name");
+ UUID owner = plugin.userData.get(set.getInt("owner")).getUuid();
+ List members = new ArrayList<>();
+ for (String stringMember : set.getString("members").split(","))
+ members.add(plugin.userData.get(Integer.parseInt(stringMember)).getUuid());
+ List moderators = new ArrayList<>();
+ if (set.getString("moderators") != null)
+ {
+ for (String stringModerator : set.getString("moderators").split(","))
+ moderators.add(plugin.userData.get(Integer.parseInt(stringModerator)).getUuid());
+ }
+ String tag = set.getString("tag");
+ GuildState state = GuildState.values()[set.getInt("state")];
+ List ranks = new ArrayList<>();
+ if (set.getString("ranks") != null)
+ {
+ for (String rankString : Arrays.asList(set.getString("ranks").split(",")))
+ ranks.add(plugin.rankData.get(identifier, rankString));
+ }
+ String motd = set.getString("motd");
+ Location home = new Location(plugin.worldData.getWorld(set.getInt("world")),
+ set.getDouble("x"),
+ set.getDouble("y"),
+ set.getDouble("z"));
+ String defaultRank = set.getString("default_rank");
+ long creation = set.getLong("creation");
+ return new Guild(identifier, name, owner, members, moderators, tag, state, ranks, motd, home, creation, defaultRank);
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ public Guild get(Player player)
+ {
+ for (Guild guild : getAll())
+ {
+ if (guild.getMembers().contains(player.getUniqueId()))
+ return guild;
+ }
+ return null;
+ }
+
+ public List getAll()
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(SELECT_ALL);
+ ResultSet set = statement.executeQuery();
+ List guilds = new ArrayList<>();
+ while (set.next())
+ guilds.add(get(set.getString("identifier")));
+ return guilds;
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ /*
+ Guild guild = new Guild(identifier,
+ name,
+ owner.getName(),
+ Collections.singletonList(owner.getName()),
+ new ArrayList<>(),
+ ChatColor.DARK_GRAY + "[" + ChatColor.GRAY + name + ChatColor.DARK_GRAY + "]",
+ GuildState.INVITE_ONLY,
+ new ArrayList<>(),
+ null,
+ null,
+ System.currentTimeMillis(),
+ null);
+ */
+
+ public Guild create(String identifier, String name, Player owner)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(INSERT);
+ statement.setString(1, identifier);
+ statement.setString(2, name);
+ int ownerID = plugin.userData.get(owner.getUniqueId()).getId();
+ statement.setInt(3, ownerID);
+ statement.setString(4, "" + ownerID);
+ statement.setString(5, null);
+ statement.setString(6, "&8[&7" + name + "&8]");
+ statement.setInt(7, GuildState.INVITE_ONLY.ordinal());
+ statement.setString(8, null);
+ statement.setString(9, null);
+ statement.setDouble(10, 0.0);
+ statement.setDouble(11, 100.0);
+ statement.setDouble(12, 0.0);
+ statement.setInt(13, plugin.worldData.getWorldID(Bukkit.getWorlds().get(0)));
+ statement.setString(14, null);
+ long creation = System.currentTimeMillis();
+ statement.setLong(15, creation);
+ statement.execute();
+ return new Guild(identifier, name, owner.getUniqueId(), Collections.singletonList(owner.getUniqueId()), new ArrayList<>(),
+ ChatColor.DARK_GRAY + "[" + ChatColor.GRAY + name + ChatColor.DARK_GRAY + "]",
+ GuildState.INVITE_ONLY, new ArrayList<>(), null, new Location(Bukkit.getWorlds().get(0), 0.0, 100.0, 0.0), creation, null);
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ public void save(Guild guild)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(UPDATE);
+ statement.setString(1, guild.getName());
+ statement.setString(2, "" + plugin.userData.get(guild.getOwner()).getId());
+ List members = new ArrayList<>();
+ for (UUID member : guild.getMembers())
+ members.add("" + plugin.userData.get(member).getId());
+ statement.setString(3, members.size() == 0 ? null : StringUtils.join(members, ","));
+ List moderators = new ArrayList<>();
+ for (UUID moderator : guild.getModerators())
+ moderators.add("" + plugin.userData.get(moderator).getId());
+ statement.setString(4, moderators.size() == 0 ? null : StringUtils.join(moderators, ","));
+ statement.setString(5, guild.getTag());
+ statement.setInt(6, guild.getState().ordinal());
+ List stringRanks = new ArrayList<>();
+ for (GuildRank rank : guild.getRanks())
+ stringRanks.add(rank.getIdentifier());
+ statement.setString(7, stringRanks.size() == 0 ? null : StringUtils.join(stringRanks, ","));
+ statement.setString(8, guild.getMotd());
+ Location home = guild.getHome();
+ statement.setDouble(9, home == null ? 0.0 : home.getX());
+ statement.setDouble(10, home == null ? 100.0 : home.getY());
+ statement.setDouble(11, home == null ? 0.0 : home.getZ());
+ statement.setInt(12, home == null ? plugin.worldData.getWorldID(Bukkit.getWorlds().get(0)) : plugin.worldData.getWorldID(home.getWorld()));
+ statement.setString(13, guild.getDefaultRank());
+ statement.setString(14, guild.getIdentifier());
+ statement.execute();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public void delete(Guild guild)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(DELETE);
+ statement.setString(1, guild.getIdentifier());
+ statement.execute();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
new file mode 100644
index 0000000..ec11742
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
@@ -0,0 +1,142 @@
+package me.totalfreedom.tfguilds.sql;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+import me.totalfreedom.tfguilds.TFGuilds;
+import me.totalfreedom.tfguilds.guild.Guild;
+import me.totalfreedom.tfguilds.guild.GuildRank;
+import me.totalfreedom.tfguilds.guild.GuildState;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+
+public class SQLRankData
+{
+ private static final TFGuilds plugin = TFGuilds.getPlugin();
+ private static final String TABLE_NAME = "ranks";
+
+ private final String SELECT = "SELECT * FROM `" + TABLE_NAME + "` WHERE guild_identifier=? AND identifier=?";
+ private final String UPDATE = "UPDATE `" + TABLE_NAME + "` SET name=?, members=? WHERE guild_identifier=? AND identifier=?";
+ private final String UPDATE_GUILD = "UPDATE `" + TABLE_NAME + "` SET guild_identifier=? WHERE guild_identifier=? AND identifier=?";
+ private final String DELETE = "DELETE `" + TABLE_NAME + "` WHERE guild_identifier=? AND identifier=?";
+ private final String INSERT = "INSERT INTO `" + TABLE_NAME + "` (`guild_identifier`, `identifier`, `name`, `members`) " +
+ "VALUES (?, ?, ?, ?);";
+
+ public boolean exists(String guildIdentifier, String identifier)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(SELECT);
+ statement.setString(1, guildIdentifier);
+ statement.setString(2, identifier);
+ ResultSet set = statement.executeQuery();
+ return set.next();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return false;
+ }
+
+ public GuildRank get(String guildIdentifier, String identifier)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(SELECT);
+ statement.setString(1, guildIdentifier);
+ statement.setString(2, identifier);
+ ResultSet set = statement.executeQuery();
+ set.next();
+ String name = set.getString("name");
+ List members = new ArrayList<>();
+ if (set.getString("members") != null)
+ {
+ for (String stringMember : set.getString("members").split(","))
+ members.add(plugin.userData.get(Integer.parseInt(stringMember)).getUuid());
+ }
+ return new GuildRank(guildIdentifier, identifier, name, members);
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ public GuildRank create(String guildIdentifier, String identifier, String name)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(INSERT);
+ statement.setString(1, guildIdentifier);
+ statement.setString(2, identifier);
+ statement.setString(3, name);
+ statement.setString(4, null);
+ statement.execute();
+ return new GuildRank(guildIdentifier, identifier, name, new ArrayList<>());
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ public void save(GuildRank rank)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(UPDATE);
+ statement.setString(1, rank.getName());
+ List members = new ArrayList<>();
+ for (UUID member : rank.getMembers())
+ members.add("" + plugin.userData.get(member).getId());
+ statement.setString(2, members.size() == 0 ? null : StringUtils.join(members, ","));
+ statement.setString(3, rank.getIguild());
+ statement.setString(4, rank.getIdentifier());
+ statement.execute();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public void updateGuildIdentifier(GuildRank rank, String newIdentifier)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(UPDATE_GUILD);
+ statement.setString(1, newIdentifier);
+ statement.setString(2, rank.getIguild());
+ statement.setString(3, rank.getIdentifier());
+ statement.execute();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public void delete(GuildRank rank)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(DELETE);
+ statement.setString(1, rank.getIguild());
+ statement.setString(2, rank.getIdentifier());
+ statement.execute();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java
new file mode 100644
index 0000000..46dcfd3
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java
@@ -0,0 +1,156 @@
+package me.totalfreedom.tfguilds.sql;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+import me.totalfreedom.tfguilds.TFGuilds;
+import me.totalfreedom.tfguilds.guild.Guild;
+import me.totalfreedom.tfguilds.guild.GuildRank;
+import me.totalfreedom.tfguilds.guild.GuildState;
+import me.totalfreedom.tfguilds.user.User;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+
+public class SQLUserData
+{
+ private static final TFGuilds plugin = TFGuilds.getPlugin();
+ private static final String TABLE_NAME = "users";
+
+ private final String SELECT = "SELECT * FROM `" + TABLE_NAME + "` WHERE uuid=?";
+ private final String SELECT_ID = "SELECT * FROM `" + TABLE_NAME + "` WHERE id=?";
+ private final String UPDATE = "UPDATE `" + TABLE_NAME + "` SET tag=? WHERE uuid=?";
+ private final String INSERT = "INSERT INTO `" + TABLE_NAME + "` (`id`, `uuid`, `tag`) " +
+ "VALUES (?, ?, ?);";
+ private final String COUNT = "SELECT COUNT(*) AS rows FROM `" + TABLE_NAME + "`";
+
+ public boolean exists(UUID uuid)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(SELECT);
+ statement.setString(1, uuid.toString());
+ ResultSet set = statement.executeQuery();
+ return set.next();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return false;
+ }
+
+ public boolean existsID(int id)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(SELECT_ID);
+ statement.setInt(1, id);
+ ResultSet set = statement.executeQuery();
+ return set.next();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return false;
+ }
+
+ public User get(UUID uuid)
+ {
+ if (!exists(uuid)) create(uuid);
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(SELECT);
+ statement.setString(1, uuid.toString());
+ ResultSet set = statement.executeQuery();
+ set.next();
+ int id = set.getInt("id");
+ boolean tag = set.getBoolean("tag");
+ return new User(id, uuid, tag);
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ public User get(int id)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(SELECT_ID);
+ statement.setInt(1, id);
+ ResultSet set = statement.executeQuery();
+ set.next();
+ UUID uuid = UUID.fromString(set.getString("uuid"));
+ boolean tag = set.getBoolean("tag");
+ return new User(id, uuid, tag);
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ public User create(UUID uuid)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(INSERT);
+ int id = getUserCount() + 1;
+ statement.setInt(1, id);
+ statement.setString(2, uuid.toString());
+ statement.setBoolean(3, true);
+ statement.execute();
+ return new User(id, uuid, true);
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ public void save(User user)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(UPDATE);
+ statement.setBoolean(1, user.isTag());
+ statement.setString(2, user.getUuid().toString());
+ statement.execute();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public int getUserCount()
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(COUNT);
+ ResultSet set = statement.executeQuery();
+ set.next();
+ int count = set.getInt("rows");
+ set.close();
+ return count;
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return 0;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java
new file mode 100644
index 0000000..d8b91f1
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java
@@ -0,0 +1,116 @@
+package me.totalfreedom.tfguilds.sql;
+
+import me.totalfreedom.tfguilds.TFGuilds;
+import org.bukkit.Bukkit;
+import org.bukkit.World;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+public class SQLWorldData
+{
+ private static final TFGuilds plugin = TFGuilds.getPlugin();
+
+ private final String SELECT = "SELECT * FROM `worlds` WHERE name=?";
+ private final String SELECT_ID = "SELECT * FROM `worlds` WHERE id=?";
+ private final String INSERT = "INSERT INTO `worlds` (`id`, `name`) VALUES (?, ?);";
+ private final String COUNT = "SELECT COUNT(*) AS rows FROM `worlds`";
+
+ public boolean exists(World world)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(SELECT);
+ statement.setString(1, world.getName());
+ ResultSet set = statement.executeQuery();
+ return set.next();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return false;
+ }
+
+ public boolean existsID(int id)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(SELECT_ID);
+ statement.setInt(1, id);
+ ResultSet set = statement.executeQuery();
+ return set.next();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return false;
+ }
+
+ public int getWorldID(World world)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ if (!exists(world))
+ {
+ PreparedStatement statement = connection.prepareStatement(INSERT);
+ statement.setInt(1, getWorldCount() + 1);
+ statement.setString(2, world.getName());
+ statement.execute();
+ }
+ PreparedStatement statement = connection.prepareStatement(SELECT);
+ statement.setString(1, world.getName());
+ ResultSet set = statement.executeQuery();
+ set.next();
+ int id = set.getInt("id");
+ set.close();
+ return id;
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return -1;
+ }
+
+ public World getWorld(int id)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ if (!existsID(id)) return null;
+ PreparedStatement statement = connection.prepareStatement(SELECT_ID);
+ statement.setInt(1, id);
+ ResultSet set = statement.executeQuery();
+ set.next();
+ String name = set.getString("name");
+ set.close();
+ return Bukkit.getWorld(name);
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ public int getWorldCount()
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(COUNT);
+ ResultSet set = statement.executeQuery();
+ set.next();
+ int count = set.getInt("rows");
+ set.close();
+ return count;
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return 0;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/user/User.java b/src/main/java/me/totalfreedom/tfguilds/user/User.java
new file mode 100644
index 0000000..0d57e48
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/user/User.java
@@ -0,0 +1,27 @@
+package me.totalfreedom.tfguilds.user;
+
+import java.util.UUID;
+import lombok.Getter;
+import lombok.Setter;
+import me.totalfreedom.tfguilds.TFGuilds;
+
+@Getter
+public class User
+{
+ private final int id;
+ private final UUID uuid;
+ @Setter
+ private boolean tag;
+
+ public User(int id, UUID uuid, boolean tag)
+ {
+ this.id = id;
+ this.uuid = uuid;
+ this.tag = tag;
+ }
+
+ public void save()
+ {
+ TFGuilds.getPlugin().userData.save(this);
+ }
+}
diff --git a/src/main/resources/database.db b/src/main/resources/database.db
new file mode 100644
index 0000000..e69de29
diff --git a/src/main/resources/guilds.yml b/src/main/resources/guilds.yml
deleted file mode 100644
index c4f8235..0000000
--- a/src/main/resources/guilds.yml
+++ /dev/null
@@ -1,3 +0,0 @@
-#
-# Guild data for TFGuilds
-#
diff --git a/src/main/resources/players.yml b/src/main/resources/players.yml
deleted file mode 100644
index 27e0340..0000000
--- a/src/main/resources/players.yml
+++ /dev/null
@@ -1,3 +0,0 @@
-#
-# Player data for TFGuilds
-#
\ No newline at end of file
From 16cc2c29212650c85f48ec6e924809cca78c3b6b Mon Sep 17 00:00:00 2001
From: super
Date: Thu, 3 Dec 2020 02:02:05 -0500
Subject: [PATCH 06/41] uh oh stupid idiot me
---
.../me/totalfreedom/tfguilds/guild/Guild.java | 7 +---
.../tfguilds/sql/SQLGuildData.java | 38 +++++++++++--------
.../tfguilds/sql/SQLRankData.java | 2 +-
3 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
index d2e2b11..78405bf 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
@@ -347,21 +347,18 @@ public class Guild
public void rename(String name)
{
+ String oldIdentifier = this.identifier;
this.identifier = GUtil.flatten(name);
updateRankIdentifiers();
this.name = name;
this.tag = GUtil.colorize("&8[&7" + name + "&8]");
- this.save();
+ plugin.guildData.save(this, oldIdentifier);
}
public void updateRankIdentifiers()
{
for (GuildRank rank : ranks)
- {
- rank.delete();
rank.updateGuildIdentifier(identifier);
- rank.save();
- }
}
public static Guild createGuild(String identifier, String name, Player owner)
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
index 07cddef..785ad60 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
@@ -27,7 +27,7 @@ public class SQLGuildData
private final String SELECT = "SELECT * FROM `" + TABLE_NAME + "` WHERE identifier=?";
private final String SELECT_MEMBER = "SELECT * FROM `" + TABLE_NAME + "` WHERE members LIKE ?";
private final String SELECT_ALL = "SELECT * FROM `" + TABLE_NAME + "`";
- private final String UPDATE = "UPDATE `" + TABLE_NAME + "` SET name=?, owner=?, members=?, moderators=?, tag=?, state=?, ranks=?, motd=?, x=?, y=?, z=?, world=?, default_rank=? WHERE identifier=?";
+ private final String UPDATE = "UPDATE `" + TABLE_NAME + "` SET identifier=?, name=?, owner=?, members=?, moderators=?, tag=?, state=?, ranks=?, motd=?, x=?, y=?, z=?, world=?, default_rank=? WHERE identifier=?";
private final String DELETE = "DELETE FROM `" + TABLE_NAME + "` WHERE identifier=?";
private final String INSERT = "INSERT INTO `" + TABLE_NAME + "` (`identifier`, `name`, `owner`, `members`, " +
"`moderators`, `tag`, `state`, `ranks`, `motd`, `x`, `y`, `z`, `world`, `default_rank`, `creation`) " +
@@ -170,35 +170,36 @@ public class SQLGuildData
return null;
}
- public void save(Guild guild)
+ public void save(Guild guild, String identifier)
{
try (Connection connection = plugin.sql.getConnection())
{
PreparedStatement statement = connection.prepareStatement(UPDATE);
- statement.setString(1, guild.getName());
- statement.setString(2, "" + plugin.userData.get(guild.getOwner()).getId());
+ statement.setString(1, guild.getIdentifier());
+ statement.setString(2, guild.getName());
+ statement.setString(3, "" + plugin.userData.get(guild.getOwner()).getId());
List members = new ArrayList<>();
for (UUID member : guild.getMembers())
members.add("" + plugin.userData.get(member).getId());
- statement.setString(3, members.size() == 0 ? null : StringUtils.join(members, ","));
+ statement.setString(4, members.size() == 0 ? null : StringUtils.join(members, ","));
List moderators = new ArrayList<>();
for (UUID moderator : guild.getModerators())
moderators.add("" + plugin.userData.get(moderator).getId());
- statement.setString(4, moderators.size() == 0 ? null : StringUtils.join(moderators, ","));
- statement.setString(5, guild.getTag());
- statement.setInt(6, guild.getState().ordinal());
+ statement.setString(5, moderators.size() == 0 ? null : StringUtils.join(moderators, ","));
+ statement.setString(6, guild.getTag());
+ statement.setInt(7, guild.getState().ordinal());
List stringRanks = new ArrayList<>();
for (GuildRank rank : guild.getRanks())
stringRanks.add(rank.getIdentifier());
- statement.setString(7, stringRanks.size() == 0 ? null : StringUtils.join(stringRanks, ","));
- statement.setString(8, guild.getMotd());
+ statement.setString(8, stringRanks.size() == 0 ? null : StringUtils.join(stringRanks, ","));
+ statement.setString(9, guild.getMotd());
Location home = guild.getHome();
- statement.setDouble(9, home == null ? 0.0 : home.getX());
- statement.setDouble(10, home == null ? 100.0 : home.getY());
- statement.setDouble(11, home == null ? 0.0 : home.getZ());
- statement.setInt(12, home == null ? plugin.worldData.getWorldID(Bukkit.getWorlds().get(0)) : plugin.worldData.getWorldID(home.getWorld()));
- statement.setString(13, guild.getDefaultRank());
- statement.setString(14, guild.getIdentifier());
+ statement.setDouble(10, home == null ? 0.0 : home.getX());
+ statement.setDouble(11, home == null ? 100.0 : home.getY());
+ statement.setDouble(12, home == null ? 0.0 : home.getZ());
+ statement.setInt(13, home == null ? plugin.worldData.getWorldID(Bukkit.getWorlds().get(0)) : plugin.worldData.getWorldID(home.getWorld()));
+ statement.setString(14, guild.getDefaultRank());
+ statement.setString(15, identifier);
statement.execute();
}
catch (SQLException ex)
@@ -207,6 +208,11 @@ public class SQLGuildData
}
}
+ public void save(Guild guild)
+ {
+ save(guild, guild.getIdentifier());
+ }
+
public void delete(Guild guild)
{
try (Connection connection = plugin.sql.getConnection())
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
index ec11742..ce97d56 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
@@ -24,7 +24,7 @@ public class SQLRankData
private final String SELECT = "SELECT * FROM `" + TABLE_NAME + "` WHERE guild_identifier=? AND identifier=?";
private final String UPDATE = "UPDATE `" + TABLE_NAME + "` SET name=?, members=? WHERE guild_identifier=? AND identifier=?";
private final String UPDATE_GUILD = "UPDATE `" + TABLE_NAME + "` SET guild_identifier=? WHERE guild_identifier=? AND identifier=?";
- private final String DELETE = "DELETE `" + TABLE_NAME + "` WHERE guild_identifier=? AND identifier=?";
+ private final String DELETE = "DELETE FROM `" + TABLE_NAME + "` WHERE guild_identifier=? AND identifier=?";
private final String INSERT = "INSERT INTO `" + TABLE_NAME + "` (`guild_identifier`, `identifier`, `name`, `members`) " +
"VALUES (?, ?, ?, ?);";
From 398cef14ec67281fae5eee498f089b43186e91fa Mon Sep 17 00:00:00 2001
From: super
Date: Thu, 3 Dec 2020 08:38:37 -0500
Subject: [PATCH 07/41] optimize imports
---
.idea/TFGuilds.iml | 13 +++++++++++--
.idea/compiler.xml | 1 +
pom.xml | 8 ++++++++
.../me/totalfreedom/tfguilds/TFGuilds.java | 2 --
.../tfguilds/command/CreateSubcommand.java | 6 ++----
.../tfguilds/command/DisbandSubcommand.java | 1 -
.../tfguilds/command/RenameSubcommand.java | 5 ++---
.../tfguilds/command/ToggleTagSubcommand.java | 1 -
.../totalfreedom/tfguilds/config/Config.java | 3 +--
.../me/totalfreedom/tfguilds/guild/Guild.java | 2 +-
.../totalfreedom/tfguilds/guild/GuildRank.java | 9 ++++-----
.../totalfreedom/tfguilds/sql/SQLDatabase.java | 3 +--
.../tfguilds/sql/SQLGuildData.java | 18 +-----------------
.../totalfreedom/tfguilds/sql/SQLRankData.java | 5 -----
.../totalfreedom/tfguilds/sql/SQLUserData.java | 11 -----------
.../tfguilds/sql/SQLWorldData.java | 7 +++----
16 files changed, 35 insertions(+), 60 deletions(-)
diff --git a/.idea/TFGuilds.iml b/.idea/TFGuilds.iml
index 4742ffe..f11b5de 100644
--- a/.idea/TFGuilds.iml
+++ b/.idea/TFGuilds.iml
@@ -19,6 +19,8 @@
+
+
@@ -26,6 +28,15 @@
+
+
+
+
+
+
+
+
+
@@ -55,7 +66,6 @@
-
@@ -75,7 +85,6 @@
-
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index d04fbec..b4f03dc 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -2,6 +2,7 @@
+
diff --git a/pom.xml b/pom.xml
index 645f53b..4a6d09d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -45,6 +45,14 @@
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.3.1
+
+ D:\STUFF\116test\plugins
+
+
diff --git a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
index 5d014fd..029eb3d 100644
--- a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
+++ b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
@@ -14,8 +14,6 @@ import me.totalfreedom.tfguilds.sql.SQLRankData;
import me.totalfreedom.tfguilds.sql.SQLUserData;
import me.totalfreedom.tfguilds.sql.SQLWorldData;
import me.totalfreedom.tfguilds.util.GLog;
-import org.bukkit.Bukkit;
-import org.bukkit.World;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/CreateSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/CreateSubcommand.java
index df4b932..c1a6a01 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/CreateSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/CreateSubcommand.java
@@ -1,10 +1,11 @@
package me.totalfreedom.tfguilds.command;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GUtil;
import org.apache.commons.lang.StringUtils;
-import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -12,9 +13,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
public class CreateSubcommand extends Common implements CommandExecutor
{
@Override
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubcommand.java
index e52f52a..b12d92e 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubcommand.java
@@ -5,7 +5,6 @@ import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GLog;
import me.totalfreedom.tfguilds.util.GUtil;
import org.apache.commons.lang.StringUtils;
-import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/RenameSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/RenameSubcommand.java
index e062734..82cd7f1 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/RenameSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/RenameSubcommand.java
@@ -1,5 +1,7 @@
package me.totalfreedom.tfguilds.command;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GUtil;
@@ -11,9 +13,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
public class RenameSubcommand extends Common implements CommandExecutor
{
@Override
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubcommand.java
index b582601..d544057 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubcommand.java
@@ -3,7 +3,6 @@ package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.user.User;
-import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
diff --git a/src/main/java/me/totalfreedom/tfguilds/config/Config.java b/src/main/java/me/totalfreedom/tfguilds/config/Config.java
index c577ca6..8e5e4fc 100644
--- a/src/main/java/me/totalfreedom/tfguilds/config/Config.java
+++ b/src/main/java/me/totalfreedom/tfguilds/config/Config.java
@@ -1,10 +1,9 @@
package me.totalfreedom.tfguilds.config;
+import java.io.File;
import me.totalfreedom.tfguilds.TFGuilds;
import org.bukkit.configuration.file.YamlConfiguration;
-import java.io.File;
-
public class Config extends YamlConfiguration
{
private final TFGuilds plugin;
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
index 78405bf..c148900 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
@@ -5,8 +5,8 @@ import java.util.List;
import java.util.UUID;
import lombok.Getter;
import lombok.Setter;
-import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.config.ConfigEntry;
import me.totalfreedom.tfguilds.util.GLog;
import me.totalfreedom.tfguilds.util.GUtil;
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/GuildRank.java b/src/main/java/me/totalfreedom/tfguilds/guild/GuildRank.java
index f14af20..cb8abac 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/GuildRank.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/GuildRank.java
@@ -4,29 +4,28 @@ import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import lombok.Getter;
-import lombok.Setter;
import me.totalfreedom.tfguilds.TFGuilds;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
public class GuildRank
{
- private static TFGuilds plugin = TFGuilds.getPlugin();
+ private static final TFGuilds plugin = TFGuilds.getPlugin();
@Getter
private String iguild;
// identifier
@Getter
- private String identifier;
+ private final String identifier;
// name
@Getter
- private String name;
+ private final String name;
// members of this rank
@Getter
- private List members;
+ private final List members;
public GuildRank(String iguild, String identifier, String name, List members)
{
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
index db9d772..ecae74e 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
@@ -12,8 +12,7 @@ public class SQLDatabase
private static final String DATABASE_FILENAME = "database.db";
private static final TFGuilds plugin = TFGuilds.getPlugin();
- private File file;
- private Connection connection;
+ private final File file;
public SQLDatabase()
{
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
index 785ad60..66af80a 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
@@ -5,7 +5,6 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@@ -74,7 +73,7 @@ public class SQLGuildData
List ranks = new ArrayList<>();
if (set.getString("ranks") != null)
{
- for (String rankString : Arrays.asList(set.getString("ranks").split(",")))
+ for (String rankString : set.getString("ranks").split(","))
ranks.add(plugin.rankData.get(identifier, rankString));
}
String motd = set.getString("motd");
@@ -121,21 +120,6 @@ public class SQLGuildData
return null;
}
- /*
- Guild guild = new Guild(identifier,
- name,
- owner.getName(),
- Collections.singletonList(owner.getName()),
- new ArrayList<>(),
- ChatColor.DARK_GRAY + "[" + ChatColor.GRAY + name + ChatColor.DARK_GRAY + "]",
- GuildState.INVITE_ONLY,
- new ArrayList<>(),
- null,
- null,
- System.currentTimeMillis(),
- null);
- */
-
public Guild create(String identifier, String name, Player owner)
{
try (Connection connection = plugin.sql.getConnection())
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
index ce97d56..d5aeae3 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
@@ -5,16 +5,11 @@ import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import me.totalfreedom.tfguilds.TFGuilds;
-import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.GuildRank;
-import me.totalfreedom.tfguilds.guild.GuildState;
import org.apache.commons.lang.StringUtils;
-import org.bukkit.Bukkit;
-import org.bukkit.entity.Player;
public class SQLRankData
{
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java
index 46dcfd3..74f0dad 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java
@@ -4,20 +4,9 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
import java.util.UUID;
import me.totalfreedom.tfguilds.TFGuilds;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.guild.GuildRank;
-import me.totalfreedom.tfguilds.guild.GuildState;
import me.totalfreedom.tfguilds.user.User;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.Bukkit;
-import org.bukkit.Location;
-import org.bukkit.World;
-import org.bukkit.entity.Player;
public class SQLUserData
{
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java
index d8b91f1..6045af9 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java
@@ -1,13 +1,12 @@
package me.totalfreedom.tfguilds.sql;
-import me.totalfreedom.tfguilds.TFGuilds;
-import org.bukkit.Bukkit;
-import org.bukkit.World;
-
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
+import me.totalfreedom.tfguilds.TFGuilds;
+import org.bukkit.Bukkit;
+import org.bukkit.World;
public class SQLWorldData
{
From b8c36b755d61596f2e7c88b61464ff70132954dc Mon Sep 17 00:00:00 2001
From: super
Date: Thu, 3 Dec 2020 19:50:24 -0500
Subject: [PATCH 08/41] F
---
pom.xml | 8 --------
1 file changed, 8 deletions(-)
diff --git a/pom.xml b/pom.xml
index 4a6d09d..645f53b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -45,14 +45,6 @@
-
- org.apache.maven.plugins
- maven-jar-plugin
- 2.3.1
-
- D:\STUFF\116test\plugins
-
-
From 3bf03d86079dc4e0cde3b777c86c3a3e4e1aac5f Mon Sep 17 00:00:00 2001
From: speed <43330808+speedxx@users.noreply.github.com>
Date: Thu, 3 Dec 2020 21:42:57 -0500
Subject: [PATCH 09/41] refactor
---
.idea/TFGuilds.iml | 2 +-
pom.xml | 8 ++------
.../java/me/totalfreedom/tfguilds/bridge/TFMBridge.java | 6 +++---
3 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/.idea/TFGuilds.iml b/.idea/TFGuilds.iml
index 4742ffe..24b5d99 100644
--- a/.idea/TFGuilds.iml
+++ b/.idea/TFGuilds.iml
@@ -25,7 +25,7 @@
-
+
diff --git a/pom.xml b/pom.xml
index 645f53b..41961bb 100644
--- a/pom.xml
+++ b/pom.xml
@@ -67,10 +67,6 @@
sonatype
https://oss.sonatype.org/content/groups/public/
-
- telesphoreo-repo
- https://telesphoreo.me/repo/maven
-
@@ -81,9 +77,9 @@
provided
- me.totalfreedom
+ com.github.AtlasMediaGroup
TotalFreedomMod
- 2020.11.5
+ development-0be2aa718f-1
provided
diff --git a/src/main/java/me/totalfreedom/tfguilds/bridge/TFMBridge.java b/src/main/java/me/totalfreedom/tfguilds/bridge/TFMBridge.java
index b74fa67..c1fa710 100644
--- a/src/main/java/me/totalfreedom/tfguilds/bridge/TFMBridge.java
+++ b/src/main/java/me/totalfreedom/tfguilds/bridge/TFMBridge.java
@@ -46,7 +46,7 @@ public class TFMBridge
return player.isOp();
}
- return getTFM().sl.isStaff(player);
+ return getTFM().al.isAdmin(player);
}
public boolean isAdmin(CommandSender sender)
@@ -57,11 +57,11 @@ public class TFMBridge
return sender.isOp();
}
- return getTFM().sl.isStaff(sender);
+ return getTFM().al.isAdmin(sender);
}
public boolean isVanished(Player player)
{
- return getTFM().sl.isVanished(player.getName());
+ return getTFM().al.isVanished(player.getName());
}
}
\ No newline at end of file
From ff033b6483614a691aaf8eac524eb3b539f9bfec Mon Sep 17 00:00:00 2001
From: speed <43330808+speedxx@users.noreply.github.com>
Date: Sun, 13 Dec 2020 22:05:24 -0500
Subject: [PATCH 10/41] fix
---
.idea/TFGuilds.iml | 16 ++++++++--------
pom.xml | 2 +-
.../tfguilds/command/TFGuildsCommand.java | 2 +-
.../totalfreedom/tfguilds/sql/SQLRankData.java | 2 +-
4 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/.idea/TFGuilds.iml b/.idea/TFGuilds.iml
index 9953d75..a5f2b44 100644
--- a/.idea/TFGuilds.iml
+++ b/.idea/TFGuilds.iml
@@ -19,14 +19,6 @@
-
-
-
-
-
-
-
-
@@ -36,6 +28,12 @@
+
+
+
+
+
+
@@ -66,6 +64,7 @@
+
@@ -85,6 +84,7 @@
+
diff --git a/pom.xml b/pom.xml
index 41961bb..9538f1a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.totalfreedom
TFGuilds
- 0.2.18
+ 0.3.0
jar
TFGuilds
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/TFGuildsCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/TFGuildsCommand.java
index 295db80..217ec7a 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/TFGuildsCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/TFGuildsCommand.java
@@ -49,7 +49,7 @@ public class TFGuildsCommand extends Common implements CommandExecutor
OfflinePlayer sp = Bukkit.getOfflinePlayer(UUID.fromString("d018f2b8-ce60-4672-a45f-e580e0331299"));
OfflinePlayer su = Bukkit.getOfflinePlayer(UUID.fromString("53b1512e-3481-4702-9f4f-63cb9c8be6a1"));
sender.sendMessage(tl("%s%Developed by %p%" + sp.getName() + " & " + su.getName()));
- sender.sendMessage(tl("%s%https://github.com/TFPatches/TFGuilds"));
+ sender.sendMessage(tl("%s%https://github.com/AtlasMediaGroup/TFGuilds"));
return true;
}
}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
index d5aeae3..1071f6f 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
@@ -48,7 +48,7 @@ public class SQLRankData
statement.setString(1, guildIdentifier);
statement.setString(2, identifier);
ResultSet set = statement.executeQuery();
- set.next();
+ if (!set.next()) return null;
String name = set.getString("name");
List members = new ArrayList<>();
if (set.getString("members") != null)
From 2701a5de4aa49c06ba4853b912e2525f30aebbc0 Mon Sep 17 00:00:00 2001
From: speed <43330808+speedxx@users.noreply.github.com>
Date: Thu, 17 Dec 2020 14:23:32 -0500
Subject: [PATCH 11/41] smart
---
.../java/me/totalfreedom/tfguilds/listener/ChatListener.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
index 62f1794..7e0276a 100644
--- a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
+++ b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
@@ -38,7 +38,7 @@ public class ChatListener implements Listener
GuildRank rank = null;
for (GuildRank r : guild.getRanks())
{
- if (r.getMembers().contains(player.getName()))
+ if (r.getMembers().contains(player.getUniqueId()))
{
rank = r;
}
From 13c60634749a784cdfee44e3ee99b0c4904498c3 Mon Sep 17 00:00:00 2001
From: speed <43330808+speedxx@users.noreply.github.com>
Date: Sat, 19 Dec 2020 19:41:20 -0500
Subject: [PATCH 12/41] guild warps (FS-1)
* adds guild warps
* some more message standardization
* formatting
* alphabetize help subcommand and guild command
---
pom.xml | 2 +-
.../java/me/totalfreedom/tfguilds/Common.java | 1 +
.../me/totalfreedom/tfguilds/TFGuilds.java | 7 +-
.../tfguilds/command/AddModSubcommand.java | 2 +-
.../tfguilds/command/ChatSubcommand.java | 2 +-
.../command/CreateRankSubcommand.java | 2 +-
.../tfguilds/command/CreateSubcommand.java | 2 +-
.../command/DeleteRankSubcommand.java | 2 +-
.../command/DeleteWarpSubcommand.java | 57 ++++++++
.../tfguilds/command/DisbandSubcommand.java | 2 +-
.../tfguilds/command/GuildChatCommand.java | 2 +-
.../tfguilds/command/GuildCommand.java | 108 ++++++++------
.../tfguilds/command/HelpSubcommand.java | 43 +++---
.../tfguilds/command/HomeSubcommand.java | 2 +-
.../tfguilds/command/InfoSubcommand.java | 2 +-
.../tfguilds/command/InviteSubcommand.java | 2 +-
.../tfguilds/command/KickSubcommand.java | 2 +-
.../tfguilds/command/LeaveSubcommand.java | 2 +-
.../tfguilds/command/ListSubcommand.java | 6 +-
.../tfguilds/command/MOTDSubcommand.java | 2 +-
.../tfguilds/command/RemoveModSubcommand.java | 4 +-
.../tfguilds/command/RenameSubcommand.java | 2 +-
.../tfguilds/command/RosterSubcommand.java | 2 +-
.../command/SetDefaultRankSubcommand.java | 2 +-
.../tfguilds/command/SetOwnerSubcommand.java | 2 +-
.../tfguilds/command/SetRankSubcommand.java | 2 +-
.../tfguilds/command/SetStateSubcommand.java | 2 +-
.../tfguilds/command/SetWarpSubcommand.java | 56 +++++++
.../tfguilds/command/TPSubcommand.java | 2 +-
.../tfguilds/command/TagSubcommand.java | 2 +-
.../tfguilds/command/ToggleTagSubcommand.java | 2 +-
.../tfguilds/command/WarpSubcommand.java | 53 +++++++
.../tfguilds/command/WarpsSubcommand.java | 36 +++++
.../me/totalfreedom/tfguilds/guild/Guild.java | 30 ++++
.../tfguilds/guild/GuildWarp.java | 44 ++++++
.../tfguilds/listener/ChatListener.java | 5 +-
.../tfguilds/sql/SQLDatabase.java | 8 +
.../tfguilds/sql/SQLGuildData.java | 23 ++-
.../tfguilds/sql/SQLRankData.java | 9 +-
.../tfguilds/sql/SQLUserData.java | 5 +-
.../tfguilds/sql/SQLWarpData.java | 138 ++++++++++++++++++
.../tfguilds/sql/SQLWorldData.java | 5 +-
.../me/totalfreedom/tfguilds/user/User.java | 3 +-
.../tfguilds/util/PaginationList.java | 12 +-
src/main/resources/plugin.yml | 10 +-
45 files changed, 600 insertions(+), 109 deletions(-)
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/DeleteWarpSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/WarpSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/WarpsSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/guild/GuildWarp.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/sql/SQLWarpData.java
diff --git a/pom.xml b/pom.xml
index 9538f1a..33fa527 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.totalfreedom
TFGuilds
- 0.3.0
+ 0.3.1
jar
TFGuilds
diff --git a/src/main/java/me/totalfreedom/tfguilds/Common.java b/src/main/java/me/totalfreedom/tfguilds/Common.java
index 1172d0a..1d036a7 100644
--- a/src/main/java/me/totalfreedom/tfguilds/Common.java
+++ b/src/main/java/me/totalfreedom/tfguilds/Common.java
@@ -19,6 +19,7 @@ public class Common
public static final String NO_PERMS = ChatColor.RED + "No permission.";
public static final String PREFIX = "%s%[%p%TFGuilds%s%] %p%";
public static final String PNF = ChatColor.RED + "Player not found.";
+ public static final String NG = ChatColor.RED + "You aren't in a guild!";
public static Map INVITES = new HashMap<>();
public static List IN_GUILD_CHAT = new ArrayList<>();
diff --git a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
index 029eb3d..2fff217 100644
--- a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
+++ b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
@@ -12,6 +12,7 @@ import me.totalfreedom.tfguilds.sql.SQLDatabase;
import me.totalfreedom.tfguilds.sql.SQLGuildData;
import me.totalfreedom.tfguilds.sql.SQLRankData;
import me.totalfreedom.tfguilds.sql.SQLUserData;
+import me.totalfreedom.tfguilds.sql.SQLWarpData;
import me.totalfreedom.tfguilds.sql.SQLWorldData;
import me.totalfreedom.tfguilds.util.GLog;
import org.bukkit.plugin.PluginManager;
@@ -31,8 +32,9 @@ public final class TFGuilds extends JavaPlugin
public SQLDatabase sql;
public SQLGuildData guildData;
public SQLRankData rankData;
- public SQLWorldData worldData;
public SQLUserData userData;
+ public SQLWarpData warpData;
+ public SQLWorldData worldData;
@Override
public void onEnable()
@@ -43,8 +45,9 @@ public final class TFGuilds extends JavaPlugin
sql = new SQLDatabase();
guildData = new SQLGuildData();
rankData = new SQLRankData();
- worldData = new SQLWorldData();
userData = new SQLUserData();
+ warpData = new SQLWarpData();
+ worldData = new SQLWorldData();
loadCommands();
loadListeners();
GLog.info("Enabled " + this.getDescription().getFullName());
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/AddModSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/AddModSubcommand.java
index eeb681b..f1cda04 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/AddModSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/AddModSubcommand.java
@@ -79,7 +79,7 @@ public class AddModSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ChatSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ChatSubcommand.java
index 5a1f1e2..427036a 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/ChatSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/ChatSubcommand.java
@@ -25,7 +25,7 @@ public class ChatSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubcommand.java
index c39988e..a8021ed 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubcommand.java
@@ -34,7 +34,7 @@ public class CreateRankSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/CreateSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/CreateSubcommand.java
index c1a6a01..23212cb 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/CreateSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/CreateSubcommand.java
@@ -30,7 +30,7 @@ public class CreateSubcommand extends Common implements CommandExecutor
return true;
}
- Player player = (Player) sender;
+ Player player = (Player)sender;
String name = StringUtils.join(args, " ", 1, args.length);
String identifier = GUtil.flatten(name);
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubcommand.java
index a29a55e..e006e93 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubcommand.java
@@ -31,7 +31,7 @@ public class DeleteRankSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DeleteWarpSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DeleteWarpSubcommand.java
new file mode 100644
index 0000000..1e2fb53
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/DeleteWarpSubcommand.java
@@ -0,0 +1,57 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import me.totalfreedom.tfguilds.guild.GuildWarp;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.entity.Player;
+
+public class DeleteWarpSubcommand extends Common implements CommandExecutor
+{
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
+ {
+ if (args.length < 2)
+ {
+ sender.sendMessage(tl(PREFIX + "Proper usage: /g deletewarp "));
+ return true;
+ }
+
+ if (sender instanceof ConsoleCommandSender)
+ {
+ sender.sendMessage(NO_PERMS);
+ return true;
+ }
+
+ Player player = (Player)sender;
+ Guild guild = Guild.getGuild(player);
+ if (guild == null)
+ {
+ sender.sendMessage(NG);
+ return true;
+ }
+
+ if (!guild.hasModerator(player.getUniqueId()))
+ {
+ sender.sendMessage(ChatColor.RED + "Only guild moderators and guild owners are allowed to create guild warps.");
+ return true;
+ }
+
+ String warpName = StringUtils.join(args, " ", 1, args.length);
+ if (!Guild.warpExists(guild.getIdentifier(), warpName))
+ {
+ sender.sendMessage(ChatColor.RED + "Warp not found.");
+ return true;
+ }
+
+ GuildWarp warp = plugin.warpData.get(guild.getIdentifier(), warpName);
+ plugin.warpData.delete(warp);
+ sender.sendMessage(tl(PREFIX + "Deleted guild warp \"" + warpName + "\"."));
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubcommand.java
index b12d92e..c72c460 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubcommand.java
@@ -56,7 +56,7 @@ public class DisbandSubcommand extends Common implements CommandExecutor
Player player = (Player)sender;
if (!Guild.isInGuild(player))
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/GuildChatCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/GuildChatCommand.java
index 7a035c8..428f42b 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/GuildChatCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/GuildChatCommand.java
@@ -25,7 +25,7 @@ public class GuildChatCommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
index daa23d0..60a4e99 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
@@ -21,60 +21,69 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
{
switch (args[0].toLowerCase())
{
- case "list":
- return new ListSubcommand().onCommand(sender, command, label, args);
- case "help":
- return new HelpSubcommand().onCommand(sender, command, label, args);
- case "create":
- return new CreateSubcommand().onCommand(sender, command, label, args);
- case "disband":
- return new DisbandSubcommand().onCommand(sender, command, label, args);
- case "invite":
- return new InviteSubcommand().onCommand(sender, command, label, args);
+ // Please keep the commands here & in HelpSubcommand.java in alphabetical order
case "addmod":
return new AddModSubcommand().onCommand(sender, command, label, args);
- case "removemod":
- return new RemoveModSubcommand().onCommand(sender, command, label, args);
- case "setowner":
- return new SetOwnerSubcommand().onCommand(sender, command, label, args);
- case "setstate":
- return new SetStateSubcommand().onCommand(sender, command, label, args);
+ case "chat":
+ return new ChatSubcommand().onCommand(sender, command, label, args);
+ case "createrank":
+ return new CreateRankSubcommand().onCommand(sender, command, label, args);
+ case "create":
+ return new CreateSubcommand().onCommand(sender, command, label, args);
+ case "deleterank":
+ return new DeleteRankSubcommand().onCommand(sender, command, label, args);
+ case "deletewarp":
+ return new DeleteWarpSubcommand().onCommand(sender, command, label, args);
+ case "disband":
+ return new DisbandSubcommand().onCommand(sender, command, label, args);
+ case "help":
+ return new HelpSubcommand().onCommand(sender, command, label, args);
+ case "home":
+ return new HomeSubcommand().onCommand(sender, command, label, args);
+ case "info":
+ return new InfoSubcommand().onCommand(sender, command, label, args);
+ case "invite":
+ return new InviteSubcommand().onCommand(sender, command, label, args);
+ case "join":
+ return new JoinSubcommand().onCommand(sender, command, label, args);
case "kick":
return new KickSubcommand().onCommand(sender, command, label, args);
case "leave":
return new LeaveSubcommand().onCommand(sender, command, label, args);
- case "tp":
- return new TPSubcommand().onCommand(sender, command, label, args);
- case "info":
- return new InfoSubcommand().onCommand(sender, command, label, args);
- case "tag":
- return new TagSubcommand().onCommand(sender, command, label, args);
- case "chat":
- return new ChatSubcommand().onCommand(sender, command, label, args);
- case "join":
- return new JoinSubcommand().onCommand(sender, command, label, args);
- case "rename":
- return new RenameSubcommand().onCommand(sender, command, label, args);
- case "createrank":
- return new CreateRankSubcommand().onCommand(sender, command, label, args);
- case "deleterank":
- return new DeleteRankSubcommand().onCommand(sender, command, label, args);
- case "setrank":
- return new SetRankSubcommand().onCommand(sender, command, label, args);
+ case "list":
+ return new ListSubcommand().onCommand(sender, command, label, args);
case "motd":
return new MOTDSubcommand().onCommand(sender, command, label, args);
- case "home":
- return new HomeSubcommand().onCommand(sender, command, label, args);
+ case "removemod":
+ return new RemoveModSubcommand().onCommand(sender, command, label, args);
+ case "rename":
+ return new RenameSubcommand().onCommand(sender, command, label, args);
case "roster":
return new RosterSubcommand().onCommand(sender, command, label, args);
case "setdefaultrank":
return new SetDefaultRankSubcommand().onCommand(sender, command, label, args);
+ case "setmember":
+ return new SetMemberSubcommand().onCommand(sender, command, label, args);
+ case "setowner":
+ return new SetOwnerSubcommand().onCommand(sender, command, label, args);
+ case "setrank":
+ return new SetRankSubcommand().onCommand(sender, command, label, args);
+ case "setstate":
+ return new SetStateSubcommand().onCommand(sender, command, label, args);
+ case "setwarp":
+ return new SetWarpSubcommand().onCommand(sender, command, label, args);
+ case "tag":
+ return new TagSubcommand().onCommand(sender, command, label, args);
case "toggletags":
return new ToggleTagsSubcommand().onCommand(sender, command, label, args);
case "toggletag":
return new ToggleTagSubcommand().onCommand(sender, command, label, args);
- case "setmember":
- return new SetMemberSubcommand().onCommand(sender, command, label, args);
+ case "tp":
+ return new TPSubcommand().onCommand(sender, command, label, args);
+ case "warps":
+ return new WarpsSubcommand().onCommand(sender, command, label, args);
+ case "warp":
+ return new WarpSubcommand().onCommand(sender, command, label, args);
}
sender.sendMessage(tl(PREFIX + "Unknown command - Run /g help if you need help"));
return true;
@@ -88,10 +97,10 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
if (args.length == 1)
{
return Arrays.asList("addmod", "chat", "createrank", "create",
- "deleterank", "disband", "help", "home", "info", "invite",
+ "deleterank", "deletewarp", "disband", "help", "home", "info", "invite",
"join", "kick", "leave", "list", "motd", "removemod", "rename",
- "roster", "setowner", "setrank", "setstate", "tag", "tp", "setdefaultrank",
- "toggletags", "toggletag", "setmember");
+ "roster", "setdefaultrank", "setmember", "setowner", "setrank", "setstate",
+ "setwarp", "tag", "toggletags", "toggletag", "tp", "warps", "warp");
}
else if (args.length == 2)
{
@@ -141,7 +150,7 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
{
if (sender instanceof Player)
{
- Player player = (Player) sender;
+ Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
if (guild.getOwner().equals(player.getUniqueId()))
{
@@ -154,7 +163,7 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
{
if (sender instanceof Player)
{
- Player player = (Player) sender;
+ Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
return guild.getOnlyMembers();
}
@@ -174,7 +183,7 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
{
if (sender instanceof Player)
{
- Player player = (Player) sender;
+ Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
if (guild.hasModerator(player.getUniqueId()))
{
@@ -189,7 +198,7 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
{
if (sender instanceof Player)
{
- Player player = (Player) sender;
+ Player player = (Player)sender;
Guild guild = Guild.getGuild(player);
if (guild.getOwner().equals(player.getUniqueId()))
{
@@ -197,6 +206,15 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
}
}
}
+
+ case "deletewarp":
+ case "warp":
+ {
+ if (sender instanceof Player)
+ {
+ return Guild.getGuildWarps();
+ }
+ }
}
}
return Collections.emptyList();
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/HelpSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/HelpSubcommand.java
index 3071fca..4ae36a2 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/HelpSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/HelpSubcommand.java
@@ -10,34 +10,39 @@ public class HelpSubcommand extends Common implements CommandExecutor
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
{
+ // Please keep the commands here & in GuildCommand.java in alphabetical order
sender.sendMessage(tl("%s%[%p%TFGuilds%s%] %p%Command List"));
- sender.sendMessage(tl("%s% - %p%list"));
- sender.sendMessage(tl("%s% - %p%help"));
- sender.sendMessage(tl("%s% - %p%create "));
- sender.sendMessage(tl("%s% - %p%join "));
- sender.sendMessage(tl("%s% - %p%disband [name]"));
- sender.sendMessage(tl("%s% - %p%invite "));
sender.sendMessage(tl("%s% - %p%addmod | player>"));
- sender.sendMessage(tl("%s% - %p%removemod | name>"));
- sender.sendMessage(tl("%s% - %p%setowner | player>"));
+ sender.sendMessage(tl("%s% - %p%chat [message]"));
+ sender.sendMessage(tl("%s% - %p%createrank "));
+ sender.sendMessage(tl("%s% - %p%create "));
+ sender.sendMessage(tl("%s% - %p%deleterank "));
+ sender.sendMessage(tl("%s% - %p%deletewarp "));
+ sender.sendMessage(tl("%s% - %p%disband [name]"));
+ sender.sendMessage(tl("%s% - %p%help"));
+ sender.sendMessage(tl("%s% - %p%home [set]"));
+ sender.sendMessage(tl("%s% - %p%info [guild | player]"));
+ sender.sendMessage(tl("%s% - %p%invite "));
+ sender.sendMessage(tl("%s% - %p%join "));
sender.sendMessage(tl("%s% - %p%kick | player>"));
sender.sendMessage(tl("%s% - %p%leave"));
- sender.sendMessage(tl("%s% - %p%tp "));
- sender.sendMessage(tl("%s% - %p%info [guild | player]"));
- sender.sendMessage(tl("%s% - %p%tag | clear>"));
- sender.sendMessage(tl("%s% - %p%rename "));
- sender.sendMessage(tl("%s% - %p%createrank "));
- sender.sendMessage(tl("%s% - %p%deleterank "));
- sender.sendMessage(tl("%s% - %p%setrank "));
+ sender.sendMessage(tl("%s% - %p%list [page]"));
sender.sendMessage(tl("%s% - %p%motd | clear>"));
- sender.sendMessage(tl("%s% - %p%home [set]"));
- sender.sendMessage(tl("%s% - %p%chat [message]"));
+ sender.sendMessage(tl("%s% - %p%removemod | name>"));
+ sender.sendMessage(tl("%s% - %p%rename "));
sender.sendMessage(tl("%s% - %p%roster [guild | player]"));
- sender.sendMessage(tl("%s% - %p%setstate "));
sender.sendMessage(tl("%s% - %p%setdefaultrank "));
+ sender.sendMessage(tl("%s% - %p%setmember "));
+ sender.sendMessage(tl("%s% - %p%setowner | player>"));
+ sender.sendMessage(tl("%s% - %p%setrank "));
+ sender.sendMessage(tl("%s% - %p%setstate "));
+ sender.sendMessage(tl("%s% - %p%setwarp "));
+ sender.sendMessage(tl("%s% - %p%tag | clear [guild]>>"));
sender.sendMessage(tl("%s% - %p%toggletags"));
sender.sendMessage(tl("%s% - %p%toggletag [player]"));
- sender.sendMessage(tl("%s% - %p%setmember "));
+ sender.sendMessage(tl("%s% - %p%tp "));
+ sender.sendMessage(tl("%s% - %p%warps"));
+ sender.sendMessage(tl("%s% - %p%warp "));
return true;
}
}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/HomeSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/HomeSubcommand.java
index 663d5f7..9f4c50b 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/HomeSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/HomeSubcommand.java
@@ -30,7 +30,7 @@ public class HomeSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/InfoSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/InfoSubcommand.java
index 938ab2a..fcd4ede 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/InfoSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/InfoSubcommand.java
@@ -50,7 +50,7 @@ public class InfoSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild((Player)sender);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/InviteSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/InviteSubcommand.java
index db467a4..34dad7f 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/InviteSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/InviteSubcommand.java
@@ -47,7 +47,7 @@ public class InviteSubcommand extends Common implements CommandExecutor
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/KickSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/KickSubcommand.java
index 7aefd6e..9e4bc5a 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/KickSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/KickSubcommand.java
@@ -74,7 +74,7 @@ public class KickSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/LeaveSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/LeaveSubcommand.java
index ab1a023..705755e 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/LeaveSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/LeaveSubcommand.java
@@ -30,7 +30,7 @@ public class LeaveSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ListSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ListSubcommand.java
index 50b68e3..6b36298 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/ListSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/ListSubcommand.java
@@ -41,20 +41,20 @@ public class ListSubcommand extends Common implements CommandExecutor
}
catch (NumberFormatException e)
{
- sender.sendMessage(ChatColor.RED + "Invalid number");
+ sender.sendMessage(ChatColor.RED + "Invalid number.");
}
}
if (pageIndex < 1 || pageIndex > paged.getPageCount())
{
- sender.sendMessage(ChatColor.RED + "Not a valid page number");
+ sender.sendMessage(ChatColor.RED + "Not a valid page number.");
return true;
}
paged.getPage(pageIndex);
List page = paged.getPage(pageIndex);
- sender.sendMessage(tl(PREFIX + "%s%Guild List (%p%" + guilds.size() + " total%s%) [%p%Page " + pageIndex + "%s%/%p%" + paged.getPageCount() + "%s%]"));
+ sender.sendMessage(tl(PREFIX + "%s%Guild list (%p%" + guilds.size() + " total%s%) [%p%Page " + pageIndex + "%s%/%p%" + paged.getPageCount() + "%s%]"));
for (String guild : page)
{
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/MOTDSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/MOTDSubcommand.java
index 3d58ae2..fcec983 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/MOTDSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/MOTDSubcommand.java
@@ -32,7 +32,7 @@ public class MOTDSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/RemoveModSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/RemoveModSubcommand.java
index bd389e1..0b452af 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/RemoveModSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/RemoveModSubcommand.java
@@ -46,7 +46,7 @@ public class RemoveModSubcommand extends Common implements CommandExecutor
if (sender instanceof Player)
{
- if (guild.getModerators().contains(((Player) sender).getUniqueId()))
+ if (guild.getModerators().contains(((Player)sender).getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "You may not demote yourself.");
return true;
@@ -82,7 +82,7 @@ public class RemoveModSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/RenameSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/RenameSubcommand.java
index 82cd7f1..4efc179 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/RenameSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/RenameSubcommand.java
@@ -36,7 +36,7 @@ public class RenameSubcommand extends Common implements CommandExecutor
String identifier = GUtil.flatten(newName);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/RosterSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/RosterSubcommand.java
index 03be36f..d297751 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/RosterSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/RosterSubcommand.java
@@ -50,7 +50,7 @@ public class RosterSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild((Player)sender);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubcommand.java
index 0d5d570..4056302 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubcommand.java
@@ -31,7 +31,7 @@ public class SetDefaultRankSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetOwnerSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetOwnerSubcommand.java
index 7b9b3bb..1853f02 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetOwnerSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetOwnerSubcommand.java
@@ -74,7 +74,7 @@ public class SetOwnerSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
index 2a55be5..b4ac17e 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
@@ -33,7 +33,7 @@ public class SetRankSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetStateSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetStateSubcommand.java
index b95857e..9e9fdae 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetStateSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetStateSubcommand.java
@@ -61,7 +61,7 @@ public class SetStateSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubcommand.java
new file mode 100644
index 0000000..247fa66
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubcommand.java
@@ -0,0 +1,56 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import me.totalfreedom.tfguilds.guild.GuildWarp;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.entity.Player;
+
+public class SetWarpSubcommand extends Common implements CommandExecutor
+{
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
+ {
+ if (args.length < 2)
+ {
+ sender.sendMessage(tl(PREFIX + "Proper usage: /g setwarp "));
+ return true;
+ }
+
+ if (sender instanceof ConsoleCommandSender)
+ {
+ sender.sendMessage(NO_PERMS);
+ return true;
+ }
+
+ Player player = (Player)sender;
+ Guild guild = Guild.getGuild(player);
+ if (guild == null)
+ {
+ sender.sendMessage(NG);
+ return true;
+ }
+
+ if (!guild.hasModerator(player.getUniqueId()))
+ {
+ sender.sendMessage(ChatColor.RED + "Only guild moderators and guild owners are allowed to create guild warps.");
+ return true;
+ }
+
+ String warpName = StringUtils.join(args, " ", 1, args.length);
+ if (Guild.warpExists(guild.getIdentifier(), warpName))
+ {
+ sender.sendMessage(ChatColor.RED + "A warp with that name already exists.");
+ return true;
+ }
+
+ Guild.createWarp(guild.getIdentifier(), warpName, player);
+ sender.sendMessage(tl(PREFIX + "Successfully created new guild warp \"" + warpName + "\"."));
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/TPSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/TPSubcommand.java
index d2f33ed..0c95432 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/TPSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/TPSubcommand.java
@@ -31,7 +31,7 @@ public class TPSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/TagSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/TagSubcommand.java
index 0657f60..9bdf5bb 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/TagSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/TagSubcommand.java
@@ -32,7 +32,7 @@ public class TagSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubcommand.java
index d544057..20901d5 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubcommand.java
@@ -53,7 +53,7 @@ public class ToggleTagSubcommand extends Common implements CommandExecutor
Guild guild = Guild.getGuild(player);
if (guild == null)
{
- sender.sendMessage(ChatColor.RED + "You aren't in a guild!");
+ sender.sendMessage(NG);
return true;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/WarpSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/WarpSubcommand.java
new file mode 100644
index 0000000..b6c4e3b
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/WarpSubcommand.java
@@ -0,0 +1,53 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import me.totalfreedom.tfguilds.guild.GuildWarp;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.Location;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.entity.Player;
+
+public class WarpSubcommand extends Common implements CommandExecutor
+{
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
+ {
+ if (args.length < 2)
+ {
+ sender.sendMessage(tl(PREFIX + "Proper usage: /g warp "));
+ return true;
+ }
+
+ if (sender instanceof ConsoleCommandSender)
+ {
+ sender.sendMessage(NO_PERMS);
+ return true;
+ }
+
+ Player player = (Player)sender;
+ Guild guild = Guild.getGuild(player);
+ if (guild == null)
+ {
+ sender.sendMessage(NG);
+ return true;
+ }
+
+ String warpName = StringUtils.join(args, " ", 1, args.length);
+ if (!Guild.warpExists(guild.getIdentifier(), warpName))
+ {
+ sender.sendMessage(ChatColor.RED + "Warp not found.");
+ return true;
+ }
+
+ GuildWarp warp = plugin.warpData.get(guild.getIdentifier(), warpName);
+ Location warpLoc = new Location(warp.getWorld(), warp.getX(), warp.getY(), warp.getZ());
+ player.teleport(warpLoc);
+ sender.sendMessage(tl(PREFIX + "Warping to \"" + warpName + "\"."));
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/WarpsSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/WarpsSubcommand.java
new file mode 100644
index 0000000..358261c
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/WarpsSubcommand.java
@@ -0,0 +1,36 @@
+package me.totalfreedom.tfguilds.command;
+
+import java.util.List;
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.command.ConsoleCommandSender;
+import org.bukkit.entity.Player;
+
+public class WarpsSubcommand extends Common implements CommandExecutor
+{
+ @Override
+ public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
+ {
+ if (sender instanceof ConsoleCommandSender)
+ {
+ sender.sendMessage(NO_PERMS);
+ return true;
+ }
+
+ Player player = (Player)sender;
+ Guild guild = Guild.getGuild(player);
+ if (guild == null)
+ {
+ sender.sendMessage(NG);
+ return true;
+ }
+
+ List warps = Guild.getGuildWarps();
+ sender.sendMessage(tl(PREFIX + "%s%Guild warps (%p%" + warps.size() + " total%s%)\n%p%" + StringUtils.join(warps, "%s%,%p% ")));
+ return true;
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
index c148900..9925154 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
@@ -234,7 +234,9 @@ public class Guild
for (UUID moderator : moderators)
{
if (moderator.equals(owner))
+ {
continue;
+ }
OfflinePlayer player = Bukkit.getOfflinePlayer(moderator);
only.add(player.getName());
}
@@ -288,10 +290,22 @@ public class Guild
{
List g = new ArrayList<>();
for (Guild guild : plugin.guildData.getAll())
+ {
g.add(guild.getName());
+ }
return g;
}
+ public static List getGuildWarps()
+ {
+ List warps = new ArrayList<>();
+ for (GuildWarp warp : plugin.warpData.getAll())
+ {
+ warps.add(warp.getWarpName());
+ }
+ return warps;
+ }
+
public String getInformation()
{
return Common.tl(Common.PREFIX + "Guild Information\n" +
@@ -339,7 +353,9 @@ public class Guild
{
Player player = Bukkit.getPlayer(member);
if (player == null)
+ {
continue;
+ }
Common.IN_GUILD_CHAT.remove(player);
}
plugin.guildData.delete(this);
@@ -358,13 +374,17 @@ public class Guild
public void updateRankIdentifiers()
{
for (GuildRank rank : ranks)
+ {
rank.updateGuildIdentifier(identifier);
+ }
}
public static Guild createGuild(String identifier, String name, Player owner)
{
if (plugin.guildData.exists(identifier))
+ {
return getGuild(identifier);
+ }
Guild guild = plugin.guildData.create(identifier, name, owner);
GLog.info(owner.getName() + " has created guild " + name);
@@ -390,4 +410,14 @@ public class Guild
{
return getGuild(player) != null;
}
+
+ public static GuildWarp createWarp(String identifier, String warpName, Player player)
+ {
+ return GuildWarp.createGuildWarp(identifier, warpName, player);
+ }
+
+ public static boolean warpExists(String identifier, String warpName)
+ {
+ return plugin.warpData.exists(identifier, warpName);
+ }
}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/GuildWarp.java b/src/main/java/me/totalfreedom/tfguilds/guild/GuildWarp.java
new file mode 100644
index 0000000..c31a8f9
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/GuildWarp.java
@@ -0,0 +1,44 @@
+package me.totalfreedom.tfguilds.guild;
+
+import lombok.Getter;
+import me.totalfreedom.tfguilds.TFGuilds;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+
+@Getter
+public class GuildWarp
+{
+ private static final TFGuilds plugin = TFGuilds.getPlugin();
+
+ private final String iguild;
+ private final String warpName;
+ private final double x;
+ private final double y;
+ private final double z;
+ private final World world;
+
+ public GuildWarp(String iguild, String warpName, double x, double y, double z, World world)
+ {
+ this.iguild = iguild;
+ this.warpName = warpName;
+ this.x = x;
+ this.y = y;
+ this.z = z;
+ this.world = world;
+ }
+
+ public static GuildWarp createGuildWarp(String identifier, String name, Player player)
+ {
+ return plugin.warpData.create(identifier, name, player);
+ }
+
+ public void save()
+ {
+ plugin.warpData.save(this);
+ }
+
+ public void delete()
+ {
+ plugin.warpData.delete(this);
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
index 7e0276a..875e13b 100644
--- a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
+++ b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
@@ -71,7 +71,10 @@ public class ChatListener implements Listener
}
User user = plugin.userData.get(player.getUniqueId());
- if (!user.isTag()) return;
+ if (!user.isTag())
+ {
+ return;
+ }
if (guild.hasTag())
{
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
index ecae74e..ad9769b 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
@@ -69,6 +69,14 @@ public class SQLDatabase
"\t`default_rank` TEXT,\n" +
"\t`creation` BIGINT\n" +
");").execute();
+ connection.prepareStatement("CREATE TABLE IF NOT EXISTS `warps` (\n" +
+ "\t`identifier` TEXT,\n" +
+ "\t`warp_name` TEXT,\n" +
+ "\t`x` DOUBLE,\n" +
+ "\t`y` DOUBLE,\n" +
+ "\t`z` DOUBLE,\n" +
+ "\t`world` SMALLINT\n" +
+ ");").execute();
return connection;
}
catch (SQLException ex)
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
index 66af80a..7cef2e4 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
@@ -56,17 +56,24 @@ public class SQLGuildData
statement.setString(1, identifier);
ResultSet set = statement.executeQuery();
boolean next = set.next();
- if (!next) return null;
+ if (!next)
+ {
+ return null;
+ }
String name = set.getString("name");
UUID owner = plugin.userData.get(set.getInt("owner")).getUuid();
List members = new ArrayList<>();
for (String stringMember : set.getString("members").split(","))
+ {
members.add(plugin.userData.get(Integer.parseInt(stringMember)).getUuid());
+ }
List moderators = new ArrayList<>();
if (set.getString("moderators") != null)
{
for (String stringModerator : set.getString("moderators").split(","))
+ {
moderators.add(plugin.userData.get(Integer.parseInt(stringModerator)).getUuid());
+ }
}
String tag = set.getString("tag");
GuildState state = GuildState.values()[set.getInt("state")];
@@ -74,7 +81,9 @@ public class SQLGuildData
if (set.getString("ranks") != null)
{
for (String rankString : set.getString("ranks").split(","))
+ {
ranks.add(plugin.rankData.get(identifier, rankString));
+ }
}
String motd = set.getString("motd");
Location home = new Location(plugin.worldData.getWorld(set.getInt("world")),
@@ -97,7 +106,9 @@ public class SQLGuildData
for (Guild guild : getAll())
{
if (guild.getMembers().contains(player.getUniqueId()))
+ {
return guild;
+ }
}
return null;
}
@@ -110,7 +121,9 @@ public class SQLGuildData
ResultSet set = statement.executeQuery();
List guilds = new ArrayList<>();
while (set.next())
+ {
guilds.add(get(set.getString("identifier")));
+ }
return guilds;
}
catch (SQLException ex)
@@ -164,21 +177,27 @@ public class SQLGuildData
statement.setString(3, "" + plugin.userData.get(guild.getOwner()).getId());
List members = new ArrayList<>();
for (UUID member : guild.getMembers())
+ {
members.add("" + plugin.userData.get(member).getId());
+ }
statement.setString(4, members.size() == 0 ? null : StringUtils.join(members, ","));
List moderators = new ArrayList<>();
for (UUID moderator : guild.getModerators())
+ {
moderators.add("" + plugin.userData.get(moderator).getId());
+ }
statement.setString(5, moderators.size() == 0 ? null : StringUtils.join(moderators, ","));
statement.setString(6, guild.getTag());
statement.setInt(7, guild.getState().ordinal());
List stringRanks = new ArrayList<>();
for (GuildRank rank : guild.getRanks())
+ {
stringRanks.add(rank.getIdentifier());
+ }
statement.setString(8, stringRanks.size() == 0 ? null : StringUtils.join(stringRanks, ","));
statement.setString(9, guild.getMotd());
Location home = guild.getHome();
- statement.setDouble(10, home == null ? 0.0 : home.getX());
+ statement.setDouble(10, home == null ? 0.0 : home.getX());
statement.setDouble(11, home == null ? 100.0 : home.getY());
statement.setDouble(12, home == null ? 0.0 : home.getZ());
statement.setInt(13, home == null ? plugin.worldData.getWorldID(Bukkit.getWorlds().get(0)) : plugin.worldData.getWorldID(home.getWorld()));
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
index 1071f6f..2782b83 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
@@ -48,13 +48,18 @@ public class SQLRankData
statement.setString(1, guildIdentifier);
statement.setString(2, identifier);
ResultSet set = statement.executeQuery();
- if (!set.next()) return null;
+ if (!set.next())
+ {
+ return null;
+ }
String name = set.getString("name");
List members = new ArrayList<>();
if (set.getString("members") != null)
{
for (String stringMember : set.getString("members").split(","))
+ {
members.add(plugin.userData.get(Integer.parseInt(stringMember)).getUuid());
+ }
}
return new GuildRank(guildIdentifier, identifier, name, members);
}
@@ -92,7 +97,9 @@ public class SQLRankData
statement.setString(1, rank.getName());
List members = new ArrayList<>();
for (UUID member : rank.getMembers())
+ {
members.add("" + plugin.userData.get(member).getId());
+ }
statement.setString(2, members.size() == 0 ? null : StringUtils.join(members, ","));
statement.setString(3, rank.getIguild());
statement.setString(4, rank.getIdentifier());
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java
index 74f0dad..141a4a7 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java
@@ -54,7 +54,10 @@ public class SQLUserData
public User get(UUID uuid)
{
- if (!exists(uuid)) create(uuid);
+ if (!exists(uuid))
+ {
+ create(uuid);
+ }
try (Connection connection = plugin.sql.getConnection())
{
PreparedStatement statement = connection.prepareStatement(SELECT);
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLWarpData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLWarpData.java
new file mode 100644
index 0000000..88ed374
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLWarpData.java
@@ -0,0 +1,138 @@
+package me.totalfreedom.tfguilds.sql;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+import me.totalfreedom.tfguilds.TFGuilds;
+import me.totalfreedom.tfguilds.guild.GuildWarp;
+import org.bukkit.World;
+import org.bukkit.entity.Player;
+
+public class SQLWarpData
+{
+ private static final TFGuilds plugin = TFGuilds.getPlugin();
+ private static final String TABLE_NAME = "warps";
+
+ private final String SELECT = "SELECT * FROM `" + TABLE_NAME + "` WHERE identifier=? AND warp_name=?";
+ private final String SELECT_ALL = "SELECT * FROM `" + TABLE_NAME + "`";
+ private final String UPDATE = "UPDATE `" + TABLE_NAME + "` WHERE identifier=? AND warp_name=? SET x=?, y=?, z=?, world=?";
+ private final String DELETE = "DELETE FROM `" + TABLE_NAME + "` WHERE identifier=? AND warp_name=?";
+ private final String INSERT = "INSERT INTO `" + TABLE_NAME + "` (`identifier`, `warp_name`, `x`, `y`, `z`, `world`) VALUES (?, ?, ?, ?, ?, ?);";
+
+ public boolean exists(String identifier, String warpName)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(SELECT);
+ statement.setString(1, identifier);
+ statement.setString(2, warpName);
+ ResultSet set = statement.executeQuery();
+ return set.next();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return false;
+ }
+
+ public GuildWarp get(String identifier, String warpName)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(SELECT);
+ statement.setString(1, identifier);
+ statement.setString(2, warpName);
+ ResultSet set = statement.executeQuery();
+ double x = set.getDouble("x");
+ double y = set.getDouble("y");
+ double z = set.getDouble("z");
+ World world = plugin.worldData.getWorld(set.getInt("world"));
+ return new GuildWarp(identifier, warpName, x, y, z, world);
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ public List getAll()
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(SELECT_ALL);
+ ResultSet set = statement.executeQuery();
+ List warps = new ArrayList<>();
+ while (set.next())
+ {
+ warps.add(get(set.getString("identifier"), set.getString("warp_name")));
+ }
+ return warps;
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ public GuildWarp create(String identifier, String warpName, Player player)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(INSERT);
+ statement.setString(1, identifier);
+ statement.setString(2, warpName);
+ statement.setDouble(3, player.getLocation().getX());
+ statement.setDouble(4, player.getLocation().getY());
+ statement.setDouble(5, player.getLocation().getZ());
+ statement.setInt(6, plugin.worldData.getWorldID(player.getWorld()));
+ statement.execute();
+ return new GuildWarp(identifier, warpName, player.getLocation().getX(), player.getLocation().getY(),
+ player.getLocation().getZ(), player.getWorld());
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ return null;
+ }
+
+ public void save(GuildWarp warp)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(UPDATE);
+ statement.setString(1, warp.getIguild());
+ statement.setString(2, warp.getWarpName());
+ statement.setDouble(3, warp.getX());
+ statement.setDouble(4, warp.getY());
+ statement.setDouble(5, warp.getZ());
+ statement.setInt(6, plugin.worldData.getWorldID(warp.getWorld()));
+ statement.execute();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public void delete(GuildWarp warp)
+ {
+ try (Connection connection = plugin.sql.getConnection())
+ {
+ PreparedStatement statement = connection.prepareStatement(DELETE);
+ statement.setString(1, warp.getIguild());
+ statement.setString(2, warp.getWarpName());
+ statement.execute();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java
index 6045af9..91281e5 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java
@@ -79,7 +79,10 @@ public class SQLWorldData
{
try (Connection connection = plugin.sql.getConnection())
{
- if (!existsID(id)) return null;
+ if (!existsID(id))
+ {
+ return null;
+ }
PreparedStatement statement = connection.prepareStatement(SELECT_ID);
statement.setInt(1, id);
ResultSet set = statement.executeQuery();
diff --git a/src/main/java/me/totalfreedom/tfguilds/user/User.java b/src/main/java/me/totalfreedom/tfguilds/user/User.java
index 0d57e48..163b9ab 100644
--- a/src/main/java/me/totalfreedom/tfguilds/user/User.java
+++ b/src/main/java/me/totalfreedom/tfguilds/user/User.java
@@ -10,6 +10,7 @@ public class User
{
private final int id;
private final UUID uuid;
+
@Setter
private boolean tag;
@@ -24,4 +25,4 @@ public class User
{
TFGuilds.getPlugin().userData.save(this);
}
-}
+}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/util/PaginationList.java b/src/main/java/me/totalfreedom/tfguilds/util/PaginationList.java
index 1060caa..bb64e03 100644
--- a/src/main/java/me/totalfreedom/tfguilds/util/PaginationList.java
+++ b/src/main/java/me/totalfreedom/tfguilds/util/PaginationList.java
@@ -10,6 +10,7 @@ public class PaginationList extends ArrayList
/**
* Defines a new Pagination List.
+ *
* @param epp Elements per page - how many elements will be included on a page of the list.
*/
public PaginationList(int epp)
@@ -20,7 +21,8 @@ public class PaginationList extends ArrayList
/**
* Defines a new Pagination List.
- * @param epp Elements per page - how many elements will be included on a page of the list.
+ *
+ * @param epp Elements per page - how many elements will be included on a page of the list.
* @param elements Elements to add to the list immediately.
*/
@SafeVarargs
@@ -35,17 +37,21 @@ public class PaginationList extends ArrayList
*/
public int getPageCount()
{
- return (int) Math.ceil((double) size() / (double) epp);
+ return (int)Math.ceil((double)size() / (double)epp);
}
/**
* Get a page from the list.
+ *
* @param page Page you want to access.
* @return A sublist of only the elements from that page.
*/
public List getPage(int page)
{
- if (page < 1 || page > getPageCount()) return null;
+ if (page < 1 || page > getPageCount())
+ {
+ return null;
+ }
int startIndex = (page - 1) * epp;
int endIndex = Math.min(startIndex + (epp - 1), this.size() - 1);
return subList(startIndex, endIndex + 1);
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 6ec65e3..ddd9483 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -2,22 +2,22 @@ name: TFGuilds
version: ${project.version}
main: me.totalfreedom.tfguilds.TFGuilds
api-version: 1.16
-authors: [speed, super]
+authors: [ speed, super ]
description: A guilds plugin for the TotalFreedom server.
commands:
guild:
description: The main command of TFGuilds.
usage: /
- aliases: [g]
+ aliases: [ g ]
guildchat:
description: Talk in chat with your guild.
usage: / [message]
- aliases: [gchat]
+ aliases: [ gchat ]
tfguilds:
description: Information about the plugin.
usage: /
- aliases: [tfg]
+ aliases: [ tfg ]
guildchatspy:
description: An admin only command which allows for spying on guild chat.
usage: /
- aliases: [gchatspy, gcs]
\ No newline at end of file
+ aliases: [ gchatspy, gcs ]
\ No newline at end of file
From 5c9282441190fa2e65a1967a996c3aabf9bde7ad Mon Sep 17 00:00:00 2001
From: speed <43330808+speedxx@users.noreply.github.com>
Date: Sat, 19 Dec 2020 19:48:14 -0500
Subject: [PATCH 13/41] Delete .travis.yml
---
.travis.yml | 1 -
1 file changed, 1 deletion(-)
delete mode 100644 .travis.yml
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index dff5f3a..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1 +0,0 @@
-language: java
From 56134e2f32569334de2516eedf2ab543f7c80efb Mon Sep 17 00:00:00 2001
From: speed <43330808+speedxx@users.noreply.github.com>
Date: Tue, 29 Dec 2020 14:26:16 -0500
Subject: [PATCH 14/41] lol
---
.idea/TFGuilds.iml | 1 -
.../java/me/totalfreedom/tfguilds/command/AddModSubcommand.java | 2 +-
.../me/totalfreedom/tfguilds/command/SetWarpSubcommand.java | 1 -
3 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/.idea/TFGuilds.iml b/.idea/TFGuilds.iml
index a5f2b44..fa88e47 100644
--- a/.idea/TFGuilds.iml
+++ b/.idea/TFGuilds.iml
@@ -26,7 +26,6 @@
-
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/AddModSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/AddModSubcommand.java
index f1cda04..81c37d0 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/AddModSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/AddModSubcommand.java
@@ -50,7 +50,7 @@ public class AddModSubcommand extends Common implements CommandExecutor
return true;
}
- if (guild.getOwner().equals(player.getName()))
+ if (guild.getOwner().equals(player.getUniqueId()))
{
sender.sendMessage(ChatColor.RED + "No need to make the owner a moderator!");
return true;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubcommand.java
index 247fa66..5e309f9 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubcommand.java
@@ -2,7 +2,6 @@ package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.guild.GuildWarp;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
From ca7e623dd5ae6424a4a0fc478f64cb1875b5d1bd Mon Sep 17 00:00:00 2001
From: speed <43330808+speedxx@users.noreply.github.com>
Date: Wed, 6 Jan 2021 10:56:20 -0500
Subject: [PATCH 15/41] fix??????????????
---
.../totalfreedom/tfguilds/listener/ChatListener.java | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
index 875e13b..bd3cc51 100644
--- a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
+++ b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
@@ -38,9 +38,15 @@ public class ChatListener implements Listener
GuildRank rank = null;
for (GuildRank r : guild.getRanks())
{
- if (r.getMembers().contains(player.getUniqueId()))
+ if (r != null)
{
- rank = r;
+ if (r.getMembers() != null)
+ {
+ if (r.getMembers().contains(player.getUniqueId()))
+ {
+ rank = r;
+ }
+ }
}
}
From 4128950c468b7f08a2e80d5fef50fe29397e0172 Mon Sep 17 00:00:00 2001
From: abhiram
Date: Thu, 25 Feb 2021 02:01:54 +0530
Subject: [PATCH 16/41] Fixed invalid config path, it was causing tag not
displaying
---
.idea/TFGuilds.iml | 13 +++++------
.idea/jarRepositories.xml | 22 +++++++++----------
.idea/misc.xml | 4 ++++
.../tfguilds/config/ConfigEntry.java | 7 +++---
.../tfguilds/listener/ChatListener.java | 1 +
5 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/.idea/TFGuilds.iml b/.idea/TFGuilds.iml
index fa88e47..163e931 100644
--- a/.idea/TFGuilds.iml
+++ b/.idea/TFGuilds.iml
@@ -1,5 +1,10 @@
+
+
+
@@ -19,14 +24,6 @@
-
-
-
-
-
-
-
-
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index b008060..bcc693d 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -6,15 +6,20 @@
+
+
+
+
+
-
-
-
+
+
+
@@ -22,19 +27,14 @@
-
-
-
+
+
+
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index cffed5d..d2b0ede 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -1,5 +1,9 @@
+
+
+
+
diff --git a/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java b/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java
index 4f5db02..bd8c900 100644
--- a/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java
+++ b/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java
@@ -9,17 +9,16 @@ public enum ConfigEntry
SCHEME_SECONDARY("scheme.secondary"),
// Server
GUILD_CHAT_LOGGING_ENABLED("server.guild_chat_logging.enabled"),
- GUILD_TAGS_ENABLED("server.guild_tags.enabled");
+ GUILD_TAGS_ENABLED("server.guild_tags_enabled.enabled");
private final String path;
-
+ private final Config config;
ConfigEntry(String path)
{
this.path = path;
+ this.config = TFGuilds.getPlugin().config;
}
- private static final Config config = TFGuilds.getPlugin().config;
-
public boolean getBoolean()
{
return config.getBoolean(path);
diff --git a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
index bd3cc51..d819bee 100644
--- a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
+++ b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
@@ -84,6 +84,7 @@ public class ChatListener implements Listener
if (guild.hasTag())
{
+ System.out.println(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + e.getFormat());
e.setFormat(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + e.getFormat());
}
}
From 65700237626369e68f31dd668b83ebed3eaa21ca Mon Sep 17 00:00:00 2001
From: abhiram
Date: Thu, 25 Feb 2021 02:03:15 +0530
Subject: [PATCH 17/41] Fixed invalid config path, it was causing guild tag not
displaying
---
.idea/checkstyle-idea.xml | 16 ++++++++++++++++
.idea/discord.xml | 6 ++++++
2 files changed, 22 insertions(+)
create mode 100644 .idea/checkstyle-idea.xml
create mode 100644 .idea/discord.xml
diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml
new file mode 100644
index 0000000..658f152
--- /dev/null
+++ b/.idea/checkstyle-idea.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/discord.xml b/.idea/discord.xml
new file mode 100644
index 0000000..cd711a0
--- /dev/null
+++ b/.idea/discord.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
From 3c412ca0e8436d7db39b292e77182e6c9d87dfe8 Mon Sep 17 00:00:00 2001
From: Ryan Wild
Date: Fri, 5 Mar 2021 22:56:39 +0000
Subject: [PATCH 18/41] 2021.03-RC01 Release
Bumped version numbers and made sure we build Java 11. Also fixed a bug where we seem to double log entries.
---
nb-configuration.xml | 19 +++++++++++++++++++
pom.xml | 6 +++---
.../tfguilds/listener/ChatListener.java | 3 ++-
3 files changed, 24 insertions(+), 4 deletions(-)
create mode 100644 nb-configuration.xml
diff --git a/nb-configuration.xml b/nb-configuration.xml
new file mode 100644
index 0000000..5616f15
--- /dev/null
+++ b/nb-configuration.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+ JDK_11
+ true
+
+
diff --git a/pom.xml b/pom.xml
index 33fa527..707a078 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.totalfreedom
TFGuilds
- 0.3.1
+ 2021.03-RC01
jar
TFGuilds
@@ -25,8 +25,8 @@
maven-compiler-plugin
3.8.1
-
- 1.8
+
+ 11
diff --git a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
index d819bee..2dfe501 100644
--- a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
+++ b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
@@ -84,7 +84,8 @@ public class ChatListener implements Listener
if (guild.hasTag())
{
- System.out.println(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + e.getFormat());
+ // This seems to result in the entry being logged twice on the console, which is silly... Not sure if there was a good reason for it.
+ //System.out.println(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + e.getFormat());
e.setFormat(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + e.getFormat());
}
}
From 02e1df6e9c1671bd59e345c49bd65fb3aedd4ff8 Mon Sep 17 00:00:00 2001
From: Nathan Curran <30569566+Focusvity@users.noreply.github.com>
Date: Sun, 7 Mar 2021 15:43:08 +1100
Subject: [PATCH 19/41] Save data when removing a player from rank (FS-134)
---
.gitignore | 6 +-----
.../me/totalfreedom/tfguilds/command/SetRankSubcommand.java | 3 ++-
2 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/.gitignore b/.gitignore
index 89a26f4..166641b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,7 +1,3 @@
-/.idea/artifacts
-/.idea/libraries
-/.idea/workspace.xml
-/.idea/modules.xml
-/.idea/uiDesigner.xml
+/.idea/
target/
out/
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
index b4ac17e..2527f70 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
@@ -57,7 +57,7 @@ public class SetRankSubcommand extends Common implements CommandExecutor
}
String name = StringUtils.join(args, " ", 2, args.length);
- if (name.toLowerCase().equals("none"))
+ if (name.equalsIgnoreCase("none"))
{
for (GuildRank gr : guild.getRanks())
{
@@ -80,6 +80,7 @@ public class SetRankSubcommand extends Common implements CommandExecutor
for (GuildRank gr : guild.getRanks())
{
gr.getMembers().remove(r.getUniqueId());
+ gr.save();
}
rank.getMembers().add(r.getUniqueId());
From c9972c2879a5e49815733753805969a205b85404 Mon Sep 17 00:00:00 2001
From: Nathan Curran <30569566+Focusvity@users.noreply.github.com>
Date: Sun, 7 Mar 2021 15:53:19 +1100
Subject: [PATCH 20/41] Added another missed save statement
---
.../java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
index 2527f70..71fbecf 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
@@ -62,6 +62,7 @@ public class SetRankSubcommand extends Common implements CommandExecutor
for (GuildRank gr : guild.getRanks())
{
gr.getMembers().remove(r.getUniqueId());
+ gr.save();
}
sender.sendMessage(tl(PREFIX + "Removed the rank of %s%" + r.getName() + "%p% in your guild."));
From a0075b2163c4a449f007a100d8d11187fc97c3fd Mon Sep 17 00:00:00 2001
From: Nathan Curran <30569566+Focusvity@users.noreply.github.com>
Date: Sun, 7 Mar 2021 19:17:44 +1100
Subject: [PATCH 21/41] Use toLowerCase instead
---
.../me/totalfreedom/tfguilds/command/SetRankSubcommand.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
index 71fbecf..967a3ec 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
@@ -56,8 +56,8 @@ public class SetRankSubcommand extends Common implements CommandExecutor
return true;
}
- String name = StringUtils.join(args, " ", 2, args.length);
- if (name.equalsIgnoreCase("none"))
+ String name = StringUtils.join(args, " ", 2, args.length).toLowerCase();
+ if (name.equals("none"))
{
for (GuildRank gr : guild.getRanks())
{
From 1708039c607b5e4e221034337d36500d8c4abff0 Mon Sep 17 00:00:00 2001
From: Ryan
Date: Sun, 7 Mar 2021 17:51:25 +0000
Subject: [PATCH 22/41] Tell CodeQL We're building Java 11
---
.github/workflows/codeql-analysis.yml | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml
index a80c844..91eb6c6 100644
--- a/.github/workflows/codeql-analysis.yml
+++ b/.github/workflows/codeql-analysis.yml
@@ -36,6 +36,12 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v2
+
+ - name: Setup Java JDK
+ uses: actions/setup-java@v1.4.3
+ with:
+ # The Java version to make available on the path. Takes a whole or semver Java version, or 1.x syntax (e.g. 1.8 => Java 8.x). Early access versions can be specified in the form of e.g. 14-ea, 14.0.0-ea, or 14.0.0-ea.28
+ java-version: 11
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
From b9c16dcd1a14fc85bd9ef4fd2244eaebf18ccc4a Mon Sep 17 00:00:00 2001
From: Ryan Wild
Date: Sun, 21 Mar 2021 15:18:24 +0000
Subject: [PATCH 23/41] Bump version
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 707a078..c3efb8b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.totalfreedom
TFGuilds
- 2021.03-RC01
+ 2021.03-RC02
jar
TFGuilds
From 9d58522fc6a884ae9657c492b1f8a6539976bec7 Mon Sep 17 00:00:00 2001
From: Nathan Curran <30569566+Focusvity@users.noreply.github.com>
Date: Mon, 5 Apr 2021 22:26:29 +1000
Subject: [PATCH 24/41] Improve plugin performance (FS-151)
This is what Freedom-01 is running on and this will have to do until we start a rewrite.
---
.../me/totalfreedom/tfguilds/TFGuilds.java | 13 +++
.../command/DeleteWarpSubcommand.java | 2 +-
.../tfguilds/command/SetWarpSubcommand.java | 2 +-
.../tfguilds/command/WarpSubcommand.java | 4 +-
.../me/totalfreedom/tfguilds/guild/Guild.java | 18 ++-
.../tfguilds/listener/ChatListener.java | 2 -
.../tfguilds/sql/SQLDatabase.java | 109 +++++++++---------
.../tfguilds/sql/SQLGuildData.java | 45 ++++----
.../tfguilds/sql/SQLRankData.java | 18 ++-
.../tfguilds/sql/SQLUserData.java | 21 ++--
.../tfguilds/sql/SQLWarpData.java | 44 ++++---
.../tfguilds/sql/SQLWorldData.java | 15 ++-
12 files changed, 164 insertions(+), 129 deletions(-)
diff --git a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
index 2fff217..71d9793 100644
--- a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
+++ b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
@@ -1,11 +1,15 @@
package me.totalfreedom.tfguilds;
+import java.util.HashMap;
+import java.util.Map;
import me.totalfreedom.tfguilds.bridge.TFMBridge;
import me.totalfreedom.tfguilds.command.GuildChatCommand;
import me.totalfreedom.tfguilds.command.GuildChatSpyCommand;
import me.totalfreedom.tfguilds.command.GuildCommand;
import me.totalfreedom.tfguilds.command.TFGuildsCommand;
import me.totalfreedom.tfguilds.config.Config;
+import me.totalfreedom.tfguilds.guild.Guild;
+import me.totalfreedom.tfguilds.guild.GuildWarp;
import me.totalfreedom.tfguilds.listener.ChatListener;
import me.totalfreedom.tfguilds.listener.JoinListener;
import me.totalfreedom.tfguilds.sql.SQLDatabase;
@@ -36,18 +40,27 @@ public final class TFGuilds extends JavaPlugin
public SQLWarpData warpData;
public SQLWorldData worldData;
+
+ // TEMP FIX UNTIL REWRITE
+ public Map guilds;
+ public Map warps;
+
@Override
public void onEnable()
{
plugin = this;
config = new Config("config.yml");
bridge = new TFMBridge();
+ guilds = new HashMap<>();
+ warps = new HashMap<>();
sql = new SQLDatabase();
guildData = new SQLGuildData();
rankData = new SQLRankData();
userData = new SQLUserData();
warpData = new SQLWarpData();
worldData = new SQLWorldData();
+ guildData.getAll();
+ warpData.getAll();
loadCommands();
loadListeners();
GLog.info("Enabled " + this.getDescription().getFullName());
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DeleteWarpSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DeleteWarpSubcommand.java
index 1e2fb53..9d284f1 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/DeleteWarpSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/DeleteWarpSubcommand.java
@@ -43,7 +43,7 @@ public class DeleteWarpSubcommand extends Common implements CommandExecutor
}
String warpName = StringUtils.join(args, " ", 1, args.length);
- if (!Guild.warpExists(guild.getIdentifier(), warpName))
+ if (!guild.warpExists(warpName))
{
sender.sendMessage(ChatColor.RED + "Warp not found.");
return true;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubcommand.java
index 5e309f9..e58860d 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubcommand.java
@@ -42,7 +42,7 @@ public class SetWarpSubcommand extends Common implements CommandExecutor
}
String warpName = StringUtils.join(args, " ", 1, args.length);
- if (Guild.warpExists(guild.getIdentifier(), warpName))
+ if (guild.warpExists(warpName))
{
sender.sendMessage(ChatColor.RED + "A warp with that name already exists.");
return true;
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/WarpSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/WarpSubcommand.java
index b6c4e3b..245a11d 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/WarpSubcommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/WarpSubcommand.java
@@ -38,13 +38,13 @@ public class WarpSubcommand extends Common implements CommandExecutor
}
String warpName = StringUtils.join(args, " ", 1, args.length);
- if (!Guild.warpExists(guild.getIdentifier(), warpName))
+ if (!guild.warpExists(warpName))
{
sender.sendMessage(ChatColor.RED + "Warp not found.");
return true;
}
- GuildWarp warp = plugin.warpData.get(guild.getIdentifier(), warpName);
+ GuildWarp warp = guild.getWarp(warpName);
Location warpLoc = new Location(warp.getWorld(), warp.getX(), warp.getY(), warp.getZ());
player.teleport(warpLoc);
sender.sendMessage(tl(PREFIX + "Warping to \"" + warpName + "\"."));
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
index 9925154..52a060b 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
@@ -289,7 +289,7 @@ public class Guild
public static List getGuildList()
{
List g = new ArrayList<>();
- for (Guild guild : plugin.guildData.getAll())
+ for (Guild guild : plugin.guilds.values())
{
g.add(guild.getName());
}
@@ -299,13 +299,23 @@ public class Guild
public static List getGuildWarps()
{
List warps = new ArrayList<>();
- for (GuildWarp warp : plugin.warpData.getAll())
+ for (GuildWarp warp : plugin.warps.values())
{
warps.add(warp.getWarpName());
}
return warps;
}
+ public GuildWarp getWarp(String warpName)
+ {
+ GuildWarp warp = plugin.warps.get(identifier);
+ if (warp != null && warp.getWarpName().equalsIgnoreCase(warpName))
+ {
+ return warp;
+ }
+ return null;
+ }
+
public String getInformation()
{
return Common.tl(Common.PREFIX + "Guild Information\n" +
@@ -393,7 +403,7 @@ public class Guild
public static Guild getGuild(String identifier)
{
- return plugin.guildData.get(identifier);
+ return plugin.guilds.get(identifier);
}
public static Guild getGuild(Player player)
@@ -416,7 +426,7 @@ public class Guild
return GuildWarp.createGuildWarp(identifier, warpName, player);
}
- public static boolean warpExists(String identifier, String warpName)
+ public boolean warpExists(String warpName)
{
return plugin.warpData.exists(identifier, warpName);
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
index 2dfe501..bd3cc51 100644
--- a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
+++ b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
@@ -84,8 +84,6 @@ public class ChatListener implements Listener
if (guild.hasTag())
{
- // This seems to result in the entry being logged twice on the console, which is silly... Not sure if there was a good reason for it.
- //System.out.println(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + e.getFormat());
e.setFormat(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + e.getFormat());
}
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
index ad9769b..6743a19 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
@@ -10,79 +10,82 @@ import me.totalfreedom.tfguilds.TFGuilds;
public class SQLDatabase
{
private static final String DATABASE_FILENAME = "database.db";
- private static final TFGuilds plugin = TFGuilds.getPlugin();
-
- private final File file;
+ private final File FILE;
+ private Connection connection;
public SQLDatabase()
{
- File file = new File(plugin.getDataFolder(), DATABASE_FILENAME);
+ File file = new File(TFGuilds.getPlugin().getDataFolder(), DATABASE_FILENAME);
if (!file.exists())
{
try
{
file.createNewFile();
- plugin.saveResource(DATABASE_FILENAME, false);
+ TFGuilds.getPlugin().saveResource(DATABASE_FILENAME, false);
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
- this.file = file;
- }
-
- public Connection getConnection()
- {
+ this.FILE = file;
try
{
- Connection connection = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath());
- connection.prepareStatement("CREATE TABLE IF NOT EXISTS `users` (\n" +
- "\t`id` INT,\n" +
- "\t`uuid` TINYTEXT,\n" +
- "\t`tag` BOOL\n" +
- ");").execute();
- connection.prepareStatement("CREATE TABLE IF NOT EXISTS `worlds` (\n" +
- "\t`id` SMALLINT,\n" +
- "\t`name` TINYTEXT\n" +
- ");").execute();
- connection.prepareStatement("CREATE TABLE IF NOT EXISTS `ranks` (\n" +
- "\t`guild_identifier` TEXT,\n" +
- "\t`identifier` TEXT,\n" +
- "\t`name` TEXT,\n" +
- "\t`members` TEXT\n" +
- ");").execute();
- connection.prepareStatement("CREATE TABLE IF NOT EXISTS `guilds` (\n" +
- "\t`identifier` TEXT,\n" +
- "\t`name` TEXT,\n" +
- "\t`owner` INT,\n" +
- "\t`moderators` TEXT,\n" +
- "\t`members` TEXT,\n" +
- "\t`tag` TEXT,\n" +
- "\t`state` TINYINT,\n" +
- "\t`ranks` TEXT,\n" +
- "\t`motd` TEXT,\n" +
- "\t`x` DOUBLE,\n" +
- "\t`y` DOUBLE,\n" +
- "\t`z` DOUBLE,\n" +
- "\t`world` SMALLINT,\n" +
- "\t`default_rank` TEXT,\n" +
- "\t`creation` BIGINT\n" +
- ");").execute();
- connection.prepareStatement("CREATE TABLE IF NOT EXISTS `warps` (\n" +
- "\t`identifier` TEXT,\n" +
- "\t`warp_name` TEXT,\n" +
- "\t`x` DOUBLE,\n" +
- "\t`y` DOUBLE,\n" +
- "\t`z` DOUBLE,\n" +
- "\t`world` SMALLINT\n" +
- ");").execute();
- return connection;
+ connection = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath());
+ createTables();
}
catch (SQLException ex)
{
ex.printStackTrace();
}
- return null;
+ }
+
+ public Connection getConnection()
+ {
+ return connection;
+ }
+
+ private void createTables() throws SQLException
+ {
+ connection.prepareStatement("CREATE TABLE IF NOT EXISTS `users` (\n" +
+ "\t`id` INT,\n" +
+ "\t`uuid` TINYTEXT,\n" +
+ "\t`tag` BOOL\n" +
+ ");").execute();
+ connection.prepareStatement("CREATE TABLE IF NOT EXISTS `worlds` (\n" +
+ "\t`id` SMALLINT,\n" +
+ "\t`name` TINYTEXT\n" +
+ ");").execute();
+ connection.prepareStatement("CREATE TABLE IF NOT EXISTS `ranks` (\n" +
+ "\t`guild_identifier` TEXT,\n" +
+ "\t`identifier` TEXT,\n" +
+ "\t`name` TEXT,\n" +
+ "\t`members` TEXT\n" +
+ ");").execute();
+ connection.prepareStatement("CREATE TABLE IF NOT EXISTS `guilds` (\n" +
+ "\t`identifier` TEXT,\n" +
+ "\t`name` TEXT,\n" +
+ "\t`owner` INT,\n" +
+ "\t`moderators` TEXT,\n" +
+ "\t`members` TEXT,\n" +
+ "\t`tag` TEXT,\n" +
+ "\t`state` TINYINT,\n" +
+ "\t`ranks` TEXT,\n" +
+ "\t`motd` TEXT,\n" +
+ "\t`x` DOUBLE,\n" +
+ "\t`y` DOUBLE,\n" +
+ "\t`z` DOUBLE,\n" +
+ "\t`world` SMALLINT,\n" +
+ "\t`default_rank` TEXT,\n" +
+ "\t`creation` BIGINT\n" +
+ ");").execute();
+ connection.prepareStatement("CREATE TABLE IF NOT EXISTS `warps` (\n" +
+ "\t`identifier` TEXT,\n" +
+ "\t`warp_name` TEXT,\n" +
+ "\t`x` DOUBLE,\n" +
+ "\t`y` DOUBLE,\n" +
+ "\t`z` DOUBLE,\n" +
+ "\t`world` SMALLINT\n" +
+ ");").execute();
}
}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
index 7cef2e4..6649083 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
@@ -20,6 +20,7 @@ import org.bukkit.entity.Player;
public class SQLGuildData
{
+
private static final TFGuilds plugin = TFGuilds.getPlugin();
private static final String TABLE_NAME = "guilds";
@@ -34,23 +35,13 @@ public class SQLGuildData
public boolean exists(String identifier)
{
- try (Connection connection = plugin.sql.getConnection())
- {
- PreparedStatement statement = connection.prepareStatement(SELECT);
- statement.setString(1, identifier);
- ResultSet set = statement.executeQuery();
- return set.next();
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return false;
+ return plugin.guilds.containsKey(identifier);
}
public Guild get(String identifier)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, identifier);
@@ -103,7 +94,7 @@ public class SQLGuildData
public Guild get(Player player)
{
- for (Guild guild : getAll())
+ for (Guild guild : plugin.guilds.values())
{
if (guild.getMembers().contains(player.getUniqueId()))
{
@@ -113,29 +104,29 @@ public class SQLGuildData
return null;
}
- public List getAll()
+ public void getAll()
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(SELECT_ALL);
ResultSet set = statement.executeQuery();
- List guilds = new ArrayList<>();
while (set.next())
{
- guilds.add(get(set.getString("identifier")));
+ String identifier = set.getString("identifier");
+ plugin.guilds.put(identifier, get(identifier));
}
- return guilds;
}
catch (SQLException ex)
{
ex.printStackTrace();
}
- return null;
}
public Guild create(String identifier, String name, Player owner)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(INSERT);
statement.setString(1, identifier);
@@ -156,9 +147,11 @@ public class SQLGuildData
long creation = System.currentTimeMillis();
statement.setLong(15, creation);
statement.execute();
- return new Guild(identifier, name, owner.getUniqueId(), Collections.singletonList(owner.getUniqueId()), new ArrayList<>(),
+ Guild guild = new Guild(identifier, name, owner.getUniqueId(), Collections.singletonList(owner.getUniqueId()), new ArrayList<>(),
ChatColor.DARK_GRAY + "[" + ChatColor.GRAY + name + ChatColor.DARK_GRAY + "]",
GuildState.INVITE_ONLY, new ArrayList<>(), null, new Location(Bukkit.getWorlds().get(0), 0.0, 100.0, 0.0), creation, null);
+ plugin.guilds.put(identifier, guild);
+ return guild;
}
catch (SQLException ex)
{
@@ -169,7 +162,8 @@ public class SQLGuildData
public void save(Guild guild, String identifier)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(UPDATE);
statement.setString(1, guild.getIdentifier());
@@ -204,6 +198,7 @@ public class SQLGuildData
statement.setString(14, guild.getDefaultRank());
statement.setString(15, identifier);
statement.execute();
+ plugin.guilds.put(identifier, guild);
}
catch (SQLException ex)
{
@@ -218,11 +213,13 @@ public class SQLGuildData
public void delete(Guild guild)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(DELETE);
statement.setString(1, guild.getIdentifier());
statement.execute();
+ plugin.guilds.remove(guild.getIdentifier());
}
catch (SQLException ex)
{
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
index 2782b83..420dcc9 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
@@ -25,7 +25,8 @@ public class SQLRankData
public boolean exists(String guildIdentifier, String identifier)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, guildIdentifier);
@@ -42,7 +43,8 @@ public class SQLRankData
public GuildRank get(String guildIdentifier, String identifier)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, guildIdentifier);
@@ -72,7 +74,8 @@ public class SQLRankData
public GuildRank create(String guildIdentifier, String identifier, String name)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(INSERT);
statement.setString(1, guildIdentifier);
@@ -91,7 +94,8 @@ public class SQLRankData
public void save(GuildRank rank)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(UPDATE);
statement.setString(1, rank.getName());
@@ -113,7 +117,8 @@ public class SQLRankData
public void updateGuildIdentifier(GuildRank rank, String newIdentifier)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(UPDATE_GUILD);
statement.setString(1, newIdentifier);
@@ -129,7 +134,8 @@ public class SQLRankData
public void delete(GuildRank rank)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(DELETE);
statement.setString(1, rank.getIguild());
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java
index 141a4a7..af25ec0 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java
@@ -22,7 +22,8 @@ public class SQLUserData
public boolean exists(UUID uuid)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, uuid.toString());
@@ -38,7 +39,8 @@ public class SQLUserData
public boolean existsID(int id)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(SELECT_ID);
statement.setInt(1, id);
@@ -58,7 +60,8 @@ public class SQLUserData
{
create(uuid);
}
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, uuid.toString());
@@ -77,7 +80,8 @@ public class SQLUserData
public User get(int id)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(SELECT_ID);
statement.setInt(1, id);
@@ -96,7 +100,8 @@ public class SQLUserData
public User create(UUID uuid)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(INSERT);
int id = getUserCount() + 1;
@@ -115,7 +120,8 @@ public class SQLUserData
public void save(User user)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(UPDATE);
statement.setBoolean(1, user.isTag());
@@ -130,7 +136,8 @@ public class SQLUserData
public int getUserCount()
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(COUNT);
ResultSet set = statement.executeQuery();
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLWarpData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLWarpData.java
index 88ed374..0cec480 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLWarpData.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLWarpData.java
@@ -24,24 +24,14 @@ public class SQLWarpData
public boolean exists(String identifier, String warpName)
{
- try (Connection connection = plugin.sql.getConnection())
- {
- PreparedStatement statement = connection.prepareStatement(SELECT);
- statement.setString(1, identifier);
- statement.setString(2, warpName);
- ResultSet set = statement.executeQuery();
- return set.next();
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return false;
+ GuildWarp warp = plugin.warps.get(identifier);
+ return warp != null && warp.getWarpName().equalsIgnoreCase(warpName);
}
public GuildWarp get(String identifier, String warpName)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, identifier);
@@ -60,29 +50,29 @@ public class SQLWarpData
return null;
}
- public List getAll()
+ public void getAll()
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(SELECT_ALL);
ResultSet set = statement.executeQuery();
- List warps = new ArrayList<>();
while (set.next())
{
- warps.add(get(set.getString("identifier"), set.getString("warp_name")));
+ String identifier = set.getString("identifier");
+ plugin.warps.put(identifier, get(identifier, set.getString("warp_name")));
}
- return warps;
}
catch (SQLException ex)
{
ex.printStackTrace();
}
- return null;
}
public GuildWarp create(String identifier, String warpName, Player player)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(INSERT);
statement.setString(1, identifier);
@@ -92,8 +82,10 @@ public class SQLWarpData
statement.setDouble(5, player.getLocation().getZ());
statement.setInt(6, plugin.worldData.getWorldID(player.getWorld()));
statement.execute();
- return new GuildWarp(identifier, warpName, player.getLocation().getX(), player.getLocation().getY(),
+ GuildWarp warp = new GuildWarp(identifier, warpName, player.getLocation().getX(), player.getLocation().getY(),
player.getLocation().getZ(), player.getWorld());
+ plugin.warps.put(identifier, warp);
+ return warp;
}
catch (SQLException ex)
{
@@ -104,7 +96,8 @@ public class SQLWarpData
public void save(GuildWarp warp)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(UPDATE);
statement.setString(1, warp.getIguild());
@@ -114,6 +107,7 @@ public class SQLWarpData
statement.setDouble(5, warp.getZ());
statement.setInt(6, plugin.worldData.getWorldID(warp.getWorld()));
statement.execute();
+ plugin.warps.put(warp.getIguild(), warp);
}
catch (SQLException ex)
{
@@ -123,12 +117,14 @@ public class SQLWarpData
public void delete(GuildWarp warp)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(DELETE);
statement.setString(1, warp.getIguild());
statement.setString(2, warp.getWarpName());
statement.execute();
+ plugin.warps.remove(warp.getIguild());
}
catch (SQLException ex)
{
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java
index 91281e5..2a776bd 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java
@@ -19,7 +19,8 @@ public class SQLWorldData
public boolean exists(World world)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(SELECT);
statement.setString(1, world.getName());
@@ -35,7 +36,8 @@ public class SQLWorldData
public boolean existsID(int id)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(SELECT_ID);
statement.setInt(1, id);
@@ -51,7 +53,8 @@ public class SQLWorldData
public int getWorldID(World world)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
if (!exists(world))
{
@@ -77,7 +80,8 @@ public class SQLWorldData
public World getWorld(int id)
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
if (!existsID(id))
{
@@ -100,7 +104,8 @@ public class SQLWorldData
public int getWorldCount()
{
- try (Connection connection = plugin.sql.getConnection())
+ Connection connection = plugin.sql.getConnection();
+ try
{
PreparedStatement statement = connection.prepareStatement(COUNT);
ResultSet set = statement.executeQuery();
From c4d65c21d21e26d3629b249ce696cc42f7d2a7f5 Mon Sep 17 00:00:00 2001
From: Nathan Curran <30569566+Focusvity@users.noreply.github.com>
Date: Sun, 11 Apr 2021 00:03:44 +1000
Subject: [PATCH 25/41] Fix Codacy issues
---
src/main/java/me/totalfreedom/tfguilds/TFGuilds.java | 10 +++++-----
.../java/me/totalfreedom/tfguilds/sql/SQLDatabase.java | 2 --
2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
index 71d9793..c68d26b 100644
--- a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
+++ b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
@@ -24,6 +24,11 @@ import org.bukkit.plugin.java.JavaPlugin;
public final class TFGuilds extends JavaPlugin
{
+
+ // TEMP FIX UNTIL REWRITE
+ public Map guilds;
+ public Map warps;
+
private static TFGuilds plugin;
public static TFGuilds getPlugin()
@@ -40,11 +45,6 @@ public final class TFGuilds extends JavaPlugin
public SQLWarpData warpData;
public SQLWorldData worldData;
-
- // TEMP FIX UNTIL REWRITE
- public Map guilds;
- public Map warps;
-
@Override
public void onEnable()
{
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
index 6743a19..0926641 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
@@ -10,7 +10,6 @@ import me.totalfreedom.tfguilds.TFGuilds;
public class SQLDatabase
{
private static final String DATABASE_FILENAME = "database.db";
- private final File FILE;
private Connection connection;
public SQLDatabase()
@@ -28,7 +27,6 @@ public class SQLDatabase
ex.printStackTrace();
}
}
- this.FILE = file;
try
{
connection = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath());
From 8b16fc57e8d7016272b784059717a0d744eed670 Mon Sep 17 00:00:00 2001
From: Ryan Wild
Date: Sat, 10 Apr 2021 20:06:49 +0100
Subject: [PATCH 26/41] Bump release version
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index c3efb8b..d54f138 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.totalfreedom
TFGuilds
- 2021.03-RC02
+ 2021.03
jar
TFGuilds
From e6d3dc6b128ff446dc4091920ea30317f57cedfe Mon Sep 17 00:00:00 2001
From: Nathan Curran <30569566+Focusvity@users.noreply.github.com>
Date: Sat, 22 May 2021 14:26:48 +1000
Subject: [PATCH 27/41] TFGuilds Rewrite (FS-164, FS-133, FS-244) (#7)
* TFGuilds rewrite almost completed (FS-164 FS-133 FS-244)
The rewrite is nearing completion - few modifications to TFGuilds and TFM and it will be ready for production
* Finalise few things
* Code cleanup
* Use empty list instead and true instead of false
---
.idea/codeStyles/Project.xml | 18 -
.idea/compiler.xml | 2 +-
.idea/jarRepositories.xml | 30 +-
TFGuilds.iml | 34 +-
pom.xml | 14 +-
.../java/me/totalfreedom/tfguilds/Common.java | 36 +-
.../me/totalfreedom/tfguilds/TFGuilds.java | 132 +-
.../me/totalfreedom/tfguilds/TFMBridge.java | 64 +
.../tfguilds/bridge/TFMBridge.java | 72 --
.../tfguilds/command/AddModSubCommand.java | 70 ++
.../tfguilds/command/AddModSubcommand.java | 123 --
.../tfguilds/command/ChatSubCommand.java | 46 +
.../tfguilds/command/ChatSubcommand.java | 50 -
.../command/CreateRankSubCommand.java | 70 ++
.../command/CreateRankSubcommand.java | 87 --
.../tfguilds/command/CreateSubCommand.java | 65 +
.../tfguilds/command/CreateSubcommand.java | 81 --
.../command/DeleteRankSubCommand.java | 51 +
.../command/DeleteRankSubcommand.java | 63 -
.../command/DeleteWarpSubCommand.java | 51 +
.../command/DeleteWarpSubcommand.java | 57 -
.../tfguilds/command/DisbandSubCommand.java | 60 +
.../tfguilds/command/DisbandSubcommand.java | 77 --
.../tfguilds/command/GuildChatCommand.java | 50 -
.../tfguilds/command/GuildChatSpyCommand.java | 25 +-
.../tfguilds/command/GuildCommand.java | 216 +---
.../tfguilds/command/HelpSubCommand.java | 22 +
.../tfguilds/command/HelpSubcommand.java | 48 -
.../tfguilds/command/HomeSubCommand.java | 56 +
.../tfguilds/command/HomeSubcommand.java | 65 -
.../tfguilds/command/InfoSubCommand.java | 55 +
.../tfguilds/command/InfoSubcommand.java | 60 -
.../tfguilds/command/InviteSubCommand.java | 98 ++
.../tfguilds/command/InviteSubcommand.java | 92 --
.../tfguilds/command/JoinSubCommand.java | 60 +
.../tfguilds/command/JoinSubcommand.java | 67 --
.../tfguilds/command/KickSubCommand.java | 70 ++
.../tfguilds/command/KickSubcommand.java | 113 --
.../tfguilds/command/LeaveSubCommand.java | 38 +
.../tfguilds/command/LeaveSubcommand.java | 50 -
.../tfguilds/command/ListSubCommand.java | 60 +
.../tfguilds/command/ListSubcommand.java | 65 -
.../tfguilds/command/MOTDSubcommand.java | 68 --
.../tfguilds/command/MotdSubCommand.java | 66 +
.../tfguilds/command/RemoveModSubCommand.java | 70 ++
.../tfguilds/command/RemoveModSubcommand.java | 126 --
.../tfguilds/command/RenameSubcommand.java | 88 --
.../tfguilds/command/RosterSubCommand.java | 59 +
.../tfguilds/command/RosterSubcommand.java | 60 -
.../command/SetDefaultRankSubCommand.java | 71 ++
.../command/SetDefaultRankSubcommand.java | 64 -
.../tfguilds/command/SetMemberSubcommand.java | 54 -
.../tfguilds/command/SetOwnerSubCommand.java | 65 +
.../tfguilds/command/SetOwnerSubcommand.java | 113 --
.../tfguilds/command/SetRankSubCommand.java | 66 +
.../tfguilds/command/SetRankSubcommand.java | 94 --
.../tfguilds/command/SetStateSubCommand.java | 53 +
.../tfguilds/command/SetStateSubcommand.java | 87 --
.../tfguilds/command/SetWarpSubCommand.java | 57 +
.../tfguilds/command/SetWarpSubcommand.java | 55 -
.../tfguilds/command/SubCommand.java | 10 +
.../tfguilds/command/TFGuildsCommand.java | 57 +-
.../tfguilds/command/TPSubcommand.java | 56 -
.../tfguilds/command/TagSubCommand.java | 100 ++
.../tfguilds/command/TagSubcommand.java | 107 --
.../tfguilds/command/ToggleTagSubCommand.java | 36 +
.../tfguilds/command/ToggleTagSubcommand.java | 66 -
.../command/ToggleTagsSubCommand.java | 36 +
.../command/ToggleTagsSubcommand.java | 36 -
.../tfguilds/command/TpSubCommand.java | 51 +
.../tfguilds/command/WarpSubCommand.java | 47 +
.../tfguilds/command/WarpSubcommand.java | 53 -
.../tfguilds/command/WarpsSubCommand.java | 37 +
.../tfguilds/command/WarpsSubcommand.java | 36 -
.../totalfreedom/tfguilds/config/Config.java | 40 +-
.../tfguilds/config/ConfigEntry.java | 28 +-
.../me/totalfreedom/tfguilds/guild/Guild.java | 1066 ++++++++++++-----
.../tfguilds/guild/GuildRank.java | 69 --
.../tfguilds/guild/GuildState.java | 41 -
.../tfguilds/guild/GuildWarp.java | 44 -
.../me/totalfreedom/tfguilds/guild/User.java | 141 +++
.../tfguilds/listener/ChatListener.java | 65 +-
.../tfguilds/listener/JoinListener.java | 29 +-
.../tfguilds/sql/SQLDatabase.java | 109 +-
.../tfguilds/sql/SQLGuildData.java | 229 ----
.../tfguilds/sql/SQLRankData.java | 150 ---
.../tfguilds/sql/SQLUserData.java | 155 ---
.../tfguilds/sql/SQLWarpData.java | 134 ---
.../tfguilds/sql/SQLWorldData.java | 123 --
.../me/totalfreedom/tfguilds/user/User.java | 28 -
.../me/totalfreedom/tfguilds/util/GLog.java | 30 -
.../me/totalfreedom/tfguilds/util/GUtil.java | 76 +-
.../tfguilds/util/PaginationList.java | 3 +-
src/main/resources/config.yml | 22 +-
src/main/resources/database.db | 0
src/main/resources/plugin.yml | 20 +-
96 files changed, 3018 insertions(+), 4291 deletions(-)
create mode 100644 src/main/java/me/totalfreedom/tfguilds/TFMBridge.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/bridge/TFMBridge.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/AddModSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/AddModSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/ChatSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/ChatSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/CreateSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/CreateSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/DeleteWarpSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/DeleteWarpSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/DisbandSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/DisbandSubcommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/GuildChatCommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/HelpSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/HelpSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/HomeSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/HomeSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/InfoSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/InfoSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/InviteSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/InviteSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/JoinSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/JoinSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/KickSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/KickSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/LeaveSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/LeaveSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/ListSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/ListSubcommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/MOTDSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/MotdSubCommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/RemoveModSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/RemoveModSubcommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/RenameSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/RosterSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/RosterSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubcommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/SetMemberSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/SetOwnerSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/SetOwnerSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/SetRankSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/SetStateSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/SetStateSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/SubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/TPSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/TagSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/TagSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/ToggleTagsSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/ToggleTagsSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/TpSubCommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/WarpSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/WarpSubcommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/WarpsSubCommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/command/WarpsSubcommand.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/guild/GuildRank.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/guild/GuildState.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/guild/GuildWarp.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/guild/User.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/sql/SQLWarpData.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/user/User.java
delete mode 100644 src/main/java/me/totalfreedom/tfguilds/util/GLog.java
delete mode 100644 src/main/resources/database.db
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 86bb373..9898a0e 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -9,24 +9,6 @@
-
-
-
-
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index b4f03dc..e67be4a 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -11,7 +11,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index bcc693d..b008060 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -6,35 +6,35 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/TFGuilds.iml b/TFGuilds.iml
index d0c8bd9..f2e91f0 100644
--- a/TFGuilds.iml
+++ b/TFGuilds.iml
@@ -9,7 +9,7 @@
-
+
@@ -19,26 +19,13 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
@@ -68,6 +55,7 @@
+
@@ -87,6 +75,7 @@
+
@@ -105,6 +94,13 @@
-
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index d54f138..c7b46d6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -63,29 +63,19 @@
spigotmc-repo
https://hub.spigotmc.org/nexus/content/repositories/snapshots/
-
- sonatype
- https://oss.sonatype.org/content/groups/public/
-
org.spigotmc
spigot-api
- 1.16.4-R0.1-SNAPSHOT
+ 1.16.5-R0.1-SNAPSHOT
provided
com.github.AtlasMediaGroup
TotalFreedomMod
- development-0be2aa718f-1
- provided
-
-
- org.projectlombok
- lombok
- 1.18.16
+ main-SNAPSHOT
provided
diff --git a/src/main/java/me/totalfreedom/tfguilds/Common.java b/src/main/java/me/totalfreedom/tfguilds/Common.java
index 1d036a7..ffd279a 100644
--- a/src/main/java/me/totalfreedom/tfguilds/Common.java
+++ b/src/main/java/me/totalfreedom/tfguilds/Common.java
@@ -1,37 +1,23 @@
package me.totalfreedom.tfguilds;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-import me.totalfreedom.tfguilds.config.ConfigEntry;
-import me.totalfreedom.tfguilds.guild.Guild;
-import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
public class Common
{
- protected static TFGuilds plugin = TFGuilds.getPlugin();
- public static final ChatColor PRIMARY = ConfigEntry.SCHEME_PRIMARY.getChatColor();
- public static final ChatColor SECONDARY = ConfigEntry.SCHEME_SECONDARY.getChatColor();
- public static final String NO_PERMS = ChatColor.RED + "No permission.";
- public static final String PREFIX = "%s%[%p%TFGuilds%s%] %p%";
- public static final String PNF = ChatColor.RED + "Player not found.";
- public static final String NG = ChatColor.RED + "You aren't in a guild!";
+ public static final String PREFIX = ChatColor.AQUA + "TFGuilds " + ChatColor.DARK_GRAY + "\u00BB " + ChatColor.GRAY;
+ public static final String NOT_IN_GUILD = PREFIX + "You are not in a guild.";
+ public static final String IN_GUILD = PREFIX + "You are already in a guild.";
+ public static final String PLAYER_NOT_FOUND = PREFIX + "That player is not online.";
+ public static final String PLAYER_NOT_IN_GUILD = PREFIX + "That player is not in your guild.";
+ public static final String IN_GAME_ONLY = PREFIX + "You must be in-game to interact with guilds";
+ public static final String USAGE = PREFIX + "Correct usage: " + ChatColor.GOLD;
- public static Map INVITES = new HashMap<>();
- public static List IN_GUILD_CHAT = new ArrayList<>();
- public static List CHAT_SPY = new ArrayList<>();
+ public static final TFMBridge tfmBridge = TFGuilds.getPlugin().getTfmBridge();
- public static String tl(String in)
- {
- return in.replaceAll("%p%", PRIMARY + "").replaceAll("%s%", SECONDARY + "");
- }
-
- public static void broadcast(String msg)
- {
- Bukkit.broadcastMessage(msg);
- }
-}
\ No newline at end of file
+ public static List GUILD_CHAT = new ArrayList<>();
+ public static List GUILD_CHAT_SPY = new ArrayList<>();
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
index c68d26b..25b2f96 100644
--- a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
+++ b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
@@ -1,91 +1,115 @@
package me.totalfreedom.tfguilds;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
-import me.totalfreedom.tfguilds.bridge.TFMBridge;
-import me.totalfreedom.tfguilds.command.GuildChatCommand;
-import me.totalfreedom.tfguilds.command.GuildChatSpyCommand;
-import me.totalfreedom.tfguilds.command.GuildCommand;
-import me.totalfreedom.tfguilds.command.TFGuildsCommand;
+import me.totalfreedom.tfguilds.command.*;
import me.totalfreedom.tfguilds.config.Config;
import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.guild.GuildWarp;
+import me.totalfreedom.tfguilds.guild.User;
import me.totalfreedom.tfguilds.listener.ChatListener;
import me.totalfreedom.tfguilds.listener.JoinListener;
import me.totalfreedom.tfguilds.sql.SQLDatabase;
-import me.totalfreedom.tfguilds.sql.SQLGuildData;
-import me.totalfreedom.tfguilds.sql.SQLRankData;
-import me.totalfreedom.tfguilds.sql.SQLUserData;
-import me.totalfreedom.tfguilds.sql.SQLWarpData;
-import me.totalfreedom.tfguilds.sql.SQLWorldData;
-import me.totalfreedom.tfguilds.util.GLog;
-import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
-public final class TFGuilds extends JavaPlugin
+public class TFGuilds extends JavaPlugin
{
- // TEMP FIX UNTIL REWRITE
- public Map guilds;
- public Map warps;
-
private static TFGuilds plugin;
+ private Config config;
+ private SQLDatabase sqlDatabase;
+ private TFMBridge tfmBridge;
+ private Map subCommands = new HashMap<>();
public static TFGuilds getPlugin()
{
return plugin;
}
- public Config config;
- public TFMBridge bridge;
- public SQLDatabase sql;
- public SQLGuildData guildData;
- public SQLRankData rankData;
- public SQLUserData userData;
- public SQLWarpData warpData;
- public SQLWorldData worldData;
-
@Override
public void onEnable()
{
- plugin = this;
+ this.plugin = this;
config = new Config("config.yml");
- bridge = new TFMBridge();
- guilds = new HashMap<>();
- warps = new HashMap<>();
- sql = new SQLDatabase();
- guildData = new SQLGuildData();
- rankData = new SQLRankData();
- userData = new SQLUserData();
- warpData = new SQLWarpData();
- worldData = new SQLWorldData();
- guildData.getAll();
- warpData.getAll();
- loadCommands();
- loadListeners();
- GLog.info("Enabled " + this.getDescription().getFullName());
+ sqlDatabase = new SQLDatabase(this);
+ User.loadAll();
+ Guild.loadAll();
+ tfmBridge = new TFMBridge();
+ tfmBridge.getTfm();
+ new JoinListener(this);
+ new ChatListener(this);
+ loadSubCommands();
+ getCommand("tfguilds").setExecutor(new TFGuildsCommand());
+ getCommand("guild").setExecutor(new GuildCommand());
+ getCommand("guildchatspy").setExecutor(new GuildChatSpyCommand());
}
@Override
public void onDisable()
{
- plugin = null;
config.save();
- GLog.info("Disabled " + this.getDescription().getFullName());
+ this.plugin = null;
}
- private void loadCommands()
+ public Config getConfig()
{
- this.getCommand("guild").setExecutor(new GuildCommand());
- this.getCommand("guildchat").setExecutor(new GuildChatCommand());
- this.getCommand("tfguilds").setExecutor(new TFGuildsCommand());
- this.getCommand("guildchatspy").setExecutor(new GuildChatSpyCommand());
+ return config;
}
- private void loadListeners()
+ public SQLDatabase getSQL()
{
- PluginManager manager = this.getServer().getPluginManager();
- manager.registerEvents(new ChatListener(), this);
- manager.registerEvents(new JoinListener(), this);
+ return sqlDatabase;
}
-}
\ No newline at end of file
+
+ public TFMBridge getTfmBridge()
+ {
+ return tfmBridge;
+ }
+
+ public SubCommand getSubCommand(String name)
+ {
+ return subCommands.get(name);
+ }
+
+ public List getSubCommands()
+ {
+ List commands = new ArrayList<>(subCommands.keySet());
+ Collections.sort(commands);
+ return commands;
+ }
+
+ private void loadSubCommands()
+ {
+ subCommands.put("create", new CreateSubCommand());
+ subCommands.put("info", new InfoSubCommand());
+ subCommands.put("disband", new DisbandSubCommand());
+ subCommands.put("invite", new InviteSubCommand());
+ subCommands.put("join", new JoinSubCommand());
+ subCommands.put("leave", new LeaveSubCommand());
+ subCommands.put("warps", new WarpsSubCommand());
+ subCommands.put("setwarp", new SetWarpSubCommand());
+ subCommands.put("addmod", new AddModSubCommand());
+ subCommands.put("removemod", new RemoveModSubCommand());
+ subCommands.put("createrank", new CreateRankSubCommand());
+ subCommands.put("deleterank", new DeleteRankSubCommand());
+ subCommands.put("warp", new WarpSubCommand());
+ subCommands.put("setrank", new SetRankSubCommand());
+ subCommands.put("deletewarp", new DeleteWarpSubCommand());
+ subCommands.put("kick", new KickSubCommand());
+ subCommands.put("setowner", new SetOwnerSubCommand());
+ subCommands.put("setstate", new SetStateSubCommand());
+ subCommands.put("setdefaultrank", new SetDefaultRankSubCommand());
+ subCommands.put("home", new HomeSubCommand());
+ subCommands.put("tp", new TpSubCommand());
+ subCommands.put("roster", new RosterSubCommand());
+ subCommands.put("toggletag", new ToggleTagSubCommand());
+ subCommands.put("chat", new ChatSubCommand());
+ subCommands.put("motd", new MotdSubCommand());
+ subCommands.put("toggletags", new ToggleTagsSubCommand());
+ subCommands.put("tag", new TagSubCommand());
+ subCommands.put("list", new ListSubCommand());
+ subCommands.put("help", new HelpSubCommand());
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java b/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java
new file mode 100644
index 0000000..f440b74
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java
@@ -0,0 +1,64 @@
+package me.totalfreedom.tfguilds;
+
+import me.totalfreedom.totalfreedommod.TotalFreedomMod;
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.Plugin;
+
+public class TFMBridge
+{
+
+ private final TFGuilds plugin = TFGuilds.getPlugin();
+ private TotalFreedomMod tfm = null;
+
+ public TotalFreedomMod getTfm()
+ {
+ if (tfm == null)
+ {
+ try
+ {
+ final Plugin tfmPlugin = plugin.getServer().getPluginManager().getPlugin("TotalFreedomMod");
+ if (tfmPlugin != null && tfmPlugin.isEnabled() && tfmPlugin instanceof TotalFreedomMod)
+ {
+ tfm = (TotalFreedomMod)tfmPlugin;
+ }
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ return tfm;
+ }
+
+ public boolean isAdmin(Player player)
+ {
+ if (getTfm() == null)
+ {
+ Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead.");
+ return player.isOp();
+ }
+ return getTfm().al.isAdmin(player);
+ }
+
+ public boolean isAdmin(CommandSender sender)
+ {
+ if (getTfm() == null)
+ {
+ Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead.");
+ return sender.isOp();
+ }
+ return getTfm().al.isAdmin(sender);
+ }
+
+ public boolean isVanished(Player player)
+ {
+ if (getTfm() == null)
+ {
+ Bukkit.getLogger().warning("TotalFreedomMod not detected, vanish will return false.");
+ return false;
+ }
+ return getTfm().al.isVanished(player.getName());
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/bridge/TFMBridge.java b/src/main/java/me/totalfreedom/tfguilds/bridge/TFMBridge.java
deleted file mode 100644
index d63ef18..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/bridge/TFMBridge.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package me.totalfreedom.tfguilds.bridge;
-
-import me.totalfreedom.tfguilds.TFGuilds;
-import me.totalfreedom.tfguilds.util.GLog;
-import me.totalfreedom.totalfreedommod.TotalFreedomMod;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-import org.bukkit.plugin.Plugin;
-
-public class TFMBridge
-{
- private final TFGuilds plugin;
- private TotalFreedomMod tfmPlugin;
-
- public TFMBridge()
- {
- this.plugin = TFGuilds.getPlugin();
- this.tfmPlugin = null;
- }
-
- public TotalFreedomMod getTFM()
- {
- if (tfmPlugin == null)
- {
- try
- {
- final Plugin tfm = plugin.getServer().getPluginManager().getPlugin("TotalFreedomMod");
- if (tfm != null && tfm instanceof TotalFreedomMod)
- {
- tfmPlugin = (TotalFreedomMod)tfm;
- }
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
- return tfmPlugin;
- }
-
- public boolean isAdmin(Player player)
- {
- if (getTFM() == null)
- {
- GLog.warn("TFM not detected on the server. Checking if player is OP...");
- return player.isOp();
- }
-
- return getTFM().al.isAdmin(player);
- }
-
- public boolean isAdmin(CommandSender sender)
- {
- if (getTFM() == null)
- {
- GLog.warn("TFM not detected on the server. Checking if sender is OP...");
- return sender.isOp();
- }
-
- return getTFM().al.isAdmin(sender);
- }
-
- public boolean isVanished(Player player)
- {
- if (getTFM() == null)
- {
- GLog.warn("TFM not detected on the server.");
- return false;
- }
- return getTFM().al.isVanished(player.getName());
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/AddModSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/AddModSubCommand.java
new file mode 100644
index 0000000..843f850
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/AddModSubCommand.java
@@ -0,0 +1,70 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class AddModSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length != 2)
+ {
+ sender.sendMessage(USAGE + "/g addmod ");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ Player player = Bukkit.getPlayer(args[1]);
+ if (player == null || tfmBridge.isVanished(player))
+ {
+ sender.sendMessage(PLAYER_NOT_FOUND);
+ return;
+ }
+
+ if (!guild.getOwner().equals(playerSender.getUniqueId()))
+ {
+ sender.sendMessage(PREFIX + "You must be the guild owner to add moderators!");
+ return;
+ }
+
+ if (playerSender.equals(player))
+ {
+ sender.sendMessage(PREFIX + "You are the owner of your guild, you are already a moderator.");
+ return;
+ }
+
+ if (!guild.isMember(player))
+ {
+ sender.sendMessage(PLAYER_NOT_IN_GUILD);
+ return;
+ }
+
+ if (guild.isModerator(player))
+ {
+ sender.sendMessage(PREFIX + "That player is already a moderator!");
+ return;
+ }
+
+ guild.addModerator(player);
+ sender.sendMessage(PREFIX + "Successfully added " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " as a moderator.");
+ player.sendMessage(PREFIX + "You are now a guild moderator for your guild!");
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/AddModSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/AddModSubcommand.java
deleted file mode 100644
index 81c37d0..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/AddModSubcommand.java
+++ /dev/null
@@ -1,123 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.util.GUtil;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class AddModSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length == 1 || args.length > 3)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g addmod | player>"));
- return true;
- }
-
- if (args.length == 3)
- {
- if (!plugin.bridge.isAdmin(sender))
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Guild guild = Guild.getGuild(args[1]);
- if (guild == null)
- {
- sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
- return true;
- }
-
- Player player = Bukkit.getPlayer(args[2]);
- if (player == null)
- {
- sender.sendMessage(PNF);
- return true;
- }
-
- if (!guild.hasMember(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
- return true;
- }
-
- if (guild.getOwner().equals(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "No need to make the owner a moderator!");
- return true;
- }
-
- if (guild.hasModerator(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "This member is already a moderator for this guild!");
- return true;
- }
-
- guild.addModerator(player.getUniqueId());
- sender.sendMessage(tl(PREFIX + "Added %s%" + player.getName() + "%p% as a moderator for %s%" + GUtil.colorize(guild.getName()) + "%p%."));
- guild.broadcast(tl("%s%" + player.getName() + " %p%has been made a moderator of your guild."));
- guild.save();
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (!guild.getOwner().equals(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You can't change who is a moderator in your guild!");
- return true;
- }
-
- Player n = Bukkit.getPlayer(args[1]);
- if (n == null)
- {
- sender.sendMessage(PNF);
- return true;
- }
-
- if (guild.getOwner().equals(n.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "No need to make yourself a moderator!");
- return true;
- }
-
- if (!guild.hasMember(n.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
- return true;
- }
-
- if (guild.hasModerator(n.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "This member is already a moderator for your guild!");
- return true;
- }
-
- guild.addModerator(n.getUniqueId());
- sender.sendMessage(tl(PREFIX + "Added %s%" + n.getName() + "%p% as a moderator for your guild."));
- guild.broadcast(tl("%s%" + n.getName() + " %p%has been made a moderator of your guild."));
- guild.save();
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ChatSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ChatSubCommand.java
new file mode 100644
index 0000000..bd2fa2c
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/ChatSubCommand.java
@@ -0,0 +1,46 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class ChatSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (args.length >= 2)
+ {
+ String message = StringUtils.join(args, " ", 1, args.length);
+ guild.chat(playerSender, message);
+ return;
+ }
+
+ if (GUILD_CHAT.contains(playerSender))
+ {
+ GUILD_CHAT.remove(playerSender);
+ sender.sendMessage(PREFIX + "Guild chat " + ChatColor.GOLD + "disabled");
+ return;
+ }
+
+ GUILD_CHAT.add(playerSender);
+ sender.sendMessage(PREFIX + "Guild chat " + ChatColor.GOLD + "enabled");
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ChatSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ChatSubcommand.java
deleted file mode 100644
index 427036a..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/ChatSubcommand.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class ChatSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (args.length >= 2)
- {
- String message = StringUtils.join(args, " ", 1, args.length);
- guild.chat(player.getName(), message);
- return true;
- }
-
- if (IN_GUILD_CHAT.contains(player))
- {
- IN_GUILD_CHAT.remove(player);
- sender.sendMessage(tl("%p%Guild chat toggled off."));
- return true;
- }
-
- IN_GUILD_CHAT.add(player);
- sender.sendMessage(tl("%p%Guild chat toggled on."));
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubCommand.java
new file mode 100644
index 0000000..4413ca9
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubCommand.java
@@ -0,0 +1,70 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import me.totalfreedom.tfguilds.util.GUtil;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class CreateRankSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length < 2)
+ {
+ sender.sendMessage(USAGE + " /g createrank ");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (!guild.getOwner().equals(playerSender.getUniqueId()))
+ {
+ sender.sendMessage(PREFIX + "Only the guild owner can create ranks for the guild!");
+ return;
+ }
+
+ String name = StringUtils.join(args, " ", 1, args.length);
+ if (!StringUtils.isAlphanumericSpace(name) || name.isBlank())
+ {
+ sender.sendMessage(PREFIX + "The rank name must be alphanumeric!");
+ return;
+ }
+
+ if (name.length() > 15)
+ {
+ sender.sendMessage(PREFIX + "The rank name cannot go over 15 characters limit.");
+ return;
+ }
+
+ if (GUtil.containsBlacklistedWord(name))
+ {
+ sender.sendMessage(PREFIX + "The guild name contains a blacklisted word.");
+ return;
+ }
+
+ if (guild.hasRank(name))
+ {
+ sender.sendMessage(PREFIX + "That rank already exists!");
+ return;
+ }
+
+ guild.createRank(name);
+ sender.sendMessage(PREFIX + "Successfully created a new rank " + ChatColor.GOLD + name);
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubcommand.java
deleted file mode 100644
index a8021ed..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/CreateRankSubcommand.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.util.GUtil;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class CreateRankSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- if (args.length < 2)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g createrank "));
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (!guild.getOwner().equals(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You can't create ranks for your guild!");
- return true;
- }
-
- String rank = StringUtils.join(args, " ", 1, args.length);
-
- for (String blacklisted : GUtil.BLACKLISTED_NAMES_AND_TAGS)
- {
- if (rank.equalsIgnoreCase(blacklisted))
- {
- if (!plugin.bridge.isAdmin(player))
- {
- player.sendMessage(ChatColor.RED + "You may not use that name.");
- return true;
- }
- }
- }
-
- Pattern pattern = Pattern.compile("^[A-Za-z0-9? ,_-]+$");
- Matcher matcher = pattern.matcher(rank);
-
- if (!matcher.matches())
- {
- sender.sendMessage(ChatColor.RED + "Guild rank names must be alphanumeric.");
- return true;
- }
-
- if (rank.length() > 15)
- {
- sender.sendMessage(ChatColor.RED + "Guild rank names may not be over 15 characters.");
- return true;
- }
-
- if (guild.hasRank(rank))
- {
- sender.sendMessage(ChatColor.RED + "A rank of that name already exists in the guild!");
- return true;
- }
-
- guild.addRank(rank);
- sender.sendMessage(tl(PREFIX + "Created a new rank named %s%" + rank + "%p% for your guild."));
- guild.save();
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/CreateSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/CreateSubCommand.java
new file mode 100644
index 0000000..39314bb
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/CreateSubCommand.java
@@ -0,0 +1,65 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import me.totalfreedom.tfguilds.util.GUtil;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class CreateSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length < 2)
+ {
+ sender.sendMessage(USAGE + "/g create ");
+ return;
+ }
+
+ if (Guild.isAlreadyMember(playerSender))
+ {
+ sender.sendMessage(IN_GUILD);
+ return;
+ }
+
+ String name = StringUtils.join(args, " ", 1, args.length);
+ if (!StringUtils.isAlphanumericSpace(name) || name.isBlank())
+ {
+ sender.sendMessage(PREFIX + "The guild name must be alphanumeric.");
+ return;
+ }
+
+ if (name.length() > 30)
+ {
+ sender.sendMessage(PREFIX + "The guild name cannot go over 30 characters limit.");
+ return;
+ }
+
+ if (Guild.hasGuild(name))
+ {
+ sender.sendMessage(PREFIX + "The guild name is already taken.");
+ return;
+ }
+
+ if (GUtil.containsBlacklistedWord(name))
+ {
+ sender.sendMessage(PREFIX + "The guild name contains a blacklisted word.");
+ return;
+ }
+
+ Guild.create(playerSender, name);
+ sender.sendMessage(PREFIX + "The guild " + ChatColor.GOLD + name + ChatColor.GRAY + " has been created.");
+ Bukkit.broadcastMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has created a guild " + ChatColor.GOLD + name);
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/CreateSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/CreateSubcommand.java
deleted file mode 100644
index 23212cb..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/CreateSubcommand.java
+++ /dev/null
@@ -1,81 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.util.GUtil;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class CreateSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- if (args.length < 2)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g create "));
- return true;
- }
-
- Player player = (Player)sender;
- String name = StringUtils.join(args, " ", 1, args.length);
- String identifier = GUtil.flatten(name);
-
- if (Guild.isInGuild(player))
- {
- sender.sendMessage(ChatColor.RED + "You are already in a guild!");
- return true;
- }
-
- Pattern pattern = Pattern.compile("^[A-Za-z0-9? ,_-]+$");
- Matcher matcher = pattern.matcher(name);
-
- if (!matcher.matches())
- {
- sender.sendMessage(ChatColor.RED + "Guild names must be alphanumeric.");
- return true;
- }
-
- if (name.length() > 30)
- {
- sender.sendMessage(ChatColor.RED + "Your guild name may not be over 30 characters.");
- return true;
- }
-
- if (Guild.guildExists(identifier))
- {
- sender.sendMessage(ChatColor.RED + "A guild with a name similar to yours already exists!");
- return true;
- }
-
- for (String blacklisted : GUtil.BLACKLISTED_NAMES_AND_TAGS)
- {
- if (name.equalsIgnoreCase(blacklisted))
- {
- if (!plugin.bridge.isAdmin(player))
- {
- player.sendMessage(ChatColor.RED + "You may not use that name.");
- return true;
- }
- }
- }
-
- Guild.createGuild(identifier, name, player);
- sender.sendMessage(tl(PREFIX + "Created a guild named \"" + GUtil.colorize(name) + "%p%\"!"));
- broadcast(GUtil.colorize(tl("%p%" + sender.getName() + " has created guild %p%&l" + name)));
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubCommand.java
new file mode 100644
index 0000000..d41a270
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubCommand.java
@@ -0,0 +1,51 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class DeleteRankSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length < 2)
+ {
+ sender.sendMessage(USAGE + "/g deleterank ");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(PREFIX + "You are not in a guild!");
+ return;
+ }
+
+ if (!guild.getOwner().equals(playerSender.getUniqueId()))
+ {
+ sender.sendMessage(PREFIX + "Only the guild owner can delete ranks for the guild!");
+ return;
+ }
+
+ String name = StringUtils.join(args, " ", 1, args.length);
+ if (!guild.hasRank(name))
+ {
+ sender.sendMessage(PREFIX + "That rank does not exist!");
+ return;
+ }
+
+ guild.deleteRank(name);
+ sender.sendMessage(PREFIX + "Successfully deleted a rank " + ChatColor.GOLD + name);
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubcommand.java
deleted file mode 100644
index e006e93..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/DeleteRankSubcommand.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class DeleteRankSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- if (args.length < 2)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g deleterank "));
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (!guild.getOwner().equals(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You can't delete ranks from your guild!");
- return true;
- }
-
- String rank = StringUtils.join(args, " ", 1, args.length);
- if (!guild.hasRank(rank))
- {
- sender.sendMessage(ChatColor.RED + "A rank of that name does not exist in the guild!");
- return true;
- }
-
- guild.removeRank(rank);
-
- if (guild.hasDefaultRank() && rank.equals(guild.getDefaultRank()))
- {
- guild.setDefaultRank(null);
- guild.save();
- }
-
- sender.sendMessage(tl(PREFIX + "Deleted the rank named %s%" + rank + "%p% in your guild."));
- guild.save();
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DeleteWarpSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DeleteWarpSubCommand.java
new file mode 100644
index 0000000..9cd8f88
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/DeleteWarpSubCommand.java
@@ -0,0 +1,51 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class DeleteWarpSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length < 2)
+ {
+ sender.sendMessage(USAGE + "/g deletewarp ");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (!guild.isModerator(playerSender))
+ {
+ sender.sendMessage(PREFIX + "You must be a guild moderator or owner to create a warp for the guild.");
+ return;
+ }
+
+ String name = StringUtils.join(args, " ", 1, args.length);
+ if (!guild.hasWarp(name))
+ {
+ sender.sendMessage(PREFIX + "That warp does not exist.");
+ return;
+ }
+
+ guild.removeWarp(name);
+ sender.sendMessage(PREFIX + "Successfully removed a warp " + ChatColor.GOLD + name);
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DeleteWarpSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DeleteWarpSubcommand.java
deleted file mode 100644
index 9d284f1..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/DeleteWarpSubcommand.java
+++ /dev/null
@@ -1,57 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.guild.GuildWarp;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class DeleteWarpSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length < 2)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g deletewarp "));
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (!guild.hasModerator(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "Only guild moderators and guild owners are allowed to create guild warps.");
- return true;
- }
-
- String warpName = StringUtils.join(args, " ", 1, args.length);
- if (!guild.warpExists(warpName))
- {
- sender.sendMessage(ChatColor.RED + "Warp not found.");
- return true;
- }
-
- GuildWarp warp = plugin.warpData.get(guild.getIdentifier(), warpName);
- plugin.warpData.delete(warp);
- sender.sendMessage(tl(PREFIX + "Deleted guild warp \"" + warpName + "\"."));
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubCommand.java
new file mode 100644
index 0000000..e26b6b9
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubCommand.java
@@ -0,0 +1,60 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class DisbandSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length >= 2)
+ {
+ if (!tfmBridge.isAdmin(sender))
+ {
+ sender.sendMessage(PREFIX + "You do not have permission.");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(PREFIX + "That guild does not exist.");
+ return;
+ }
+
+ guild.disband();
+ sender.sendMessage(PREFIX + "The guild " + ChatColor.GOLD + guild.getName() + ChatColor.GRAY + " has been disbanded.");
+ Bukkit.broadcastMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has disbanded the guild " + ChatColor.GOLD + guild.getName());
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (!guild.getOwner().equals(playerSender.getUniqueId()))
+ {
+ sender.sendMessage(PREFIX + "You are not the guild owner!");
+ return;
+ }
+
+ sender.sendMessage(PREFIX + "The guild " + ChatColor.GOLD + guild.getName() + ChatColor.GRAY + " has been disbanded.");
+ Bukkit.broadcastMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has disbanded the guild " + ChatColor.GOLD + guild.getName());
+ guild.disband();
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubcommand.java
deleted file mode 100644
index c72c460..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubcommand.java
+++ /dev/null
@@ -1,77 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.util.GLog;
-import me.totalfreedom.tfguilds.util.GUtil;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class DisbandSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length > 2)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g disband [name]"));
- return true;
- }
-
- if (args.length == 2)
- {
- if (!plugin.bridge.isAdmin(sender))
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Guild guild = Guild.getGuild(GUtil.flatten(StringUtils.join(args, " ", 1, args.length)));
- if (guild == null)
- {
- sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
- return true;
- }
-
- String n = guild.getName();
- GLog.info("Removing guild data for " + n);
- guild.disband();
- GLog.info(sender.getName() + " deleted guild " + guild.getName());
- sender.sendMessage(tl(PREFIX + "Disbanded \"" + GUtil.colorize(n) + "%p%\"."));
- broadcast(GUtil.colorize(tl("%p%" + sender.getName() + " has disbanded guild %p%&l" + guild.getName())));
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- if (!Guild.isInGuild(player))
- {
- sender.sendMessage(NG);
- return true;
- }
-
- Guild guild = Guild.getGuild(player);
- if (!guild.getOwner().equals(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You are not the owner of this guild!");
- return true;
- }
-
- GLog.info("Removing guild data for " + guild.getName());
- guild.disband();
- GLog.info(player.getName() + " deleted guild " + guild.getName());
- sender.sendMessage(tl(PREFIX + "You have disbanded your guild!"));
- broadcast(GUtil.colorize(tl("%p%&l" + guild.getName() + "%p% has been disbanded")));
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/GuildChatCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/GuildChatCommand.java
deleted file mode 100644
index 428f42b..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/GuildChatCommand.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class GuildChatCommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (args.length >= 1)
- {
- String message = StringUtils.join(args, " ", 0, args.length);
- guild.chat(player.getName(), message);
- return true;
- }
-
- if (IN_GUILD_CHAT.contains(player))
- {
- IN_GUILD_CHAT.remove(player);
- sender.sendMessage(tl("%p%Guild chat toggled off."));
- return true;
- }
-
- IN_GUILD_CHAT.add(player);
- sender.sendMessage(tl("%p%Guild chat toggled on."));
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/GuildChatSpyCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/GuildChatSpyCommand.java
index a05960e..286d672 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/GuildChatSpyCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/GuildChatSpyCommand.java
@@ -1,39 +1,40 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
+import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public class GuildChatSpyCommand extends Common implements CommandExecutor
{
+
@Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
+ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
- if (sender instanceof ConsoleCommandSender)
+ if (!(sender instanceof Player))
{
- sender.sendMessage(NO_PERMS);
+ sender.sendMessage(PREFIX + "Console can already view guild chat.");
return true;
}
- if (!plugin.bridge.isAdmin(sender))
+ if (!tfmBridge.isAdmin(sender))
{
- sender.sendMessage(NO_PERMS);
+ sender.sendMessage(PREFIX + "You do not have the permission.");
return true;
}
Player player = (Player)sender;
- if (CHAT_SPY.contains(player))
+ if (GUILD_CHAT_SPY.contains(player))
{
- CHAT_SPY.remove(player);
- sender.sendMessage(tl(PREFIX + "%p%Global guild chat spy disabled."));
+ GUILD_CHAT_SPY.remove(player);
+ sender.sendMessage(PREFIX + ChatColor.GOLD + "Disabled " + ChatColor.GRAY + "guild chat spy.");
return true;
}
- CHAT_SPY.add(player);
- sender.sendMessage(tl(PREFIX + "%p%Global guild chat spy enabled."));
+ GUILD_CHAT_SPY.add(player);
+ sender.sendMessage(PREFIX + ChatColor.GOLD + "Enabled " + ChatColor.GRAY + "guild chat spy.");
return true;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
index 60a4e99..13af0f3 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
@@ -1,11 +1,10 @@
package me.totalfreedom.tfguilds.command;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.util.GUtil;
+import me.totalfreedom.tfguilds.TFGuilds;
+import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
@@ -14,209 +13,36 @@ import org.bukkit.entity.Player;
public class GuildCommand extends Common implements CommandExecutor, TabCompleter
{
+
@Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
+ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
+ Player playerSender = null;
+ if (sender instanceof Player)
+ {
+ playerSender = (Player)sender;
+ }
+
if (args.length >= 1)
{
- switch (args[0].toLowerCase())
+ String name = args[0].toLowerCase();
+ SubCommand command = TFGuilds.getPlugin().getSubCommand(name);
+ if (command != null)
{
- // Please keep the commands here & in HelpSubcommand.java in alphabetical order
- case "addmod":
- return new AddModSubcommand().onCommand(sender, command, label, args);
- case "chat":
- return new ChatSubcommand().onCommand(sender, command, label, args);
- case "createrank":
- return new CreateRankSubcommand().onCommand(sender, command, label, args);
- case "create":
- return new CreateSubcommand().onCommand(sender, command, label, args);
- case "deleterank":
- return new DeleteRankSubcommand().onCommand(sender, command, label, args);
- case "deletewarp":
- return new DeleteWarpSubcommand().onCommand(sender, command, label, args);
- case "disband":
- return new DisbandSubcommand().onCommand(sender, command, label, args);
- case "help":
- return new HelpSubcommand().onCommand(sender, command, label, args);
- case "home":
- return new HomeSubcommand().onCommand(sender, command, label, args);
- case "info":
- return new InfoSubcommand().onCommand(sender, command, label, args);
- case "invite":
- return new InviteSubcommand().onCommand(sender, command, label, args);
- case "join":
- return new JoinSubcommand().onCommand(sender, command, label, args);
- case "kick":
- return new KickSubcommand().onCommand(sender, command, label, args);
- case "leave":
- return new LeaveSubcommand().onCommand(sender, command, label, args);
- case "list":
- return new ListSubcommand().onCommand(sender, command, label, args);
- case "motd":
- return new MOTDSubcommand().onCommand(sender, command, label, args);
- case "removemod":
- return new RemoveModSubcommand().onCommand(sender, command, label, args);
- case "rename":
- return new RenameSubcommand().onCommand(sender, command, label, args);
- case "roster":
- return new RosterSubcommand().onCommand(sender, command, label, args);
- case "setdefaultrank":
- return new SetDefaultRankSubcommand().onCommand(sender, command, label, args);
- case "setmember":
- return new SetMemberSubcommand().onCommand(sender, command, label, args);
- case "setowner":
- return new SetOwnerSubcommand().onCommand(sender, command, label, args);
- case "setrank":
- return new SetRankSubcommand().onCommand(sender, command, label, args);
- case "setstate":
- return new SetStateSubcommand().onCommand(sender, command, label, args);
- case "setwarp":
- return new SetWarpSubcommand().onCommand(sender, command, label, args);
- case "tag":
- return new TagSubcommand().onCommand(sender, command, label, args);
- case "toggletags":
- return new ToggleTagsSubcommand().onCommand(sender, command, label, args);
- case "toggletag":
- return new ToggleTagSubcommand().onCommand(sender, command, label, args);
- case "tp":
- return new TPSubcommand().onCommand(sender, command, label, args);
- case "warps":
- return new WarpsSubcommand().onCommand(sender, command, label, args);
- case "warp":
- return new WarpSubcommand().onCommand(sender, command, label, args);
+ command.execute(sender, playerSender, args);
+ }
+ else
+ {
+ sender.sendMessage(PREFIX + "Unknown subcommand, do " + ChatColor.GOLD + "/g help" + ChatColor.GRAY + " for help.");
}
- sender.sendMessage(tl(PREFIX + "Unknown command - Run /g help if you need help"));
return true;
}
- return new HelpSubcommand().onCommand(sender, command, label, args);
+ return true;
}
@Override
- public List onTabComplete(CommandSender sender, Command command, String label, String[] args)
+ public List onTabComplete(CommandSender sender, Command cmd, String label, String[] args)
{
- if (args.length == 1)
- {
- return Arrays.asList("addmod", "chat", "createrank", "create",
- "deleterank", "deletewarp", "disband", "help", "home", "info", "invite",
- "join", "kick", "leave", "list", "motd", "removemod", "rename",
- "roster", "setdefaultrank", "setmember", "setowner", "setrank", "setstate",
- "setwarp", "tag", "toggletags", "toggletag", "tp", "warps", "warp");
- }
- else if (args.length == 2)
- {
- switch (args[0])
- {
- case "home":
- {
- return Arrays.asList("set");
- }
-
- case "info":
- case "join":
- case "roster":
- case "setmember":
- {
- return Guild.getGuildList();
- }
-
- case "toggletag":
- {
- if (!plugin.bridge.isAdmin(sender))
- {
- return Collections.emptyList();
- }
-
- return GUtil.getPlayerList();
- }
-
- case "motd":
- case "tag":
- {
- return Arrays.asList("set", "clear");
- }
-
- case "setstate":
- {
- return Arrays.asList("OPEN", "INVITE", "CLOSED");
- }
-
- case "invite":
- {
- return GUtil.getPlayerList();
- }
-
- case "deleterank":
- case "setdefaultrank":
- {
- if (sender instanceof Player)
- {
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild.getOwner().equals(player.getUniqueId()))
- {
- return guild.getRankNames();
- }
- }
- }
-
- case "tp":
- {
- if (sender instanceof Player)
- {
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- return guild.getOnlyMembers();
- }
- }
-
- case "disband":
- {
- if (!plugin.bridge.isAdmin(sender))
- {
- return Collections.emptyList();
- }
-
- return Guild.getGuildList();
- }
-
- case "kick":
- {
- if (sender instanceof Player)
- {
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild.hasModerator(player.getUniqueId()))
- {
- return guild.getOnlyMembers();
- }
- }
- }
-
- case "removemod":
- case "addmod":
- case "setowner":
- {
- if (sender instanceof Player)
- {
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild.getOwner().equals(player.getUniqueId()))
- {
- return guild.getOnlyMembers();
- }
- }
- }
-
- case "deletewarp":
- case "warp":
- {
- if (sender instanceof Player)
- {
- return Guild.getGuildWarps();
- }
- }
- }
- }
return Collections.emptyList();
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/HelpSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/HelpSubCommand.java
new file mode 100644
index 0000000..838be05
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/HelpSubCommand.java
@@ -0,0 +1,22 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.TFGuilds;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class HelpSubCommand extends Common implements SubCommand
+{
+
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ sender.sendMessage(PREFIX + "Command List");
+ for (String command : TFGuilds.getPlugin().getSubCommands())
+ {
+ sender.sendMessage(ChatColor.GRAY + " - " + ChatColor.GOLD + command);
+ }
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/HelpSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/HelpSubcommand.java
deleted file mode 100644
index 4ae36a2..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/HelpSubcommand.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-
-public class HelpSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- // Please keep the commands here & in GuildCommand.java in alphabetical order
- sender.sendMessage(tl("%s%[%p%TFGuilds%s%] %p%Command List"));
- sender.sendMessage(tl("%s% - %p%addmod | player>"));
- sender.sendMessage(tl("%s% - %p%chat [message]"));
- sender.sendMessage(tl("%s% - %p%createrank "));
- sender.sendMessage(tl("%s% - %p%create "));
- sender.sendMessage(tl("%s% - %p%deleterank "));
- sender.sendMessage(tl("%s% - %p%deletewarp "));
- sender.sendMessage(tl("%s% - %p%disband [name]"));
- sender.sendMessage(tl("%s% - %p%help"));
- sender.sendMessage(tl("%s% - %p%home [set]"));
- sender.sendMessage(tl("%s% - %p%info [guild | player]"));
- sender.sendMessage(tl("%s% - %p%invite "));
- sender.sendMessage(tl("%s% - %p%join "));
- sender.sendMessage(tl("%s% - %p%kick | player>"));
- sender.sendMessage(tl("%s% - %p%leave"));
- sender.sendMessage(tl("%s% - %p%list [page]"));
- sender.sendMessage(tl("%s% - %p%motd | clear>"));
- sender.sendMessage(tl("%s% - %p%removemod | name>"));
- sender.sendMessage(tl("%s% - %p%rename "));
- sender.sendMessage(tl("%s% - %p%roster [guild | player]"));
- sender.sendMessage(tl("%s% - %p%setdefaultrank "));
- sender.sendMessage(tl("%s% - %p%setmember "));
- sender.sendMessage(tl("%s% - %p%setowner | player>"));
- sender.sendMessage(tl("%s% - %p%setrank "));
- sender.sendMessage(tl("%s% - %p%setstate "));
- sender.sendMessage(tl("%s% - %p%setwarp "));
- sender.sendMessage(tl("%s% - %p%tag | clear [guild]>>"));
- sender.sendMessage(tl("%s% - %p%toggletags"));
- sender.sendMessage(tl("%s% - %p%toggletag [player]"));
- sender.sendMessage(tl("%s% - %p%tp "));
- sender.sendMessage(tl("%s% - %p%warps"));
- sender.sendMessage(tl("%s% - %p%warp "));
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/HomeSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/HomeSubCommand.java
new file mode 100644
index 0000000..236cd56
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/HomeSubCommand.java
@@ -0,0 +1,56 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class HomeSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length > 2)
+ {
+ sender.sendMessage(USAGE + "/g home [set]");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (args.length == 2)
+ {
+ if (args[1].equalsIgnoreCase("set"))
+ {
+ if (!guild.isModerator(playerSender))
+ {
+ sender.sendMessage(PREFIX + "Only guild moderators can set guild's home location");
+ return;
+ }
+
+ guild.setHome(playerSender.getLocation());
+ sender.sendMessage(PREFIX + "Successfully set guild's home to your location");
+ }
+ else
+ {
+ sender.sendMessage(USAGE + "/g home [set]");
+ }
+ return;
+ }
+
+ playerSender.teleport(guild.getHome());
+ sender.sendMessage(PREFIX + "Teleported to your guild's home!");
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/HomeSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/HomeSubcommand.java
deleted file mode 100644
index 9f4c50b..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/HomeSubcommand.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class HomeSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length > 2)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g home [set]"));
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (args.length == 2)
- {
- if (args[1].equalsIgnoreCase("set"))
- {
- if (!guild.hasModerator(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You can't modify your guild's home!");
- return true;
- }
-
- guild.setHome(player.getLocation());
- guild.save();
- sender.sendMessage(tl(PREFIX + "Set your current location as the new home of your guild%p%."));
- return true;
- }
- return false;
- }
-
- if (!guild.hasHome())
- {
- sender.sendMessage(ChatColor.RED + "Your guild doesn't have a home!");
- return true;
- }
-
- player.teleport(guild.getHome());
- sender.sendMessage(tl("%p%Teleported you to your guild's home!"));
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/InfoSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/InfoSubCommand.java
new file mode 100644
index 0000000..b493428
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/InfoSubCommand.java
@@ -0,0 +1,55 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class InfoSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (args.length >= 2)
+ {
+ Player player = Bukkit.getPlayer(args[1]);
+ if (player != null && !tfmBridge.isVanished(player))
+ {
+ Guild guild = Guild.getGuild(player);
+ if (guild != null)
+ {
+ sender.sendMessage(guild.toString());
+ return;
+ }
+ }
+
+ Guild guild = Guild.getGuild(StringUtils.join(args, " ", 1, args.length));
+ if (guild == null)
+ {
+ sender.sendMessage(PREFIX + "That guild does not exist.");
+ return;
+ }
+
+ sender.sendMessage(guild.toString());
+ return;
+ }
+
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(USAGE + "/g info ");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ sender.sendMessage(guild.toString());
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/InfoSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/InfoSubcommand.java
deleted file mode 100644
index fcd4ede..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/InfoSubcommand.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.util.GUtil;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class InfoSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length >= 2)
- {
- Player player = Bukkit.getPlayer(args[1]);
- if (player != null)
- {
- Guild guild = Guild.getGuild(player);
- if (guild != null)
- {
- sender.sendMessage(guild.getInformation());
- return true;
- }
- }
-
- Guild guild = Guild.getGuild(GUtil.flatten(StringUtils.join(args, " ", 1, args.length)));
- if (guild == null)
- {
- sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
- return true;
- }
-
- sender.sendMessage(guild.getInformation());
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Guild guild = Guild.getGuild((Player)sender);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- sender.sendMessage(guild.getInformation());
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/InviteSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/InviteSubCommand.java
new file mode 100644
index 0000000..2dc73f2
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/InviteSubCommand.java
@@ -0,0 +1,98 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.TFGuilds;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+import org.bukkit.scheduler.BukkitRunnable;
+
+public class InviteSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length != 2)
+ {
+ sender.sendMessage(USAGE + "/g invite ");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (guild.getState() == Guild.State.CLOSED)
+ {
+ sender.sendMessage(PREFIX + "The guild is closed.");
+ return;
+ }
+
+ if (guild.getState() == Guild.State.OPEN)
+ {
+ sender.sendMessage(PREFIX + "The guild is open to public, tell your friends to join by " + ChatColor.GOLD + "/g join " + guild.getName());
+ return;
+ }
+
+ Player player = Bukkit.getPlayer(args[1]);
+ if (player == null || tfmBridge.isVanished(player))
+ {
+ sender.sendMessage(PLAYER_NOT_FOUND);
+ return;
+ }
+
+ if (player.equals(playerSender))
+ {
+ sender.sendMessage(PREFIX + "You cannot invite yourself.");
+ return;
+ }
+
+ if (Guild.getGuild(player) != null)
+ {
+ sender.sendMessage(PREFIX + "That player is already in a guild.");
+ return;
+ }
+
+ if (guild.isInvited(player))
+ {
+ sender.sendMessage(PREFIX + "That player is already been invited.");
+ return;
+ }
+
+ guild.invite(player);
+ player.sendMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has sent you an invite to join " + ChatColor.GOLD + guild.getName());
+ player.sendMessage("Do " + ChatColor.GOLD + "/g join " + guild.getName() + ChatColor.GRAY + " to join!");
+ player.sendMessage(PREFIX + "The invite will expire in 90 seconds.");
+ sender.sendMessage(PREFIX + "The invite has been sent to " + ChatColor.GOLD + player.getName());
+
+ new BukkitRunnable()
+ {
+ @Override
+ public void run()
+ {
+ if (!guild.isInvited(player))
+ {
+ return;
+ }
+ guild.removeInvite(player);
+ if (player.isOnline())
+ {
+ player.sendMessage(PREFIX + "The invite to " + ChatColor.GOLD + guild.getName() + ChatColor.GRAY + " has expired!");
+ sender.sendMessage(PREFIX + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " has not accepted your invite.");
+ }
+ }
+ }.runTaskLater(TFGuilds.getPlugin(), 20 * 90);
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/InviteSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/InviteSubcommand.java
deleted file mode 100644
index 34dad7f..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/InviteSubcommand.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.guild.GuildState;
-import me.totalfreedom.tfguilds.util.GUtil;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-import org.bukkit.scheduler.BukkitRunnable;
-
-public class InviteSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- if (args.length != 2)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g invite "));
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- Player invitee = Bukkit.getPlayer(args[1]);
- if (invitee == null || plugin.bridge.isVanished(invitee))
- {
- sender.sendMessage(PNF);
- return true;
- }
-
- if (Guild.getGuild(invitee) != null)
- {
- sender.sendMessage(ChatColor.RED + "This player is already in another guild!");
- return true;
- }
-
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (guild.getState() == GuildState.CLOSED)
- {
- sender.sendMessage(ChatColor.RED + "The guild is currently closed!");
- return true;
- }
-
- if (guild.getState() == GuildState.OPEN)
- {
- sender.sendMessage(ChatColor.RED + "The guild is open! Tell your friend to join using \"/g join\"!");
- return true;
- }
-
- if (INVITES.containsKey(invitee))
- {
- sender.sendMessage(ChatColor.RED + "They have already been invited to your guild!");
- return true;
- }
-
- INVITES.put(invitee, guild);
- invitee.sendMessage(tl("%p%You have been invited to join %s%" + GUtil.colorize(guild.getName()) + "%p% through %s%" + player.getName() + "%p%'s invite!"));
- invitee.sendMessage(tl("%p%Do %s%/g join " + ChatColor.stripColor(GUtil.colorize(guild.getName())) + "%p% to join!"));
- invitee.sendMessage(tl("%p%This invite will expire in 90 seconds."));
- sender.sendMessage(tl("%p%Invite sent!"));
- new BukkitRunnable()
- {
- public void run()
- {
- if (!INVITES.containsKey(invitee))
- {
- return;
- }
- INVITES.remove(player);
- invitee.sendMessage(ChatColor.RED + "Invite expired.");
- sender.sendMessage(ChatColor.RED + "It has been 90 seconds and " + invitee.getName() + " did not accept your invitation.");
- }
- }.runTaskLater(plugin, 20 * 90);
- return true;
- }
-}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/JoinSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/JoinSubCommand.java
new file mode 100644
index 0000000..6780229
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/JoinSubCommand.java
@@ -0,0 +1,60 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class JoinSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length < 2)
+ {
+ sender.sendMessage(USAGE + "/g join ");
+ return;
+ }
+
+ if (Guild.getGuild(playerSender) != null)
+ {
+ sender.sendMessage(IN_GUILD);
+ return;
+ }
+
+ Guild guild = Guild.getGuild(StringUtils.join(args, " ", 1, args.length));
+ if (guild == null)
+ {
+ sender.sendMessage(PREFIX + "That guild does not exist.");
+ return;
+ }
+
+ if (guild.getState() == Guild.State.CLOSED)
+ {
+ sender.sendMessage(PREFIX + "That guild is currently closed.");
+ return;
+ }
+
+ if (guild.getState() == Guild.State.INVITE_ONLY)
+ {
+ if (guild.isInvited(playerSender))
+ {
+ sender.sendMessage(PREFIX + "You must be invited to join the guild.");
+ return;
+ }
+ guild.removeInvite(playerSender);
+ }
+
+ guild.addMember(playerSender);
+ guild.broadcast(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has joined the guild.");
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/JoinSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/JoinSubcommand.java
deleted file mode 100644
index 56a38a2..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/JoinSubcommand.java
+++ /dev/null
@@ -1,67 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.guild.GuildState;
-import me.totalfreedom.tfguilds.util.GUtil;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class JoinSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- if (args.length < 2)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g join "));
- return true;
- }
-
- Player player = (Player)sender;
- if (Guild.getGuild(player) != null)
- {
- sender.sendMessage(ChatColor.RED + "You are already in a guild!");
- return true;
- }
-
- Guild guild = Guild.getGuild(GUtil.flatten(StringUtils.join(args, " ", 1, args.length)));
- if (guild == null)
- {
- sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
- return true;
- }
-
- if (guild.getState() == GuildState.CLOSED)
- {
- sender.sendMessage(ChatColor.RED + "That guild is currently closed!");
- return true;
- }
-
- if (guild.getState() == GuildState.INVITE_ONLY)
- {
- if (!INVITES.containsKey(player))
- {
- sender.sendMessage(ChatColor.RED + "You have not been invited to this guild!");
- return true;
- }
- INVITES.remove(player);
- }
-
- guild.addMember(player.getUniqueId());
- guild.broadcast(tl("%s%" + player.getName() + " %p%has joined the guild."));
- guild.save();
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/KickSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/KickSubCommand.java
new file mode 100644
index 0000000..f869833
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/KickSubCommand.java
@@ -0,0 +1,70 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class KickSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length < 2)
+ {
+ sender.sendMessage(USAGE + "/g kick ");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (!guild.isModerator(playerSender))
+ {
+ sender.sendMessage(PREFIX + "Only the guild owner and moderators can kick members.");
+ return;
+ }
+
+ Player player = Bukkit.getPlayer(args[1]);
+ if (player == null || tfmBridge.isVanished(player))
+ {
+ sender.sendMessage(PLAYER_NOT_FOUND);
+ return;
+ }
+
+ if (playerSender.equals(player))
+ {
+ sender.sendMessage(PREFIX + "You cannot kick yourself.");
+ return;
+ }
+
+ if (guild.getOwner().equals(player.getUniqueId()) || guild.isModerator(player) && !guild.getOwner().equals(playerSender.getUniqueId()))
+ {
+ sender.sendMessage(PREFIX + "You may not kick the guild owner or moderators from your guild.");
+ return;
+ }
+
+ if (!guild.isMember(player))
+ {
+ sender.sendMessage(PLAYER_NOT_IN_GUILD);
+ return;
+ }
+
+ guild.removeMember(player);
+ sender.sendMessage(PREFIX + "Successfully kicked " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " from your guild.");
+ player.sendMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has kicked you from " + ChatColor.GOLD + guild.getName());
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/KickSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/KickSubcommand.java
deleted file mode 100644
index 9e4bc5a..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/KickSubcommand.java
+++ /dev/null
@@ -1,113 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.util.GUtil;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class KickSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length > 3)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g kick | player>"));
- return true;
- }
-
- if (args.length == 3)
- {
- if (!plugin.bridge.isAdmin(sender))
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Guild guild = Guild.getGuild(args[1]);
- if (guild == null)
- {
- sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
- return true;
- }
-
- Player player = Bukkit.getPlayer(args[2]);
- if (player == null)
- {
- sender.sendMessage(PNF);
- return true;
- }
-
- if (!guild.hasMember(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
- return true;
- }
-
- if (guild.getOwner().equals(player.getUniqueId()) || guild.hasModerator(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You cannot kick the owner/moderator(s) of a guild!");
- return true;
- }
-
- guild.removeMember(player.getUniqueId());
- sender.sendMessage(tl(PREFIX + "Kicked %s%" + player.getName() + "%p% from %s%" + GUtil.colorize(guild.getName()) + "%p%."));
- player.sendMessage(tl("%s%You have been kicked from your guild."));
- guild.broadcast(tl("%s%" + player.getName() + " %p%has been kicked from your guild."));
- guild.save();
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (!guild.hasModerator(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You can't kick people from your guild!");
- return true;
- }
-
- Player n = Bukkit.getPlayer(args[1]);
- if (n == null)
- {
- sender.sendMessage(PNF);
- return true;
- }
-
- if (!guild.hasMember(n.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
- return true;
- }
-
- if (guild.getOwner().equals(n.getUniqueId()) || guild.hasModerator(n.getUniqueId()) && !guild.getOwner().equals(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You cannot kick the owner/moderator(s) of a guild!");
- return true;
- }
-
- guild.removeMember(n.getUniqueId());
- sender.sendMessage(tl(PREFIX + "Kicked %s%" + n.getName() + "%p% from your guild."));
- n.sendMessage(tl("%s%You have been kicked from your guild."));
- guild.broadcast(tl("%s%" + n.getName() + " %p%has been kicked from your guild."));
- guild.save();
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/LeaveSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/LeaveSubCommand.java
new file mode 100644
index 0000000..1663ffd
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/LeaveSubCommand.java
@@ -0,0 +1,38 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class LeaveSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (guild.getOwner().equals(playerSender.getUniqueId()))
+ {
+ sender.sendMessage(PREFIX + "You may not leave your guild as the owner, please disband the guild instead.");
+ return;
+ }
+
+ guild.removeMember(playerSender);
+ guild.broadcast(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has left the guild.");
+ sender.sendMessage(PREFIX + "You have left the guild.");
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/LeaveSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/LeaveSubcommand.java
deleted file mode 100644
index 705755e..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/LeaveSubcommand.java
+++ /dev/null
@@ -1,50 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class LeaveSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length > 1)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g leave"));
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (guild.getOwner().equals(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You cannot leave as you are the owner!");
- return true;
- }
-
- guild.removeModerator(player.getUniqueId());
- guild.removeMember(player.getUniqueId());
- guild.save();
- sender.sendMessage(tl("%p%You left your guild."));
- guild.broadcast(tl("%s%" + sender.getName() + " %p%left the guild."));
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ListSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ListSubCommand.java
new file mode 100644
index 0000000..10ef9f4
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/ListSubCommand.java
@@ -0,0 +1,60 @@
+package me.totalfreedom.tfguilds.command;
+
+import java.util.List;
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import me.totalfreedom.tfguilds.util.PaginationList;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class ListSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (args.length > 2)
+ {
+ sender.sendMessage(USAGE + "/g list [page]");
+ return;
+ }
+
+ List guilds = Guild.getGuildNames();
+ if (guilds.isEmpty())
+ {
+ sender.sendMessage(PREFIX + "There are no guilds.");
+ return;
+ }
+
+ PaginationList pagination = new PaginationList<>(10);
+ pagination.addAll(guilds);
+ int index = 1;
+
+ if (args.length == 2)
+ {
+ try
+ {
+ index = Integer.parseInt(args[1]);
+ }
+ catch (NumberFormatException ex)
+ {
+ sender.sendMessage(PREFIX + ChatColor.GOLD + args[1] + ChatColor.GRAY + " is not a valid number.");
+ return;
+ }
+ }
+
+ if (index < 1 || index > pagination.getPageCount())
+ {
+ sender.sendMessage(PREFIX + "Please pick a number between 1 and " + pagination.getPageCount());
+ return;
+ }
+
+ List page = pagination.getPage(index);
+ sender.sendMessage(PREFIX + "Guild list (" + ChatColor.GOLD + index + "/" + pagination.getPageCount() + ChatColor.GRAY + ")");
+ for (String guild : page)
+ {
+ sender.sendMessage(ChatColor.GRAY + " - " + ChatColor.GOLD + guild);
+ }
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ListSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ListSubcommand.java
deleted file mode 100644
index 6b36298..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/ListSubcommand.java
+++ /dev/null
@@ -1,65 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import java.util.List;
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.util.PaginationList;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-
-public class ListSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length > 2)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g list [page]"));
- return true;
- }
-
- List guilds = Guild.getGuildList();
- PaginationList paged = new PaginationList<>(10);
-
- if (guilds.isEmpty())
- {
- sender.sendMessage(ChatColor.RED + "Nobody has made a guild yet.");
- return true;
- }
-
- paged.addAll(guilds);
-
- int pageIndex = 1;
-
- if (args.length >= 2)
- {
- try
- {
- pageIndex = Integer.parseInt(args[1]);
- }
- catch (NumberFormatException e)
- {
- sender.sendMessage(ChatColor.RED + "Invalid number.");
- }
- }
-
- if (pageIndex < 1 || pageIndex > paged.getPageCount())
- {
- sender.sendMessage(ChatColor.RED + "Not a valid page number.");
- return true;
- }
-
- paged.getPage(pageIndex);
- List page = paged.getPage(pageIndex);
-
- sender.sendMessage(tl(PREFIX + "%s%Guild list (%p%" + guilds.size() + " total%s%) [%p%Page " + pageIndex + "%s%/%p%" + paged.getPageCount() + "%s%]"));
-
- for (String guild : page)
- {
- sender.sendMessage(tl("%s%- %p%" + guild));
- }
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/MOTDSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/MOTDSubcommand.java
deleted file mode 100644
index fcec983..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/MOTDSubcommand.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.util.GUtil;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class MOTDSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length == 1)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g motd | clear>"));
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (!guild.hasModerator(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You can't modify your guild's MOTD!");
- return true;
- }
-
- if (args.length >= 3)
- {
- if (args[1].equalsIgnoreCase("set"))
- {
- String motd = StringUtils.join(args, " ", 2, args.length);
- guild.setMotd(motd);
- guild.save();
- sender.sendMessage(tl(PREFIX + "Set %s%" + GUtil.colorize(motd) + "%p% as the new MOTD of your guild%p%."));
- return true;
- }
- return false;
- }
-
- if (!args[1].equalsIgnoreCase("clear"))
- {
- return false;
- }
-
- guild.setMotd(null);
- guild.save();
- sender.sendMessage(tl(PREFIX + "Cleared your guild's MOTD."));
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/MotdSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/MotdSubCommand.java
new file mode 100644
index 0000000..0f38a2f
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/MotdSubCommand.java
@@ -0,0 +1,66 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import me.totalfreedom.tfguilds.util.GUtil;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class MotdSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length == 1)
+ {
+ sender.sendMessage(USAGE + "/g motd | clear>");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (!guild.isModerator(playerSender))
+ {
+ sender.sendMessage(PREFIX + "Only guild moderators can modify the guild's MOTD");
+ return;
+ }
+
+ if (args.length >= 3)
+ {
+ if (args[1].equalsIgnoreCase("set"))
+ {
+ String message = StringUtils.join(args, " ", 2, args.length);
+ guild.setMotd(message);
+ sender.sendMessage(PREFIX + "Set the guild's MOTD to " + ChatColor.GOLD + GUtil.colorize(message));
+ }
+ else
+ {
+ sender.sendMessage(USAGE + "/g motd | clear>");
+ }
+ return;
+ }
+
+ if (!args[1].equalsIgnoreCase("clear"))
+ {
+ sender.sendMessage(USAGE + "/g motd | clear>");
+ return;
+ }
+
+ guild.setMotd(null);
+ sender.sendMessage(PREFIX + "Successfully cleared the guild's MOTD");
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/RemoveModSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/RemoveModSubCommand.java
new file mode 100644
index 0000000..2d741d6
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/RemoveModSubCommand.java
@@ -0,0 +1,70 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class RemoveModSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length != 2)
+ {
+ sender.sendMessage(USAGE + "/g removemod ");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ Player player = Bukkit.getPlayer(args[1]);
+ if (player == null || tfmBridge.isVanished(player))
+ {
+ sender.sendMessage(PLAYER_NOT_FOUND);
+ return;
+ }
+
+ if (!guild.getOwner().equals(playerSender.getUniqueId()))
+ {
+ sender.sendMessage(PREFIX + "You must be the guild owner to remove moderators.");
+ return;
+ }
+
+ if (guild.getOwner().equals(player.getUniqueId()))
+ {
+ sender.sendMessage(PREFIX + "You are the owner of your guild, you cannot remove yourself.");
+ return;
+ }
+
+ if (!guild.isMember(player))
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (!guild.isModerator(player))
+ {
+ sender.sendMessage(PREFIX + "That player is not a moderator.");
+ return;
+ }
+
+ guild.removeModerator(player);
+ sender.sendMessage(PREFIX + "Successfully removed " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " as a moderator.");
+ player.sendMessage(PREFIX + "You are no longer a guild moderator for your guild.");
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/RemoveModSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/RemoveModSubcommand.java
deleted file mode 100644
index 0b452af..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/RemoveModSubcommand.java
+++ /dev/null
@@ -1,126 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.util.GUtil;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class RemoveModSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length == 1 || args.length > 3)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g removemod | name>>"));
- return true;
- }
-
- if (args.length == 3)
- {
- if (!plugin.bridge.isAdmin(sender))
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Guild guild = Guild.getGuild(args[1]);
- if (guild == null)
- {
- sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
- return true;
- }
-
- Player player = Bukkit.getPlayer(args[2]);
- if (player == null)
- {
- sender.sendMessage(PNF);
- return true;
- }
-
- if (sender instanceof Player)
- {
- if (guild.getModerators().contains(((Player)sender).getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You may not demote yourself.");
- return true;
- }
- }
-
- if (!guild.hasMember(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
- return true;
- }
-
- if (!guild.hasModerator(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "This member is not a moderator for this guild!");
- return true;
- }
-
- guild.removeModerator(player.getUniqueId());
- sender.sendMessage(tl(PREFIX + "Removed %s%" + player.getName() + "%p% as a moderator for %s%" + GUtil.colorize(guild.getName()) + "%p%."));
- guild.broadcast(tl("%s%" + player.getName() + " %p%has been made a member of your guild."));
- guild.save();
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (!guild.getOwner().equals(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You can't change who is a moderator in your guild!");
- return true;
- }
-
- Player n = Bukkit.getPlayer(args[1]);
- if (n == null)
- {
- sender.sendMessage(PNF);
- return true;
- }
-
- if (n == player)
- {
- sender.sendMessage(ChatColor.RED + "You may not demote yourself.");
- return true;
- }
-
- if (!guild.hasMember(n.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
- return true;
- }
-
- if (!guild.hasModerator(n.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "This member is not a moderator for your guild!");
- return true;
- }
-
- guild.removeModerator(n.getUniqueId());
- sender.sendMessage(tl(PREFIX + "Removed %s%" + n.getName() + "%p% as a moderator for your guild."));
- guild.broadcast(tl("%s%" + n.getName() + " %p%has been made a member of your guild."));
- guild.save();
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/RenameSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/RenameSubcommand.java
deleted file mode 100644
index 4efc179..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/RenameSubcommand.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.util.GUtil;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class RenameSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length < 2)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g rename "));
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- String newName = StringUtils.join(args, " ", 1, args.length);
- String identifier = GUtil.flatten(newName);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (!guild.getOwner().equals(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You can't change the name of your guild!");
- return true;
- }
-
- Pattern pattern = Pattern.compile("^[A-Za-z0-9? ,_-]+$");
- Matcher matcher = pattern.matcher(newName);
-
- if (!matcher.matches())
- {
- sender.sendMessage(ChatColor.RED + "Guild names must be alphanumeric.");
- return true;
- }
-
- if (identifier.length() > 30)
- {
- sender.sendMessage(ChatColor.RED + "Your new guild name may not be over 30 characters.");
- return true;
- }
-
- if (Guild.guildExists(identifier))
- {
- sender.sendMessage(ChatColor.RED + "A guild with a name similar to yours already exists!");
- return true;
- }
-
- for (String blacklisted : GUtil.BLACKLISTED_NAMES_AND_TAGS)
- {
- if (args[0].equalsIgnoreCase(blacklisted))
- {
- if (!plugin.bridge.isAdmin(player))
- {
- player.sendMessage(ChatColor.RED + "You may not use that name.");
- return true;
- }
- }
- }
-
- guild.rename(newName);
- sender.sendMessage(tl(PREFIX + "Set %s%" + GUtil.colorize(newName) + "%p% as the new name of your guild%p%."));
- guild.broadcast(tl("%p%Your guild has been renamed to " + GUtil.colorize(newName) + "%p%."));
- guild.save();
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/RosterSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/RosterSubCommand.java
new file mode 100644
index 0000000..ac349e9
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/RosterSubCommand.java
@@ -0,0 +1,59 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class RosterSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ Guild guild;
+ if (args.length >= 2)
+ {
+ Player player = Bukkit.getPlayer(args[1]);
+ if (player != null && !tfmBridge.isVanished(player))
+ {
+ guild = Guild.getGuild(player);
+ if (guild == null)
+ {
+ sender.sendMessage(PLAYER_NOT_IN_GUILD);
+ return;
+ }
+
+ sender.sendMessage(guild.getRoster());
+ return;
+ }
+
+ guild = Guild.getGuild(StringUtils.join(args, " ", 1, args.length));
+ if (guild == null)
+ {
+ sender.sendMessage(PREFIX + "That guild does not exist.");
+ return;
+ }
+
+ sender.sendMessage(guild.getRoster());
+ return;
+ }
+
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(USAGE + "/g roster ");
+ return;
+ }
+
+ guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ sender.sendMessage(guild.getRoster());
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/RosterSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/RosterSubcommand.java
deleted file mode 100644
index d297751..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/RosterSubcommand.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.util.GUtil;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class RosterSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length >= 2)
- {
- Player player = Bukkit.getPlayer(args[1]);
- if (player != null)
- {
- Guild guild = Guild.getGuild(player);
- if (guild != null)
- {
- sender.sendMessage(guild.getRoster());
- return true;
- }
- }
-
- Guild guild = Guild.getGuild(GUtil.flatten(StringUtils.join(args, " ", 1, args.length)));
- if (guild == null)
- {
- sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
- return true;
- }
-
- sender.sendMessage(guild.getRoster());
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Guild guild = Guild.getGuild((Player)sender);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- sender.sendMessage(guild.getRoster());
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubCommand.java
new file mode 100644
index 0000000..5b2a309
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubCommand.java
@@ -0,0 +1,71 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import me.totalfreedom.tfguilds.util.GUtil;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class SetDefaultRankSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length < 2)
+ {
+ sender.sendMessage(USAGE + "/g setdefaultrank ");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (!guild.getOwner().equals(playerSender.getUniqueId()))
+ {
+ sender.sendMessage(PREFIX + "Only the guild owner can set default rank.");
+ return;
+ }
+
+ String name = StringUtils.join(args, " ", 1, args.length);
+ if (name.equalsIgnoreCase("none"))
+ {
+ guild.setDefaultRank(null);
+ sender.sendMessage(PREFIX + "Removed default rank.");
+ return;
+ }
+
+ if (!StringUtils.isAlphanumericSpace(name) || name.isBlank())
+ {
+ sender.sendMessage(PREFIX + "The name must be alphanumeric.");
+ return;
+ }
+
+ if (name.length() > 15)
+ {
+ sender.sendMessage(PREFIX + "The rank name cannot go over 15 characters limit.");
+ return;
+ }
+
+ if (GUtil.containsBlacklistedWord(name))
+ {
+ sender.sendMessage(PREFIX + "The guild name contains a blacklisted word.");
+ return;
+ }
+
+ guild.setDefaultRank(name);
+ sender.sendMessage(PREFIX + "Successfully set " + ChatColor.GOLD + name + ChatColor.GRAY + " as the default rank of your guild.");
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubcommand.java
deleted file mode 100644
index 4056302..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetDefaultRankSubcommand.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class SetDefaultRankSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- if (args.length == 0)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g setdefaultrank "));
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (!guild.getOwner().equals(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You do not have permissions to manage ranks in your guild!");
- return true;
- }
-
- String rank = StringUtils.join(args, " ", 1, args.length);
- if (rank.equalsIgnoreCase("none"))
- {
- guild.setDefaultRank(null);
- guild.save();
- sender.sendMessage(tl(PREFIX + "Removed the default guild rank."));
- return true;
- }
-
- if (!guild.hasRank(rank))
- {
- sender.sendMessage(ChatColor.RED + "A rank of that name does not exist in the guild!");
- return true;
- }
-
- guild.setDefaultRank(rank);
- guild.save();
- sender.sendMessage(tl(PREFIX + "Set %s%\"" + rank + "\"%p% as the default rank for your guild."));
- return true;
- }
-}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetMemberSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetMemberSubcommand.java
deleted file mode 100644
index ae95a01..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetMemberSubcommand.java
+++ /dev/null
@@ -1,54 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.entity.Player;
-
-public class SetMemberSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length == 1 || args.length == 2 || args.length > 3)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g setmember "));
- return true;
- }
-
- if (!plugin.bridge.isAdmin(sender))
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Guild guild = Guild.getGuild(args[1]);
- if (guild == null)
- {
- sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
- return true;
- }
-
- Player player = Bukkit.getPlayer(args[2]);
- if (player == null)
- {
- sender.sendMessage(PNF);
- return true;
- }
-
- if (Guild.getGuild(player) != null)
- {
- sender.sendMessage(ChatColor.RED + "This player is already in another guild!");
- return true;
- }
-
- guild.addMember(player.getUniqueId());
- guild.broadcast(tl("%s%" + player.getName() + " %p%has joined the guild."));
- guild.save();
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetOwnerSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetOwnerSubCommand.java
new file mode 100644
index 0000000..93b005c
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetOwnerSubCommand.java
@@ -0,0 +1,65 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class SetOwnerSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length < 2)
+ {
+ sender.sendMessage(USAGE + "/g setowner ");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (!guild.getOwner().equals(playerSender.getUniqueId()))
+ {
+ sender.sendMessage(PREFIX + "Only the guild owner can set the owner of the guild.");
+ return;
+ }
+
+ Player player = Bukkit.getPlayer(args[1]);
+ if (player == null || tfmBridge.isVanished(player))
+ {
+ sender.sendMessage(PLAYER_NOT_FOUND);
+ return;
+ }
+
+ if (playerSender.equals(player))
+ {
+ sender.sendMessage(PREFIX + "You are already the owner of the guild.");
+ return;
+ }
+
+ if (!guild.isMember(player))
+ {
+ sender.sendMessage(PREFIX + "That player is not in your guild.");
+ return;
+ }
+
+ guild.setOwner(player);
+ sender.sendMessage(PREFIX + "Successfully set " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " as the new owner of the guild.");
+ guild.broadcast(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has set " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + " as the new owner of the guild.");
+ player.sendMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has set you as the owner of " + ChatColor.GOLD + guild.getName());
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetOwnerSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetOwnerSubcommand.java
deleted file mode 100644
index 1853f02..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetOwnerSubcommand.java
+++ /dev/null
@@ -1,113 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.util.GUtil;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class SetOwnerSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length == 1 || args.length > 3)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g setowner | player>"));
- return true;
- }
-
- if (args.length == 3)
- {
- if (!plugin.bridge.isAdmin(sender))
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Guild guild = Guild.getGuild(args[1]);
- if (guild == null)
- {
- sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
- return true;
- }
-
- Player player = Bukkit.getPlayer(args[2]);
- if (player == null)
- {
- sender.sendMessage(PNF);
- return true;
- }
-
- if (guild.getOwner().equals(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "This player is already the owner of that guild!");
- return true;
- }
-
- if (!guild.hasMember(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "This player is not in the specified guild!");
- return true;
- }
-
- guild.removeModerator(player.getUniqueId());
- guild.setOwner(player.getUniqueId());
- sender.sendMessage(tl(PREFIX + "Ownership has been transferred to %s%" + player.getName() + "%p% in %s%" + GUtil.colorize(guild.getName()) + "%p%."));
- guild.broadcast(tl("%s%" + player.getName() + " %p%has been made the owner of your guild."));
- guild.save();
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (!guild.getOwner().equals(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You can't change who is the owner of your guild!");
- return true;
- }
-
- Player n = Bukkit.getPlayer(args[1]);
- if (n == null)
- {
- sender.sendMessage(PNF);
- return true;
- }
-
- if (n == player)
- {
- sender.sendMessage(ChatColor.RED + "You are already the owner of your guild.");
- return true;
- }
-
- if (!guild.hasMember(n.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
- return true;
- }
-
- guild.removeModerator(n.getUniqueId());
- guild.setOwner(n.getUniqueId());
- sender.sendMessage(tl(PREFIX + "Ownership has been transferred to %s%" + n.getName() + "%p% in your guild."));
- guild.broadcast(tl("%s%" + n.getName() + " %p%has been made the owner of your guild."));
- guild.save();
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubCommand.java
new file mode 100644
index 0000000..51ed885
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubCommand.java
@@ -0,0 +1,66 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class SetRankSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length < 3)
+ {
+ sender.sendMessage(USAGE + "/g setrank ");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (!guild.isModerator(playerSender))
+ {
+ sender.sendMessage(PREFIX + "You must be a guild moderator to set player's rank for your guild.");
+ return;
+ }
+
+ Player player = Bukkit.getPlayer(args[1]);
+ if (player == null || tfmBridge.isVanished(player))
+ {
+ sender.sendMessage(PLAYER_NOT_FOUND);
+ return;
+ }
+
+ if (!guild.isMember(player))
+ {
+ sender.sendMessage(PLAYER_NOT_IN_GUILD);
+ return;
+ }
+
+ String name = StringUtils.join(args, " ", 2, args.length);
+ if (!guild.hasRank(name))
+ {
+ sender.sendMessage(PREFIX + "That rank does not exist.");
+ return;
+ }
+
+ guild.setPlayerRank(player, name);
+ sender.sendMessage(PREFIX + "Successfully set " + ChatColor.GOLD + player.getName() + ChatColor.GRAY + "'s guild rank to " + ChatColor.GOLD + name);
+ player.sendMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has set your guild rank to " + ChatColor.GOLD + name);
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
deleted file mode 100644
index 967a3ec..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetRankSubcommand.java
+++ /dev/null
@@ -1,94 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.guild.GuildRank;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class SetRankSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length == 1)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g setrank "));
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (!guild.hasModerator(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You can't change the ranks of your guild members!");
- return true;
- }
-
- Player r = Bukkit.getPlayer(args[1]);
- if (r == null)
- {
- sender.sendMessage(PNF);
- return true;
- }
-
- if (!guild.hasMember(r.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "This player is not in your guild!");
- return true;
- }
-
- String name = StringUtils.join(args, " ", 2, args.length).toLowerCase();
- if (name.equals("none"))
- {
- for (GuildRank gr : guild.getRanks())
- {
- gr.getMembers().remove(r.getUniqueId());
- gr.save();
- }
-
- sender.sendMessage(tl(PREFIX + "Removed the rank of %s%" + r.getName() + "%p% in your guild."));
- r.sendMessage(tl("%p%Your rank in your guild has been removed."));
- guild.save();
- return true;
- }
-
- GuildRank rank = guild.getRank(name);
- if (rank == null)
- {
- sender.sendMessage(ChatColor.RED + "A rank of that name does not exist in the guild!");
- return true;
- }
-
- for (GuildRank gr : guild.getRanks())
- {
- gr.getMembers().remove(r.getUniqueId());
- gr.save();
- }
-
- rank.getMembers().add(r.getUniqueId());
- rank.save();
- sender.sendMessage(tl(PREFIX + "Set the rank of %s%" + r.getName() + "%p% in your guild to %s%" + rank.getName() + "%p%."));
- r.sendMessage(tl("%p%Your rank in your guild has been set to %s%" + rank.getName() + "%p%."));
- guild.save();
- return true;
- }
-}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetStateSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetStateSubCommand.java
new file mode 100644
index 0000000..3cae41b
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetStateSubCommand.java
@@ -0,0 +1,53 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class SetStateSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length != 2)
+ {
+ sender.sendMessage(USAGE + "/g setstate ");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (!guild.isModerator(playerSender))
+ {
+ sender.sendMessage(PREFIX + "Only guild moderators can change the state.");
+ return;
+ }
+
+ Guild.State state = Guild.State.fromString(args[1]);
+ if (state == null)
+ {
+ sender.sendMessage(PREFIX + ChatColor.GOLD + args[1] + ChatColor.GRAY + " is not a valid state. Available options: "
+ + ChatColor.GOLD + StringUtils.join(Guild.State.values(), ", "));
+ return;
+ }
+
+ guild.setState(state);
+ sender.sendMessage(PREFIX + "Successfully set the guild state to " + ChatColor.GOLD + state.name());
+ guild.broadcast(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has set the guild state to " + ChatColor.GOLD + state.name());
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetStateSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetStateSubcommand.java
deleted file mode 100644
index 9e9fdae..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetStateSubcommand.java
+++ /dev/null
@@ -1,87 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.guild.GuildState;
-import me.totalfreedom.tfguilds.util.GUtil;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class SetStateSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length == 1)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g setstate "));
- return true;
- }
-
- if (args.length == 3)
- {
- if (!plugin.bridge.isAdmin(sender))
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Guild guild = Guild.getGuild(args[1]);
- if (guild == null)
- {
- sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
- return true;
- }
-
- GuildState state = GuildState.findState(args[2]);
- if (state == null)
- {
- sender.sendMessage(ChatColor.RED + "That is not a valid state!");
- return true;
- }
-
- guild.setState(state);
- sender.sendMessage(tl(PREFIX + "Set the guild state to %s%" + state.getDisplay().toLowerCase() + "%p% in %s%" + GUtil.colorize(guild.getName()) + "%p%."));
- guild.broadcast(tl("%p%The guild is now %s%" + state.getDisplay().toLowerCase() + "%p%."));
- guild.save();
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (!guild.hasModerator(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You can't change the state of the guild!");
- return true;
- }
-
- GuildState state = GuildState.findState(args[1]);
- if (state == null)
- {
- sender.sendMessage(ChatColor.RED + "That is not a valid state!");
- return true;
- }
-
- guild.setState(state);
- sender.sendMessage(tl(PREFIX + "Set the guild state to %s%" + state.getDisplay().toLowerCase() + "%p% in your guild."));
- guild.broadcast(tl("%p%The guild is now %s%" + state.getDisplay().toLowerCase() + "%p%."));
- guild.save();
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubCommand.java
new file mode 100644
index 0000000..755a03c
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubCommand.java
@@ -0,0 +1,57 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class SetWarpSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length < 2)
+ {
+ sender.sendMessage(USAGE + "/g setwarp ");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (!guild.isModerator(playerSender))
+ {
+ sender.sendMessage(PREFIX + "You must be a guild moderator or owner to create a warp for the guild.");
+ return;
+ }
+
+ String name = StringUtils.join(args, " ", 1, args.length);
+ if (!StringUtils.isAlphanumericSpace(name))
+ {
+ sender.sendMessage(PREFIX + "The name must be alphanumeric.");
+ return;
+ }
+
+ if (guild.hasWarp(name))
+ {
+ sender.sendMessage(PREFIX + "A warp with that name already exist.");
+ return;
+ }
+
+ guild.addWarp(name, playerSender.getLocation());
+ sender.sendMessage(PREFIX + "A warp with the name " + ChatColor.GOLD + name + ChatColor.GRAY + " has been successfully created.");
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubcommand.java
deleted file mode 100644
index e58860d..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/SetWarpSubcommand.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class SetWarpSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length < 2)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g setwarp "));
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (!guild.hasModerator(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "Only guild moderators and guild owners are allowed to create guild warps.");
- return true;
- }
-
- String warpName = StringUtils.join(args, " ", 1, args.length);
- if (guild.warpExists(warpName))
- {
- sender.sendMessage(ChatColor.RED + "A warp with that name already exists.");
- return true;
- }
-
- Guild.createWarp(guild.getIdentifier(), warpName, player);
- sender.sendMessage(tl(PREFIX + "Successfully created new guild warp \"" + warpName + "\"."));
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/SubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/SubCommand.java
new file mode 100644
index 0000000..2a131e7
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/SubCommand.java
@@ -0,0 +1,10 @@
+package me.totalfreedom.tfguilds.command;
+
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public interface SubCommand
+{
+
+ void execute(CommandSender sender, Player playerSender, String[] args);
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/TFGuildsCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/TFGuildsCommand.java
index 217ec7a..3d0973a 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/TFGuildsCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/TFGuildsCommand.java
@@ -1,55 +1,50 @@
package me.totalfreedom.tfguilds.command;
-import java.util.UUID;
import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.util.GLog;
-import org.bukkit.Bukkit;
-import org.bukkit.OfflinePlayer;
+import me.totalfreedom.tfguilds.TFGuilds;
+import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
public class TFGuildsCommand extends Common implements CommandExecutor
{
+
@Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
+ public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
{
if (args.length > 1)
{
return false;
}
- if (args.length == 1)
+ if (args.length == 1 && args[0].equalsIgnoreCase("reload"))
{
- if (args[0].toLowerCase().equals("reload"))
+ if (!tfmBridge.isAdmin(sender))
{
- if (!plugin.bridge.isAdmin(sender))
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- try
- {
- plugin.config.load();
- GLog.info("All configs reloaded successfully");
- sender.sendMessage(tl(PREFIX + "All configuration files have been reloaded successfully."));
- return true;
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
+ sender.sendMessage(PREFIX + "You do not have the permission.");
return true;
}
+
+ try
+ {
+ TFGuilds.getPlugin().getConfig().load();
+ TFGuilds.getPlugin().getLogger().info("Successfully reload the configuration file.");
+ sender.sendMessage(PREFIX + "The configuration file have been reloaded successfully.");
+ return true;
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ return true;
}
- sender.sendMessage(tl("%p%TFGuilds %s%is a plugin which allows for players to make their own guilds, providing guild chat, guild teleportation, and more."));
- sender.sendMessage(tl("%s%Version %p%v" + plugin.getDescription().getVersion()));
- OfflinePlayer sp = Bukkit.getOfflinePlayer(UUID.fromString("d018f2b8-ce60-4672-a45f-e580e0331299"));
- OfflinePlayer su = Bukkit.getOfflinePlayer(UUID.fromString("53b1512e-3481-4702-9f4f-63cb9c8be6a1"));
- sender.sendMessage(tl("%s%Developed by %p%" + sp.getName() + " & " + su.getName()));
- sender.sendMessage(tl("%s%https://github.com/AtlasMediaGroup/TFGuilds"));
+ sender.sendMessage(ChatColor.AQUA + "TFGuilds " + ChatColor.GRAY + "is a plugin which allows players to create their own guilds, provide guild chat, guild teleportation and many more.");
+ sender.sendMessage(ChatColor.GRAY + "Version " + ChatColor.GOLD + TFGuilds.getPlugin().getDescription().getVersion());
+ sender.sendMessage(ChatColor.GRAY + "Originally created by " + ChatColor.GOLD + "speednt " + ChatColor.GRAY + "and " + ChatColor.GOLD + "supernt");
+ sender.sendMessage(ChatColor.GRAY + "Developed by " + ChatColor.GOLD + "NotInSync");
+ sender.sendMessage(ChatColor.GRAY + "Source code " + ChatColor.GOLD + "https://github.com/AtlasMediaGroup/TFGuilds");
return true;
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/TPSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/TPSubcommand.java
deleted file mode 100644
index 0c95432..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/TPSubcommand.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class TPSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- if (args.length != 2)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g tp "));
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- Player to = Bukkit.getPlayer(args[1]);
- if (to == null)
- {
- sender.sendMessage(PNF);
- return true;
- }
-
- if (!guild.getMembers().contains(to.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "That player is not in your guild.");
- return true;
- }
-
- player.teleport(to.getLocation());
- sender.sendMessage(tl("%p%Teleported to %s%" + to.getName() + "%p%."));
- to.sendMessage(tl("%s%" + sender.getName() + " %p%has teleported to you."));
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/TagSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/TagSubCommand.java
new file mode 100644
index 0000000..bb7f653
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/TagSubCommand.java
@@ -0,0 +1,100 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import me.totalfreedom.tfguilds.util.GUtil;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class TagSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length < 2)
+ {
+ sender.sendMessage(USAGE + "/g tag | clear [guild]>");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (!guild.getOwner().equals(playerSender.getUniqueId()))
+ {
+ sender.sendMessage(PREFIX + "Only the guild owner can edit the guild's tag.");
+ return;
+ }
+
+ if (args.length >= 3)
+ {
+ if (args[1].equalsIgnoreCase("set"))
+ {
+ String tag = StringUtils.join(args, " ", 2, args.length);
+ tag = tag.replace("%tag%", guild.getName());
+ if (tag.length() > 15)
+ {
+ sender.sendMessage(PREFIX + "The guild tag cannot go over 15 characters limit.");
+ return;
+ }
+
+ if (GUtil.containsBlacklistedWord(tag) && tfmBridge.isAdmin(sender))
+ {
+ sender.sendMessage(PREFIX + "The guild tag contains forbidden word(s).");
+ return;
+ }
+
+ guild.setTag(tag);
+ sender.sendMessage(PREFIX + "The guild tag has been changed to " + ChatColor.GOLD + GUtil.colorize(tag).replace("%rank%", "Guild Owner"));
+ }
+ else
+ {
+ sender.sendMessage(USAGE + "/g tag | clear [guild]>");
+ }
+ return;
+ }
+
+ if (args[1].equalsIgnoreCase("clear"))
+ {
+ if (args.length >= 3)
+ {
+ if (!tfmBridge.isAdmin(sender))
+ {
+ sender.sendMessage(PREFIX + "You do not have the permission to use this command.");
+ return;
+ }
+
+ guild = Guild.getGuild(StringUtils.join(args, " ", 2, args.length));
+ if (guild == null)
+ {
+ sender.sendMessage(PREFIX + "That guild does not exist.");
+ return;
+ }
+
+ guild.setTag(null);
+ sender.sendMessage(PREFIX + "Successfully cleared the guild tag for " + ChatColor.GOLD + guild.getName());
+ return;
+ }
+
+ guild.setTag(null);
+ sender.sendMessage(PREFIX + "Successfully cleared the guild tag.");
+ }
+ else
+ {
+ sender.sendMessage(USAGE + "/g tag | clear [guild]>");
+ }
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/TagSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/TagSubcommand.java
deleted file mode 100644
index 9bdf5bb..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/TagSubcommand.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.util.GUtil;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class TagSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- if (args.length < 2)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g tag | clear [guild]>>"));
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- if (!guild.getOwner().equals(player.getUniqueId()))
- {
- sender.sendMessage(ChatColor.RED + "You can't modify your guild's tag!");
- return true;
- }
-
- if (args.length >= 3)
- {
- if (args[1].equalsIgnoreCase("set"))
- {
- String tag = StringUtils.join(args, " ", 2, args.length);
-
- tag = tag.replace("%tag%", guild.getName());
-
- if (tag.length() > 30)
- {
- player.sendMessage(ChatColor.RED + "Your guild tag must not be over 30 characters.");
- return true;
- }
-
- for (String blacklisted : GUtil.BLACKLISTED_NAMES_AND_TAGS)
- {
- if (tag.equalsIgnoreCase(blacklisted))
- {
- if (!plugin.bridge.isAdmin(player))
- {
- player.sendMessage(ChatColor.RED + "You may not use that name.");
- return true;
- }
- }
- }
-
- guild.setTag(tag);
- guild.save();
- sender.sendMessage(tl("%p%Your guild tag has been changed to be \"" + GUtil.colorize(tag).replace("%rank%", "Guild Owner") + "%p%\"."));
- return true;
- }
- }
-
- if (args[1].equalsIgnoreCase("clear"))
- {
- if (args.length >= 3)
- {
- if (!plugin.bridge.isAdmin(sender))
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Guild g = Guild.getGuild(GUtil.flatten(StringUtils.join(args, " ", 2, args.length)));
- if (g == null)
- {
- sender.sendMessage(ChatColor.RED + "That guild doesn't exist!");
- return true;
- }
-
- g.setTag(null);
- g.save();
- sender.sendMessage(tl("%p%Cleared guild tag for " + g.getName() + "."));
- return true;
- }
-
- guild.setTag(null);
- guild.save();
- sender.sendMessage(tl("%p%Your guild tag has been cleared."));
- }
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubCommand.java
new file mode 100644
index 0000000..f4310fc
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubCommand.java
@@ -0,0 +1,36 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.User;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class ToggleTagSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (args.length > 1)
+ {
+ sender.sendMessage(USAGE + "/g toggletag");
+ return;
+ }
+
+ User user = User.getUserFromPlayer(playerSender);
+ if (user == null)
+ {
+ user = User.create(playerSender);
+ }
+
+ user.setDisplayTag(!user.displayTag());
+ sender.sendMessage(PREFIX + ChatColor.GOLD + (user.displayTag() ? "Enabled" : "Disabled") + ChatColor.GRAY + " personal guild tag.");
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubcommand.java
deleted file mode 100644
index 20901d5..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagSubcommand.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.user.User;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class ToggleTagSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length > 2)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g toggletag [player]"));
- return true;
- }
-
- if (args.length == 2)
- {
- if (!plugin.bridge.isAdmin(sender))
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = Bukkit.getPlayer(args[1]);
- if (player == null)
- {
- sender.sendMessage(PNF);
- return true;
- }
- User user = plugin.userData.get(player.getUniqueId());
- user.setTag(!user.isTag());
- user.save();
- sender.sendMessage(tl(PREFIX + (user.isTag() ? "Enabled" : "Disabled") + " personal guild tag for " + player.getName() + "."));
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- User user = plugin.userData.get(player.getUniqueId());
- user.setTag(!user.isTag());
- user.save();
- sender.sendMessage(tl(PREFIX + (user.isTag() ? "Enabled" : "Disabled") + " personal guild tag."));
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagsSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagsSubCommand.java
new file mode 100644
index 0000000..ebc589c
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagsSubCommand.java
@@ -0,0 +1,36 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.config.ConfigEntry;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class ToggleTagsSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!tfmBridge.isAdmin(sender))
+ {
+ sender.sendMessage(PREFIX + "You do not have the permission.");
+ return;
+ }
+
+ boolean enabled = ConfigEntry.GUILD_TAGS.getBoolean();
+ if (enabled)
+ {
+ ConfigEntry.GUILD_TAGS.setBoolean(false);
+ sender.sendMessage(PREFIX + ChatColor.GOLD + "Disabled " + ChatColor.GRAY + "global guild tags.");
+ Bukkit.broadcastMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has globally disabled guild tags.");
+ }
+ else
+ {
+ ConfigEntry.GUILD_TAGS.setBoolean(true);
+ sender.sendMessage(PREFIX + ChatColor.GOLD + "Enabled " + ChatColor.GRAY + " global guild tags.");
+ Bukkit.broadcastMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has globally enabled guild tags.");
+ }
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagsSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagsSubcommand.java
deleted file mode 100644
index 16a2982..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/ToggleTagsSubcommand.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.config.ConfigEntry;
-import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-
-public class ToggleTagsSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (!plugin.bridge.isAdmin(sender))
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- boolean enabled = ConfigEntry.GUILD_TAGS_ENABLED.getBoolean();
- if (enabled)
- {
- ConfigEntry.GUILD_TAGS_ENABLED.setBoolean(false);
- sender.sendMessage(tl(PREFIX + "Globally disabled guild tags."));
- broadcast(ChatColor.RED + sender.getName() + " - Globally disabling guild tags");
- }
- else
- {
- ConfigEntry.GUILD_TAGS_ENABLED.setBoolean(true);
- sender.sendMessage(tl(PREFIX + "Globally enabled guild tags."));
- broadcast(ChatColor.RED + sender.getName() + " - Globally enabling guild tags");
- }
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/TpSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/TpSubCommand.java
new file mode 100644
index 0000000..b033154
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/TpSubCommand.java
@@ -0,0 +1,51 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class TpSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length != 2)
+ {
+ sender.sendMessage(USAGE + "/g tp ");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ Player player = Bukkit.getPlayer(args[1]);
+ if (player == null || tfmBridge.isVanished(player))
+ {
+ sender.sendMessage(PLAYER_NOT_FOUND);
+ return;
+ }
+
+ if (!guild.isMember(player))
+ {
+ sender.sendMessage(PLAYER_NOT_IN_GUILD);
+ return;
+ }
+
+ playerSender.teleport(player);
+ sender.sendMessage(PREFIX + "Successfully teleported to " + ChatColor.GOLD + player.getName());
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/WarpSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/WarpSubCommand.java
new file mode 100644
index 0000000..9138933
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/WarpSubCommand.java
@@ -0,0 +1,47 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.Location;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class WarpSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ if (args.length < 2)
+ {
+ sender.sendMessage(USAGE + "/g warp ");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ String name = StringUtils.join(args, " ", 1, args.length);
+ if (!guild.hasWarp(name))
+ {
+ sender.sendMessage(PREFIX + "The guild does not have the warp named " + ChatColor.GOLD + name);
+ return;
+ }
+
+ Location location = guild.getWarp(name);
+ playerSender.teleport(location);
+ sender.sendMessage(PREFIX + "Successfully warped to " + ChatColor.GOLD + name);
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/WarpSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/WarpSubcommand.java
deleted file mode 100644
index 245a11d..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/WarpSubcommand.java
+++ /dev/null
@@ -1,53 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.guild.GuildWarp;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.ChatColor;
-import org.bukkit.Location;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class WarpSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (args.length < 2)
- {
- sender.sendMessage(tl(PREFIX + "Proper usage: /g warp "));
- return true;
- }
-
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- String warpName = StringUtils.join(args, " ", 1, args.length);
- if (!guild.warpExists(warpName))
- {
- sender.sendMessage(ChatColor.RED + "Warp not found.");
- return true;
- }
-
- GuildWarp warp = guild.getWarp(warpName);
- Location warpLoc = new Location(warp.getWorld(), warp.getX(), warp.getY(), warp.getZ());
- player.teleport(warpLoc);
- sender.sendMessage(tl(PREFIX + "Warping to \"" + warpName + "\"."));
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/WarpsSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/WarpsSubCommand.java
new file mode 100644
index 0000000..94d5eb9
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/WarpsSubCommand.java
@@ -0,0 +1,37 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class WarpsSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (guild.getWarps().isEmpty())
+ {
+ sender.sendMessage(PREFIX + "There are no warps.");
+ return;
+ }
+
+ sender.sendMessage(PREFIX + "Warps (" + guild.getWarps().size() + "): " + ChatColor.GOLD + StringUtils.join(guild.getWarpNames(), ", "));
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/WarpsSubcommand.java b/src/main/java/me/totalfreedom/tfguilds/command/WarpsSubcommand.java
deleted file mode 100644
index 358261c..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/command/WarpsSubcommand.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package me.totalfreedom.tfguilds.command;
-
-import java.util.List;
-import me.totalfreedom.tfguilds.Common;
-import me.totalfreedom.tfguilds.guild.Guild;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.command.Command;
-import org.bukkit.command.CommandExecutor;
-import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
-import org.bukkit.entity.Player;
-
-public class WarpsSubcommand extends Common implements CommandExecutor
-{
- @Override
- public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
- {
- if (sender instanceof ConsoleCommandSender)
- {
- sender.sendMessage(NO_PERMS);
- return true;
- }
-
- Player player = (Player)sender;
- Guild guild = Guild.getGuild(player);
- if (guild == null)
- {
- sender.sendMessage(NG);
- return true;
- }
-
- List warps = Guild.getGuildWarps();
- sender.sendMessage(tl(PREFIX + "%s%Guild warps (%p%" + warps.size() + " total%s%)\n%p%" + StringUtils.join(warps, "%s%,%p% ")));
- return true;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/config/Config.java b/src/main/java/me/totalfreedom/tfguilds/config/Config.java
index 8e5e4fc..ac5daae 100644
--- a/src/main/java/me/totalfreedom/tfguilds/config/Config.java
+++ b/src/main/java/me/totalfreedom/tfguilds/config/Config.java
@@ -1,37 +1,29 @@
package me.totalfreedom.tfguilds.config;
import java.io.File;
+import java.io.IOException;
import me.totalfreedom.tfguilds.TFGuilds;
+import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
public class Config extends YamlConfiguration
{
+
private final TFGuilds plugin;
private final File file;
- public Config(String name)
+ public Config(String fileName)
{
this.plugin = TFGuilds.getPlugin();
- this.file = new File(plugin.getDataFolder(), name);
+ this.file = new File(plugin.getDataFolder(), fileName);
if (!file.exists())
{
options().copyDefaults(true);
- plugin.saveResource(name, false);
+ plugin.saveResource(fileName, false);
}
- load();
- }
- public void load()
- {
- try
- {
- super.load(file);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- }
+ load();
}
public void save()
@@ -40,9 +32,21 @@ public class Config extends YamlConfiguration
{
super.save(file);
}
- catch (Exception e)
+ catch (IOException ex)
{
- e.printStackTrace();
+ ex.printStackTrace();
}
}
-}
\ No newline at end of file
+
+ public void load()
+ {
+ try
+ {
+ super.load(file);
+ }
+ catch (IOException | InvalidConfigurationException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java b/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java
index bd8c900..89eaecf 100644
--- a/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java
+++ b/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java
@@ -1,22 +1,25 @@
package me.totalfreedom.tfguilds.config;
import me.totalfreedom.tfguilds.TFGuilds;
-import org.bukkit.ChatColor;
public enum ConfigEntry
{
- SCHEME_PRIMARY("scheme.primary"),
- SCHEME_SECONDARY("scheme.secondary"),
- // Server
- GUILD_CHAT_LOGGING_ENABLED("server.guild_chat_logging.enabled"),
- GUILD_TAGS_ENABLED("server.guild_tags_enabled.enabled");
+
+ GUILD_CHAT_LOGGING("server.guild_chat_logging"),
+ GUILD_TAGS("server.guild_tags"),
+ MYSQL_HOST("mysql.host"),
+ MYSQL_PORT("mysql.port"),
+ MYSQL_USERNAME("mysql.username"),
+ MYSQL_PASSWORD("mysql.password"),
+ MYSQL_DATABASE("mysql.database");
private final String path;
private final Config config;
+
ConfigEntry(String path)
{
this.path = path;
- this.config = TFGuilds.getPlugin().config;
+ this.config = TFGuilds.getPlugin().getConfig();
}
public boolean getBoolean()
@@ -30,8 +33,13 @@ public enum ConfigEntry
config.save();
}
- public ChatColor getChatColor()
+ public int getInteger()
{
- return ChatColor.valueOf(config.getString(path).toUpperCase());
+ return config.getInt(path);
}
-}
\ No newline at end of file
+
+ public String getString()
+ {
+ return config.getString(path);
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
index 52a060b..7691ba5 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
@@ -1,183 +1,117 @@
package me.totalfreedom.tfguilds.guild;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import java.util.UUID;
-import lombok.Getter;
-import lombok.Setter;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.config.ConfigEntry;
-import me.totalfreedom.tfguilds.util.GLog;
import me.totalfreedom.tfguilds.util.GUtil;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
-import org.bukkit.OfflinePlayer;
+import org.bukkit.World;
import org.bukkit.entity.Player;
public class Guild
{
- private static final TFGuilds plugin = TFGuilds.getPlugin();
- @Getter
- @Setter
- private String identifier;
-
- @Getter
- @Setter
- private String name;
-
- @Getter
- @Setter
+ private static Map guilds = new HashMap<>();
+ //
+ private final String id;
+ private final String name;
+ private final long createdAt;
+ private List invites = new ArrayList<>();
private UUID owner;
-
- @Getter
- private final List moderators;
-
- @Getter
- private final List members;
-
- @Getter
- @Setter
+ private List moderators;
+ private List members;
+ private Map> ranks;
+ private Map warps;
+ private String defaultRank;
private String tag;
-
- @Getter
- @Setter
- private GuildState state;
-
- @Getter
- private final List ranks;
-
- @Getter
- @Setter
+ private State state;
private String motd;
-
- @Getter
- @Setter
private Location home;
- @Getter
- @Setter
- private String defaultRank;
-
- @Getter
- private final long creation;
-
- public Guild(String identifier,
- String name,
+ public Guild(String name,
UUID owner,
- List members,
List moderators,
- String tag,
- GuildState state,
- List ranks,
+ List members,
+ Map> ranks,
+ Map warps,
+ String defaultRank,
+ State state,
String motd,
- Location home,
- long creation,
- String defaultrank)
+ double x,
+ double y,
+ double z,
+ String world,
+ long createdAt)
{
- this.identifier = identifier;
+ this.id = name.toLowerCase().replaceAll(" ", "_");
this.name = name;
this.owner = owner;
- this.members = members;
this.moderators = moderators;
- this.tag = tag;
- this.state = state;
+ this.members = members;
this.ranks = ranks;
+ this.warps = warps;
+ this.defaultRank = defaultRank;
+ this.state = state;
this.motd = motd;
- this.home = home;
- this.creation = creation;
- this.defaultRank = defaultrank;
- }
-
- public void save()
- {
- plugin.guildData.save(this);
- }
-
- public void addMember(UUID uuid)
- {
- if (hasDefaultRank())
+ World w;
+ if (world == null)
{
- getRank(defaultRank).getMembers().add(uuid);
+ w = Bukkit.getWorlds().get(0);
}
-
- members.add(uuid);
- }
-
- public void removeMember(UUID uuid)
- {
- Player player = Bukkit.getPlayer(uuid);
- if (player != null)
+ else
{
- Common.IN_GUILD_CHAT.remove(player);
+ w = Bukkit.getWorld(world);
}
-
- members.remove(uuid);
- for (GuildRank gr : getRanks())
+ if (w == null)
{
- getRank(gr.getName()).getMembers().remove(uuid);
+ w = Bukkit.getWorlds().get(0);
}
- moderators.remove(uuid);
+ this.home = new Location(w, x, y, z);
+ this.createdAt = createdAt;
}
- public boolean hasMember(UUID uuid)
+ public Guild(Player player, String name)
{
- return members.contains(uuid);
+ this(name,
+ player.getUniqueId(),
+ new ArrayList<>(),
+ new ArrayList<>(),
+ new HashMap<>(),
+ new HashMap<>(),
+ null,
+ State.OPEN,
+ null,
+ 0,
+ 50,
+ 0,
+ null,
+ System.currentTimeMillis());
+ save(true);
}
- public void addModerator(UUID uuid)
+ public static void create(Player player, String name)
{
- moderators.add(uuid);
+ guilds.put(name.toLowerCase().replaceAll(" ", "_"),
+ new Guild(player, name));
}
- public void removeModerator(UUID uuid)
+ public static boolean isAlreadyMember(Player player)
{
- moderators.remove(uuid);
- }
-
- public boolean hasModerator(UUID uuid)
- {
- if (owner.equals(uuid))
+ for (Guild guild : guilds.values())
{
- return true;
- }
-
- return moderators.contains(uuid);
- }
-
- public void addRank(String name)
- {
- ranks.add(GuildRank.createGuildRank(identifier, GUtil.flatten(name), name));
- }
-
- public void removeRank(String name)
- {
- GuildRank remove = null;
- for (GuildRank rank : ranks)
- {
- if (GUtil.flatten(name).equals(rank.getIdentifier()))
- {
- remove = rank;
- }
- }
-
- if (remove == null)
- {
- return;
- }
-
- remove.delete();
- ranks.remove(remove);
- }
-
- public boolean hasRank(String name)
- {
- for (GuildRank rank : ranks)
- {
- if (GUtil.flatten(name).equals(rank.getIdentifier()))
+ if (guild.isMember(player))
{
return true;
}
@@ -185,249 +119,747 @@ public class Guild
return false;
}
- public GuildRank getRank(String name)
+ public static void loadAll()
{
- for (GuildRank rank : ranks)
+ Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
+ try
{
- if (GUtil.flatten(name).equals(rank.getIdentifier()))
+ ResultSet set = connection.prepareStatement("SELECT * FROM guilds;").executeQuery();
+ while (set.next())
{
- return rank;
+ String id = set.getString("id");
+ UUID owner = User.getUserFromId(set.getInt("owner")).getUuid();
+ List moderators = new ArrayList<>();
+ if (set.getString("moderators") != null)
+ {
+ for (String string : set.getString("moderators").split(","))
+ {
+ User user = User.getUserFromId(Integer.parseInt(string));
+ if (user != null)
+ {
+ moderators.add(user.getUuid());
+ }
+ }
+ }
+ List members = new ArrayList<>();
+ members.add(owner);
+ if (set.getString("members") != null)
+ {
+ for (String string : set.getString("members").split(","))
+ {
+ User user = User.getUserFromId(Integer.parseInt(string));
+ if (user != null)
+ {
+ members.add(user.getUuid());
+ }
+ }
+ }
+ Map> ranks = new HashMap<>();
+ PreparedStatement rankStatement = connection.prepareStatement("SELECT * FROM ranks WHERE guild_id=?;");
+ rankStatement.setString(1, id);
+ ResultSet rankSet = rankStatement.executeQuery();
+ while (rankSet.next())
+ {
+ List rankMembers = new ArrayList<>();
+ if (rankSet.getString("members") != null)
+ {
+ for (String string : rankSet.getString("members").split(","))
+ {
+ if (string == null || string.isEmpty())
+ {
+ break;
+ }
+ User user = User.getUserFromId(Integer.parseInt(string));
+ if (user != null)
+ {
+ rankMembers.add(user.getUuid());
+ }
+ }
+ }
+ ranks.put(rankSet.getString("name"), rankMembers);
+ }
+ Map warps = new HashMap<>();
+ PreparedStatement warpStatement = connection.prepareStatement("SELECT * FROM warps WHERE guild_id=?;");
+ warpStatement.setString(1, id);
+ ResultSet warpSet = warpStatement.executeQuery();
+ while (warpSet.next())
+ {
+ World w = Bukkit.getWorld(warpSet.getString("world"));
+ if (w == null)
+ {
+ continue;
+ }
+ double x = warpSet.getDouble("x");
+ double y = warpSet.getDouble("y");
+ double z = warpSet.getDouble("z");
+ Location location = new Location(w, x, y, z);
+ warps.put(set.getString("name"), location);
+ }
+ Guild guild = new Guild(set.getString("name"),
+ owner,
+ moderators,
+ members,
+ ranks,
+ warps,
+ set.getString("default_rank"),
+ State.fromInt(set.getInt("state")),
+ set.getString("motd"),
+ set.getDouble("x"),
+ set.getDouble("y"),
+ set.getDouble("z"),
+ set.getString("world"),
+ set.getLong("creation"));
+ guilds.put(id, guild);
+ }
+ TFGuilds.getPlugin().getLogger().info(guilds.size() + " guilds loaded!");
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public static Guild getGuild(Player player)
+ {
+ for (Guild guild : guilds.values())
+ {
+ if (guild.isMember(player))
+ {
+ return guild;
}
}
return null;
}
- public boolean hasTag()
+ public static Guild getGuild(String string)
{
- return tag != null;
+ for (Guild guild : guilds.values())
+ {
+ if (guild.getName().equalsIgnoreCase(string))
+ {
+ return guild;
+ }
+ }
+ return guilds.get(string) != null ? guilds.get(string) : null;
}
- public boolean hasMOTD()
+ public static boolean hasGuild(String string)
{
- return motd != null;
+ for (Guild guild : guilds.values())
+ {
+ if (guild.getName().equalsIgnoreCase(string))
+ {
+ return true;
+ }
+ }
+ return guilds.get(string) != null;
}
- public boolean hasHome()
+ public static List getGuildNames()
{
- return home != null;
+ List names = new ArrayList<>();
+ guilds.values().forEach(guild ->
+ names.add(guild.getName()));
+ return names;
}
- public boolean hasDefaultRank()
+ public void addMember(Player player)
{
- return defaultRank != null;
+ if (!isMember(player))
+ {
+ members.add(player.getUniqueId());
+ save();
+ }
+ }
+
+ public void removeMember(Player player)
+ {
+ if (isMember(player))
+ {
+ if (isModerator(player))
+ {
+ moderators.remove(player);
+ }
+ members.remove(player.getUniqueId());
+ save();
+ }
+ }
+
+ public boolean isMember(Player player)
+ {
+ return members.contains(player.getUniqueId()) || owner.equals(player.getUniqueId());
+ }
+
+ public void addModerator(Player player)
+ {
+ if (!isModerator(player))
+ {
+ moderators.add(player.getUniqueId());
+ save();
+ }
+ }
+
+ public void removeModerator(Player player)
+ {
+ if (isModerator(player))
+ {
+ moderators.remove(player.getUniqueId());
+ save();
+ }
+ }
+
+ public boolean isModerator(Player player)
+ {
+ return moderators.contains(player.getUniqueId()) || owner.equals(player.getUniqueId());
+ }
+
+ public void addWarp(String name, Location location)
+ {
+ if (!hasWarp(name))
+ {
+ warps.put(name, location);
+ saveWarp(name);
+ }
+ }
+
+ public void removeWarp(String name)
+ {
+ if (hasWarp(name))
+ {
+ warps.remove(name);
+ Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
+ try
+ {
+ PreparedStatement statement = connection.prepareStatement("DELETE FROM warps WHERE guild_id=? AND name=?");
+ statement.setString(1, id);
+ statement.setString(2, name);
+ statement.execute();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ public boolean hasWarp(String name)
+ {
+ return warps.get(name) != null;
+ }
+
+ public void createRank(String name)
+ {
+ ranks.put(name.toLowerCase().replaceAll(" ", "_"), new ArrayList<>());
+ Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
+ try
+ {
+ PreparedStatement statement = connection.prepareStatement("INSERT INTO ranks (guild_id, name, members) VALUES (?, ?, ?)");
+ statement.setString(1, id);
+ statement.setString(2, name);
+ statement.setString(3, null);
+ statement.execute();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public void deleteRank(String name)
+ {
+ if (hasRank(name))
+ {
+ ranks.remove(name);
+ Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
+ try
+ {
+ PreparedStatement statement = connection.prepareStatement("DELETE FROM ranks WHERE guild_id=? AND name=?");
+ statement.setString(1, id);
+ statement.setString(2, name);
+ statement.execute();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ public boolean hasRank(String name)
+ {
+ return ranks.get(name) != null;
+ }
+
+ public void setPlayerRank(Player player, String name)
+ {
+ if (hasRank(name))
+ {
+ String str = getPlayerRank(player);
+ if (!str.equals(name) && !str.equals(defaultRank))
+ {
+ removePlayerRank(player, str);
+ }
+ List list = ranks.get(name);
+ list.add(player.getUniqueId());
+ ranks.put(name, list);
+ saveRankMembers(name);
+ }
+ }
+
+ public void removePlayerRank(Player player, String name)
+ {
+ if (hasRank(name))
+ {
+ List list = ranks.get(name);
+ list.remove(player.getUniqueId());
+ ranks.put(name, list);
+ saveRankMembers(name);
+ }
+ }
+
+ public String getPlayerRank(Player player)
+ {
+ for (String rank : ranks.keySet())
+ {
+ if (ranks.get(rank).contains(player.getUniqueId()))
+ {
+ return rank;
+ }
+ }
+ return defaultRank;
+ }
+
+ public String getModeratorIds()
+ {
+ List mod = new ArrayList<>();
+ moderators.forEach(uuid ->
+ mod.add(User.getUserFromUuid(uuid).getId()));
+ return StringUtils.join(mod, ",");
+ }
+
+ public String getMemberIds()
+ {
+ List mem = new ArrayList<>();
+ members.forEach(member ->
+ mem.add(User.getUserFromUuid(member).getId()));
+ return StringUtils.join(mem, ",");
+ }
+
+ public String getMotd()
+ {
+ return GUtil.colorize(motd);
+ }
+
+ public void setMotd(String motd)
+ {
+ this.motd = motd;
+ }
+
+ public void invite(Player player)
+ {
+ invites.add(player);
+ }
+
+ public void removeInvite(Player player)
+ {
+ invites.remove(player);
+ }
+
+ public boolean isInvited(Player player)
+ {
+ return invites.contains(player);
+ }
+
+ public void save(boolean newSave)
+ {
+ Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
+ try
+ {
+ PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO guilds VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
+ : connection.prepareStatement("UPDATE guilds SET owner=?," +
+ "moderators=?," +
+ "members=?," +
+ "tag=?," +
+ "default_rank=?," +
+ "state=?," +
+ "motd=?," +
+ "x=?," +
+ "y=?," +
+ "z=?," +
+ "world=? WHERE id=?");
+ if (newSave)
+ {
+ statement.setString(1, id);
+ statement.setString(2, name);
+ statement.setInt(3, User.getUserFromUuid(owner).getId());
+ statement.setString(4, null);
+ statement.setString(5, null);
+ statement.setString(6, tag);
+ statement.setString(7, defaultRank);
+ statement.setInt(8, state.ordinal());
+ statement.setString(9, motd);
+ statement.setDouble(10, home.getX());
+ statement.setDouble(11, home.getY());
+ statement.setDouble(12, home.getZ());
+ statement.setString(13, home.getWorld().getName());
+ statement.setLong(14, createdAt);
+ }
+ else
+ {
+ statement.setInt(1, User.getUserFromUuid(owner).getId());
+ statement.setString(2, moderators.isEmpty() ? null : getModeratorIds());
+ statement.setString(3, members.isEmpty() ? null : getMemberIds());
+ statement.setString(4, tag);
+ statement.setString(5, defaultRank);
+ statement.setInt(6, state.ordinal());
+ statement.setString(7, motd);
+ statement.setDouble(8, home.getX());
+ statement.setDouble(9, home.getY());
+ statement.setDouble(10, home.getZ());
+ statement.setString(11, home.getWorld().getName());
+ statement.setString(12, id);
+ }
+ statement.execute();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public void save()
+ {
+ save(false);
+ }
+
+ public void saveRankMembers(String name)
+ {
+ if (hasRank(name))
+ {
+ Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
+ try
+ {
+ PreparedStatement statement = connection.prepareStatement("UPDATE ranks SET members=? WHERE guild_id=? AND name=?");
+ statement.setString(1, ranks.get(name).isEmpty() ? null : getMemberIdsByRank(name));
+ statement.setString(2, id);
+ statement.setString(3, name);
+ statement.execute();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ public void saveWarp(String name)
+ {
+ if (hasWarp(name))
+ {
+ Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
+ try
+ {
+ PreparedStatement statement = connection.prepareStatement("INSERT INTO warps VALUES (?, ?, ?, ?, ?, ?)");
+ statement.setString(1, id);
+ statement.setString(2, name);
+ Location location = warps.get(name);
+ statement.setDouble(3, location.getX());
+ statement.setDouble(4, location.getY());
+ statement.setDouble(5, location.getZ());
+ statement.setString(6, location.getWorld().getName());
+ statement.execute();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ public String getMemberIdsByRank(String name)
+ {
+ if (hasRank(name))
+ {
+ ArrayList rankMembers = new ArrayList<>();
+ ranks.get(name).forEach(uuid ->
+ rankMembers.add(User.getUserFromUuid(uuid).getId()));
+ return StringUtils.join(rankMembers, ",");
+ }
+ return null;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public UUID getOwner()
+ {
+ return owner;
+ }
+
+ public void setOwner(Player player)
+ {
+ members.add(owner);
+ owner = player.getUniqueId();
+ members.remove(player.getUniqueId());
+ save();
+ }
+
+ public List getModerators()
+ {
+ return moderators;
+ }
+
+ public List getModeratorNames()
+ {
+ List names = new ArrayList<>();
+ moderators.forEach(uuid ->
+ names.add(Bukkit.getOfflinePlayer(uuid).getName()));
+ return names;
+ }
+
+ public List getMembers()
+ {
+ return members;
+ }
+
+ public List getMemberOnlyNames()
+ {
+ List names = new ArrayList<>();
+ for (UUID uuid : members)
+ {
+ if (!moderators.contains(uuid) && !uuid.equals(owner))
+ {
+ names.add(Bukkit.getOfflinePlayer(uuid).getName());
+ }
+ }
+ return names;
+ }
+
+ public List getNamesByRank(String name)
+ {
+ List names = new ArrayList<>();
+ if (hasRank(name))
+ {
+ ranks.get(name).forEach(uuid ->
+ names.add(Bukkit.getOfflinePlayer(uuid).getName()));
+ }
+ return names;
+ }
+
+ public Map> getRanks()
+ {
+ return ranks;
+ }
+
+ public List getRankNames()
+ {
+ List names = new ArrayList<>();
+ ranks.keySet().forEach(rank ->
+ names.add(rank));
+ return names;
+ }
+
+ public Map getWarps()
+ {
+ return warps;
+ }
+
+ public List getWarpNames()
+ {
+ List names = new ArrayList<>();
+ warps.keySet().forEach(name ->
+ names.add(name));
+ return names;
+ }
+
+ public Location getWarp(String name)
+ {
+ if (hasWarp(name))
+ {
+ return warps.get(name);
+ }
+ return null;
+ }
+
+ public String getDefaultRank()
+ {
+ return defaultRank;
+ }
+
+ public void setDefaultRank(String defaultRank)
+ {
+ this.defaultRank = defaultRank;
+ save();
+ }
+
+ public String getTag()
+ {
+ return tag;
+ }
+
+ public void setTag(String tag)
+ {
+ this.tag = tag;
+ save();
+ }
+
+ public State getState()
+ {
+ return state;
+ }
+
+ public void setState(State state)
+ {
+ this.state = state;
+ save();
+ }
+
+ public Location getHome()
+ {
+ return home;
+ }
+
+ public void setHome(Location home)
+ {
+ this.home = home;
+ save();
+ }
+
+ public void disband()
+ {
+ if (hasGuild(name))
+ {
+ Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
+ try
+ {
+ PreparedStatement ranks = connection.prepareStatement("DELETE FROM ranks WHERE guild_id=?");
+ ranks.setString(1, id);
+ ranks.execute();
+ PreparedStatement warps = connection.prepareStatement("DELETE FROM warps WHERE guild_id=?");
+ warps.setString(1, id);
+ warps.execute();
+ PreparedStatement guild = connection.prepareStatement("DELETE FROM guilds WHERE id=?");
+ guild.setString(1, id);
+ guild.execute();
+ guilds.remove(id);
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
}
public void broadcast(String message)
{
for (Player player : Bukkit.getOnlinePlayers())
{
- if (members.contains(player.getUniqueId()))
+ if (isMember(player))
{
player.sendMessage(message);
}
}
}
- public List getModeratorNames()
+ public void chat(Player player, String message)
{
- List only = new ArrayList<>();
- for (UUID moderator : moderators)
- {
- if (moderator.equals(owner))
- {
- continue;
- }
- OfflinePlayer player = Bukkit.getOfflinePlayer(moderator);
- only.add(player.getName());
- }
- return only;
- }
+ broadcast(GUtil.colorize("&7[&bGuild Chat &7| &b" + name + "&7] " + player.getName() + " &8\u00BB &6") + message);
- public List getOnlyMembers()
- {
- List only = new ArrayList<>();
- for (UUID member : members)
+ if (ConfigEntry.GUILD_CHAT_LOGGING.getBoolean())
{
- if (member.equals(owner) || moderators.contains(member))
- {
- continue;
- }
- OfflinePlayer player = Bukkit.getOfflinePlayer(member);
- only.add(player.getName());
+ Bukkit.getServer().getLogger().info("[Guild Chat | " + name + "] " + player.getName() + " \u00BB " + message);
}
- return only;
- }
- public List getRankNames()
- {
- List names = new ArrayList<>();
- for (GuildRank rank : ranks)
+ for (Player p : Bukkit.getOnlinePlayers())
{
- names.add(rank.getName());
+ if (Common.GUILD_CHAT_SPY.contains(p) && player != p)
+ {
+ p.sendMessage(GUtil.colorize("&7[&bGuild Chat Spy &7| &b" + name + "&7] " + player.getName() + " &8\u00BB &6") + message);
+ }
}
- return names;
}
public String getRoster()
{
- StringBuilder list = new StringBuilder(Common.PREFIX + "Guild Roster for " + name + "\n" +
- "%s%Owner%p% - " + Bukkit.getOfflinePlayer(owner).getName() + "\n" +
- "%s%Moderators%p% - " + StringUtils.join(getModeratorNames(), ", ") + "\n");
+ StringBuilder builder = new StringBuilder();
+ builder.append(ChatColor.AQUA).append("Guild Roster for ").append(ChatColor.GOLD).append(name).append("\n")
+ .append(ChatColor.GRAY).append("Owner: ")
+ .append(ChatColor.GOLD).append(Bukkit.getOfflinePlayer(owner).getName()).append("\n")
+ .append(ChatColor.GRAY).append("Moderators: ")
+ .append(ChatColor.GOLD).append(StringUtils.join(getModeratorNames(), ", ")).append("\n");
- for (GuildRank rank : ranks)
+ for (String rank : ranks.keySet())
{
- list.append("%s%")
- .append(rank.getName()).append("%p% - ")
- .append(StringUtils.join(rank.getMemberNames(), ", "))
- .append("\n");
+ builder.append(ChatColor.GRAY).append(rank).append(": ")
+ .append(ChatColor.GOLD).append(StringUtils.join(getNamesByRank(rank), ", ")).append("\n");
}
- return Common.tl(list +
- "%s%Members%p% - " + StringUtils.join(getOnlyMembers(), ", "));
+ builder.append(ChatColor.GRAY).append("Members: ")
+ .append(ChatColor.GOLD).append(StringUtils.join(getMemberOnlyNames(), ", "));
+ return builder.toString();
}
- public static List getGuildList()
+ @Override
+ public String toString()
{
- List g = new ArrayList<>();
- for (Guild guild : plugin.guilds.values())
- {
- g.add(guild.getName());
- }
- return g;
+ StringBuilder builder = new StringBuilder();
+ builder.append(ChatColor.AQUA).append("Guild Information").append("\n").append(ChatColor.GRAY)
+ .append(" Identifier: ").append(ChatColor.GOLD).append(id).append("\n")
+ .append(ChatColor.GRAY).append(" Name: ").append(ChatColor.GOLD).append(name).append("\n")
+ .append(ChatColor.GRAY).append(" Owner: ").append(ChatColor.GOLD).append(Bukkit.getOfflinePlayer(owner).getName()).append("\n")
+ .append(ChatColor.GRAY).append(" Moderators (").append(getModerators().size()).append("): ").append(ChatColor.GOLD).append(StringUtils.join(getModeratorNames(), ", ")).append("\n")
+ .append(ChatColor.GRAY).append(" Members (").append(getMembers().size()).append("): ").append(ChatColor.GOLD).append(StringUtils.join(getMemberOnlyNames(), ", ")).append("\n")
+ .append(ChatColor.GRAY).append(" Tag: ").append(ChatColor.GOLD).append(tag != null ? GUtil.colorize(tag) : "None").append("\n")
+ .append(ChatColor.GRAY).append(" State: ").append(ChatColor.GOLD).append(state.name()).append("\n")
+ .append(ChatColor.GRAY).append(" Ranks (").append(ranks.size()).append("): ").append(ChatColor.GOLD).append(StringUtils.join(getRankNames(), ", ")).append("\n")
+ .append(ChatColor.GRAY).append(" Created At: ").append(ChatColor.GOLD).append(GUtil.formatTime(createdAt));
+ return builder.toString();
}
- public static List getGuildWarps()
+ public long getCreatedAt()
{
- List warps = new ArrayList<>();
- for (GuildWarp warp : plugin.warps.values())
- {
- warps.add(warp.getWarpName());
- }
- return warps;
+ return createdAt;
}
- public GuildWarp getWarp(String warpName)
+ public enum State
{
- GuildWarp warp = plugin.warps.get(identifier);
- if (warp != null && warp.getWarpName().equalsIgnoreCase(warpName))
+ OPEN,
+ INVITE_ONLY,
+ CLOSED;
+
+ public static State fromString(String string)
{
- return warp;
- }
- return null;
- }
-
- public String getInformation()
- {
- return Common.tl(Common.PREFIX + "Guild Information\n" +
- "%s%Name%p%: " + name + "\n" +
- "%s%Owner%p%: " + Bukkit.getOfflinePlayer(owner).getName() + "\n" +
- "%s%Moderators%p%: " + StringUtils.join(getModeratorNames(), ", ") + "\n" +
- "%s%Members%p%: " + StringUtils.join(getOnlyMembers(), ", ") + "\n" +
- "%s%Tag%p%: " + (tag == null ? "None" : GUtil.colorize(tag)) + "\n" +
- "%s%State%p%: " + state.getDisplay() + "\n" +
- "%s%Ranks%p%: " + StringUtils.join(getRankNames(), ", ") + "\n" +
- "%s%Creation%p%: " + GUtil.format(creation) + "\n" +
- "%s%Identifier (Technical)%p%: " + identifier);
- }
-
- public void chat(String as, String msg)
- {
- broadcast(Common.tl("%s%[%p%Guild Chat %s%| %p%" + GUtil.colorize(name) + "%s%] %p%" + as + ChatColor.WHITE + ": %p%" + msg));
-
- if (ConfigEntry.GUILD_CHAT_LOGGING_ENABLED.getBoolean())
- {
- GLog.info(Common.tl("%s%[%p%Guild Chat %s%| %p%" + GUtil.colorize(name) + "%s%] %p%" + as + ChatColor.WHITE + ": %p%" + msg));
- }
-
- Player sender = Bukkit.getPlayer(as);
-
- for (Player player : Bukkit.getOnlinePlayers())
- {
- if (Common.CHAT_SPY.contains(player))
+ if (string.contains(" "))
{
- if (sender != null)
+ string = string.replaceAll(" ", "_");
+ }
+ try
+ {
+ return valueOf(string.toUpperCase());
+ }
+ catch (Exception ex)
+ {
+ }
+ return null;
+ }
+
+ public static State fromInt(int value)
+ {
+ for (State state : values())
+ {
+ if (state.ordinal() == value)
{
- if (player == sender)
- {
- continue;
- }
+ return state;
}
- player.sendMessage(GUtil.colorize("&7[GUILD CHAT SPY | " + GUtil.colorize(name) + "] " + as + ": " + msg));
}
+ return null;
}
}
-
- public void disband()
- {
- for (UUID member : members)
- {
- Player player = Bukkit.getPlayer(member);
- if (player == null)
- {
- continue;
- }
- Common.IN_GUILD_CHAT.remove(player);
- }
- plugin.guildData.delete(this);
- }
-
- public void rename(String name)
- {
- String oldIdentifier = this.identifier;
- this.identifier = GUtil.flatten(name);
- updateRankIdentifiers();
- this.name = name;
- this.tag = GUtil.colorize("&8[&7" + name + "&8]");
- plugin.guildData.save(this, oldIdentifier);
- }
-
- public void updateRankIdentifiers()
- {
- for (GuildRank rank : ranks)
- {
- rank.updateGuildIdentifier(identifier);
- }
- }
-
- public static Guild createGuild(String identifier, String name, Player owner)
- {
- if (plugin.guildData.exists(identifier))
- {
- return getGuild(identifier);
- }
-
- Guild guild = plugin.guildData.create(identifier, name, owner);
- GLog.info(owner.getName() + " has created guild " + name);
- return guild;
- }
-
- public static Guild getGuild(String identifier)
- {
- return plugin.guilds.get(identifier);
- }
-
- public static Guild getGuild(Player player)
- {
- return plugin.guildData.get(player);
- }
-
- public static boolean guildExists(String identifier)
- {
- return plugin.guildData.exists(identifier);
- }
-
- public static boolean isInGuild(Player player)
- {
- return getGuild(player) != null;
- }
-
- public static GuildWarp createWarp(String identifier, String warpName, Player player)
- {
- return GuildWarp.createGuildWarp(identifier, warpName, player);
- }
-
- public boolean warpExists(String warpName)
- {
- return plugin.warpData.exists(identifier, warpName);
- }
-}
\ No newline at end of file
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/GuildRank.java b/src/main/java/me/totalfreedom/tfguilds/guild/GuildRank.java
deleted file mode 100644
index cb8abac..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/guild/GuildRank.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package me.totalfreedom.tfguilds.guild;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-import lombok.Getter;
-import me.totalfreedom.tfguilds.TFGuilds;
-import org.bukkit.Bukkit;
-import org.bukkit.OfflinePlayer;
-
-public class GuildRank
-{
- private static final TFGuilds plugin = TFGuilds.getPlugin();
-
- @Getter
- private String iguild;
-
- // identifier
- @Getter
- private final String identifier;
-
- // name
- @Getter
- private final String name;
-
- // members of this rank
- @Getter
- private final List members;
-
- public GuildRank(String iguild, String identifier, String name, List members)
- {
- this.iguild = iguild;
- this.identifier = identifier;
- this.name = name;
- this.members = members;
- }
-
- public List getMemberNames()
- {
- List only = new ArrayList<>();
- for (UUID member : members)
- {
- OfflinePlayer player = Bukkit.getOfflinePlayer(member);
- only.add(player.getName());
- }
- return only;
- }
-
- public static GuildRank createGuildRank(String guildIdentifier, String identifier, String name)
- {
- return plugin.rankData.create(guildIdentifier, identifier, name);
- }
-
- public void save()
- {
- plugin.rankData.save(this);
- }
-
- public void updateGuildIdentifier(String newIdentifier)
- {
- plugin.rankData.updateGuildIdentifier(this, newIdentifier);
- this.iguild = newIdentifier;
- }
-
- public void delete()
- {
- plugin.rankData.delete(this);
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/GuildState.java b/src/main/java/me/totalfreedom/tfguilds/guild/GuildState.java
deleted file mode 100644
index 1e69972..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/guild/GuildState.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package me.totalfreedom.tfguilds.guild;
-
-import lombok.Getter;
-
-public enum GuildState
-{
- OPEN("Open"),
- INVITE_ONLY("Invite-only"),
- CLOSED("Closed");
-
- @Getter
- private final String display;
-
- GuildState(String display)
- {
- this.display = display;
- }
-
- public static GuildState findState(String string)
- {
- if (string == null)
- {
- return null;
- }
-
- switch (string.toLowerCase())
- {
- case "open":
- case "opened":
- return OPEN;
- case "invite":
- case "inviteonly":
- case "invite_only":
- return INVITE_ONLY;
- case "closed":
- case "close":
- return CLOSED;
- }
- return null;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/GuildWarp.java b/src/main/java/me/totalfreedom/tfguilds/guild/GuildWarp.java
deleted file mode 100644
index c31a8f9..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/guild/GuildWarp.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package me.totalfreedom.tfguilds.guild;
-
-import lombok.Getter;
-import me.totalfreedom.tfguilds.TFGuilds;
-import org.bukkit.World;
-import org.bukkit.entity.Player;
-
-@Getter
-public class GuildWarp
-{
- private static final TFGuilds plugin = TFGuilds.getPlugin();
-
- private final String iguild;
- private final String warpName;
- private final double x;
- private final double y;
- private final double z;
- private final World world;
-
- public GuildWarp(String iguild, String warpName, double x, double y, double z, World world)
- {
- this.iguild = iguild;
- this.warpName = warpName;
- this.x = x;
- this.y = y;
- this.z = z;
- this.world = world;
- }
-
- public static GuildWarp createGuildWarp(String identifier, String name, Player player)
- {
- return plugin.warpData.create(identifier, name, player);
- }
-
- public void save()
- {
- plugin.warpData.save(this);
- }
-
- public void delete()
- {
- plugin.warpData.delete(this);
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/User.java b/src/main/java/me/totalfreedom/tfguilds/guild/User.java
new file mode 100644
index 0000000..1e2fef1
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/User.java
@@ -0,0 +1,141 @@
+package me.totalfreedom.tfguilds.guild;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+import me.totalfreedom.tfguilds.TFGuilds;
+import org.bukkit.entity.Player;
+
+public class User
+{
+
+ private static Map users = new HashMap<>();
+ //
+ private final int id;
+ private final UUID uuid;
+ private boolean tag;
+
+ public User(int id, UUID uuid, boolean tag)
+ {
+ this.id = id;
+ this.uuid = uuid;
+ this.tag = tag;
+ }
+
+ public static User create(Player player)
+ {
+ int id = users.size() + 1;
+ User user = new User(id, player.getUniqueId(), true);
+ users.put(id, user);
+ user.save(true);
+ return user;
+ }
+
+ public static void loadAll()
+ {
+ Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
+ try
+ {
+ ResultSet set = connection.prepareStatement("SELECT * FROM users").executeQuery();
+ while (set.next())
+ {
+ int id = set.getInt("id");
+ UUID uuid = UUID.fromString(set.getString("uuid"));
+ boolean tag = set.getBoolean("tag");
+ users.put(id, new User(id, uuid, tag));
+ }
+ TFGuilds.getPlugin().getLogger().info(users.size() + " users loaded!");
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public static boolean hasUser(int id)
+ {
+ return users.get(id) != null;
+ }
+
+ public static User getUserFromId(int id)
+ {
+ if (hasUser(id))
+ {
+ return users.get(id);
+ }
+ return null;
+ }
+
+ public static User getUserFromUuid(UUID uuid)
+ {
+ for (User user : users.values())
+ {
+ if (user.getUuid().equals(uuid))
+ {
+ return user;
+ }
+ }
+ return null;
+ }
+
+ public static User getUserFromPlayer(Player player)
+ {
+ return getUserFromUuid(player.getUniqueId());
+ }
+
+ public int getId()
+ {
+ return id;
+ }
+
+ public UUID getUuid()
+ {
+ return uuid;
+ }
+
+ public boolean displayTag()
+ {
+ return tag;
+ }
+
+ public void setDisplayTag(boolean tag)
+ {
+ this.tag = tag;
+ save();
+ }
+
+ public void save(boolean newSave)
+ {
+ Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
+ try
+ {
+ PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO users VALUES (?, ?, ?)")
+ : connection.prepareStatement("UPDATE users SET tag=? WHERE id=?");
+ if (newSave)
+ {
+ statement.setString(1, uuid.toString());
+ statement.setInt(2, id);
+ statement.setBoolean(3, tag);
+ }
+ else
+ {
+ statement.setBoolean(1, tag);
+ statement.setInt(2, id);
+ }
+ statement.execute();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public void save()
+ {
+ save(false);
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
index bd3cc51..ab7bbb3 100644
--- a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
+++ b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
@@ -4,8 +4,7 @@ import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.config.ConfigEntry;
import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.guild.GuildRank;
-import me.totalfreedom.tfguilds.user.User;
+import me.totalfreedom.tfguilds.guild.User;
import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
@@ -16,75 +15,55 @@ import org.bukkit.event.player.AsyncPlayerChatEvent;
public class ChatListener implements Listener
{
- private static final TFGuilds plugin = TFGuilds.getPlugin();
+
+ public ChatListener(TFGuilds plugin)
+ {
+ plugin.getServer().getPluginManager().registerEvents(this, plugin);
+ }
@EventHandler(priority = EventPriority.HIGHEST)
- public void onPlayerChat(AsyncPlayerChatEvent e)
+ public void onPlayerChat(AsyncPlayerChatEvent event)
{
- Player player = e.getPlayer();
+ Player player = event.getPlayer();
Guild guild = Guild.getGuild(player);
if (guild == null)
{
return;
}
- if (Common.IN_GUILD_CHAT.contains(player))
+ if (Common.GUILD_CHAT.contains(player))
{
- guild.chat(player.getName(), e.getMessage());
- e.setCancelled(true);
+ event.setCancelled(true);
+ guild.chat(player, event.getMessage());
return;
}
- GuildRank rank = null;
- for (GuildRank r : guild.getRanks())
+ if (!ConfigEntry.GUILD_TAGS.getBoolean())
{
- if (r != null)
- {
- if (r.getMembers() != null)
- {
- if (r.getMembers().contains(player.getUniqueId()))
- {
- rank = r;
- }
- }
- }
+ return;
}
- String display;
- if (rank == null)
+ String display = guild.getPlayerRank(player);
+ if (display == guild.getDefaultRank())
{
if (guild.getOwner().equals(player.getUniqueId()))
{
display = "Guild Owner";
}
- else if (guild.hasModerator(player.getUniqueId()))
+ else if (guild.isModerator(player))
{
display = "Guild Moderator";
}
- else
- {
- display = "Guild Member";
- }
}
- else
+ else if (display == null)
{
- display = rank.getName();
+ display = "Guild Member";
}
- if (!ConfigEntry.GUILD_TAGS_ENABLED.getBoolean())
+ User user = User.getUserFromPlayer(player);
+ if (guild.getTag() != null && user.displayTag())
{
- return;
- }
-
- User user = plugin.userData.get(player.getUniqueId());
- if (!user.isTag())
- {
- return;
- }
-
- if (guild.hasTag())
- {
- e.setFormat(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + e.getFormat());
+ event.setFormat(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + event.getFormat());
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/listener/JoinListener.java b/src/main/java/me/totalfreedom/tfguilds/listener/JoinListener.java
index 1aabd3d..7297ed8 100644
--- a/src/main/java/me/totalfreedom/tfguilds/listener/JoinListener.java
+++ b/src/main/java/me/totalfreedom/tfguilds/listener/JoinListener.java
@@ -1,27 +1,42 @@
package me.totalfreedom.tfguilds.listener;
+import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.util.GUtil;
+import me.totalfreedom.tfguilds.guild.User;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
+import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
public class JoinListener implements Listener
{
- @EventHandler
- public void onPlayerJoin(PlayerJoinEvent e)
+
+ public JoinListener(TFGuilds plugin)
{
- Player player = e.getPlayer();
+ plugin.getServer().getPluginManager().registerEvents(this, plugin);
+ }
+
+ @EventHandler(priority = EventPriority.HIGHEST)
+ public void onPlayerJoin(PlayerJoinEvent event)
+ {
+ Player player = event.getPlayer();
+
+ User user = User.getUserFromPlayer(player);
+ if (user == null)
+ {
+ User.create(player);
+ }
+
Guild guild = Guild.getGuild(player);
if (guild == null)
{
return;
}
- if (guild.hasMOTD())
+ if (guild.getMotd() != null && !guild.getMotd().isEmpty())
{
- player.sendMessage(GUtil.colorize(guild.getMotd()));
+ player.sendMessage(guild.getMotd());
}
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
index 0926641..4a23839 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
@@ -1,40 +1,39 @@
package me.totalfreedom.tfguilds.sql;
-import java.io.File;
-import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import me.totalfreedom.tfguilds.TFGuilds;
+import me.totalfreedom.tfguilds.config.ConfigEntry;
+import org.bukkit.Bukkit;
public class SQLDatabase
{
- private static final String DATABASE_FILENAME = "database.db";
+
private Connection connection;
- public SQLDatabase()
+ public SQLDatabase(TFGuilds plugin)
{
- File file = new File(TFGuilds.getPlugin().getDataFolder(), DATABASE_FILENAME);
- if (!file.exists())
+ String password = ConfigEntry.MYSQL_PASSWORD.getString();
+ if (password == null)
{
- try
- {
- file.createNewFile();
- TFGuilds.getPlugin().saveResource(DATABASE_FILENAME, false);
- }
- catch (IOException ex)
- {
- ex.printStackTrace();
- }
+ password = "";
}
try
{
- connection = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath());
+ Bukkit.getLogger().info(ConfigEntry.MYSQL_USERNAME.getString());
+ connection = DriverManager.getConnection(String.format("jdbc:mysql://%s:%d/%s",
+ ConfigEntry.MYSQL_HOST.getString(),
+ ConfigEntry.MYSQL_PORT.getInteger(),
+ ConfigEntry.MYSQL_DATABASE.getString()),
+ ConfigEntry.MYSQL_USERNAME.getString(),
+ password);
createTables();
+ plugin.getLogger().info("Connection to the MySQL server established!");
}
catch (SQLException ex)
{
- ex.printStackTrace();
+ plugin.getLogger().severe("Could not connect to MySQL server!");
}
}
@@ -45,45 +44,39 @@ public class SQLDatabase
private void createTables() throws SQLException
{
- connection.prepareStatement("CREATE TABLE IF NOT EXISTS `users` (\n" +
- "\t`id` INT,\n" +
- "\t`uuid` TINYTEXT,\n" +
- "\t`tag` BOOL\n" +
- ");").execute();
- connection.prepareStatement("CREATE TABLE IF NOT EXISTS `worlds` (\n" +
- "\t`id` SMALLINT,\n" +
- "\t`name` TINYTEXT\n" +
- ");").execute();
- connection.prepareStatement("CREATE TABLE IF NOT EXISTS `ranks` (\n" +
- "\t`guild_identifier` TEXT,\n" +
- "\t`identifier` TEXT,\n" +
- "\t`name` TEXT,\n" +
- "\t`members` TEXT\n" +
- ");").execute();
- connection.prepareStatement("CREATE TABLE IF NOT EXISTS `guilds` (\n" +
- "\t`identifier` TEXT,\n" +
- "\t`name` TEXT,\n" +
- "\t`owner` INT,\n" +
- "\t`moderators` TEXT,\n" +
- "\t`members` TEXT,\n" +
- "\t`tag` TEXT,\n" +
- "\t`state` TINYINT,\n" +
- "\t`ranks` TEXT,\n" +
- "\t`motd` TEXT,\n" +
- "\t`x` DOUBLE,\n" +
- "\t`y` DOUBLE,\n" +
- "\t`z` DOUBLE,\n" +
- "\t`world` SMALLINT,\n" +
- "\t`default_rank` TEXT,\n" +
- "\t`creation` BIGINT\n" +
- ");").execute();
- connection.prepareStatement("CREATE TABLE IF NOT EXISTS `warps` (\n" +
- "\t`identifier` TEXT,\n" +
- "\t`warp_name` TEXT,\n" +
- "\t`x` DOUBLE,\n" +
- "\t`y` DOUBLE,\n" +
- "\t`z` DOUBLE,\n" +
- "\t`world` SMALLINT\n" +
- ");").execute();
+ connection.prepareStatement("CREATE TABLE IF NOT EXISTS `users` (" +
+ "`uuid` TEXT," +
+ "`id` INT," +
+ "`tag` BOOLEAN)")
+ .execute();
+ connection.prepareStatement("CREATE TABLE IF NOT EXISTS `warps` (" +
+ "`guild_id` TEXT," +
+ "`name` TEXT," +
+ "`x` DOUBLE," +
+ "`y` DOUBLE," +
+ "`z` DOUBLE," +
+ "`world` TEXT)")
+ .execute();
+ connection.prepareStatement("CREATE TABLE IF NOT EXISTS `guilds` (" +
+ "`id` TEXT," +
+ "`name` TEXT," +
+ "`owner` INT," +
+ "`moderators` TEXT," +
+ "`members` TEXT," +
+ "`tag` TEXT," +
+ "`default_rank` TEXT," +
+ "`state` INT," +
+ "`motd` TEXT," +
+ "`x` DOUBLE," +
+ "`y` DOUBLE," +
+ "`z` DOUBLE," +
+ "`world` TEXT," +
+ "`creation` LONG)")
+ .execute();
+ connection.prepareStatement("CREATE TABLE IF NOT EXISTS `ranks` (" +
+ "`guild_id` TEXT," +
+ "`name` TEXT," +
+ "`members` TEXT)")
+ .execute();
}
-}
\ No newline at end of file
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
deleted file mode 100644
index 6649083..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLGuildData.java
+++ /dev/null
@@ -1,229 +0,0 @@
-package me.totalfreedom.tfguilds.sql;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.UUID;
-import me.totalfreedom.tfguilds.TFGuilds;
-import me.totalfreedom.tfguilds.guild.Guild;
-import me.totalfreedom.tfguilds.guild.GuildRank;
-import me.totalfreedom.tfguilds.guild.GuildState;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.Location;
-import org.bukkit.entity.Player;
-
-public class SQLGuildData
-{
-
- private static final TFGuilds plugin = TFGuilds.getPlugin();
- private static final String TABLE_NAME = "guilds";
-
- private final String SELECT = "SELECT * FROM `" + TABLE_NAME + "` WHERE identifier=?";
- private final String SELECT_MEMBER = "SELECT * FROM `" + TABLE_NAME + "` WHERE members LIKE ?";
- private final String SELECT_ALL = "SELECT * FROM `" + TABLE_NAME + "`";
- private final String UPDATE = "UPDATE `" + TABLE_NAME + "` SET identifier=?, name=?, owner=?, members=?, moderators=?, tag=?, state=?, ranks=?, motd=?, x=?, y=?, z=?, world=?, default_rank=? WHERE identifier=?";
- private final String DELETE = "DELETE FROM `" + TABLE_NAME + "` WHERE identifier=?";
- private final String INSERT = "INSERT INTO `" + TABLE_NAME + "` (`identifier`, `name`, `owner`, `members`, " +
- "`moderators`, `tag`, `state`, `ranks`, `motd`, `x`, `y`, `z`, `world`, `default_rank`, `creation`) " +
- "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);";
-
- public boolean exists(String identifier)
- {
- return plugin.guilds.containsKey(identifier);
- }
-
- public Guild get(String identifier)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(SELECT);
- statement.setString(1, identifier);
- ResultSet set = statement.executeQuery();
- boolean next = set.next();
- if (!next)
- {
- return null;
- }
- String name = set.getString("name");
- UUID owner = plugin.userData.get(set.getInt("owner")).getUuid();
- List members = new ArrayList<>();
- for (String stringMember : set.getString("members").split(","))
- {
- members.add(plugin.userData.get(Integer.parseInt(stringMember)).getUuid());
- }
- List moderators = new ArrayList<>();
- if (set.getString("moderators") != null)
- {
- for (String stringModerator : set.getString("moderators").split(","))
- {
- moderators.add(plugin.userData.get(Integer.parseInt(stringModerator)).getUuid());
- }
- }
- String tag = set.getString("tag");
- GuildState state = GuildState.values()[set.getInt("state")];
- List ranks = new ArrayList<>();
- if (set.getString("ranks") != null)
- {
- for (String rankString : set.getString("ranks").split(","))
- {
- ranks.add(plugin.rankData.get(identifier, rankString));
- }
- }
- String motd = set.getString("motd");
- Location home = new Location(plugin.worldData.getWorld(set.getInt("world")),
- set.getDouble("x"),
- set.getDouble("y"),
- set.getDouble("z"));
- String defaultRank = set.getString("default_rank");
- long creation = set.getLong("creation");
- return new Guild(identifier, name, owner, members, moderators, tag, state, ranks, motd, home, creation, defaultRank);
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return null;
- }
-
- public Guild get(Player player)
- {
- for (Guild guild : plugin.guilds.values())
- {
- if (guild.getMembers().contains(player.getUniqueId()))
- {
- return guild;
- }
- }
- return null;
- }
-
- public void getAll()
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(SELECT_ALL);
- ResultSet set = statement.executeQuery();
- while (set.next())
- {
- String identifier = set.getString("identifier");
- plugin.guilds.put(identifier, get(identifier));
- }
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- }
-
- public Guild create(String identifier, String name, Player owner)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(INSERT);
- statement.setString(1, identifier);
- statement.setString(2, name);
- int ownerID = plugin.userData.get(owner.getUniqueId()).getId();
- statement.setInt(3, ownerID);
- statement.setString(4, "" + ownerID);
- statement.setString(5, null);
- statement.setString(6, "&8[&7" + name + "&8]");
- statement.setInt(7, GuildState.INVITE_ONLY.ordinal());
- statement.setString(8, null);
- statement.setString(9, null);
- statement.setDouble(10, 0.0);
- statement.setDouble(11, 100.0);
- statement.setDouble(12, 0.0);
- statement.setInt(13, plugin.worldData.getWorldID(Bukkit.getWorlds().get(0)));
- statement.setString(14, null);
- long creation = System.currentTimeMillis();
- statement.setLong(15, creation);
- statement.execute();
- Guild guild = new Guild(identifier, name, owner.getUniqueId(), Collections.singletonList(owner.getUniqueId()), new ArrayList<>(),
- ChatColor.DARK_GRAY + "[" + ChatColor.GRAY + name + ChatColor.DARK_GRAY + "]",
- GuildState.INVITE_ONLY, new ArrayList<>(), null, new Location(Bukkit.getWorlds().get(0), 0.0, 100.0, 0.0), creation, null);
- plugin.guilds.put(identifier, guild);
- return guild;
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return null;
- }
-
- public void save(Guild guild, String identifier)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(UPDATE);
- statement.setString(1, guild.getIdentifier());
- statement.setString(2, guild.getName());
- statement.setString(3, "" + plugin.userData.get(guild.getOwner()).getId());
- List members = new ArrayList<>();
- for (UUID member : guild.getMembers())
- {
- members.add("" + plugin.userData.get(member).getId());
- }
- statement.setString(4, members.size() == 0 ? null : StringUtils.join(members, ","));
- List moderators = new ArrayList<>();
- for (UUID moderator : guild.getModerators())
- {
- moderators.add("" + plugin.userData.get(moderator).getId());
- }
- statement.setString(5, moderators.size() == 0 ? null : StringUtils.join(moderators, ","));
- statement.setString(6, guild.getTag());
- statement.setInt(7, guild.getState().ordinal());
- List stringRanks = new ArrayList<>();
- for (GuildRank rank : guild.getRanks())
- {
- stringRanks.add(rank.getIdentifier());
- }
- statement.setString(8, stringRanks.size() == 0 ? null : StringUtils.join(stringRanks, ","));
- statement.setString(9, guild.getMotd());
- Location home = guild.getHome();
- statement.setDouble(10, home == null ? 0.0 : home.getX());
- statement.setDouble(11, home == null ? 100.0 : home.getY());
- statement.setDouble(12, home == null ? 0.0 : home.getZ());
- statement.setInt(13, home == null ? plugin.worldData.getWorldID(Bukkit.getWorlds().get(0)) : plugin.worldData.getWorldID(home.getWorld()));
- statement.setString(14, guild.getDefaultRank());
- statement.setString(15, identifier);
- statement.execute();
- plugin.guilds.put(identifier, guild);
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- }
-
- public void save(Guild guild)
- {
- save(guild, guild.getIdentifier());
- }
-
- public void delete(Guild guild)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(DELETE);
- statement.setString(1, guild.getIdentifier());
- statement.execute();
- plugin.guilds.remove(guild.getIdentifier());
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
deleted file mode 100644
index 420dcc9..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLRankData.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package me.totalfreedom.tfguilds.sql;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-import me.totalfreedom.tfguilds.TFGuilds;
-import me.totalfreedom.tfguilds.guild.GuildRank;
-import org.apache.commons.lang.StringUtils;
-
-public class SQLRankData
-{
- private static final TFGuilds plugin = TFGuilds.getPlugin();
- private static final String TABLE_NAME = "ranks";
-
- private final String SELECT = "SELECT * FROM `" + TABLE_NAME + "` WHERE guild_identifier=? AND identifier=?";
- private final String UPDATE = "UPDATE `" + TABLE_NAME + "` SET name=?, members=? WHERE guild_identifier=? AND identifier=?";
- private final String UPDATE_GUILD = "UPDATE `" + TABLE_NAME + "` SET guild_identifier=? WHERE guild_identifier=? AND identifier=?";
- private final String DELETE = "DELETE FROM `" + TABLE_NAME + "` WHERE guild_identifier=? AND identifier=?";
- private final String INSERT = "INSERT INTO `" + TABLE_NAME + "` (`guild_identifier`, `identifier`, `name`, `members`) " +
- "VALUES (?, ?, ?, ?);";
-
- public boolean exists(String guildIdentifier, String identifier)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(SELECT);
- statement.setString(1, guildIdentifier);
- statement.setString(2, identifier);
- ResultSet set = statement.executeQuery();
- return set.next();
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return false;
- }
-
- public GuildRank get(String guildIdentifier, String identifier)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(SELECT);
- statement.setString(1, guildIdentifier);
- statement.setString(2, identifier);
- ResultSet set = statement.executeQuery();
- if (!set.next())
- {
- return null;
- }
- String name = set.getString("name");
- List members = new ArrayList<>();
- if (set.getString("members") != null)
- {
- for (String stringMember : set.getString("members").split(","))
- {
- members.add(plugin.userData.get(Integer.parseInt(stringMember)).getUuid());
- }
- }
- return new GuildRank(guildIdentifier, identifier, name, members);
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return null;
- }
-
- public GuildRank create(String guildIdentifier, String identifier, String name)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(INSERT);
- statement.setString(1, guildIdentifier);
- statement.setString(2, identifier);
- statement.setString(3, name);
- statement.setString(4, null);
- statement.execute();
- return new GuildRank(guildIdentifier, identifier, name, new ArrayList<>());
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return null;
- }
-
- public void save(GuildRank rank)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(UPDATE);
- statement.setString(1, rank.getName());
- List members = new ArrayList<>();
- for (UUID member : rank.getMembers())
- {
- members.add("" + plugin.userData.get(member).getId());
- }
- statement.setString(2, members.size() == 0 ? null : StringUtils.join(members, ","));
- statement.setString(3, rank.getIguild());
- statement.setString(4, rank.getIdentifier());
- statement.execute();
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- }
-
- public void updateGuildIdentifier(GuildRank rank, String newIdentifier)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(UPDATE_GUILD);
- statement.setString(1, newIdentifier);
- statement.setString(2, rank.getIguild());
- statement.setString(3, rank.getIdentifier());
- statement.execute();
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- }
-
- public void delete(GuildRank rank)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(DELETE);
- statement.setString(1, rank.getIguild());
- statement.setString(2, rank.getIdentifier());
- statement.execute();
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java
deleted file mode 100644
index af25ec0..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLUserData.java
+++ /dev/null
@@ -1,155 +0,0 @@
-package me.totalfreedom.tfguilds.sql;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.UUID;
-import me.totalfreedom.tfguilds.TFGuilds;
-import me.totalfreedom.tfguilds.user.User;
-
-public class SQLUserData
-{
- private static final TFGuilds plugin = TFGuilds.getPlugin();
- private static final String TABLE_NAME = "users";
-
- private final String SELECT = "SELECT * FROM `" + TABLE_NAME + "` WHERE uuid=?";
- private final String SELECT_ID = "SELECT * FROM `" + TABLE_NAME + "` WHERE id=?";
- private final String UPDATE = "UPDATE `" + TABLE_NAME + "` SET tag=? WHERE uuid=?";
- private final String INSERT = "INSERT INTO `" + TABLE_NAME + "` (`id`, `uuid`, `tag`) " +
- "VALUES (?, ?, ?);";
- private final String COUNT = "SELECT COUNT(*) AS rows FROM `" + TABLE_NAME + "`";
-
- public boolean exists(UUID uuid)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(SELECT);
- statement.setString(1, uuid.toString());
- ResultSet set = statement.executeQuery();
- return set.next();
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return false;
- }
-
- public boolean existsID(int id)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(SELECT_ID);
- statement.setInt(1, id);
- ResultSet set = statement.executeQuery();
- return set.next();
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return false;
- }
-
- public User get(UUID uuid)
- {
- if (!exists(uuid))
- {
- create(uuid);
- }
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(SELECT);
- statement.setString(1, uuid.toString());
- ResultSet set = statement.executeQuery();
- set.next();
- int id = set.getInt("id");
- boolean tag = set.getBoolean("tag");
- return new User(id, uuid, tag);
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return null;
- }
-
- public User get(int id)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(SELECT_ID);
- statement.setInt(1, id);
- ResultSet set = statement.executeQuery();
- set.next();
- UUID uuid = UUID.fromString(set.getString("uuid"));
- boolean tag = set.getBoolean("tag");
- return new User(id, uuid, tag);
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return null;
- }
-
- public User create(UUID uuid)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(INSERT);
- int id = getUserCount() + 1;
- statement.setInt(1, id);
- statement.setString(2, uuid.toString());
- statement.setBoolean(3, true);
- statement.execute();
- return new User(id, uuid, true);
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return null;
- }
-
- public void save(User user)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(UPDATE);
- statement.setBoolean(1, user.isTag());
- statement.setString(2, user.getUuid().toString());
- statement.execute();
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- }
-
- public int getUserCount()
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(COUNT);
- ResultSet set = statement.executeQuery();
- set.next();
- int count = set.getInt("rows");
- set.close();
- return count;
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return 0;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLWarpData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLWarpData.java
deleted file mode 100644
index 0cec480..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLWarpData.java
+++ /dev/null
@@ -1,134 +0,0 @@
-package me.totalfreedom.tfguilds.sql;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.List;
-import me.totalfreedom.tfguilds.TFGuilds;
-import me.totalfreedom.tfguilds.guild.GuildWarp;
-import org.bukkit.World;
-import org.bukkit.entity.Player;
-
-public class SQLWarpData
-{
- private static final TFGuilds plugin = TFGuilds.getPlugin();
- private static final String TABLE_NAME = "warps";
-
- private final String SELECT = "SELECT * FROM `" + TABLE_NAME + "` WHERE identifier=? AND warp_name=?";
- private final String SELECT_ALL = "SELECT * FROM `" + TABLE_NAME + "`";
- private final String UPDATE = "UPDATE `" + TABLE_NAME + "` WHERE identifier=? AND warp_name=? SET x=?, y=?, z=?, world=?";
- private final String DELETE = "DELETE FROM `" + TABLE_NAME + "` WHERE identifier=? AND warp_name=?";
- private final String INSERT = "INSERT INTO `" + TABLE_NAME + "` (`identifier`, `warp_name`, `x`, `y`, `z`, `world`) VALUES (?, ?, ?, ?, ?, ?);";
-
- public boolean exists(String identifier, String warpName)
- {
- GuildWarp warp = plugin.warps.get(identifier);
- return warp != null && warp.getWarpName().equalsIgnoreCase(warpName);
- }
-
- public GuildWarp get(String identifier, String warpName)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(SELECT);
- statement.setString(1, identifier);
- statement.setString(2, warpName);
- ResultSet set = statement.executeQuery();
- double x = set.getDouble("x");
- double y = set.getDouble("y");
- double z = set.getDouble("z");
- World world = plugin.worldData.getWorld(set.getInt("world"));
- return new GuildWarp(identifier, warpName, x, y, z, world);
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return null;
- }
-
- public void getAll()
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(SELECT_ALL);
- ResultSet set = statement.executeQuery();
- while (set.next())
- {
- String identifier = set.getString("identifier");
- plugin.warps.put(identifier, get(identifier, set.getString("warp_name")));
- }
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- }
-
- public GuildWarp create(String identifier, String warpName, Player player)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(INSERT);
- statement.setString(1, identifier);
- statement.setString(2, warpName);
- statement.setDouble(3, player.getLocation().getX());
- statement.setDouble(4, player.getLocation().getY());
- statement.setDouble(5, player.getLocation().getZ());
- statement.setInt(6, plugin.worldData.getWorldID(player.getWorld()));
- statement.execute();
- GuildWarp warp = new GuildWarp(identifier, warpName, player.getLocation().getX(), player.getLocation().getY(),
- player.getLocation().getZ(), player.getWorld());
- plugin.warps.put(identifier, warp);
- return warp;
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return null;
- }
-
- public void save(GuildWarp warp)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(UPDATE);
- statement.setString(1, warp.getIguild());
- statement.setString(2, warp.getWarpName());
- statement.setDouble(3, warp.getX());
- statement.setDouble(4, warp.getY());
- statement.setDouble(5, warp.getZ());
- statement.setInt(6, plugin.worldData.getWorldID(warp.getWorld()));
- statement.execute();
- plugin.warps.put(warp.getIguild(), warp);
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- }
-
- public void delete(GuildWarp warp)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(DELETE);
- statement.setString(1, warp.getIguild());
- statement.setString(2, warp.getWarpName());
- statement.execute();
- plugin.warps.remove(warp.getIguild());
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java
deleted file mode 100644
index 2a776bd..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLWorldData.java
+++ /dev/null
@@ -1,123 +0,0 @@
-package me.totalfreedom.tfguilds.sql;
-
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import me.totalfreedom.tfguilds.TFGuilds;
-import org.bukkit.Bukkit;
-import org.bukkit.World;
-
-public class SQLWorldData
-{
- private static final TFGuilds plugin = TFGuilds.getPlugin();
-
- private final String SELECT = "SELECT * FROM `worlds` WHERE name=?";
- private final String SELECT_ID = "SELECT * FROM `worlds` WHERE id=?";
- private final String INSERT = "INSERT INTO `worlds` (`id`, `name`) VALUES (?, ?);";
- private final String COUNT = "SELECT COUNT(*) AS rows FROM `worlds`";
-
- public boolean exists(World world)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(SELECT);
- statement.setString(1, world.getName());
- ResultSet set = statement.executeQuery();
- return set.next();
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return false;
- }
-
- public boolean existsID(int id)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(SELECT_ID);
- statement.setInt(1, id);
- ResultSet set = statement.executeQuery();
- return set.next();
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return false;
- }
-
- public int getWorldID(World world)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- if (!exists(world))
- {
- PreparedStatement statement = connection.prepareStatement(INSERT);
- statement.setInt(1, getWorldCount() + 1);
- statement.setString(2, world.getName());
- statement.execute();
- }
- PreparedStatement statement = connection.prepareStatement(SELECT);
- statement.setString(1, world.getName());
- ResultSet set = statement.executeQuery();
- set.next();
- int id = set.getInt("id");
- set.close();
- return id;
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return -1;
- }
-
- public World getWorld(int id)
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- if (!existsID(id))
- {
- return null;
- }
- PreparedStatement statement = connection.prepareStatement(SELECT_ID);
- statement.setInt(1, id);
- ResultSet set = statement.executeQuery();
- set.next();
- String name = set.getString("name");
- set.close();
- return Bukkit.getWorld(name);
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return null;
- }
-
- public int getWorldCount()
- {
- Connection connection = plugin.sql.getConnection();
- try
- {
- PreparedStatement statement = connection.prepareStatement(COUNT);
- ResultSet set = statement.executeQuery();
- set.next();
- int count = set.getInt("rows");
- set.close();
- return count;
- }
- catch (SQLException ex)
- {
- ex.printStackTrace();
- }
- return 0;
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/user/User.java b/src/main/java/me/totalfreedom/tfguilds/user/User.java
deleted file mode 100644
index 163b9ab..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/user/User.java
+++ /dev/null
@@ -1,28 +0,0 @@
-package me.totalfreedom.tfguilds.user;
-
-import java.util.UUID;
-import lombok.Getter;
-import lombok.Setter;
-import me.totalfreedom.tfguilds.TFGuilds;
-
-@Getter
-public class User
-{
- private final int id;
- private final UUID uuid;
-
- @Setter
- private boolean tag;
-
- public User(int id, UUID uuid, boolean tag)
- {
- this.id = id;
- this.uuid = uuid;
- this.tag = tag;
- }
-
- public void save()
- {
- TFGuilds.getPlugin().userData.save(this);
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/util/GLog.java b/src/main/java/me/totalfreedom/tfguilds/util/GLog.java
deleted file mode 100644
index 76eeee0..0000000
--- a/src/main/java/me/totalfreedom/tfguilds/util/GLog.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package me.totalfreedom.tfguilds.util;
-
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class GLog
-{
- private static final Logger LOGGER = Logger.getLogger("Minecraft");
- private static final String PREFIX = "[TFGuilds]";
-
- private static void log(Object o, Level l)
- {
- LOGGER.log(l, PREFIX + " " + o);
- }
-
- public static void info(Object o)
- {
- log(o, Level.INFO);
- }
-
- public static void warn(Object o)
- {
- log(o, Level.WARNING);
- }
-
- public static void severe(Object o)
- {
- log(o, Level.SEVERE);
- }
-}
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java b/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java
index 3be055f..4ae65a1 100644
--- a/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java
+++ b/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java
@@ -1,67 +1,53 @@
package me.totalfreedom.tfguilds.util;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import me.totalfreedom.tfguilds.TFGuilds;
-import org.apache.commons.lang.StringUtils;
-import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
-import org.bukkit.entity.Player;
+import net.md_5.bungee.api.ChatColor;
public class GUtil
{
- private static final SimpleDateFormat STANDARD = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss");
- private static final TFGuilds plugin = TFGuilds.getPlugin();
- public static String flatten(String s)
- {
- String[] split = s.split(" ");
- for (int i = 0; i < split.length; i++)
- {
- split[i] = ChatColor.stripColor(colorize(split[i].toLowerCase()));
- }
- return StringUtils.join(split, "_");
- }
-
- public static String colorize(String string)
- {
- Matcher matcher = Pattern.compile("[a-f0-9A-F]{6}").matcher(string);
- while (matcher.find())
- {
- String code = matcher.group().replace("&", "");
- string = string.replace("&" + code, net.md_5.bungee.api.ChatColor.of(code) + "");
- }
-
- string = ChatColor.translateAlternateColorCodes('&', string);
- return string;
- }
-
- public static String format(long time)
- {
- Date date = new Date(time);
- return STANDARD.format(date);
- }
-
- public static List BLACKLISTED_NAMES_AND_TAGS = Arrays.asList(
+ private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("EEE d MMM yyyy HH:mm:ss");
+ private static final List BLACKLISTED_NAMES_AND_TAGS = Arrays.asList(
"admin", "owner", "moderator", "developer", "console", "dev", "staff",
"mod", "sra", "sta", "sa", "super admin", "telnet admin", "senior admin",
"trial mod", "trial moderator", "trialmod", "trialmoderator");
- public static List getPlayerList()
+ public static String colorize(String string)
{
- List players = new ArrayList<>();
- for (Player player : Bukkit.getOnlinePlayers())
+ if (string != null)
{
- if (!plugin.bridge.isVanished(player))
+ Matcher matcher = Pattern.compile("[a-f0-9A-F]{6}").matcher(string);
+ while (matcher.find())
{
- players.add(player.getName());
+ String code = matcher.group().replace("&", "");
+ string = string.replace("&" + code, ChatColor.of(code) + "");
+ }
+
+ string = ChatColor.translateAlternateColorCodes('&', string);
+ }
+ return string;
+ }
+
+ public static boolean containsBlacklistedWord(String string)
+ {
+ for (String blacklist : BLACKLISTED_NAMES_AND_TAGS)
+ {
+ if (string.contains(blacklist))
+ {
+ return true;
}
}
- return players;
+ return false;
}
-}
\ No newline at end of file
+
+ public static String formatTime(long time)
+ {
+ Date date = new Date(time);
+ return DATE_FORMAT.format(date);
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/util/PaginationList.java b/src/main/java/me/totalfreedom/tfguilds/util/PaginationList.java
index bb64e03..900492b 100644
--- a/src/main/java/me/totalfreedom/tfguilds/util/PaginationList.java
+++ b/src/main/java/me/totalfreedom/tfguilds/util/PaginationList.java
@@ -6,6 +6,7 @@ import java.util.List;
public class PaginationList extends ArrayList
{
+
private final int epp;
/**
@@ -69,4 +70,4 @@ public class PaginationList extends ArrayList
}
return res.toString();
}*/
-}
\ No newline at end of file
+}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 2eb6264..660f649 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -3,20 +3,16 @@
#
server:
-
# Log guild chat to console?
- guild_chat_logging:
- enabled: true
+ guild_chat_logging: true
# Enable guild tags globally?
- guild_tags_enabled:
- enabled: true
+ guild_tags_enabled: true
- # Color scheme used for TFGuilds
-scheme:
-
- # Primary color
- primary: GREEN
-
- # Secondary color
- secondary: DARK_GREEN
\ No newline at end of file
+# MySQL configuration
+mysql:
+ host: localhost
+ port: 3306
+ username: root
+ password: password
+ database: TFGuilds
\ No newline at end of file
diff --git a/src/main/resources/database.db b/src/main/resources/database.db
deleted file mode 100644
index e69de29..0000000
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index ddd9483..6174e6a 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -2,22 +2,20 @@ name: TFGuilds
version: ${project.version}
main: me.totalfreedom.tfguilds.TFGuilds
api-version: 1.16
-authors: [ speed, super ]
+authors: [ Fleek, super, speed ]
description: A guilds plugin for the TotalFreedom server.
+softdepend:
+ - TotalFreedomMod
commands:
guild:
- description: The main command of TFGuilds.
- usage: /
+ description: A command to manage guilds
+ usage: / help
aliases: [ g ]
- guildchat:
- description: Talk in chat with your guild.
- usage: / [message]
- aliases: [ gchat ]
tfguilds:
- description: Information about the plugin.
- usage: /
+ description: An information of TFGuilds plugin
+ usage: / [reload]
aliases: [ tfg ]
guildchatspy:
- description: An admin only command which allows for spying on guild chat.
+ description: Spy on guild chat
usage: /
- aliases: [ gchatspy, gcs ]
\ No newline at end of file
+ aliases: [ gchatspy, gcs ]
From a1a1f8edb0efa302699734990015aca85d15c0bb Mon Sep 17 00:00:00 2001
From: Nathan Curran <30569566+Focusvity@users.noreply.github.com>
Date: Sun, 23 May 2021 17:42:43 +1000
Subject: [PATCH 28/41] TFGuilds 2021.05 First Release Candidate
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index c7b46d6..9f6cb48 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.totalfreedom
TFGuilds
- 2021.03
+ 2021.05-RC1
jar
TFGuilds
From 8636c88f94ed8055fb0fac9ea0c3b742e52bd314 Mon Sep 17 00:00:00 2001
From: Nathan Curran <30569566+Focusvity@users.noreply.github.com>
Date: Fri, 4 Jun 2021 09:21:23 +1000
Subject: [PATCH 29/41] Modification to SQL statements and fix invites (#8)
* Add primary key (rowid) to database
* Fix players not being able to join after being invited
---
.../tfguilds/command/InviteSubCommand.java | 4 +++-
.../tfguilds/command/JoinSubCommand.java | 2 +-
.../java/me/totalfreedom/tfguilds/guild/Guild.java | 7 ++++---
.../java/me/totalfreedom/tfguilds/guild/User.java | 2 +-
.../me/totalfreedom/tfguilds/sql/SQLDatabase.java | 13 ++++++++-----
5 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/InviteSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/InviteSubCommand.java
index 2dc73f2..6b5e740 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/InviteSubCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/InviteSubCommand.java
@@ -73,7 +73,7 @@ public class InviteSubCommand extends Common implements SubCommand
guild.invite(player);
player.sendMessage(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has sent you an invite to join " + ChatColor.GOLD + guild.getName());
- player.sendMessage("Do " + ChatColor.GOLD + "/g join " + guild.getName() + ChatColor.GRAY + " to join!");
+ player.sendMessage(PREFIX + "Do " + ChatColor.GOLD + "/g join " + guild.getName() + ChatColor.GRAY + " to join!");
player.sendMessage(PREFIX + "The invite will expire in 90 seconds.");
sender.sendMessage(PREFIX + "The invite has been sent to " + ChatColor.GOLD + player.getName());
@@ -86,7 +86,9 @@ public class InviteSubCommand extends Common implements SubCommand
{
return;
}
+
guild.removeInvite(player);
+
if (player.isOnline())
{
player.sendMessage(PREFIX + "The invite to " + ChatColor.GOLD + guild.getName() + ChatColor.GRAY + " has expired!");
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/JoinSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/JoinSubCommand.java
index 6780229..b13104e 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/JoinSubCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/JoinSubCommand.java
@@ -46,7 +46,7 @@ public class JoinSubCommand extends Common implements SubCommand
if (guild.getState() == Guild.State.INVITE_ONLY)
{
- if (guild.isInvited(playerSender))
+ if (!guild.isInvited(playerSender))
{
sender.sendMessage(PREFIX + "You must be invited to join the guild.");
return;
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
index 7691ba5..42e3511 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
@@ -353,7 +353,7 @@ public class Guild
Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
try
{
- PreparedStatement statement = connection.prepareStatement("INSERT INTO ranks (guild_id, name, members) VALUES (?, ?, ?)");
+ PreparedStatement statement = connection.prepareStatement("INSERT INTO ranks (`guild_id`, `name`, `members`) VALUES (?, ?, ?)");
statement.setString(1, id);
statement.setString(2, name);
statement.setString(3, null);
@@ -475,7 +475,8 @@ public class Guild
Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
try
{
- PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO guilds VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
+ PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO guilds (`id`, `name`, `owner`, `moderators`, `members`, `tag`, `default_rank`, `state`, `motd`, `x`, `y`, `z`, `world`, `creation`)" +
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
: connection.prepareStatement("UPDATE guilds SET owner=?," +
"moderators=?," +
"members=?," +
@@ -559,7 +560,7 @@ public class Guild
Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
try
{
- PreparedStatement statement = connection.prepareStatement("INSERT INTO warps VALUES (?, ?, ?, ?, ?, ?)");
+ PreparedStatement statement = connection.prepareStatement("INSERT INTO warps (`guild_id`, `name`, `x`, `y`, `z`, `world`) VALUES (?, ?, ?, ?, ?, ?)");
statement.setString(1, id);
statement.setString(2, name);
Location location = warps.get(name);
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/User.java b/src/main/java/me/totalfreedom/tfguilds/guild/User.java
index 1e2fef1..90c69cd 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/User.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/User.java
@@ -113,7 +113,7 @@ public class User
Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
try
{
- PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO users VALUES (?, ?, ?)")
+ PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO users (`uuid`, `id`, `tag`) VALUES (?, ?, ?)")
: connection.prepareStatement("UPDATE users SET tag=? WHERE id=?");
if (newSave)
{
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
index 4a23839..d5a2267 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
@@ -21,7 +21,6 @@ public class SQLDatabase
}
try
{
- Bukkit.getLogger().info(ConfigEntry.MYSQL_USERNAME.getString());
connection = DriverManager.getConnection(String.format("jdbc:mysql://%s:%d/%s",
ConfigEntry.MYSQL_HOST.getString(),
ConfigEntry.MYSQL_PORT.getInteger(),
@@ -47,7 +46,8 @@ public class SQLDatabase
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `users` (" +
"`uuid` TEXT," +
"`id` INT," +
- "`tag` BOOLEAN)")
+ "`tag` BOOLEAN," +
+ "`rowid` INTEGER AUTO_INCREMENT PRIMARY KEY)")
.execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `warps` (" +
"`guild_id` TEXT," +
@@ -55,7 +55,8 @@ public class SQLDatabase
"`x` DOUBLE," +
"`y` DOUBLE," +
"`z` DOUBLE," +
- "`world` TEXT)")
+ "`world` TEXT," +
+ "`rowid` INTEGER AUTO_INCREMENT PRIMARY KEY)")
.execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `guilds` (" +
"`id` TEXT," +
@@ -71,12 +72,14 @@ public class SQLDatabase
"`y` DOUBLE," +
"`z` DOUBLE," +
"`world` TEXT," +
- "`creation` LONG)")
+ "`creation` LONG," +
+ "`rowid` INTEGER AUTO_INCREMENT PRIMARY KEY)")
.execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `ranks` (" +
"`guild_id` TEXT," +
"`name` TEXT," +
- "`members` TEXT)")
+ "`members` TEXT," +
+ "`rowid` INTEGER AUTO_INCREMENT PRIMARY KEY)")
.execute();
}
}
From 8afe7220fb0b3dc1d47ab225abeebb3656e97b24 Mon Sep 17 00:00:00 2001
From: Nathan Curran <30569566+Focusvity@users.noreply.github.com>
Date: Sat, 5 Jun 2021 17:07:20 +1000
Subject: [PATCH 30/41] TFGuilds Release Candidate 2
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 9f6cb48..b8639ea 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.totalfreedom
TFGuilds
- 2021.05-RC1
+ 2021.05-RC2
jar
TFGuilds
From 3f970a50d832d90f427cdd5b668b7f9860936898 Mon Sep 17 00:00:00 2001
From: Nathan Curran <30569566+Focusvity@users.noreply.github.com>
Date: Sun, 6 Jun 2021 14:04:15 +1000
Subject: [PATCH 31/41] TFGuilds May Update
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index b8639ea..ea0e406 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.totalfreedom
TFGuilds
- 2021.05-RC2
+ 2021.05
jar
TFGuilds
From 8263e8b20f883405451e338762f1fd5a9cb08057 Mon Sep 17 00:00:00 2001
From: Nathan Curran <30569566+Focusvity@users.noreply.github.com>
Date: Mon, 7 Jun 2021 11:12:49 +1000
Subject: [PATCH 32/41] Fix tags not setting after loading (FS-288)
---
src/main/java/me/totalfreedom/tfguilds/guild/Guild.java | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
index 42e3511..ea7296a 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
@@ -48,6 +48,7 @@ public class Guild
Map warps,
String defaultRank,
State state,
+ String tag,
String motd,
double x,
double y,
@@ -64,6 +65,7 @@ public class Guild
this.warps = warps;
this.defaultRank = defaultRank;
this.state = state;
+ this.tag = tag;
this.motd = motd;
World w;
if (world == null)
@@ -93,6 +95,7 @@ public class Guild
null,
State.OPEN,
null,
+ null,
0,
50,
0,
@@ -203,6 +206,7 @@ public class Guild
warps,
set.getString("default_rank"),
State.fromInt(set.getInt("state")),
+ set.getString("tag"),
set.getString("motd"),
set.getDouble("x"),
set.getDouble("y"),
From b0f4017cde72937b335cc58fe023dbd79880e00d Mon Sep 17 00:00:00 2001
From: Nathan Curran <30569566+Focusvity@users.noreply.github.com>
Date: Tue, 15 Jun 2021 23:19:25 +1000
Subject: [PATCH 33/41] Remaining tickets completed
FS-96, FS-270, FS-271, FS-272, FS-282 and FS-303 are included in this commit
---
.../me/totalfreedom/tfguilds/TFGuilds.java | 3 +
.../me/totalfreedom/tfguilds/TFMBridge.java | 19 +++
.../tfguilds/command/ChatSubCommand.java | 2 +-
.../tfguilds/command/DisbandSubCommand.java | 3 +-
.../tfguilds/command/GuildCommand.java | 97 +++++++++++++++
.../tfguilds/command/ModChatSubCommand.java | 37 ++++++
.../tfguilds/command/NoTagSubCommand.java | 49 ++++++++
.../tfguilds/command/TagSubCommand.java | 31 +++--
.../command/ToggleChatSubCommand.java | 46 ++++++++
.../tfguilds/config/ConfigEntry.java | 2 +
.../me/totalfreedom/tfguilds/guild/Guild.java | 111 ++++++++++++------
.../me/totalfreedom/tfguilds/guild/User.java | 33 ++++--
.../tfguilds/listener/ChatListener.java | 31 ++---
.../tfguilds/listener/JoinListener.java | 15 ++-
.../tfguilds/sql/SQLDatabase.java | 4 +-
.../me/totalfreedom/tfguilds/util/GUtil.java | 31 +++++
src/main/resources/config.yml | 9 ++
17 files changed, 441 insertions(+), 82 deletions(-)
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/ModChatSubCommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/NoTagSubCommand.java
create mode 100644 src/main/java/me/totalfreedom/tfguilds/command/ToggleChatSubCommand.java
diff --git a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
index 25b2f96..0954330 100644
--- a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
+++ b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
@@ -111,5 +111,8 @@ public class TFGuilds extends JavaPlugin
subCommands.put("tag", new TagSubCommand());
subCommands.put("list", new ListSubCommand());
subCommands.put("help", new HelpSubCommand());
+ subCommands.put("mchat", new ModChatSubCommand());
+ subCommands.put("notag", new NoTagSubCommand());
+ subCommands.put("togglechat", new ToggleChatSubCommand());
}
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java b/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java
index f440b74..4ec8c28 100644
--- a/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java
+++ b/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java
@@ -2,6 +2,7 @@ package me.totalfreedom.tfguilds;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@@ -61,4 +62,22 @@ public class TFMBridge
}
return getTfm().al.isVanished(player.getName());
}
+
+ public String getTag(Player player)
+ {
+ if (getTfm() == null)
+ {
+ return null;
+ }
+ return ChatColor.stripColor(getTfm().pl.getPlayer(player).getTag());
+ }
+
+ public void clearTag(Player player)
+ {
+ if (getTfm() == null)
+ {
+ return;
+ }
+ getTfm().pl.getPlayer(player).setTag(null);
+ }
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ChatSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ChatSubCommand.java
index bd2fa2c..ecdb403 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/ChatSubCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/ChatSubCommand.java
@@ -29,7 +29,7 @@ public class ChatSubCommand extends Common implements SubCommand
if (args.length >= 2)
{
String message = StringUtils.join(args, " ", 1, args.length);
- guild.chat(playerSender, message);
+ guild.chat(playerSender, message, false);
return;
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubCommand.java
index e26b6b9..35f8e14 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/DisbandSubCommand.java
@@ -2,6 +2,7 @@ package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.guild.Guild;
+import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
@@ -27,7 +28,7 @@ public class DisbandSubCommand extends Common implements SubCommand
return;
}
- Guild guild = Guild.getGuild(playerSender);
+ Guild guild = Guild.getGuild(StringUtils.join(args, " ", 1, args.length));
if (guild == null)
{
sender.sendMessage(PREFIX + "That guild does not exist.");
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
index 13af0f3..b2a9fae 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
@@ -1,9 +1,12 @@
package me.totalfreedom.tfguilds.command;
+import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import me.totalfreedom.tfguilds.Common;
import me.totalfreedom.tfguilds.TFGuilds;
+import me.totalfreedom.tfguilds.guild.Guild;
+import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -43,6 +46,100 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
@Override
public List onTabComplete(CommandSender sender, Command cmd, String label, String[] args)
{
+ Guild guild = null;
+ if (sender instanceof Player)
+ {
+ guild = Guild.getGuild((Player)sender);
+ }
+ if (args.length == 1)
+ {
+ return TFGuilds.getPlugin().getSubCommands();
+ }
+ else if (args.length == 2)
+ {
+ switch (args[0])
+ {
+ case "home":
+ {
+ return Collections.singletonList("set");
+ }
+
+ case "info":
+ case "join":
+ case "roster":
+ {
+ return Guild.getGuildNames();
+ }
+
+ case "toggletag":
+ {
+ if (!tfmBridge.isAdmin(sender))
+ {
+ return Collections.emptyList();
+ }
+
+ return GUtil.getPlayerNames();
+ }
+
+ case "motd":
+ case "tag":
+ {
+ return Arrays.asList("set", "clear");
+ }
+
+ case "setstate":
+ {
+ return Arrays.asList("OPEN", "CLOSED", "INVITE_ONLY");
+ }
+
+ case "invite":
+ {
+ return GUtil.getPlayerNames();
+ }
+
+ case "deleterank":
+ case "setdefaultrank":
+ {
+ if (guild != null && guild.getOwner().equals(((Player)sender).getUniqueId()))
+ {
+ return guild.getRankNames();
+ }
+ }
+
+ case "tp":
+ {
+ return guild != null ? guild.getMemberNames() : Collections.emptyList();
+ }
+
+ case "disband":
+ {
+ if (!tfmBridge.isAdmin(sender))
+ {
+ return Collections.emptyList();
+ }
+
+ return Guild.getGuildNames();
+ }
+
+ case "kick":
+ {
+ if (guild != null && guild.isModerator((Player)sender))
+ {
+ return guild.getMemberOnlyNames();
+ }
+ }
+
+ case "removemod":
+ case "addmod":
+ case "setowner":
+ {
+ if (guild != null && guild.getOwner().equals(((Player)sender).getUniqueId()))
+ {
+ return guild.getMemberNames();
+ }
+ }
+ }
+ }
return Collections.emptyList();
}
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ModChatSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ModChatSubCommand.java
new file mode 100644
index 0000000..5b052df
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/ModChatSubCommand.java
@@ -0,0 +1,37 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class ModChatSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(IN_GAME_ONLY);
+ return;
+ }
+
+ Guild guild = Guild.getGuild(playerSender);
+ if (guild == null)
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (args.length == 1)
+ {
+ sender.sendMessage(USAGE + "/g mchat ");
+ return;
+ }
+
+ String message = StringUtils.join(args, " ", 1, args.length);
+ guild.chat(playerSender, message, true);
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/NoTagSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/NoTagSubCommand.java
new file mode 100644
index 0000000..be35267
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/NoTagSubCommand.java
@@ -0,0 +1,49 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.Guild;
+import org.apache.commons.lang.StringUtils;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class NoTagSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!tfmBridge.isAdmin(sender))
+ {
+ sender.sendMessage(PREFIX + "You do not have the permission.");
+ return;
+ }
+
+ if (args.length == 1)
+ {
+ sender.sendMessage(USAGE + "/g edittag ");
+ return;
+ }
+
+ Guild guild = Guild.getGuild(StringUtils.join(args, " ", 1, args.length));
+ if (guild == null)
+ {
+ sender.sendMessage(PREFIX + "That guild does not exist.");
+ return;
+ }
+
+ boolean enabled = guild.canUseTag();
+ if (enabled)
+ {
+ guild.setUseTag(false);
+ sender.sendMessage(PREFIX + ChatColor.GOLD + "Disabled " + ChatColor.GRAY + "guild tags for " + ChatColor.GOLD + guild.getName());
+ guild.broadcast(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has disabled guild tags for your guild.");
+ }
+ else
+ {
+ guild.setUseTag(true);
+ sender.sendMessage(PREFIX + ChatColor.GOLD + "Enabled " + ChatColor.GRAY + "guild tags for " + ChatColor.GOLD + guild.getName());
+ guild.broadcast(PREFIX + ChatColor.GOLD + sender.getName() + ChatColor.GRAY + " has enabled guild tags for your guild.");
+ }
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/TagSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/TagSubCommand.java
index bb7f653..eaa4c37 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/TagSubCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/TagSubCommand.java
@@ -1,6 +1,7 @@
package me.totalfreedom.tfguilds.command;
import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.config.ConfigEntry;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.util.GUtil;
import org.apache.commons.lang.StringUtils;
@@ -39,15 +40,22 @@ public class TagSubCommand extends Common implements SubCommand
return;
}
+ if (!guild.canUseTag())
+ {
+ sender.sendMessage(PREFIX + "You may not edit or clear your guild tag, please contact an admin if this is an error.");
+ return;
+ }
+
if (args.length >= 3)
{
if (args[1].equalsIgnoreCase("set"))
{
+ int length = ConfigEntry.GUILD_TAG_MAX_LENGTH.getInteger();
String tag = StringUtils.join(args, " ", 2, args.length);
tag = tag.replace("%tag%", guild.getName());
- if (tag.length() > 15)
+ if (GUtil.removeColorCodes(tag).length() > length && length > 0)
{
- sender.sendMessage(PREFIX + "The guild tag cannot go over 15 characters limit.");
+ sender.sendMessage(PREFIX + "The guild tag cannot go over " + length + " characters limit.");
return;
}
@@ -60,16 +68,7 @@ public class TagSubCommand extends Common implements SubCommand
guild.setTag(tag);
sender.sendMessage(PREFIX + "The guild tag has been changed to " + ChatColor.GOLD + GUtil.colorize(tag).replace("%rank%", "Guild Owner"));
}
- else
- {
- sender.sendMessage(USAGE + "/g tag | clear [guild]>");
- }
- return;
- }
-
- if (args[1].equalsIgnoreCase("clear"))
- {
- if (args.length >= 3)
+ else if (args[1].equalsIgnoreCase("clear"))
{
if (!tfmBridge.isAdmin(sender))
{
@@ -88,7 +87,15 @@ public class TagSubCommand extends Common implements SubCommand
sender.sendMessage(PREFIX + "Successfully cleared the guild tag for " + ChatColor.GOLD + guild.getName());
return;
}
+ else
+ {
+ sender.sendMessage(USAGE + "/g tag | clear [guild]>");
+ }
+ return;
+ }
+ if (args[1].equalsIgnoreCase("clear"))
+ {
guild.setTag(null);
sender.sendMessage(PREFIX + "Successfully cleared the guild tag.");
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ToggleChatSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ToggleChatSubCommand.java
new file mode 100644
index 0000000..84e1c8e
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/command/ToggleChatSubCommand.java
@@ -0,0 +1,46 @@
+package me.totalfreedom.tfguilds.command;
+
+import me.totalfreedom.tfguilds.Common;
+import me.totalfreedom.tfguilds.guild.User;
+import org.bukkit.ChatColor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
+public class ToggleChatSubCommand extends Common implements SubCommand
+{
+
+ @Override
+ public void execute(CommandSender sender, Player playerSender, String[] args)
+ {
+ if (!(sender instanceof Player))
+ {
+ sender.sendMessage(NOT_IN_GUILD);
+ return;
+ }
+
+ if (args.length > 1)
+ {
+ sender.sendMessage(USAGE + "/g togglechat");
+ return;
+ }
+
+ User user = User.getUserFromPlayer(playerSender);
+ if (user == null)
+ {
+ user = User.create(playerSender);
+ }
+
+ // Must use this otherwise the subcommand will not work properly, unlike ToggleTagSubCommand.java
+ boolean enabled = user.displayChat();
+ if (enabled)
+ {
+ user.setDisplayChat(false);
+ sender.sendMessage(PREFIX + ChatColor.GOLD + "Disabled" + ChatColor.GRAY + " personal guild chat.");
+ }
+ else
+ {
+ user.setDisplayChat(true);
+ sender.sendMessage(PREFIX + ChatColor.GOLD + "Enabled" + ChatColor.GRAY + " personal guild chat.");
+ }
+ }
+}
diff --git a/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java b/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java
index 89eaecf..950bff7 100644
--- a/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java
+++ b/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java
@@ -7,6 +7,8 @@ public enum ConfigEntry
GUILD_CHAT_LOGGING("server.guild_chat_logging"),
GUILD_TAGS("server.guild_tags"),
+ GUILD_TAG_MAX_LENGTH("server.guild_tag_max_length"),
+ GLOBAL_TAG_MAX_LENGTH("server.global_tag_max_length"),
MYSQL_HOST("mysql.host"),
MYSQL_PORT("mysql.port"),
MYSQL_USERNAME("mysql.username"),
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
index ea7296a..d65701f 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
@@ -39,6 +39,7 @@ public class Guild
private State state;
private String motd;
private Location home;
+ private boolean useTag;
public Guild(String name,
UUID owner,
@@ -54,7 +55,8 @@ public class Guild
double y,
double z,
String world,
- long createdAt)
+ long createdAt,
+ boolean useTag)
{
this.id = name.toLowerCase().replaceAll(" ", "_");
this.name = name;
@@ -82,6 +84,7 @@ public class Guild
}
this.home = new Location(w, x, y, z);
this.createdAt = createdAt;
+ this.useTag = useTag;
}
public Guild(Player player, String name)
@@ -100,7 +103,8 @@ public class Guild
50,
0,
null,
- System.currentTimeMillis());
+ System.currentTimeMillis(),
+ true);
save(true);
}
@@ -145,13 +149,12 @@ public class Guild
}
}
List members = new ArrayList<>();
- members.add(owner);
if (set.getString("members") != null)
{
for (String string : set.getString("members").split(","))
{
User user = User.getUserFromId(Integer.parseInt(string));
- if (user != null)
+ if (user != null && !user.equals(User.getUserFromUuid(owner)))
{
members.add(user.getUuid());
}
@@ -212,7 +215,8 @@ public class Guild
set.getDouble("y"),
set.getDouble("z"),
set.getString("world"),
- set.getLong("creation"));
+ set.getLong("creation"),
+ set.getBoolean("usetag"));
guilds.put(id, guild);
}
TFGuilds.getPlugin().getLogger().info(guilds.size() + " guilds loaded!");
@@ -282,7 +286,7 @@ public class Guild
{
if (isModerator(player))
{
- moderators.remove(player);
+ moderators.remove(player.getUniqueId());
}
members.remove(player.getUniqueId());
save();
@@ -430,7 +434,18 @@ public class Guild
return rank;
}
}
- return defaultRank;
+
+ if (owner.equals(player.getUniqueId()))
+ {
+ return "Guild Owner";
+ }
+
+ if (moderators.contains(player.getUniqueId()))
+ {
+ return "Guild Moderator";
+ }
+
+ return defaultRank != null ? defaultRank : "Guild Member";
}
public String getModeratorIds()
@@ -479,8 +494,8 @@ public class Guild
Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
try
{
- PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO guilds (`id`, `name`, `owner`, `moderators`, `members`, `tag`, `default_rank`, `state`, `motd`, `x`, `y`, `z`, `world`, `creation`)" +
- " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
+ PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO guilds (`id`, `name`, `owner`, `moderators`, `members`, `tag`, `default_rank`, `state`, `motd`, `x`, `y`, `z`, `world`, `creation`, `usetag`)" +
+ " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
: connection.prepareStatement("UPDATE guilds SET owner=?," +
"moderators=?," +
"members=?," +
@@ -491,7 +506,8 @@ public class Guild
"x=?," +
"y=?," +
"z=?," +
- "world=? WHERE id=?");
+ "world=?," +
+ "usetag=? WHERE id=?");
if (newSave)
{
statement.setString(1, id);
@@ -508,6 +524,7 @@ public class Guild
statement.setDouble(12, home.getZ());
statement.setString(13, home.getWorld().getName());
statement.setLong(14, createdAt);
+ statement.setBoolean(15, useTag);
}
else
{
@@ -522,7 +539,8 @@ public class Guild
statement.setDouble(9, home.getY());
statement.setDouble(10, home.getZ());
statement.setString(11, home.getWorld().getName());
- statement.setString(12, id);
+ statement.setBoolean(12, useTag);
+ statement.setString(13, id);
}
statement.execute();
}
@@ -647,6 +665,19 @@ public class Guild
return names;
}
+ public List getMemberNames()
+ {
+ List names = new ArrayList<>();
+ for (UUID uuid : members)
+ {
+ if (GUtil.getPlayerNames().contains(Bukkit.getOfflinePlayer(uuid).getName()))
+ {
+ names.add(Bukkit.getOfflinePlayer(uuid).getName());
+ }
+ }
+ return names;
+ }
+
public List getNamesByRank(String name)
{
List names = new ArrayList<>();
@@ -665,10 +696,7 @@ public class Guild
public List getRankNames()
{
- List names = new ArrayList<>();
- ranks.keySet().forEach(rank ->
- names.add(rank));
- return names;
+ return new ArrayList<>(ranks.keySet());
}
public Map getWarps()
@@ -678,10 +706,7 @@ public class Guild
public List getWarpNames()
{
- List names = new ArrayList<>();
- warps.keySet().forEach(name ->
- names.add(name));
- return names;
+ return new ArrayList<>(warps.keySet());
}
public Location getWarp(String name)
@@ -737,6 +762,17 @@ public class Guild
save();
}
+ public boolean canUseTag()
+ {
+ return useTag;
+ }
+
+ public void setUseTag(boolean useTag)
+ {
+ this.useTag = useTag;
+ save();
+ }
+
public void disband()
{
if (hasGuild(name))
@@ -773,18 +809,21 @@ public class Guild
}
}
- public void chat(Player player, String message)
+ public void chat(Player player, String message, boolean modChat)
{
- broadcast(GUtil.colorize("&7[&bGuild Chat &7| &b" + name + "&7] " + player.getName() + " &8\u00BB &6") + message);
-
if (ConfigEntry.GUILD_CHAT_LOGGING.getBoolean())
{
- Bukkit.getServer().getLogger().info("[Guild Chat | " + name + "] " + player.getName() + " \u00BB " + message);
+ Bukkit.getServer().getLogger().info("[Guild " + (modChat ? "Mod " : "") + "Chat | " + name + "] " + player.getName() + " \u00BB " + message);
}
for (Player p : Bukkit.getOnlinePlayers())
{
- if (Common.GUILD_CHAT_SPY.contains(p) && player != p)
+ if (User.getUserFromPlayer(p).displayChat() && isMember(p))
+ {
+ p.sendMessage(GUtil.colorize("&7[&bGuild " + (modChat ? "Mod " : "") + "Chat &7| &b" + name + "&7] " + player.getName() + " &8\u00BB &6") + message);
+ }
+
+ if (Common.GUILD_CHAT_SPY.contains(p) && player != p && !isMember(p))
{
p.sendMessage(GUtil.colorize("&7[&bGuild Chat Spy &7| &b" + name + "&7] " + player.getName() + " &8\u00BB &6") + message);
}
@@ -814,18 +853,16 @@ public class Guild
@Override
public String toString()
{
- StringBuilder builder = new StringBuilder();
- builder.append(ChatColor.AQUA).append("Guild Information").append("\n").append(ChatColor.GRAY)
- .append(" Identifier: ").append(ChatColor.GOLD).append(id).append("\n")
- .append(ChatColor.GRAY).append(" Name: ").append(ChatColor.GOLD).append(name).append("\n")
- .append(ChatColor.GRAY).append(" Owner: ").append(ChatColor.GOLD).append(Bukkit.getOfflinePlayer(owner).getName()).append("\n")
- .append(ChatColor.GRAY).append(" Moderators (").append(getModerators().size()).append("): ").append(ChatColor.GOLD).append(StringUtils.join(getModeratorNames(), ", ")).append("\n")
- .append(ChatColor.GRAY).append(" Members (").append(getMembers().size()).append("): ").append(ChatColor.GOLD).append(StringUtils.join(getMemberOnlyNames(), ", ")).append("\n")
- .append(ChatColor.GRAY).append(" Tag: ").append(ChatColor.GOLD).append(tag != null ? GUtil.colorize(tag) : "None").append("\n")
- .append(ChatColor.GRAY).append(" State: ").append(ChatColor.GOLD).append(state.name()).append("\n")
- .append(ChatColor.GRAY).append(" Ranks (").append(ranks.size()).append("): ").append(ChatColor.GOLD).append(StringUtils.join(getRankNames(), ", ")).append("\n")
- .append(ChatColor.GRAY).append(" Created At: ").append(ChatColor.GOLD).append(GUtil.formatTime(createdAt));
- return builder.toString();
+ return ChatColor.AQUA + "Guild Information" + "\n" + ChatColor.GRAY +
+ " Identifier: " + ChatColor.GOLD + id + "\n" +
+ ChatColor.GRAY + " Name: " + ChatColor.GOLD + name + "\n" +
+ ChatColor.GRAY + " Owner: " + ChatColor.GOLD + Bukkit.getOfflinePlayer(owner).getName() + "\n" +
+ ChatColor.GRAY + " Moderators: " + ChatColor.GOLD + moderators.size() + "\n" +
+ ChatColor.GRAY + " Members: " + ChatColor.GOLD + members.size() + "\n" +
+ ChatColor.GRAY + " Tag: " + ChatColor.GOLD + (tag != null ? GUtil.colorize(tag) : "None") + "\n" +
+ ChatColor.GRAY + " State: " + ChatColor.GOLD + state.name() + "\n" +
+ ChatColor.GRAY + " Ranks (" + ranks.size() + "): " + ChatColor.GOLD + StringUtils.join(getRankNames(), ", ") + "\n" +
+ ChatColor.GRAY + " Created At: " + ChatColor.GOLD + GUtil.formatTime(createdAt);
}
public long getCreatedAt()
@@ -849,7 +886,7 @@ public class Guild
{
return valueOf(string.toUpperCase());
}
- catch (Exception ex)
+ catch (Exception ignored)
{
}
return null;
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/User.java b/src/main/java/me/totalfreedom/tfguilds/guild/User.java
index 90c69cd..c7dd4b0 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/User.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/User.java
@@ -18,18 +18,20 @@ public class User
private final int id;
private final UUID uuid;
private boolean tag;
+ private boolean chat;
- public User(int id, UUID uuid, boolean tag)
+ public User(int id, UUID uuid, boolean tag, boolean chat)
{
this.id = id;
this.uuid = uuid;
this.tag = tag;
+ this.chat = chat;
}
public static User create(Player player)
{
int id = users.size() + 1;
- User user = new User(id, player.getUniqueId(), true);
+ User user = new User(id, player.getUniqueId(), true, true);
users.put(id, user);
user.save(true);
return user;
@@ -43,10 +45,11 @@ public class User
ResultSet set = connection.prepareStatement("SELECT * FROM users").executeQuery();
while (set.next())
{
- int id = set.getInt("id");
+ int id = set.getInt("rowid");
UUID uuid = UUID.fromString(set.getString("uuid"));
boolean tag = set.getBoolean("tag");
- users.put(id, new User(id, uuid, tag));
+ boolean chat = set.getBoolean("chat");
+ users.put(id, new User(id, uuid, tag, chat));
}
TFGuilds.getPlugin().getLogger().info(users.size() + " users loaded!");
}
@@ -108,23 +111,35 @@ public class User
save();
}
+ public boolean displayChat()
+ {
+ return chat;
+ }
+
+ public void setDisplayChat(boolean chat)
+ {
+ this.chat = chat;
+ save();
+ }
+
public void save(boolean newSave)
{
Connection connection = TFGuilds.getPlugin().getSQL().getConnection();
try
{
- PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO users (`uuid`, `id`, `tag`) VALUES (?, ?, ?)")
- : connection.prepareStatement("UPDATE users SET tag=? WHERE id=?");
+ PreparedStatement statement = newSave ? connection.prepareStatement("INSERT INTO users (`uuid`, `tag`, `chat`) VALUES (?, ?, ?)")
+ : connection.prepareStatement("UPDATE users SET tag=?, chat=? WHERE rowid=?");
if (newSave)
{
statement.setString(1, uuid.toString());
- statement.setInt(2, id);
- statement.setBoolean(3, tag);
+ statement.setBoolean(2, tag);
+ statement.setBoolean(3, chat);
}
else
{
statement.setBoolean(1, tag);
- statement.setInt(2, id);
+ statement.setBoolean(2, chat);
+ statement.setInt(3, id);
}
statement.execute();
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
index ab7bbb3..1a735b4 100644
--- a/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
+++ b/src/main/java/me/totalfreedom/tfguilds/listener/ChatListener.java
@@ -34,7 +34,7 @@ public class ChatListener implements Listener
if (Common.GUILD_CHAT.contains(player))
{
event.setCancelled(true);
- guild.chat(player, event.getMessage());
+ guild.chat(player, event.getMessage(), false);
return;
}
@@ -43,27 +43,20 @@ public class ChatListener implements Listener
return;
}
- String display = guild.getPlayerRank(player);
- if (display == guild.getDefaultRank())
- {
- if (guild.getOwner().equals(player.getUniqueId()))
- {
- display = "Guild Owner";
- }
- else if (guild.isModerator(player))
- {
- display = "Guild Moderator";
- }
- }
- else if (display == null)
- {
- display = "Guild Member";
- }
-
User user = User.getUserFromPlayer(player);
if (guild.getTag() != null && user.displayTag())
{
- event.setFormat(GUtil.colorize(guild.getTag().replace("%rank%", display)) + ChatColor.RESET + " " + event.getFormat());
+ int maxLength = ConfigEntry.GLOBAL_TAG_MAX_LENGTH.getInteger();
+ String tfmTag = TFGuilds.getPlugin().getTfmBridge().getTag(player);
+ if (tfmTag != null && maxLength > 0)
+ {
+ int length = GUtil.removeColorCodes(tfmTag).length() + GUtil.removeColorCodes(guild.getTag()).length();
+ if (length > maxLength)
+ {
+ TFGuilds.getPlugin().getTfmBridge().clearTag(player);
+ }
+ }
+ event.setFormat(GUtil.colorize(guild.getTag().replace("%rank%", guild.getPlayerRank(player))) + ChatColor.RESET + " " + event.getFormat());
}
}
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/listener/JoinListener.java b/src/main/java/me/totalfreedom/tfguilds/listener/JoinListener.java
index 7297ed8..a01c041 100644
--- a/src/main/java/me/totalfreedom/tfguilds/listener/JoinListener.java
+++ b/src/main/java/me/totalfreedom/tfguilds/listener/JoinListener.java
@@ -1,8 +1,10 @@
package me.totalfreedom.tfguilds.listener;
import me.totalfreedom.tfguilds.TFGuilds;
+import me.totalfreedom.tfguilds.config.ConfigEntry;
import me.totalfreedom.tfguilds.guild.Guild;
import me.totalfreedom.tfguilds.guild.User;
+import me.totalfreedom.tfguilds.util.GUtil;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@@ -17,7 +19,7 @@ public class JoinListener implements Listener
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
- @EventHandler(priority = EventPriority.HIGHEST)
+ @EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent event)
{
Player player = event.getPlayer();
@@ -38,5 +40,16 @@ public class JoinListener implements Listener
{
player.sendMessage(guild.getMotd());
}
+
+ int maxLength = ConfigEntry.GLOBAL_TAG_MAX_LENGTH.getInteger();
+ String tfmTag = TFGuilds.getPlugin().getTfmBridge().getTag(player);
+ if (user.displayTag() && tfmTag != null && guild.getTag() != null && maxLength > 0)
+ {
+ int length = GUtil.removeColorCodes(tfmTag).length() + GUtil.removeColorCodes(guild.getTag()).length();
+ if (length > maxLength)
+ {
+ TFGuilds.getPlugin().getTfmBridge().clearTag(player);
+ }
+ }
}
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
index d5a2267..5844953 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
@@ -5,7 +5,6 @@ import java.sql.DriverManager;
import java.sql.SQLException;
import me.totalfreedom.tfguilds.TFGuilds;
import me.totalfreedom.tfguilds.config.ConfigEntry;
-import org.bukkit.Bukkit;
public class SQLDatabase
{
@@ -45,8 +44,8 @@ public class SQLDatabase
{
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `users` (" +
"`uuid` TEXT," +
- "`id` INT," +
"`tag` BOOLEAN," +
+ "`chat` BOOLEAN," +
"`rowid` INTEGER AUTO_INCREMENT PRIMARY KEY)")
.execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `warps` (" +
@@ -73,6 +72,7 @@ public class SQLDatabase
"`z` DOUBLE," +
"`world` TEXT," +
"`creation` LONG," +
+ "`usetag` BOOLEAN," +
"`rowid` INTEGER AUTO_INCREMENT PRIMARY KEY)")
.execute();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `ranks` (" +
diff --git a/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java b/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java
index 4ae65a1..a39f96c 100644
--- a/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java
+++ b/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java
@@ -1,12 +1,16 @@
package me.totalfreedom.tfguilds.util;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import me.totalfreedom.tfguilds.TFGuilds;
import net.md_5.bungee.api.ChatColor;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
public class GUtil
{
@@ -16,6 +20,7 @@ public class GUtil
"admin", "owner", "moderator", "developer", "console", "dev", "staff",
"mod", "sra", "sta", "sa", "super admin", "telnet admin", "senior admin",
"trial mod", "trial moderator", "trialmod", "trialmoderator");
+ private static final Pattern CHAT_COLOR_FORMAT = Pattern.compile("&[a-fk-or0-9]", Pattern.CASE_INSENSITIVE);
public static String colorize(String string)
{
@@ -33,6 +38,19 @@ public class GUtil
return string;
}
+ public static String removeColorCodes(String string)
+ {
+ if (string != null)
+ {
+ Matcher matcher = CHAT_COLOR_FORMAT.matcher(string);
+ while (matcher.find())
+ {
+ string = string.replaceAll(matcher.group(), "");
+ }
+ }
+ return string;
+ }
+
public static boolean containsBlacklistedWord(String string)
{
for (String blacklist : BLACKLISTED_NAMES_AND_TAGS)
@@ -45,6 +63,19 @@ public class GUtil
return false;
}
+ public static List getPlayerNames()
+ {
+ List names = new ArrayList<>();
+ for (Player player : Bukkit.getOnlinePlayers())
+ {
+ if (!TFGuilds.getPlugin().getTfmBridge().isVanished(player))
+ {
+ names.add(player.getName());
+ }
+ }
+ return names;
+ }
+
public static String formatTime(long time)
{
Date date = new Date(time);
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 660f649..5586de3 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -9,6 +9,15 @@ server:
# Enable guild tags globally?
guild_tags_enabled: true
+ # Maximum guild tag length - 0 for unlimited.
+ # Note: chat colors are ignored
+ guild_tag_max_length: 20
+
+ # Maximum overall tag length - requires TotalFreedomMod.
+ # If the player's tag and guild tag combined exceeds the maximum overall length, guild tag will take priority. 0 for unlimited.
+ # Note: chat colors are ignored
+ global_tag_max_length: 30
+
# MySQL configuration
mysql:
host: localhost
From cc4d005d5f7f0a94b7f61c485d2fd00644b256cc Mon Sep 17 00:00:00 2001
From: Nathan Curran <30569566+Focusvity@users.noreply.github.com>
Date: Tue, 15 Jun 2021 23:33:22 +1000
Subject: [PATCH 34/41] Fix Codacy isues
---
.../java/me/totalfreedom/tfguilds/command/GuildCommand.java | 5 +++++
src/main/java/me/totalfreedom/tfguilds/guild/Guild.java | 2 +-
src/main/java/me/totalfreedom/tfguilds/util/GUtil.java | 5 +++--
3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
index b2a9fae..0589b2c 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/GuildCommand.java
@@ -138,6 +138,11 @@ public class GuildCommand extends Common implements CommandExecutor, TabComplete
return guild.getMemberNames();
}
}
+
+ default:
+ {
+ return Collections.emptyList();
+ }
}
}
return Collections.emptyList();
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
index d65701f..7ad1758 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
@@ -825,7 +825,7 @@ public class Guild
if (Common.GUILD_CHAT_SPY.contains(p) && player != p && !isMember(p))
{
- p.sendMessage(GUtil.colorize("&7[&bGuild Chat Spy &7| &b" + name + "&7] " + player.getName() + " &8\u00BB &6") + message);
+ p.sendMessage(GUtil.colorize("&7[&bGuild " + (modChat ? "Mod " : "") + "Chat Spy &7| &b" + name + "&7] " + player.getName() + " &8\u00BB &6") + message);
}
}
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java b/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java
index a39f96c..183926b 100644
--- a/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java
+++ b/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java
@@ -40,15 +40,16 @@ public class GUtil
public static String removeColorCodes(String string)
{
+ String s = null;
if (string != null)
{
Matcher matcher = CHAT_COLOR_FORMAT.matcher(string);
while (matcher.find())
{
- string = string.replaceAll(matcher.group(), "");
+ s = string.replaceAll(matcher.group(), "");
}
}
- return string;
+ return s;
}
public static boolean containsBlacklistedWord(String string)
From 50058d2b760a232f283073b57d1d1da66ce8f16a Mon Sep 17 00:00:00 2001
From: Nathan Curran <30569566+Focusvity@users.noreply.github.com>
Date: Wed, 16 Jun 2021 18:46:32 +1000
Subject: [PATCH 35/41] First release candidate for June update
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index ea0e406..ae98113 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.totalfreedom
TFGuilds
- 2021.05
+ 2021.06-RC1
jar
TFGuilds
From 32afc7c1b220c42aa5e06fb4856867684c14ba18 Mon Sep 17 00:00:00 2001
From: Nathan Curran <30569566+Focusvity@users.noreply.github.com>
Date: Sun, 20 Jun 2021 13:51:19 +1000
Subject: [PATCH 36/41] TFGuilds Second Release Candidate
- Fixed owner not being counted
- Updated regex to include hex colour codes
---
.gitignore | 3 ++-
pom.xml | 2 +-
src/main/java/me/totalfreedom/tfguilds/guild/Guild.java | 2 +-
src/main/java/me/totalfreedom/tfguilds/util/GUtil.java | 2 +-
4 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/.gitignore b/.gitignore
index 166641b..d38df4f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
/.idea/
target/
-out/
\ No newline at end of file
+out/
+TFGuilds.iml
diff --git a/pom.xml b/pom.xml
index ae98113..648c21c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.totalfreedom
TFGuilds
- 2021.06-RC1
+ 2021.06-RC2
jar
TFGuilds
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
index 7ad1758..aeeab98 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
@@ -858,7 +858,7 @@ public class Guild
ChatColor.GRAY + " Name: " + ChatColor.GOLD + name + "\n" +
ChatColor.GRAY + " Owner: " + ChatColor.GOLD + Bukkit.getOfflinePlayer(owner).getName() + "\n" +
ChatColor.GRAY + " Moderators: " + ChatColor.GOLD + moderators.size() + "\n" +
- ChatColor.GRAY + " Members: " + ChatColor.GOLD + members.size() + "\n" +
+ ChatColor.GRAY + " Members: " + ChatColor.GOLD + (members.size() + 1) + "\n" +
ChatColor.GRAY + " Tag: " + ChatColor.GOLD + (tag != null ? GUtil.colorize(tag) : "None") + "\n" +
ChatColor.GRAY + " State: " + ChatColor.GOLD + state.name() + "\n" +
ChatColor.GRAY + " Ranks (" + ranks.size() + "): " + ChatColor.GOLD + StringUtils.join(getRankNames(), ", ") + "\n" +
diff --git a/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java b/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java
index 183926b..8d97620 100644
--- a/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java
+++ b/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java
@@ -20,7 +20,7 @@ public class GUtil
"admin", "owner", "moderator", "developer", "console", "dev", "staff",
"mod", "sra", "sta", "sa", "super admin", "telnet admin", "senior admin",
"trial mod", "trial moderator", "trialmod", "trialmoderator");
- private static final Pattern CHAT_COLOR_FORMAT = Pattern.compile("&[a-fk-or0-9]", Pattern.CASE_INSENSITIVE);
+ private static final Pattern CHAT_COLOR_FORMAT = Pattern.compile("&([a-fk-or0-9]|#[a-f0-9]{6})", Pattern.CASE_INSENSITIVE);
public static String colorize(String string)
{
From 4ec00d977c082a78bb95670d376b040772d31cb8 Mon Sep 17 00:00:00 2001
From: Nathan Curran <30569566+Focusvity@users.noreply.github.com>
Date: Mon, 28 Jun 2021 22:46:46 +1000
Subject: [PATCH 37/41] Fix moderator chat
---
pom.xml | 2 +-
.../totalfreedom/tfguilds/command/ModChatSubCommand.java | 6 ++++++
src/main/java/me/totalfreedom/tfguilds/guild/Guild.java | 9 ++++++++-
3 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index 648c21c..95761d7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
me.totalfreedom
TFGuilds
- 2021.06-RC2
+ 2021.06-RC3
jar
TFGuilds
diff --git a/src/main/java/me/totalfreedom/tfguilds/command/ModChatSubCommand.java b/src/main/java/me/totalfreedom/tfguilds/command/ModChatSubCommand.java
index 5b052df..3423480 100644
--- a/src/main/java/me/totalfreedom/tfguilds/command/ModChatSubCommand.java
+++ b/src/main/java/me/totalfreedom/tfguilds/command/ModChatSubCommand.java
@@ -25,6 +25,12 @@ public class ModChatSubCommand extends Common implements SubCommand
return;
}
+ if (!guild.isModerator(playerSender))
+ {
+ sender.sendMessage(PREFIX + "You must be a guild moderator to set player's rank for your guild.");
+ return;
+ }
+
if (args.length == 1)
{
sender.sendMessage(USAGE + "/g mchat ");
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
index aeeab98..f4c5d7c 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
@@ -820,7 +820,14 @@ public class Guild
{
if (User.getUserFromPlayer(p).displayChat() && isMember(p))
{
- p.sendMessage(GUtil.colorize("&7[&bGuild " + (modChat ? "Mod " : "") + "Chat &7| &b" + name + "&7] " + player.getName() + " &8\u00BB &6") + message);
+ if (modChat && isModerator(p))
+ {
+ p.sendMessage(GUtil.colorize("&7[&bGuild Mod Chat &7| &b" + name + "&7] " + player.getName() + " &8\u00BB &6") + message);
+ }
+ else
+ {
+ p.sendMessage(GUtil.colorize("&7[&bGuild Chat &7| &b" + name + "&7] " + player.getName() + " &8\u00BB &6") + message);
+ }
}
if (Common.GUILD_CHAT_SPY.contains(p) && player != p && !isMember(p))
From 11b3e194ec59b834175eca7826a4813bc7c64ed4 Mon Sep 17 00:00:00 2001
From: spacerocket62
Date: Wed, 28 Jul 2021 15:12:32 -0700
Subject: [PATCH 38/41] Completely remove TFM as a dependency and use
reflections instead Simplify removing color codes by using
ChatColor#stripColor Have an option to use sqlite or mysql, by default it
will be sqlite
---
TFGuilds.iml | 106 ------------------
pom.xml | 8 +-
.../me/totalfreedom/tfguilds/TFGuilds.java | 9 +-
.../me/totalfreedom/tfguilds/TFMBridge.java | 81 +++++++++++--
.../totalfreedom/tfguilds/config/Config.java | 1 -
.../tfguilds/config/ConfigEntry.java | 1 +
.../me/totalfreedom/tfguilds/guild/Guild.java | 6 +-
.../tfguilds/sql/SQLDatabase.java | 38 +++++--
.../me/totalfreedom/tfguilds/util/GUtil.java | 6 +-
.../tfguilds/util/Reflections.java | 38 +++++++
src/main/resources/config.yml | 4 +
11 files changed, 162 insertions(+), 136 deletions(-)
delete mode 100644 TFGuilds.iml
create mode 100644 src/main/java/me/totalfreedom/tfguilds/util/Reflections.java
diff --git a/TFGuilds.iml b/TFGuilds.iml
deleted file mode 100644
index f2e91f0..0000000
--- a/TFGuilds.iml
+++ /dev/null
@@ -1,106 +0,0 @@
-
-
-
-
-
-
- SPIGOT
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 95761d7..74016ba 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,9 +4,9 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
- me.totalfreedom
+ com.github.AtlasMediaGroup
TFGuilds
- 2021.06-RC3
+ master-4ec00d977c-1
jar
TFGuilds
@@ -72,11 +72,11 @@
1.16.5-R0.1-SNAPSHOT
provided
-
+
\ No newline at end of file
diff --git a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
index 0954330..3d2cd17 100644
--- a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
+++ b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
@@ -1,5 +1,6 @@
package me.totalfreedom.tfguilds;
+import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -49,8 +50,14 @@ public class TFGuilds extends JavaPlugin
@Override
public void onDisable()
{
+ try
+ {
+ getSQL().getConnection().close();
+ }
+ catch (SQLException throwables)
+ {
+ }
config.save();
- this.plugin = null;
}
public Config getConfig()
diff --git a/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java b/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java
index 4ec8c28..a1211e6 100644
--- a/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java
+++ b/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java
@@ -1,8 +1,9 @@
package me.totalfreedom.tfguilds;
-import me.totalfreedom.totalfreedommod.TotalFreedomMod;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import me.totalfreedom.tfguilds.util.Reflections;
import org.bukkit.Bukkit;
-import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
@@ -11,18 +12,18 @@ public class TFMBridge
{
private final TFGuilds plugin = TFGuilds.getPlugin();
- private TotalFreedomMod tfm = null;
+ private /*TotalFreedomMod*/ Plugin tfm = null;
- public TotalFreedomMod getTfm()
+ public /*TotalFreedomMod*/ Plugin getTfm()
{
if (tfm == null)
{
try
{
final Plugin tfmPlugin = plugin.getServer().getPluginManager().getPlugin("TotalFreedomMod");
- if (tfmPlugin != null && tfmPlugin.isEnabled() && tfmPlugin instanceof TotalFreedomMod)
+ if (tfmPlugin != null && tfmPlugin.isEnabled())
{
- tfm = (TotalFreedomMod)tfmPlugin;
+ tfm = /*(TotalFreedomMod)*/tfmPlugin;
}
}
catch (Exception ex)
@@ -40,7 +41,17 @@ public class TFMBridge
Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead.");
return player.isOp();
}
- return getTfm().al.isAdmin(player);
+ Object al = Reflections.getField(getTfm(), "al");
+ Method isAdmin = Reflections.getMethod(al, "isAdmin", Player.class);
+ try
+ {
+ return (boolean)isAdmin.invoke(al, player) /*getTfm().al.isAdmin(player)*/;
+ }
+ catch (IllegalAccessException | InvocationTargetException e)
+ {
+ e.printStackTrace();
+ }
+ return false;
}
public boolean isAdmin(CommandSender sender)
@@ -50,7 +61,17 @@ public class TFMBridge
Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead.");
return sender.isOp();
}
- return getTfm().al.isAdmin(sender);
+ Object al = Reflections.getField(getTfm(), "al");
+ Method isAdmin = Reflections.getMethod(al, "isAdmin", CommandSender.class);
+ try
+ {
+ return (boolean)isAdmin.invoke(al, sender) /*getTfm().al.isAdmin(player)*/;
+ }
+ catch (IllegalAccessException | InvocationTargetException e)
+ {
+ e.printStackTrace();
+ }
+ return false;
}
public boolean isVanished(Player player)
@@ -60,7 +81,17 @@ public class TFMBridge
Bukkit.getLogger().warning("TotalFreedomMod not detected, vanish will return false.");
return false;
}
- return getTfm().al.isVanished(player.getName());
+ Object al = Reflections.getField(getTfm(), "al");
+ Method isVanished = Reflections.getMethod(al, "isVanished", String.class);
+ try
+ {
+ return (boolean)isVanished.invoke(al, player.getName()) /*getTfm().al.isVanished(player.getName)*/;
+ }
+ catch (IllegalAccessException | InvocationTargetException e)
+ {
+ e.printStackTrace();
+ }
+ return false;
}
public String getTag(Player player)
@@ -69,7 +100,22 @@ public class TFMBridge
{
return null;
}
- return ChatColor.stripColor(getTfm().pl.getPlayer(player).getTag());
+
+ Object pl = Reflections.getField(getTfm(), "pl");
+ Method getPlayer = Reflections.getMethod(pl, "getPlayer", Player.class);
+ try
+ {
+ Object fPlayer = getPlayer.invoke(pl, player);
+ Method getTag = Reflections.getMethod(fPlayer, "getTag");
+
+ return (String)getTag.invoke(fPlayer);
+ }
+ catch (IllegalAccessException | InvocationTargetException e)
+ {
+ e.printStackTrace();
+ }
+
+ return "" /*ChatColor.stripColor(getTfm().pl.getPlayer(player).getTag())*/;
}
public void clearTag(Player player)
@@ -78,6 +124,19 @@ public class TFMBridge
{
return;
}
- getTfm().pl.getPlayer(player).setTag(null);
+// getTfm().pl.getPlayer(player).setTag(null);
+ Object pl = Reflections.getField(getTfm(), "pl");
+ Method getPlayer = Reflections.getMethod(pl, "getPlayer", Player.class);
+ try
+ {
+ Object fPlayer = getPlayer.invoke(pl, player);
+ Method setTag = Reflections.getMethod(fPlayer, "setTag", String.class);
+
+ setTag.invoke(fPlayer, (Object)null);
+ }
+ catch (IllegalAccessException | InvocationTargetException e)
+ {
+ e.printStackTrace();
+ }
}
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/config/Config.java b/src/main/java/me/totalfreedom/tfguilds/config/Config.java
index ac5daae..636179e 100644
--- a/src/main/java/me/totalfreedom/tfguilds/config/Config.java
+++ b/src/main/java/me/totalfreedom/tfguilds/config/Config.java
@@ -19,7 +19,6 @@ public class Config extends YamlConfiguration
if (!file.exists())
{
- options().copyDefaults(true);
plugin.saveResource(fileName, false);
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java b/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java
index 950bff7..2889c02 100644
--- a/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java
+++ b/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java
@@ -9,6 +9,7 @@ public enum ConfigEntry
GUILD_TAGS("server.guild_tags"),
GUILD_TAG_MAX_LENGTH("server.guild_tag_max_length"),
GLOBAL_TAG_MAX_LENGTH("server.global_tag_max_length"),
+ CONNECTION_TYPE("settings.connection"),
MYSQL_HOST("mysql.host"),
MYSQL_PORT("mysql.port"),
MYSQL_USERNAME("mysql.username"),
diff --git a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
index f4c5d7c..a21fd23 100644
--- a/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
+++ b/src/main/java/me/totalfreedom/tfguilds/guild/Guild.java
@@ -135,7 +135,7 @@ public class Guild
while (set.next())
{
String id = set.getString("id");
- UUID owner = User.getUserFromId(set.getInt("owner")).getUuid();
+ UUID owner = /*User.getUserFromId(set.getInt("owner")).getUuid()*/ UUID.fromString(set.getString("owner"));
List moderators = new ArrayList<>();
if (set.getString("moderators") != null)
{
@@ -512,7 +512,7 @@ public class Guild
{
statement.setString(1, id);
statement.setString(2, name);
- statement.setInt(3, User.getUserFromUuid(owner).getId());
+ statement.setString(3, owner.toString() /*User.getUserFromUuid(owner).getId()*/);
statement.setString(4, null);
statement.setString(5, null);
statement.setString(6, tag);
@@ -528,7 +528,7 @@ public class Guild
}
else
{
- statement.setInt(1, User.getUserFromUuid(owner).getId());
+ statement.setString(1, owner.toString());
statement.setString(2, moderators.isEmpty() ? null : getModeratorIds());
statement.setString(3, members.isEmpty() ? null : getMemberIds());
statement.setString(4, tag);
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
index 5844953..4e0594e 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
@@ -1,5 +1,7 @@
package me.totalfreedom.tfguilds.sql;
+import java.io.File;
+import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
@@ -20,12 +22,34 @@ public class SQLDatabase
}
try
{
- connection = DriverManager.getConnection(String.format("jdbc:mysql://%s:%d/%s",
- ConfigEntry.MYSQL_HOST.getString(),
- ConfigEntry.MYSQL_PORT.getInteger(),
- ConfigEntry.MYSQL_DATABASE.getString()),
- ConfigEntry.MYSQL_USERNAME.getString(),
- password);
+ switch (ConfigEntry.CONNECTION_TYPE.getString().toLowerCase())
+ {
+ case "sqlite":
+ File file = new File(plugin.getDataFolder(), "database.db");
+ if (!file.exists())
+ {
+ try
+ {
+ file.createNewFile();
+ plugin.getLogger().info("Creating database.db file");
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ connection = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath().replace("%20", " "));
+ break;
+ case "mysql":
+ connection = DriverManager.getConnection(String.format("jdbc:mysql://%s:%d/%s",
+ ConfigEntry.MYSQL_HOST.getString(),
+ ConfigEntry.MYSQL_PORT.getInteger(),
+ ConfigEntry.MYSQL_DATABASE.getString()),
+ ConfigEntry.MYSQL_USERNAME.getString(),
+ password);
+ break;
+ }
+
createTables();
plugin.getLogger().info("Connection to the MySQL server established!");
}
@@ -60,7 +84,7 @@ public class SQLDatabase
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `guilds` (" +
"`id` TEXT," +
"`name` TEXT," +
- "`owner` INT," +
+ "`owner` TEXT," +
"`moderators` TEXT," +
"`members` TEXT," +
"`tag` TEXT," +
diff --git a/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java b/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java
index 8d97620..fe7158a 100644
--- a/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java
+++ b/src/main/java/me/totalfreedom/tfguilds/util/GUtil.java
@@ -40,7 +40,7 @@ public class GUtil
public static String removeColorCodes(String string)
{
- String s = null;
+ /*String s = null;
if (string != null)
{
Matcher matcher = CHAT_COLOR_FORMAT.matcher(string);
@@ -48,8 +48,8 @@ public class GUtil
{
s = string.replaceAll(matcher.group(), "");
}
- }
- return s;
+ }*/
+ return ChatColor.stripColor(string);
}
public static boolean containsBlacklistedWord(String string)
diff --git a/src/main/java/me/totalfreedom/tfguilds/util/Reflections.java b/src/main/java/me/totalfreedom/tfguilds/util/Reflections.java
new file mode 100644
index 0000000..1341407
--- /dev/null
+++ b/src/main/java/me/totalfreedom/tfguilds/util/Reflections.java
@@ -0,0 +1,38 @@
+package me.totalfreedom.tfguilds.util;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+public class Reflections
+{
+
+ public static Object getField(T instance, String name) {
+ try
+ {
+ Field f = instance.getClass().getDeclaredField(name);
+ f.setAccessible(true);
+ return f.get(instance);
+ }
+ catch (NoSuchFieldException | IllegalAccessException e)
+ {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ public static Method getMethod(T instance, String name, Class>... parameterTypes) {
+ try
+ {
+ Method f = instance.getClass().getDeclaredMethod(name, parameterTypes);
+ f.setAccessible(true);
+ return f;
+ }
+ catch (NoSuchMethodException e)
+ {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+
+}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 5586de3..cae444f 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -2,6 +2,10 @@
# TFGuilds - Configuration
#
+settings:
+ # Types: mysql, sqlite
+ connection: sqlite
+
server:
# Log guild chat to console?
guild_chat_logging: true
From eba2b655c824a603a6d03d76cf6e8a6af94fd35f Mon Sep 17 00:00:00 2001
From: spacerocket62
Date: Thu, 29 Jul 2021 16:16:39 -0700
Subject: [PATCH 39/41] rename Reflections -> ReflectionsHelper add a default
case in the switch statement
---
.idea/compiler.xml | 2 +-
pom.xml | 4 +--
.../me/totalfreedom/tfguilds/TFMBridge.java | 26 +++++++-------
.../tfguilds/sql/SQLDatabase.java | 35 +++++++++++--------
...eflections.java => ReflectionsHelper.java} | 2 +-
5 files changed, 38 insertions(+), 31 deletions(-)
rename src/main/java/me/totalfreedom/tfguilds/util/{Reflections.java => ReflectionsHelper.java} (96%)
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index e67be4a..ec2a0b4 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -11,7 +11,7 @@
-
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 74016ba..d78711d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,8 +25,8 @@
maven-compiler-plugin
3.8.1
-
- 11
+
+ 16
diff --git a/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java b/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java
index a1211e6..775d1b2 100644
--- a/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java
+++ b/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java
@@ -2,7 +2,7 @@ package me.totalfreedom.tfguilds;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import me.totalfreedom.tfguilds.util.Reflections;
+import me.totalfreedom.tfguilds.util.ReflectionsHelper;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -41,8 +41,8 @@ public class TFMBridge
Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead.");
return player.isOp();
}
- Object al = Reflections.getField(getTfm(), "al");
- Method isAdmin = Reflections.getMethod(al, "isAdmin", Player.class);
+ Object al = ReflectionsHelper.getField(getTfm(), "al");
+ Method isAdmin = ReflectionsHelper.getMethod(al, "isAdmin", Player.class);
try
{
return (boolean)isAdmin.invoke(al, player) /*getTfm().al.isAdmin(player)*/;
@@ -61,8 +61,8 @@ public class TFMBridge
Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead.");
return sender.isOp();
}
- Object al = Reflections.getField(getTfm(), "al");
- Method isAdmin = Reflections.getMethod(al, "isAdmin", CommandSender.class);
+ Object al = ReflectionsHelper.getField(getTfm(), "al");
+ Method isAdmin = ReflectionsHelper.getMethod(al, "isAdmin", CommandSender.class);
try
{
return (boolean)isAdmin.invoke(al, sender) /*getTfm().al.isAdmin(player)*/;
@@ -81,8 +81,8 @@ public class TFMBridge
Bukkit.getLogger().warning("TotalFreedomMod not detected, vanish will return false.");
return false;
}
- Object al = Reflections.getField(getTfm(), "al");
- Method isVanished = Reflections.getMethod(al, "isVanished", String.class);
+ Object al = ReflectionsHelper.getField(getTfm(), "al");
+ Method isVanished = ReflectionsHelper.getMethod(al, "isVanished", String.class);
try
{
return (boolean)isVanished.invoke(al, player.getName()) /*getTfm().al.isVanished(player.getName)*/;
@@ -101,12 +101,12 @@ public class TFMBridge
return null;
}
- Object pl = Reflections.getField(getTfm(), "pl");
- Method getPlayer = Reflections.getMethod(pl, "getPlayer", Player.class);
+ Object pl = ReflectionsHelper.getField(getTfm(), "pl");
+ Method getPlayer = ReflectionsHelper.getMethod(pl, "getPlayer", Player.class);
try
{
Object fPlayer = getPlayer.invoke(pl, player);
- Method getTag = Reflections.getMethod(fPlayer, "getTag");
+ Method getTag = ReflectionsHelper.getMethod(fPlayer, "getTag");
return (String)getTag.invoke(fPlayer);
}
@@ -125,12 +125,12 @@ public class TFMBridge
return;
}
// getTfm().pl.getPlayer(player).setTag(null);
- Object pl = Reflections.getField(getTfm(), "pl");
- Method getPlayer = Reflections.getMethod(pl, "getPlayer", Player.class);
+ Object pl = ReflectionsHelper.getField(getTfm(), "pl");
+ Method getPlayer = ReflectionsHelper.getMethod(pl, "getPlayer", Player.class);
try
{
Object fPlayer = getPlayer.invoke(pl, player);
- Method setTag = Reflections.getMethod(fPlayer, "setTag", String.class);
+ Method setTag = ReflectionsHelper.getMethod(fPlayer, "setTag", String.class);
setTag.invoke(fPlayer, (Object)null);
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
index 4e0594e..5209c46 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
@@ -25,20 +25,7 @@ public class SQLDatabase
switch (ConfigEntry.CONNECTION_TYPE.getString().toLowerCase())
{
case "sqlite":
- File file = new File(plugin.getDataFolder(), "database.db");
- if (!file.exists())
- {
- try
- {
- file.createNewFile();
- plugin.getLogger().info("Creating database.db file");
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- connection = DriverManager.getConnection("jdbc:sqlite:" + file.getAbsolutePath().replace("%20", " "));
+ connection = DriverManager.getConnection("jdbc:sqlite:" + createDBFile(plugin).getAbsolutePath().replace("%20", " "));
break;
case "mysql":
connection = DriverManager.getConnection(String.format("jdbc:mysql://%s:%d/%s",
@@ -48,6 +35,8 @@ public class SQLDatabase
ConfigEntry.MYSQL_USERNAME.getString(),
password);
break;
+ default:
+ connection = DriverManager.getConnection("jdbc:sqlite:" + createDBFile(plugin).getAbsolutePath().replace("%20", " "));
}
createTables();
@@ -106,4 +95,22 @@ public class SQLDatabase
"`rowid` INTEGER AUTO_INCREMENT PRIMARY KEY)")
.execute();
}
+
+ private File createDBFile(TFGuilds plugin)
+ {
+ File file = new File(plugin.getDataFolder(), "database.db");
+ if (!file.exists())
+ {
+ try
+ {
+ file.createNewFile();
+ plugin.getLogger().info("Creating database.db file");
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ return file;
+ }
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/util/Reflections.java b/src/main/java/me/totalfreedom/tfguilds/util/ReflectionsHelper.java
similarity index 96%
rename from src/main/java/me/totalfreedom/tfguilds/util/Reflections.java
rename to src/main/java/me/totalfreedom/tfguilds/util/ReflectionsHelper.java
index 1341407..9a6e03b 100644
--- a/src/main/java/me/totalfreedom/tfguilds/util/Reflections.java
+++ b/src/main/java/me/totalfreedom/tfguilds/util/ReflectionsHelper.java
@@ -3,7 +3,7 @@ package me.totalfreedom.tfguilds.util;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
-public class Reflections
+public class ReflectionsHelper
{
public static Object getField(T instance, String name) {
From 93cc3f4f05d179ea4f616a7b5c8a81998c05160f Mon Sep 17 00:00:00 2001
From: spacerocket62
Date: Thu, 29 Jul 2021 16:18:45 -0700
Subject: [PATCH 40/41] maybe fix invalid target release 16?
---
pom.xml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/pom.xml b/pom.xml
index d78711d..74016ba 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,8 +25,8 @@
maven-compiler-plugin
3.8.1
-
- 16
+
+ 11
From 73cfc7e46ba011a4556a418991f2cdfb653e58fa Mon Sep 17 00:00:00 2001
From: spacerocket62
Date: Thu, 29 Jul 2021 16:23:47 -0700
Subject: [PATCH 41/41] remove pom comment and change version back to a release
version
---
pom.xml | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/pom.xml b/pom.xml
index 74016ba..4658cc1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.github.AtlasMediaGroup
TFGuilds
- master-4ec00d977c-1
+ 2021.06-RC3
jar
TFGuilds
@@ -72,11 +72,5 @@
1.16.5-R0.1-SNAPSHOT
provided
-
\ No newline at end of file