generate default-ranks.json for customizable perms. perms system to be added soon

This commit is contained in:
spacerocket62 2020-10-27 14:56:05 -07:00
parent 9dfc351ebe
commit fac87d8c66
9 changed files with 128 additions and 9 deletions

View File

@ -39,6 +39,12 @@
<version>1.18.12</version> <version>1.18.12</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20200518</version>
<scope>compile</scope>
</dependency>
<!-- DATABASING --> <!-- DATABASING -->

View File

@ -6,6 +6,7 @@ import lombok.Setter;
import me.totalfreedom.plex.cache.MongoPlayerData; import me.totalfreedom.plex.cache.MongoPlayerData;
import me.totalfreedom.plex.cache.SQLPlayerData; import me.totalfreedom.plex.cache.SQLPlayerData;
import me.totalfreedom.plex.listeners.PlayerListener; import me.totalfreedom.plex.listeners.PlayerListener;
import me.totalfreedom.plex.rank.RankManager;
import me.totalfreedom.plex.storage.MongoConnection; import me.totalfreedom.plex.storage.MongoConnection;
import me.totalfreedom.plex.storage.RedisConnection; import me.totalfreedom.plex.storage.RedisConnection;
import me.totalfreedom.plex.storage.SQLConnection; import me.totalfreedom.plex.storage.SQLConnection;
@ -30,6 +31,8 @@ public class Plex extends JavaPlugin
private MongoPlayerData mongoPlayerData; private MongoPlayerData mongoPlayerData;
private SQLPlayerData sqlPlayerData; private SQLPlayerData sqlPlayerData;
private RankManager rankManager;
@Override @Override
public void onLoad() public void onLoad()
{ {
@ -43,13 +46,13 @@ public class Plex extends JavaPlugin
sqlConnection = new SQLConnection(); sqlConnection = new SQLConnection();
mongoConnection = new MongoConnection(); mongoConnection = new MongoConnection();
redisConnection = new RedisConnection(); redisConnection = new RedisConnection();
try { /*try {
redisConnection.openPool(); redisConnection.openPool();
PlexLog.log("Successfully opened redis pool. Closing."); PlexLog.log("Successfully opened redis pool. Closing.");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
redisConnection.getJedis().close(); redisConnection.getJedis().close();*/
} }
@Override @Override
@ -65,17 +68,20 @@ public class Plex extends JavaPlugin
} }
getServer().getPluginManager().registerEvents(new PlayerListener(), this); getServer().getPluginManager().registerEvents(new PlayerListener(), this);
PlexLog.log(storageType.name());
rankManager = new RankManager();
rankManager.generateDefaultRanks();
} }
@Override @Override
public void onDisable() public void onDisable()
{ {
if (redisConnection.getJedis().isConnected()) /*if (redisConnection.getJedis().isConnected())
{ {
PlexLog.log("Disabling Redis/Jedis. No memory leaks in this Anarchy server !"); PlexLog.log("Disabling Redis/Jedis. No memory leaks in this Anarchy server !");
redisConnection.getJedis().close(); redisConnection.getJedis().close();
} }*/
} }
public static Plex get() { public static Plex get() {

View File

@ -4,7 +4,7 @@ import com.google.common.reflect.TypeToken;
import com.google.gson.Gson; import com.google.gson.Gson;
import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.player.PlexPlayer; 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.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;

View File

@ -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() { public File getFile() {
return file; return file;
} }

View File

@ -7,7 +7,7 @@ import dev.morphia.annotations.Indexed;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import me.totalfreedom.plex.rank.Rank; import me.totalfreedom.plex.rank.enums.Rank;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;

View File

@ -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<String> permissions;
public DefaultRankObj(Rank rank)
{
this.name = rank.name().toUpperCase();
this.permissions = Lists.newArrayList();
}
}

View File

@ -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<DefaultRankObj> 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();
}
}
}
}

View File

@ -1,4 +1,4 @@
package me.totalfreedom.plex.rank; package me.totalfreedom.plex.rank.enums;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -21,4 +21,11 @@ public enum Rank
this.prefix = prefix; this.prefix = prefix;
} }
public String getPrefix() {
return prefix;
}
public String getLoginMSG() {
return loginMSG;
}
} }

View File

@ -1,4 +1,4 @@
package me.totalfreedom.plex.rank; package me.totalfreedom.plex.rank.enums;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;