Plex/src/main/java/me/totalfreedom/plex/Plex.java

107 lines
3.0 KiB
Java
Raw Normal View History

2020-10-26 03:55:49 +00:00
package me.totalfreedom.plex;
import lombok.Getter;
import lombok.Setter;
import me.totalfreedom.plex.cache.MongoPlayerData;
import me.totalfreedom.plex.cache.SQLPlayerData;
import me.totalfreedom.plex.command.PlexCommand;
2020-10-28 03:49:56 +00:00
import me.totalfreedom.plex.config.MainConfig;
import me.totalfreedom.plex.listener.ChatListener;
import me.totalfreedom.plex.listener.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;
import me.totalfreedom.plex.storage.StorageType;
2020-10-28 19:14:44 +00:00
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;
@Getter
@Setter
2020-10-26 03:55:49 +00:00
public class Plex extends JavaPlugin
{
public static Plex plugin;
2020-10-28 03:49:56 +00:00
public MainConfig config;
private StorageType storageType = StorageType.SQLITE;
private SQLConnection sqlConnection;
private MongoConnection mongoConnection;
private RedisConnection redisConnection;
private MongoPlayerData mongoPlayerData;
private SQLPlayerData sqlPlayerData;
private RankManager rankManager;
2020-10-28 03:49:56 +00:00
public static Plex get()
{
return plugin;
}
2020-10-26 03:55:49 +00:00
@Override
public void onLoad()
{
plugin = this;
2020-10-29 00:54:23 +00:00
config = new MainConfig(this);
saveResource("database.db", false);
sqlConnection = new SQLConnection();
mongoConnection = new MongoConnection();
redisConnection = new RedisConnection();
/*try {
redisConnection.openPool();
PlexLog.log("Successfully opened redis pool. Closing.");
} catch (Exception e) {
e.printStackTrace();
}
redisConnection.getJedis().close();*/
2020-10-26 03:55:49 +00:00
}
@Override
public void onEnable()
{
2020-10-28 03:49:56 +00:00
config.load();
2020-10-28 19:14:44 +00:00
2020-10-29 00:54:23 +00:00
try
{
2020-10-28 19:14:44 +00:00
PlexUtils.testConnections();
PlexLog.log("Connected to " + storageType.name().toUpperCase());
2020-10-29 00:54:23 +00:00
}
catch (Exception e)
2020-10-28 19:14:44 +00:00
{
PlexLog.error("Failed to connect to " + storageType.name().toUpperCase());
e.printStackTrace();
}
2020-10-28 03:49:56 +00:00
if (storageType == StorageType.MONGO)
{
mongoPlayerData = new MongoPlayerData();
2020-10-28 03:49:56 +00:00
}
else
{
sqlPlayerData = new SQLPlayerData();
}
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
getServer().getPluginManager().registerEvents(new ChatListener(), this);
rankManager = new RankManager();
rankManager.generateDefaultRanks();
rankManager.importDefaultRanks();
2020-10-28 19:14:44 +00:00
PlexLog.log("Rank Manager initialized");
getCommand("plex").setExecutor(new PlexCommand());
2020-10-26 03:55:49 +00:00
}
@Override
public void onDisable()
{
/*if (redisConnection.getJedis().isConnected())
{
PlexLog.log("Disabling Redis/Jedis. No memory leaks in this Anarchy server !");
redisConnection.getJedis().close();
}*/
2020-10-26 03:55:49 +00:00
}
}