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

84 lines
2.2 KiB
Java
Raw Normal View History

2020-10-26 03:55:49 +00:00
package me.totalfreedom.plex;
import lombok.AccessLevel;
import lombok.Getter;
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.storage.MongoConnection;
import me.totalfreedom.plex.storage.RedisConnection;
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;
@Getter
@Setter
2020-10-26 03:55:49 +00:00
public class Plex extends JavaPlugin
{
@Setter(AccessLevel.NONE)
private static Plex plugin;
private StorageType storageType = StorageType.SQLITE;
private SQLConnection sqlConnection;
private MongoConnection mongoConnection;
private RedisConnection redisConnection;
private MongoPlayerData mongoPlayerData;
private SQLPlayerData sqlPlayerData;
2020-10-26 03:55:49 +00:00
@Override
public void onLoad()
{
plugin = this;
getConfig().options().copyDefaults(true);
saveConfig();
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()
{
PlexUtils.testConnections();
if (storageType == StorageType.MONGO)
{
mongoPlayerData = new MongoPlayerData();
} else {
sqlPlayerData = new SQLPlayerData();
}
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
PlexLog.log(storageType.name());
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
}
public static Plex get() {
return plugin;
}
2020-10-26 03:55:49 +00:00
}