diff --git a/pom.xml b/pom.xml
index 24181f1..87e54f2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -39,6 +39,12 @@
1.18.12
compile
+
+ org.json
+ json
+ 20200518
+ compile
+
diff --git a/src/main/java/me/totalfreedom/plex/Plex.java b/src/main/java/me/totalfreedom/plex/Plex.java
index 9ff4dc1..8967884 100644
--- a/src/main/java/me/totalfreedom/plex/Plex.java
+++ b/src/main/java/me/totalfreedom/plex/Plex.java
@@ -6,6 +6,7 @@ import lombok.Setter;
import me.totalfreedom.plex.cache.MongoPlayerData;
import me.totalfreedom.plex.cache.SQLPlayerData;
import me.totalfreedom.plex.listeners.PlayerListener;
+import me.totalfreedom.plex.rank.RankManager;
import me.totalfreedom.plex.storage.MongoConnection;
import me.totalfreedom.plex.storage.RedisConnection;
import me.totalfreedom.plex.storage.SQLConnection;
@@ -30,6 +31,8 @@ public class Plex extends JavaPlugin
private MongoPlayerData mongoPlayerData;
private SQLPlayerData sqlPlayerData;
+ private RankManager rankManager;
+
@Override
public void onLoad()
{
@@ -43,13 +46,13 @@ public class Plex extends JavaPlugin
sqlConnection = new SQLConnection();
mongoConnection = new MongoConnection();
redisConnection = new RedisConnection();
- try {
+ /*try {
redisConnection.openPool();
PlexLog.log("Successfully opened redis pool. Closing.");
} catch (Exception e) {
e.printStackTrace();
}
- redisConnection.getJedis().close();
+ redisConnection.getJedis().close();*/
}
@Override
@@ -65,17 +68,20 @@ public class Plex extends JavaPlugin
}
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
- PlexLog.log(storageType.name());
+
+ rankManager = new RankManager();
+ rankManager.generateDefaultRanks();
+
}
@Override
public void onDisable()
{
- if (redisConnection.getJedis().isConnected())
+ /*if (redisConnection.getJedis().isConnected())
{
PlexLog.log("Disabling Redis/Jedis. No memory leaks in this Anarchy server !");
redisConnection.getJedis().close();
- }
+ }*/
}
public static Plex get() {
diff --git a/src/main/java/me/totalfreedom/plex/cache/SQLPlayerData.java b/src/main/java/me/totalfreedom/plex/cache/SQLPlayerData.java
index 16fe837..9c47821 100644
--- a/src/main/java/me/totalfreedom/plex/cache/SQLPlayerData.java
+++ b/src/main/java/me/totalfreedom/plex/cache/SQLPlayerData.java
@@ -4,7 +4,7 @@ import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.player.PlexPlayer;
-import me.totalfreedom.plex.rank.Rank;
+import me.totalfreedom.plex.rank.enums.Rank;
import java.sql.Connection;
import java.sql.PreparedStatement;
diff --git a/src/main/java/me/totalfreedom/plex/config/Config.java b/src/main/java/me/totalfreedom/plex/config/Config.java
index 7d24386..8a11cbf 100644
--- a/src/main/java/me/totalfreedom/plex/config/Config.java
+++ b/src/main/java/me/totalfreedom/plex/config/Config.java
@@ -34,6 +34,28 @@ public class Config
}
}
+ public Config(String name, boolean copy, File folder)
+ {
+ if (copy)
+ {
+ Plex.get().saveResource(name, false);
+ } else {
+ file = new File(folder, name);
+ if (!file.exists())
+ {
+ try {
+ file.createNewFile();
+ PlexLog.log("Generating " + name + " configuration file!");
+ } catch (IOException e) {
+ PlexLog.error(String.format("An error occured trying to create the following file: %s", name));
+ e.printStackTrace();
+ }
+ } else {
+ PlexLog.log(name + " configuration file was loaded.");
+ }
+ }
+ }
+
public File getFile() {
return file;
}
diff --git a/src/main/java/me/totalfreedom/plex/player/PlexPlayer.java b/src/main/java/me/totalfreedom/plex/player/PlexPlayer.java
index 63962b6..4cd1985 100644
--- a/src/main/java/me/totalfreedom/plex/player/PlexPlayer.java
+++ b/src/main/java/me/totalfreedom/plex/player/PlexPlayer.java
@@ -7,7 +7,7 @@ import dev.morphia.annotations.Indexed;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
-import me.totalfreedom.plex.rank.Rank;
+import me.totalfreedom.plex.rank.enums.Rank;
import java.util.ArrayList;
import java.util.List;
diff --git a/src/main/java/me/totalfreedom/plex/rank/DefaultRankObj.java b/src/main/java/me/totalfreedom/plex/rank/DefaultRankObj.java
new file mode 100644
index 0000000..209b5c6
--- /dev/null
+++ b/src/main/java/me/totalfreedom/plex/rank/DefaultRankObj.java
@@ -0,0 +1,23 @@
+package me.totalfreedom.plex.rank;
+
+import com.google.common.collect.Lists;
+import lombok.Getter;
+import me.totalfreedom.plex.rank.enums.Rank;
+
+import java.util.List;
+
+@Getter
+public class DefaultRankObj
+{
+
+ private String name;
+ private List permissions;
+
+ public DefaultRankObj(Rank rank)
+ {
+ this.name = rank.name().toUpperCase();
+ this.permissions = Lists.newArrayList();
+ }
+
+
+}
diff --git a/src/main/java/me/totalfreedom/plex/rank/RankManager.java b/src/main/java/me/totalfreedom/plex/rank/RankManager.java
new file mode 100644
index 0000000..df7c688
--- /dev/null
+++ b/src/main/java/me/totalfreedom/plex/rank/RankManager.java
@@ -0,0 +1,55 @@
+package me.totalfreedom.plex.rank;
+
+import com.google.common.collect.Lists;
+import me.totalfreedom.plex.Plex;
+import me.totalfreedom.plex.rank.enums.Rank;
+import me.totalfreedom.plex.util.PlexLog;
+import org.json.JSONObject;
+
+import java.io.*;
+import java.util.List;
+
+public class RankManager
+{
+
+ private File defaultRanks;
+
+ public RankManager()
+ {
+ defaultRanks = new File(new File(Plex.get().getDataFolder() + File.separator + "ranks"), "default-ranks.json");
+ }
+
+ public void generateDefaultRanks()
+ {
+ if (defaultRanks.exists())
+ {
+ return;
+ } else {
+ try {
+ defaultRanks.createNewFile();
+
+ List ranks = Lists.newArrayList();
+ for (Rank rank : Rank.values())
+ {
+ ranks.add(new DefaultRankObj(rank));
+ }
+
+ JSONObject obj = new JSONObject();
+ if (obj.length() == 0)
+ {
+ obj.put("ranks", ranks);
+
+ FileWriter writer = new FileWriter(defaultRanks);
+ writer.append(obj.toString(4));
+ writer.flush();
+ writer.close();
+ PlexLog.log("Generating default-ranks.json");
+ }
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ }
+}
diff --git a/src/main/java/me/totalfreedom/plex/rank/Rank.java b/src/main/java/me/totalfreedom/plex/rank/enums/Rank.java
similarity index 80%
rename from src/main/java/me/totalfreedom/plex/rank/Rank.java
rename to src/main/java/me/totalfreedom/plex/rank/enums/Rank.java
index fad4445..9576703 100644
--- a/src/main/java/me/totalfreedom/plex/rank/Rank.java
+++ b/src/main/java/me/totalfreedom/plex/rank/enums/Rank.java
@@ -1,4 +1,4 @@
-package me.totalfreedom.plex.rank;
+package me.totalfreedom.plex.rank.enums;
import org.bukkit.ChatColor;
@@ -21,4 +21,11 @@ public enum Rank
this.prefix = prefix;
}
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public String getLoginMSG() {
+ return loginMSG;
+ }
}
diff --git a/src/main/java/me/totalfreedom/plex/rank/Title.java b/src/main/java/me/totalfreedom/plex/rank/enums/Title.java
similarity index 93%
rename from src/main/java/me/totalfreedom/plex/rank/Title.java
rename to src/main/java/me/totalfreedom/plex/rank/enums/Title.java
index 90a341b..154cfea 100644
--- a/src/main/java/me/totalfreedom/plex/rank/Title.java
+++ b/src/main/java/me/totalfreedom/plex/rank/enums/Title.java
@@ -1,4 +1,4 @@
-package me.totalfreedom.plex.rank;
+package me.totalfreedom.plex.rank.enums;
import org.bukkit.ChatColor;