doesnt compile

This commit is contained in:
Telesphoreo 2020-10-27 22:49:56 -05:00
parent f1744f2050
commit f5c5c75ee1
21 changed files with 214 additions and 280 deletions

View File

@ -5,13 +5,13 @@ import lombok.Getter;
import lombok.Setter; 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.config.MainConfig;
import me.totalfreedom.plex.listeners.PlayerListener; import me.totalfreedom.plex.listeners.PlayerListener;
import me.totalfreedom.plex.rank.RankManager; 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;
import me.totalfreedom.plex.storage.StorageType; import me.totalfreedom.plex.storage.StorageType;
import me.totalfreedom.plex.util.PlexLog;
import me.totalfreedom.plex.util.PlexUtils; import me.totalfreedom.plex.util.PlexUtils;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -22,6 +22,8 @@ public class Plex extends JavaPlugin
@Setter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
private static Plex plugin; private static Plex plugin;
public MainConfig config;
private StorageType storageType = StorageType.SQLITE; private StorageType storageType = StorageType.SQLITE;
private SQLConnection sqlConnection; private SQLConnection sqlConnection;
@ -33,13 +35,17 @@ public class Plex extends JavaPlugin
private RankManager rankManager; private RankManager rankManager;
public static Plex get()
{
return plugin;
}
@Override @Override
public void onLoad() public void onLoad()
{ {
plugin = this; plugin = this;
getConfig().options().copyDefaults(true); config = new MainConfig(this, "config.yml");
saveConfig();
saveResource("database.db", false); saveResource("database.db", false);
@ -58,12 +64,16 @@ public class Plex extends JavaPlugin
@Override @Override
public void onEnable() public void onEnable()
{ {
config.load();
PlexUtils.testConnections(); PlexUtils.testConnections();
if (storageType == StorageType.MONGO) if (storageType == StorageType.MONGO)
{ {
mongoPlayerData = new MongoPlayerData(); mongoPlayerData = new MongoPlayerData();
} else { }
else
{
sqlPlayerData = new SQLPlayerData(); sqlPlayerData = new SQLPlayerData();
} }
@ -77,14 +87,11 @@ public class Plex extends JavaPlugin
@Override @Override
public void onDisable() public void onDisable()
{ {
config.save();
/*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() {
return plugin;
}
} }

View File

@ -1,42 +1,37 @@
package me.totalfreedom.plex.cache; package me.totalfreedom.plex.cache;
import dev.morphia.query.Query;
import dev.morphia.query.UpdateOperations;
import java.util.UUID;
import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.player.PlexPlayer; import me.totalfreedom.plex.player.PlexPlayer;
import org.mongodb.morphia.query.FindOptions;
import org.mongodb.morphia.query.Query;
import org.mongodb.morphia.query.UpdateOperations;
import java.util.UUID;
public class MongoPlayerData public class MongoPlayerData
{ {
private final PlexPlayerDAO plexPlayerDAO;
private PlexPlayerDAO plexPlayerDAO;
public MongoPlayerData() public MongoPlayerData()
{ {
this.plexPlayerDAO = new PlexPlayerDAO(PlexPlayer.class, Plex.get().getMongoConnection().getDatastore()); this.plexPlayerDAO = new PlexPlayerDAO(PlexPlayer.class, Plex.get().getMongoConnection().getDatastore());
} }
public boolean exists(UUID uuid) { public boolean exists(UUID uuid)
{
Query<PlexPlayer> query = plexPlayerDAO.createQuery(); Query<PlexPlayer> query = plexPlayerDAO.createQuery();
if (query.field("uuid").exists().field("uuid").equal(uuid.toString()).get() != null) return query.field("uuid").exists().field("uuid").equal(uuid.toString()).find().tryNext() != null;
{
return true;
}
return false;
} }
public PlexPlayer getByUUID(UUID uuid) { public PlexPlayer getByUUID(UUID uuid)
{
if (PlayerCache.getPlexPlayerMap().containsKey(uuid)) if (PlayerCache.getPlexPlayerMap().containsKey(uuid))
{ {
return PlayerCache.getPlexPlayerMap().get(uuid); return PlayerCache.getPlexPlayerMap().get(uuid);
} }
Query<PlexPlayer> query2 = plexPlayerDAO.createQuery().field("uuid").exists().field("uuid").equal(uuid.toString()); Query<PlexPlayer> query2 = plexPlayerDAO.createQuery().field("uuid").exists().field("uuid").equal(uuid.toString());
return query2.get(); return query2.first();
} }
public void update(PlexPlayer player) public void update(PlexPlayer player)
@ -49,13 +44,14 @@ public class MongoPlayerData
updateOps.set("name", player.getName()); updateOps.set("name", player.getName());
updateOps.set("loginMSG", player.getLoginMSG()); updateOps.set("loginMSG", player.getLoginMSG());
updateOps.set("prefix", player.getPrefix()); updateOps.set("prefix", player.getPrefix());
updateOps.set("rank", player.getRank().toLowerCase()); updateOps.set("rank", player.getRank() == null ? "" : player.getRank().name().toLowerCase());
updateOps.set("ips", player.getIps()); updateOps.set("ips", player.getIps());
updateOps.set("coins", player.getCoins()); updateOps.set("coins", player.getCoins());
plexPlayerDAO.update(filter, updateOps); plexPlayerDAO.update(filter, updateOps);
} }
public PlexPlayerDAO getPlexPlayerDAO() { public PlexPlayerDAO getPlexPlayerDAO()
{
return plexPlayerDAO; return plexPlayerDAO;
} }
} }

View File

@ -1,23 +1,23 @@
package me.totalfreedom.plex.cache; package me.totalfreedom.plex.cache;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import java.util.Map;
import java.util.UUID;
import me.totalfreedom.plex.player.PlexPlayer; import me.totalfreedom.plex.player.PlexPlayer;
import me.totalfreedom.plex.player.PunishedPlayer; import me.totalfreedom.plex.player.PunishedPlayer;
import java.util.Map;
import java.util.UUID;
public class PlayerCache public class PlayerCache
{ {
private static final Map<UUID, PlexPlayer> plexPlayerMap = Maps.newHashMap();
private static final Map<UUID, PunishedPlayer> punishedPlayerMap = Maps.newHashMap();
private static Map<UUID, PlexPlayer> plexPlayerMap = Maps.newHashMap(); public static Map<UUID, PunishedPlayer> getPunishedPlayerMap()
private static Map<UUID, PunishedPlayer> punishedPlayerMap = Maps.newHashMap(); {
public static Map<UUID, PunishedPlayer> getPunishedPlayerMap() {
return punishedPlayerMap; return punishedPlayerMap;
} }
public static Map<UUID, PlexPlayer> getPlexPlayerMap() { public static Map<UUID, PlexPlayer> getPlexPlayerMap()
{
return plexPlayerMap; return plexPlayerMap;
} }
} }

View File

@ -8,41 +8,46 @@ import org.mongodb.morphia.query.Query;
import org.mongodb.morphia.query.UpdateOperations; import org.mongodb.morphia.query.UpdateOperations;
import org.mongodb.morphia.query.UpdateResults; import org.mongodb.morphia.query.UpdateResults;
public class PlexPlayerDAO extends BasicDAO<PlexPlayer, Object> { public class PlexPlayerDAO extends BasicDAO<PlexPlayer, Object>
{
public PlexPlayerDAO(Class<PlexPlayer> entityclass, Datastore ds) public PlexPlayerDAO(Class<PlexPlayer> entityclass, Datastore ds)
{ {
super(entityclass, ds); super(entityclass, ds);
} }
@Override @Override
public boolean exists(Query<PlexPlayer> query) { public boolean exists(Query<PlexPlayer> query)
{
return super.exists(query); return super.exists(query);
} }
@Override @Override
public PlexPlayer findOne(String key, Object value) { public PlexPlayer findOne(String key, Object value)
{
return super.findOne(key, value); return super.findOne(key, value);
} }
@Override @Override
public PlexPlayer get(Object id) { public PlexPlayer get(Object id)
{
return super.get(id); return super.get(id);
} }
@Override @Override
public UpdateResults update(Query<PlexPlayer> query, UpdateOperations<PlexPlayer> ops) { public UpdateResults update(Query<PlexPlayer> query, UpdateOperations<PlexPlayer> ops)
{
return super.update(query, ops); return super.update(query, ops);
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj)
{
return super.equals(obj); return super.equals(obj);
} }
@Override @Override
public Key<PlexPlayer> save(PlexPlayer entity) { public Key<PlexPlayer> save(PlexPlayer entity)
{
return super.save(entity); return super.save(entity);
} }
} }

View File

@ -2,20 +2,18 @@ package me.totalfreedom.plex.cache;
import com.google.common.reflect.TypeToken; 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.player.PlexPlayer;
import me.totalfreedom.plex.rank.enums.Rank;
import java.sql.Connection; import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.player.PlexPlayer;
import me.totalfreedom.plex.rank.enums.Rank;
public class SQLPlayerData public class SQLPlayerData
{ {
private final String SELECT = "SELECT * FROM `players` WHERE uuid=?"; private final String SELECT = "SELECT * FROM `players` WHERE uuid=?";
private final String UPDATE = "UPDATE `players` SET name=?, login_msg=?, prefix=?, rank=?, ips=?, coins=? WHERE uuid=?"; private final String UPDATE = "UPDATE `players` SET name=?, login_msg=?, prefix=?, rank=?, ips=?, coins=? WHERE uuid=?";
private final String INSERT = "INSERT INTO `players` (`uuid`, `name`, `login_msg`, `prefix`, `rank`, `ips`, `coins`) VALUES (?, ?, ?, ?, ?, ?, ?);"; private final String INSERT = "INSERT INTO `players` (`uuid`, `name`, `login_msg`, `prefix`, `rank`, `ips`, `coins`) VALUES (?, ?, ?, ?, ?, ?, ?);";
@ -29,7 +27,8 @@ public class SQLPlayerData
ResultSet set = statement.executeQuery(); ResultSet set = statement.executeQuery();
return set.next(); return set.next();
} }
catch (SQLException throwables) { catch (SQLException throwables)
{
throwables.printStackTrace(); throwables.printStackTrace();
} }
return false; return false;
@ -56,7 +55,9 @@ public class SQLPlayerData
String rankName = set.getString("rank").toUpperCase(); String rankName = set.getString("rank").toUpperCase();
long coins = set.getLong("coins"); long coins = set.getLong("coins");
Rank rank = Rank.valueOf(rankName); Rank rank = Rank.valueOf(rankName);
List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>(){}.getType()); List<String> ips = new Gson().fromJson(set.getString("ips"), new TypeToken<List<String>>()
{
}.getType());
plexPlayer.setName(name); plexPlayer.setName(name);
plexPlayer.setLoginMSG(loginMSG); plexPlayer.setLoginMSG(loginMSG);
plexPlayer.setPrefix(prefix); plexPlayer.setPrefix(prefix);
@ -66,7 +67,8 @@ public class SQLPlayerData
} }
return plexPlayer; return plexPlayer;
} }
catch (SQLException throwables) { catch (SQLException throwables)
{
throwables.printStackTrace(); throwables.printStackTrace();
} }
return null; return null;
@ -86,7 +88,8 @@ public class SQLPlayerData
statement.setString(7, player.getUuid()); statement.setString(7, player.getUuid());
statement.executeUpdate(); statement.executeUpdate();
} }
catch (SQLException throwables) { catch (SQLException throwables)
{
throwables.printStackTrace(); throwables.printStackTrace();
} }
} }
@ -104,7 +107,8 @@ public class SQLPlayerData
statement.setString(6, new Gson().toJson(player.getIps())); statement.setString(6, new Gson().toJson(player.getIps()));
statement.execute(); statement.execute();
} }
catch (SQLException throwables) { catch (SQLException throwables)
{
throwables.printStackTrace(); throwables.printStackTrace();
} }
} }

View File

@ -1,62 +0,0 @@
package me.totalfreedom.plex.config;
import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.util.PlexLog;
import java.io.File;
import java.io.IOException;
public class Config
{
private File file;
public Config(String name, boolean copy)
{
if (copy)
{
Plex.get().saveResource(name, false);
} else {
file = new File(Plex.get().getDataFolder(), 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 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;
}
}

View File

@ -0,0 +1,52 @@
package me.totalfreedom.plex.config;
import java.io.File;
import me.totalfreedom.plex.Plex;
import org.bukkit.configuration.file.YamlConfiguration;
public class MainConfig extends YamlConfiguration
{
private static MainConfig config;
private final Plex plugin;
private final File file;
public MainConfig(Plex plugin, String configName)
{
this.plugin = plugin;
this.file = new File(plugin.getDataFolder(), configName);
if (!file.exists())
{
saveDefault(configName);
}
}
public void load()
{
try
{
super.load(file);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
public void save()
{
try
{
super.save(file);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
private void saveDefault(String configName)
{
plugin.saveResource(configName, false);
}
}

View File

@ -1,44 +0,0 @@
package me.totalfreedom.plex.config;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
public class YamlConfig
{
private YamlConfiguration config;
private File file;
public YamlConfig(File file)
{
this.file = file;
this.config = YamlConfiguration.loadConfiguration(file);
}
public YamlConfiguration get() {
return config;
}
public void save()
{
try {
this.config.save(file);
} catch (IOException e) {
e.printStackTrace();
}
}
public void reload()
{
try {
this.config.load(file);
} catch (IOException e) {
e.printStackTrace();
} catch (InvalidConfigurationException e) {
e.printStackTrace();
}
}
}

View File

@ -1,5 +1,6 @@
package me.totalfreedom.plex.listeners; package me.totalfreedom.plex.listeners;
import java.util.Arrays;
import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.cache.MongoPlayerData; import me.totalfreedom.plex.cache.MongoPlayerData;
import me.totalfreedom.plex.cache.PlayerCache; import me.totalfreedom.plex.cache.PlayerCache;
@ -13,13 +14,10 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import java.util.Arrays;
public class PlayerListener implements Listener public class PlayerListener implements Listener
{ {
private final MongoPlayerData mongoPlayerData = Plex.get().getMongoPlayerData() != null ? Plex.get().getMongoPlayerData() : null;
private MongoPlayerData mongoPlayerData = Plex.get().getMongoPlayerData() != null ? Plex.get().getMongoPlayerData() : null; private final SQLPlayerData sqlPlayerData = Plex.get().getSqlPlayerData() != null ? Plex.get().getSqlPlayerData() : null;
private SQLPlayerData sqlPlayerData = Plex.get().getSqlPlayerData() != null ? Plex.get().getSqlPlayerData() : null;
@EventHandler @EventHandler
public void onJoin(PlayerJoinEvent event) public void onJoin(PlayerJoinEvent event)
@ -38,12 +36,14 @@ public class PlayerListener implements Listener
plexPlayer.setIps(Arrays.asList(player.getAddress().getAddress().getHostAddress().trim())); //set the arraylist of ips plexPlayer.setIps(Arrays.asList(player.getAddress().getAddress().getHostAddress().trim())); //set the arraylist of ips
mongoPlayerData.getPlexPlayerDAO().save(plexPlayer); //and put their document in mongo collection mongoPlayerData.getPlexPlayerDAO().save(plexPlayer); //and put their document in mongo collection
}
} else { else
{
plexPlayer = mongoPlayerData.getByUUID(player.getUniqueId()); //oh they do exist! plexPlayer = mongoPlayerData.getByUUID(player.getUniqueId()); //oh they do exist!
plexPlayer.setName(plexPlayer.getName()); //set the name! plexPlayer.setName(plexPlayer.getName()); //set the name!
} }
} else if (sqlPlayerData != null) }
else if (sqlPlayerData != null)
{ {
if (!sqlPlayerData.exists(player.getUniqueId())) //okay, we're saving with mongo! now check if the player's document exists if (!sqlPlayerData.exists(player.getUniqueId())) //okay, we're saving with mongo! now check if the player's document exists
{ {
@ -51,10 +51,10 @@ public class PlayerListener implements Listener
plexPlayer = new PlexPlayer(player.getUniqueId()); //it doesn't! okay so now create the object plexPlayer = new PlexPlayer(player.getUniqueId()); //it doesn't! okay so now create the object
plexPlayer.setName(player.getName()); //set the name of the player plexPlayer.setName(player.getName()); //set the name of the player
plexPlayer.setIps(Arrays.asList(player.getAddress().getAddress().getHostAddress().trim())); //set the arraylist of ips plexPlayer.setIps(Arrays.asList(player.getAddress().getAddress().getHostAddress().trim())); //set the arraylist of ips
sqlPlayerData.insert(plexPlayer); //and put their document in mongo collection sqlPlayerData.insert(plexPlayer); //and put their document in mongo collection
}
} else { else
{
plexPlayer = sqlPlayerData.getByUUID(player.getUniqueId()); //oh they do exist! plexPlayer = sqlPlayerData.getByUUID(player.getUniqueId()); //oh they do exist!
plexPlayer.setName(plexPlayer.getName()); //set the name! plexPlayer.setName(plexPlayer.getName()); //set the name!
} }
@ -72,14 +72,13 @@ public class PlayerListener implements Listener
if (mongoPlayerData != null) //back to mongo checking if (mongoPlayerData != null) //back to mongo checking
{ {
mongoPlayerData.update(plexPlayer); //update the player's document mongoPlayerData.update(plexPlayer); //update the player's document
} else if (sqlPlayerData != null) }
else if (sqlPlayerData != null)
{ {
sqlPlayerData.update(plexPlayer); sqlPlayerData.update(plexPlayer);
} }
PlayerCache.getPlexPlayerMap().remove(event.getPlayer().getUniqueId()); //remove them from cache PlayerCache.getPlexPlayerMap().remove(event.getPlayer().getUniqueId()); //remove them from cache
PlayerCache.getPunishedPlayerMap().remove(event.getPlayer().getUniqueId()); PlayerCache.getPunishedPlayerMap().remove(event.getPlayer().getUniqueId());
} }
} }

View File

@ -1,21 +1,19 @@
package me.totalfreedom.plex.player; package me.totalfreedom.plex.player;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;
import dev.morphia.annotations.IndexOptions;
import dev.morphia.annotations.Indexed;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import me.totalfreedom.plex.rank.enums.Rank; import me.totalfreedom.plex.rank.enums.Rank;
import org.mongodb.morphia.annotations.Entity;
import org.mongodb.morphia.annotations.Id;
import org.mongodb.morphia.annotations.IndexOptions;
import org.mongodb.morphia.annotations.Indexed;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Getter @Getter
@Setter @Setter
@Entity(value = "players", noClassnameStored = true) @Entity(value = "players", noClassnameStored = true)
public class PlexPlayer public class PlexPlayer
{ {
@ -35,12 +33,10 @@ public class PlexPlayer
private long coins; private long coins;
private String rank; private Rank rank;
private List<String> ips; private List<String> ips;
public PlexPlayer(){}
public PlexPlayer(UUID playerUUID) public PlexPlayer(UUID playerUUID)
{ {
this.uuid = playerUUID.toString(); this.uuid = playerUUID.toString();
@ -56,12 +52,6 @@ public class PlexPlayer
this.ips = new ArrayList<>(); this.ips = new ArrayList<>();
this.rank = ""; this.rank = null;
} }
public Rank getRankFromString()
{
return Rank.valueOf(rank.toUpperCase());
}
} }

View File

@ -1,21 +1,18 @@
package me.totalfreedom.plex.player; package me.totalfreedom.plex.player;
import java.util.UUID;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.UUID;
@Getter @Getter
@Setter @Setter
public class PunishedPlayer public class PunishedPlayer
{ {
//everything in here will be stored in redis //everything in here will be stored in redis
@Setter(AccessLevel.NONE) @Setter(AccessLevel.NONE)
private String uuid; private String uuid;
private boolean muted; private boolean muted;
private boolean frozen; private boolean frozen;

View File

@ -1,23 +1,19 @@
package me.totalfreedom.plex.rank; package me.totalfreedom.plex.rank;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.util.List;
import lombok.Getter; import lombok.Getter;
import me.totalfreedom.plex.rank.enums.Rank; import me.totalfreedom.plex.rank.enums.Rank;
import java.util.List;
@Getter @Getter
public class DefaultRankObj public class DefaultRankObj
{ {
private final String name;
private String name; private final List<String> permissions;
private List<String> permissions;
public DefaultRankObj(Rank rank) public DefaultRankObj(Rank rank)
{ {
this.name = rank.name().toUpperCase(); this.name = rank.name().toUpperCase();
this.permissions = Lists.newArrayList(); this.permissions = Lists.newArrayList();
} }
} }

View File

@ -1,18 +1,18 @@
package me.totalfreedom.plex.rank; package me.totalfreedom.plex.rank;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.rank.enums.Rank; import me.totalfreedom.plex.rank.enums.Rank;
import me.totalfreedom.plex.util.PlexLog; import me.totalfreedom.plex.util.PlexLog;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.*;
import java.util.List;
public class RankManager public class RankManager
{ {
private final File defaultRanks;
private File defaultRanks;
public RankManager() public RankManager()
{ {
@ -24,8 +24,11 @@ public class RankManager
if (defaultRanks.exists()) if (defaultRanks.exists())
{ {
return; return;
} else { }
try { else
{
try
{
defaultRanks.createNewFile(); defaultRanks.createNewFile();
List<DefaultRankObj> ranks = Lists.newArrayList(); List<DefaultRankObj> ranks = Lists.newArrayList();
@ -45,11 +48,11 @@ public class RankManager
writer.close(); writer.close();
PlexLog.log("Generating default-ranks.json"); PlexLog.log("Generating default-ranks.json");
} }
}
} catch (IOException e) { catch (IOException e)
{
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
} }

View File

@ -4,28 +4,29 @@ import org.bukkit.ChatColor;
public enum Rank public enum Rank
{ {
IMPOSTER(-1, ChatColor.AQUA + "an " + ChatColor.YELLOW + "Imposter", ChatColor.YELLOW + "[Imp]"),
NONOP(0, ChatColor.WHITE + "a " + ChatColor.WHITE + "Non-Op", ChatColor.WHITE + ""),
OP(1, ChatColor.GREEN + "an " + ChatColor.GREEN + "Operator", ChatColor.GREEN + "[OP]"),
ADMIN(2, ChatColor.DARK_GREEN + "an " + ChatColor.DARK_GREEN + "Admin", ChatColor.DARK_GREEN + "[Admin]"),
SENIOR_ADMIN(3, ChatColor.GOLD + "a " + ChatColor.GOLD + "Senior Admin", ChatColor.GOLD + "[SrA]"),
EXECUTIVE(4, ChatColor.RED + "an " + ChatColor.RED + "Executive", ChatColor.RED + "[Exec]");
IMPOSTER(0, ChatColor.AQUA + "an " + ChatColor.YELLOW + "Imposter", ChatColor.YELLOW + "[IMP]"), private final String loginMessage;
ADMIN(1, ChatColor.AQUA + "an " + ChatColor.AQUA + "Admin", ChatColor.AQUA + "[ADMIN]"), private final String prefix;
SENIOR_ADMIN(2, ChatColor.AQUA + "a " + ChatColor.LIGHT_PURPLE + "Senior Admin", ChatColor.LIGHT_PURPLE + "[SrA]"),
EXECUTIVE(3, ChatColor.AQUA + "an " + ChatColor.RED + "Executive", ChatColor.RED + "[EXEC]");
private int level; Rank(int level, String loginMessage, String prefix)
private String loginMSG;
private String prefix;
Rank(int level, String loginMSG, String prefix)
{ {
this.level = level; this.loginMessage = loginMessage;
this.loginMSG = loginMSG;
this.prefix = prefix; this.prefix = prefix;
} }
public String getPrefix() { public String getPrefix()
{
return prefix; return prefix;
} }
public String getLoginMSG() { public String getLoginMSG()
return loginMSG; {
return loginMessage;
} }
} }

View File

@ -4,7 +4,6 @@ import org.bukkit.ChatColor;
public enum Title public enum Title
{ {
MASTER_BUILDER(0, ChatColor.AQUA + "a " + ChatColor.DARK_AQUA + "Master Builder", ChatColor.DARK_AQUA + "[MB]"), MASTER_BUILDER(0, ChatColor.AQUA + "a " + ChatColor.DARK_AQUA + "Master Builder", ChatColor.DARK_AQUA + "[MB]"),
DEV(1, ChatColor.AQUA + "a " + ChatColor.DARK_PURPLE + "Developer", ChatColor.DARK_PURPLE + "[DEV]"), DEV(1, ChatColor.AQUA + "a " + ChatColor.DARK_PURPLE + "Developer", ChatColor.DARK_PURPLE + "[DEV]"),
OWNER(2, ChatColor.AQUA + "an " + ChatColor.BLUE + "Owner", ChatColor.BLUE + "[Owner]"); OWNER(2, ChatColor.AQUA + "an " + ChatColor.BLUE + "Owner", ChatColor.BLUE + "[Owner]");
@ -19,5 +18,4 @@ public enum Title
this.loginMSG = loginMSG; this.loginMSG = loginMSG;
this.prefix = prefix; this.prefix = prefix;
} }
} }

View File

@ -2,43 +2,36 @@ package me.totalfreedom.plex.storage;
import com.mongodb.MongoClient; import com.mongodb.MongoClient;
import com.mongodb.MongoClientURI; import com.mongodb.MongoClientURI;
import dev.morphia.Datastore;
import dev.morphia.Morphia;
import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.player.PlexPlayer; import me.totalfreedom.plex.player.PlexPlayer;
import org.mongodb.morphia.Datastore;
import org.mongodb.morphia.Morphia;
public class MongoConnection public class MongoConnection
{ {
// USE MORPHIA API FOR MONGO <3 // USE MORPHIA API FOR MONGO <3
private Plex plugin = Plex.get(); private final Plex plugin = Plex.get();
public Datastore getDatastore() public Datastore getDatastore()
{ {
if (!plugin.getConfig().getString("data.central.storage").equalsIgnoreCase("mongodb")) if (!plugin.config().getString("data.central.storage").equalsIgnoreCase("mongodb"))
{ {
return null; return null;
} }
String host = plugin.getConfig().getString("data.central.hostname"); String host = plugin.config().getString("data.central.hostname");
int port = plugin.getConfig().getInt("data.central.port"); int port = plugin.config().getInt("data.central.port");
String username = plugin.getConfig().getString("data.central.user"); String username = plugin.config().getString("data.central.user");
String password = plugin.getConfig().getString("data.central.password"); String password = plugin.config().getString("data.central.password");
String database = plugin.getConfig().getString("data.central.db"); String database = plugin.config().getString("data.central.db");
String connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/?authSource=" + database; String connectionString = "mongodb://" + username + ":" + password + "@" + host + ":" + port + "/?authSource=" + database;
MongoClient client = new MongoClient(new MongoClientURI(connectionString)); MongoClient client = new MongoClient(new MongoClientURI(connectionString));
Morphia morphia = new Morphia(); Morphia morphia = new Morphia();
Datastore datastore = morphia.createDatastore(client, database); Datastore datastore = morphia.createDatastore(client, database);
datastore.getMapper().addMappedClass(PlexPlayer.class);
morphia.map(PlexPlayer.class);
datastore.ensureIndexes(); datastore.ensureIndexes();
plugin.setStorageType(StorageType.MONGO); plugin.setStorageType(StorageType.MONGO);
return datastore; return datastore;
} }
} }

View File

@ -7,7 +7,6 @@ import redis.clients.jedis.JedisPoolConfig;
public class RedisConnection public class RedisConnection
{ {
private JedisPool pool; private JedisPool pool;
private Jedis jedis; private Jedis jedis;

View File

@ -1,43 +1,44 @@
package me.totalfreedom.plex.storage; package me.totalfreedom.plex.storage;
import me.totalfreedom.plex.Plex;
import java.io.File; import java.io.File;
import java.sql.Connection; import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
import me.totalfreedom.plex.Plex;
public class SQLConnection public class SQLConnection
{ {
private Plex plugin = Plex.get(); private final Plex plugin = Plex.get();
private Connection connection; private Connection connection;
public Connection getCon() public Connection getCon()
{ {
String host = plugin.getConfig().getString("data.central.hostname"); String host = plugin.config.getString("data.central.hostname");
int port = plugin.getConfig().getInt("data.central.port"); int port = plugin.config.getInt("data.central.port");
String username = plugin.getConfig().getString("data.central.user"); String username = plugin.config.getString("data.central.user");
String password = plugin.getConfig().getString("data.central.password"); String password = plugin.config.getString("data.central.password");
String database = plugin.getConfig().getString("data.central.db"); String database = plugin.config.getString("data.central.db");
try { try
if (plugin.getConfig().getString("data.central.storage").equalsIgnoreCase("sqlite")) {
if (plugin.config.getString("data.central.storage").equalsIgnoreCase("sqlite"))
{ {
connection = DriverManager.getConnection("jdbc:sqlite:" + new File(plugin.getDataFolder(), "database.db").getAbsolutePath()); connection = DriverManager.getConnection("jdbc:sqlite:" + new File(plugin.getDataFolder(), "database.db").getAbsolutePath());
Plex.get().setStorageType(StorageType.SQLITE); Plex.get().setStorageType(StorageType.SQLITE);
} }
else if (plugin.getConfig().getString("data.central.storage").equalsIgnoreCase("mysql")) else if (plugin.config.getString("data.central.storage").equalsIgnoreCase("mysql"))
{ {
connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password); connection = DriverManager.getConnection("jdbc:mysql://" + host + ":" + port + "/" + database, username, password);
Plex.get().setStorageType(StorageType.SQL); Plex.get().setStorageType(StorageType.SQL);
} }
} catch (SQLException throwables) { }
catch (SQLException throwables)
{
throwables.printStackTrace(); throwables.printStackTrace();
} }
try { try
if (connection != null)
{ {
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `players` (\n" + connection.prepareStatement("CREATE TABLE IF NOT EXISTS `players` (\n" +
"\t`uuid` VARCHAR(46),\n" + "\t`uuid` VARCHAR(46),\n" +
@ -50,12 +51,10 @@ public class SQLConnection
"\tPRIMARY KEY (`uuid`)\n" + "\tPRIMARY KEY (`uuid`)\n" +
");").execute(); ");").execute();
} }
} catch (SQLException throwables) { catch (SQLException throwables)
{
throwables.printStackTrace(); throwables.printStackTrace();
} }
return connection; return connection;
} }
} }

View File

@ -4,7 +4,6 @@ import me.totalfreedom.plex.Plex;
public class PlexLog public class PlexLog
{ {
public static void log(String message) public static void log(String message)
{ {
Plex.get().getServer().getConsoleSender().sendMessage(String.format("§e[Plex] §7%s", message)); Plex.get().getServer().getConsoleSender().sendMessage(String.format("§e[Plex] §7%s", message));
@ -14,5 +13,4 @@ public class PlexLog
{ {
Plex.get().getServer().getConsoleSender().sendMessage(String.format("§c[Plex Error] §6%s", message)); Plex.get().getServer().getConsoleSender().sendMessage(String.format("§c[Plex Error] §6%s", message));
} }
} }

View File

@ -1,13 +1,11 @@
package me.totalfreedom.plex.util; package me.totalfreedom.plex.util;
import java.sql.SQLException;
import me.totalfreedom.plex.Plex; import me.totalfreedom.plex.Plex;
import me.totalfreedom.plex.storage.StorageType; import me.totalfreedom.plex.storage.StorageType;
import java.sql.SQLException;
public class PlexUtils public class PlexUtils
{ {
public static void testConnections() public static void testConnections()
{ {
if (Plex.get().getSqlConnection().getCon() != null) if (Plex.get().getSqlConnection().getCon() != null)
@ -15,15 +13,20 @@ public class PlexUtils
if (Plex.get().getStorageType() == StorageType.SQL) if (Plex.get().getStorageType() == StorageType.SQL)
{ {
PlexLog.log("Successfully enabled MySQL!"); PlexLog.log("Successfully enabled MySQL!");
} else if (Plex.get().getStorageType() == StorageType.SQLITE) }
else if (Plex.get().getStorageType() == StorageType.SQLITE)
{ {
PlexLog.log("Successfully enabled SQLite!"); PlexLog.log("Successfully enabled SQLite!");
} }
try { try
{
Plex.get().getSqlConnection().getCon().close(); Plex.get().getSqlConnection().getCon().close();
} catch (SQLException throwables) {
} }
} else if (Plex.get().getMongoConnection().getDatastore() != null) catch (SQLException ignored)
{
}
}
else if (Plex.get().getMongoConnection().getDatastore() != null)
{ {
PlexLog.log("Successfully enabled MongoDB!"); PlexLog.log("Successfully enabled MongoDB!");
} }