2020-10-26 03:55:49 +00:00
|
|
|
package me.totalfreedom.plex;
|
|
|
|
|
2020-10-27 18:14:34 +00:00
|
|
|
import lombok.AccessLevel;
|
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Setter;
|
2020-10-27 20:12:38 +00:00
|
|
|
import me.totalfreedom.plex.cache.MongoPlayerData;
|
2020-10-27 21:04:05 +00:00
|
|
|
import me.totalfreedom.plex.cache.SQLPlayerData;
|
2020-10-27 20:12:38 +00:00
|
|
|
import me.totalfreedom.plex.listeners.PlayerListener;
|
2020-10-27 21:56:05 +00:00
|
|
|
import me.totalfreedom.plex.rank.RankManager;
|
2020-10-27 18:14:34 +00:00
|
|
|
import me.totalfreedom.plex.storage.MongoConnection;
|
2020-10-27 21:21:57 +00:00
|
|
|
import me.totalfreedom.plex.storage.RedisConnection;
|
2020-10-27 18:14:34 +00:00
|
|
|
import me.totalfreedom.plex.storage.SQLConnection;
|
|
|
|
import me.totalfreedom.plex.storage.StorageType;
|
|
|
|
import me.totalfreedom.plex.util.PlexLog;
|
|
|
|
import me.totalfreedom.plex.util.PlexUtils;
|
2020-10-26 03:55:49 +00:00
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
|
2020-10-27 18:14:34 +00:00
|
|
|
@Getter
|
|
|
|
@Setter
|
2020-10-26 03:55:49 +00:00
|
|
|
public class Plex extends JavaPlugin
|
|
|
|
{
|
2020-10-27 18:14:34 +00:00
|
|
|
@Setter(AccessLevel.NONE)
|
|
|
|
private static Plex plugin;
|
|
|
|
|
2020-10-27 20:12:38 +00:00
|
|
|
private StorageType storageType = StorageType.SQLITE;
|
2020-10-27 18:14:34 +00:00
|
|
|
|
|
|
|
private SQLConnection sqlConnection;
|
|
|
|
private MongoConnection mongoConnection;
|
2020-10-27 21:21:57 +00:00
|
|
|
private RedisConnection redisConnection;
|
2020-10-27 18:14:34 +00:00
|
|
|
|
2020-10-27 20:12:38 +00:00
|
|
|
private MongoPlayerData mongoPlayerData;
|
2020-10-27 21:04:05 +00:00
|
|
|
private SQLPlayerData sqlPlayerData;
|
2020-10-27 20:12:38 +00:00
|
|
|
|
2020-10-27 21:56:05 +00:00
|
|
|
private RankManager rankManager;
|
|
|
|
|
2020-10-26 03:55:49 +00:00
|
|
|
@Override
|
|
|
|
public void onLoad()
|
|
|
|
{
|
2020-10-27 18:14:34 +00:00
|
|
|
plugin = this;
|
|
|
|
|
|
|
|
getConfig().options().copyDefaults(true);
|
|
|
|
saveConfig();
|
|
|
|
|
|
|
|
saveResource("database.db", false);
|
|
|
|
|
|
|
|
sqlConnection = new SQLConnection();
|
|
|
|
mongoConnection = new MongoConnection();
|
2020-10-27 21:21:57 +00:00
|
|
|
redisConnection = new RedisConnection();
|
2020-10-27 21:56:05 +00:00
|
|
|
/*try {
|
2020-10-27 21:21:57 +00:00
|
|
|
redisConnection.openPool();
|
|
|
|
PlexLog.log("Successfully opened redis pool. Closing.");
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2020-10-27 21:56:05 +00:00
|
|
|
redisConnection.getJedis().close();*/
|
2020-10-26 03:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onEnable()
|
|
|
|
{
|
2020-10-27 18:14:34 +00:00
|
|
|
PlexUtils.testConnections();
|
2020-10-27 20:12:38 +00:00
|
|
|
|
|
|
|
if (storageType == StorageType.MONGO)
|
|
|
|
{
|
|
|
|
mongoPlayerData = new MongoPlayerData();
|
2020-10-27 21:04:05 +00:00
|
|
|
} else {
|
|
|
|
sqlPlayerData = new SQLPlayerData();
|
2020-10-27 20:12:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
2020-10-27 21:56:05 +00:00
|
|
|
|
|
|
|
rankManager = new RankManager();
|
|
|
|
rankManager.generateDefaultRanks();
|
|
|
|
|
2020-10-26 03:55:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDisable()
|
|
|
|
{
|
2020-10-27 21:56:05 +00:00
|
|
|
/*if (redisConnection.getJedis().isConnected())
|
2020-10-27 21:21:57 +00:00
|
|
|
{
|
|
|
|
PlexLog.log("Disabling Redis/Jedis. No memory leaks in this Anarchy server !");
|
|
|
|
redisConnection.getJedis().close();
|
2020-10-27 21:56:05 +00:00
|
|
|
}*/
|
2020-10-26 03:55:49 +00:00
|
|
|
}
|
2020-10-27 18:14:34 +00:00
|
|
|
|
|
|
|
public static Plex get() {
|
|
|
|
return plugin;
|
|
|
|
}
|
2020-10-26 03:55:49 +00:00
|
|
|
}
|