mirror of
https://github.com/plexusorg/Plex.git
synced 2024-11-14 15:53:33 +00:00
110 lines
3.0 KiB
Java
110 lines
3.0 KiB
Java
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.config.MainConfig;
|
|
import me.totalfreedom.plex.listeners.ChatListener;
|
|
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;
|
|
import me.totalfreedom.plex.storage.StorageType;
|
|
import me.totalfreedom.plex.util.PlexLog;
|
|
import me.totalfreedom.plex.util.PlexUtils;
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
@Getter
|
|
@Setter
|
|
public class Plex extends JavaPlugin
|
|
{
|
|
@Setter(AccessLevel.NONE)
|
|
private static Plex plugin;
|
|
|
|
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;
|
|
|
|
public static Plex get()
|
|
{
|
|
return plugin;
|
|
}
|
|
|
|
@Override
|
|
public void onLoad()
|
|
{
|
|
plugin = this;
|
|
|
|
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();*/
|
|
}
|
|
|
|
@Override
|
|
public void onEnable()
|
|
{
|
|
config.load();
|
|
|
|
try
|
|
{
|
|
PlexUtils.testConnections();
|
|
PlexLog.log("Connected to " + storageType.name().toUpperCase());
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
PlexLog.error("Failed to connect to " + storageType.name().toUpperCase());
|
|
e.printStackTrace();
|
|
}
|
|
|
|
if (storageType == StorageType.MONGO)
|
|
{
|
|
mongoPlayerData = new MongoPlayerData();
|
|
}
|
|
else
|
|
{
|
|
sqlPlayerData = new SQLPlayerData();
|
|
}
|
|
|
|
getServer().getPluginManager().registerEvents(new PlayerListener(), this);
|
|
getServer().getPluginManager().registerEvents(new ChatListener(), this);
|
|
|
|
rankManager = new RankManager();
|
|
rankManager.generateDefaultRanks();
|
|
rankManager.importDefaultRanks();
|
|
PlexLog.log("Rank Manager initialized");
|
|
}
|
|
|
|
@Override
|
|
public void onDisable()
|
|
{
|
|
config.save();
|
|
/*if (redisConnection.getJedis().isConnected())
|
|
{
|
|
PlexLog.log("Disabling Redis/Jedis. No memory leaks in this Anarchy server !");
|
|
redisConnection.getJedis().close();
|
|
}*/
|
|
}
|
|
} |