mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
generate default-ranks.json for customizable perms. perms system to be added soon
This commit is contained in:
parent
9dfc351ebe
commit
fac87d8c66
6
pom.xml
6
pom.xml
@ -39,6 +39,12 @@
|
||||
<version>1.18.12</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.json</groupId>
|
||||
<artifactId>json</artifactId>
|
||||
<version>20200518</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- DATABASING -->
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
23
src/main/java/me/totalfreedom/plex/rank/DefaultRankObj.java
Normal file
23
src/main/java/me/totalfreedom/plex/rank/DefaultRankObj.java
Normal 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
55
src/main/java/me/totalfreedom/plex/rank/RankManager.java
Normal file
55
src/main/java/me/totalfreedom/plex/rank/RankManager.java
Normal 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package me.totalfreedom.plex.rank;
|
||||
package me.totalfreedom.plex.rank.enums;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
Loading…
Reference in New Issue
Block a user