diff --git a/.idea/TFGuilds.iml b/.idea/TFGuilds.iml
index 163e931..e5665da 100644
--- a/.idea/TFGuilds.iml
+++ b/.idea/TFGuilds.iml
@@ -1,20 +1,15 @@
-
-
-
- SPIGOT
+ PAPER
-
+
@@ -24,81 +19,33 @@
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index a97453e..b9600f9 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -2,6 +2,7 @@
+
@@ -10,7 +11,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index b008060..e89a848 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -11,6 +11,11 @@
+
+
+
+
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index d2b0ede..c01a206 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -16,5 +16,5 @@
-
+
\ No newline at end of file
diff --git a/nb-configuration.xml b/nb-configuration.xml
index 5616f15..a5e2dc0 100644
--- a/nb-configuration.xml
+++ b/nb-configuration.xml
@@ -13,7 +13,7 @@ You can copy and paste the single properties, into the pom.xml file and the IDE
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
- JDK_11
+ JDK_17
true
diff --git a/pom.xml b/pom.xml
index 64eb105..5a8e966 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
+ 2022.01
jar
TFGuilds
@@ -25,8 +25,8 @@
maven-compiler-plugin
3.8.1
-
- 11
+
+ 17
@@ -56,16 +56,20 @@
- spigotmc-repo
- https://hub.spigotmc.org/nexus/content/repositories/snapshots/
+ jitpack.io
+ https://jitpack.io
+
+
+ papermc
+ https://papermc.io/repo/repository/maven-public/
- org.spigotmc
- spigot-api
- 1.17.1-R0.1-SNAPSHOT
+ io.papermc.paper
+ paper-api
+ 1.18.1-R0.1-SNAPSHOT
provided
diff --git a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
index b83696e..31dc38b 100644
--- a/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
+++ b/src/main/java/me/totalfreedom/tfguilds/TFGuilds.java
@@ -6,6 +6,11 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
import me.totalfreedom.tfguilds.command.*;
import me.totalfreedom.tfguilds.config.Config;
import me.totalfreedom.tfguilds.guild.Guild;
@@ -14,6 +19,7 @@ import me.totalfreedom.tfguilds.listener.ChatListener;
import me.totalfreedom.tfguilds.listener.JoinListener;
import me.totalfreedom.tfguilds.sql.SQLDatabase;
import org.bukkit.plugin.java.JavaPlugin;
+import org.jetbrains.annotations.NotNull;
public class TFGuilds extends JavaPlugin
{
@@ -33,7 +39,7 @@ public class TFGuilds extends JavaPlugin
public void onEnable()
{
plugin = this;
- config = new Config("config.yml");
+ config = new Config(this,"config.yml");
sqlDatabase = new SQLDatabase(this);
User.loadAll();
Guild.loadAll();
@@ -54,13 +60,13 @@ public class TFGuilds extends JavaPlugin
{
getSQL().getConnection().close();
}
- catch (SQLException throwables)
+ catch (SQLException ignored)
{
}
config.save();
}
- public Config getConfig()
+ public @NotNull Config getConfig()
{
return config;
}
@@ -87,6 +93,19 @@ public class TFGuilds extends JavaPlugin
return commands;
}
+ private void forcedSQLPostLoad() {
+ ExecutorService ex = Executors.newCachedThreadPool();
+ Future future = ex.submit(() -> new SQLDatabase(getPlugin()));
+ try
+ {
+ sqlDatabase = future.get();
+ }
+ catch (InterruptedException | ExecutionException e)
+ {
+ e.printStackTrace();
+ }
+ }
+
private void loadSubCommands()
{
subCommands.put("create", new CreateSubCommand());
diff --git a/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java b/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java
index cc362d0..688bd0b 100644
--- a/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java
+++ b/src/main/java/me/totalfreedom/tfguilds/TFMBridge.java
@@ -10,10 +10,11 @@ import org.bukkit.plugin.Plugin;
public class TFMBridge
{
+
private final TFGuilds plugin = TFGuilds.getPlugin();
private /*TotalFreedomMod*/ Plugin tfm = null;
- public /*TotalFreedomMod*/ Plugin getTFM()
+ public /*TotalFreedomMod*/ Plugin getTfm()
{
if (tfm == null)
{
@@ -35,16 +36,16 @@ public class TFMBridge
public boolean isAdmin(Player player)
{
- if (getTFM() == null)
+ if (getTfm() == null)
{
Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead.");
return player.isOp();
}
- Object adminList = ReflectionsHelper.getField(getTFM(), "adminList");
+ Object adminList = ReflectionsHelper.getField(getTfm(), "adminList");
Method isAdmin = ReflectionsHelper.getMethod(adminList, "isAdmin", Player.class);
try
{
- return (boolean)isAdmin.invoke(adminList, player) /*getTfm().al.isAdmin(player)*/;
+ return (boolean)isAdmin.invoke(adminList, player) /*getTfm().adminList.isAdmin(player)*/;
}
catch (IllegalAccessException | InvocationTargetException e)
{
@@ -55,16 +56,16 @@ public class TFMBridge
public boolean isAdmin(CommandSender sender)
{
- if (getTFM() == null)
+ if (getTfm() == null)
{
Bukkit.getLogger().warning("TotalFreedomMod not detected, checking operator status instead.");
return sender.isOp();
}
- Object adminList = ReflectionsHelper.getField(getTFM(), "adminList");
+ Object adminList = ReflectionsHelper.getField(getTfm(), "adminList");
Method isAdmin = ReflectionsHelper.getMethod(adminList, "isAdmin", CommandSender.class);
try
{
- return (boolean)isAdmin.invoke(adminList, sender) /*getTfm().al.isAdmin(player)*/;
+ return (boolean)isAdmin.invoke(adminList, sender) /*getTfm().adminList.isAdmin(player)*/;
}
catch (IllegalAccessException | InvocationTargetException e)
{
@@ -75,12 +76,12 @@ public class TFMBridge
public boolean isVanished(Player player)
{
- if (getTFM() == null)
+ if (getTfm() == null)
{
Bukkit.getLogger().warning("TotalFreedomMod not detected, vanish will return false.");
return false;
}
- Object adminList = ReflectionsHelper.getField(getTFM(), "adminList");
+ Object adminList = ReflectionsHelper.getField(getTfm(), "adminList");
Method isVanished = ReflectionsHelper.getMethod(adminList, "isVanished", String.class);
try
{
@@ -95,12 +96,12 @@ public class TFMBridge
public String getTag(Player player)
{
- if (getTFM() == null)
+ if (getTfm() == null)
{
return null;
}
- Object playerList = ReflectionsHelper.getField(getTFM(), "playerList");
+ Object playerList = ReflectionsHelper.getField(getTfm(), "playerList");
Method getPlayer = ReflectionsHelper.getMethod(playerList, "getPlayer", Player.class);
try
{
@@ -119,12 +120,12 @@ public class TFMBridge
public void clearTag(Player player)
{
- if (getTFM() == null)
+ if (getTfm() == null)
{
return;
}
// getTfm().playerList.getPlayer(player).setTag(null);
- Object playerList = ReflectionsHelper.getField(getTFM(), "playerList");
+ Object playerList = ReflectionsHelper.getField(getTfm(), "playerList");
Method getPlayer = ReflectionsHelper.getMethod(playerList, "getPlayer", Player.class);
try
{
diff --git a/src/main/java/me/totalfreedom/tfguilds/config/Config.java b/src/main/java/me/totalfreedom/tfguilds/config/Config.java
index 636179e..cb65dcf 100644
--- a/src/main/java/me/totalfreedom/tfguilds/config/Config.java
+++ b/src/main/java/me/totalfreedom/tfguilds/config/Config.java
@@ -1,20 +1,32 @@
package me.totalfreedom.tfguilds.config;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.FileWriter;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Arrays;
+import java.util.concurrent.atomic.AtomicBoolean;
import me.totalfreedom.tfguilds.TFGuilds;
+import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
public class Config extends YamlConfiguration
{
- private final TFGuilds plugin;
private final File file;
+ private final TFGuilds plugin;
+ private final String fileName;
- public Config(String fileName)
+ public Config(TFGuilds plugin, String fileName)
{
- this.plugin = TFGuilds.getPlugin();
+
+ this.fileName = fileName;
+ this.plugin = plugin;
this.file = new File(plugin.getDataFolder(), fileName);
if (!file.exists())
@@ -22,6 +34,8 @@ public class Config extends YamlConfiguration
plugin.saveResource(fileName, false);
}
+ verifyConfiguration();
+
load();
}
@@ -48,4 +62,29 @@ public class Config extends YamlConfiguration
ex.printStackTrace();
}
}
+
+ public void verifyConfiguration() {
+ InputStreamReader stream = new InputStreamReader(plugin.getResource(fileName));
+ YamlConfiguration reader = YamlConfiguration.loadConfiguration(stream);
+ YamlConfiguration writer = YamlConfiguration.loadConfiguration(file);
+
+ AtomicBoolean shouldSave = new AtomicBoolean(false);
+
+ try {
+ reader.getKeys(true).forEach(key -> {
+ if (!writer.contains(key)) writer.set(key, reader.get(key));
+ if (!shouldSave.get()) shouldSave.set(true);
+ });
+ if (shouldSave.get()) {
+ writer.save(file);
+ }
+ } catch (IOException ex) {
+ TFGuilds.getPlugin()
+ .getLogger()
+ .severe("Error attempting to verify configuration: \n"
+ + ex.getMessage()
+ + "\nCaused by: "
+ + ex.getCause());
+ }
+ }
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java b/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java
index 2889c02..9777e02 100644
--- a/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java
+++ b/src/main/java/me/totalfreedom/tfguilds/config/ConfigEntry.java
@@ -45,4 +45,8 @@ public enum ConfigEntry
{
return config.getString(path);
}
+
+ public String getName() {
+ return path;
+ }
}
diff --git a/src/main/java/me/totalfreedom/tfguilds/listener/JoinListener.java b/src/main/java/me/totalfreedom/tfguilds/listener/JoinListener.java
index a01c041..bae6f31 100644
--- a/src/main/java/me/totalfreedom/tfguilds/listener/JoinListener.java
+++ b/src/main/java/me/totalfreedom/tfguilds/listener/JoinListener.java
@@ -43,13 +43,19 @@ public class JoinListener implements Listener
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)
+ if (user != null && user.displayTag() && tfmTag != null && guild.getTag() != null && maxLength > 0)
{
- int length = GUtil.removeColorCodes(tfmTag).length() + GUtil.removeColorCodes(guild.getTag()).length();
- if (length > maxLength)
+ String tfmTagStripped = GUtil.removeColorCodes(tfmTag);
+ String guildTagStripped = GUtil.removeColorCodes(guild.getTag());
+ if (tfmTagStripped != null && guildTagStripped != null)
{
- TFGuilds.getPlugin().getTfmBridge().clearTag(player);
+ int length = tfmTagStripped.length() + guildTagStripped.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 5209c46..1b3bbc4 100644
--- a/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
+++ b/src/main/java/me/totalfreedom/tfguilds/sql/SQLDatabase.java
@@ -22,21 +22,18 @@ public class SQLDatabase
}
try
{
- switch (ConfigEntry.CONNECTION_TYPE.getString().toLowerCase())
+ if ("mysql".equals(ConfigEntry.CONNECTION_TYPE.getString().toLowerCase()))
{
- case "sqlite":
- connection = DriverManager.getConnection("jdbc:sqlite:" + createDBFile(plugin).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;
- default:
- connection = DriverManager.getConnection("jdbc:sqlite:" + createDBFile(plugin).getAbsolutePath().replace("%20", " "));
+ 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);
+ }
+ else
+ {
+ connection = DriverManager.getConnection("jdbc:sqlite:" + createDBFile(plugin).getAbsolutePath().replace("%20", " "));
}
createTables();
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index cae444f..6e0a911 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -4,7 +4,7 @@
settings:
# Types: mysql, sqlite
- connection: sqlite
+ connection: mysql
server:
# Log guild chat to console?
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
index 6174e6a..81f0a04 100644
--- a/src/main/resources/plugin.yml
+++ b/src/main/resources/plugin.yml
@@ -1,7 +1,7 @@
name: TFGuilds
version: ${project.version}
main: me.totalfreedom.tfguilds.TFGuilds
-api-version: 1.16
+api-version: 1.17
authors: [ Fleek, super, speed ]
description: A guilds plugin for the TotalFreedom server.
softdepend: