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

124 lines
3.4 KiB
Java
Raw Normal View History

2020-10-26 03:55:49 +00:00
package me.totalfreedom.plex;
import lombok.Getter;
import lombok.Setter;
2020-11-05 21:17:14 +00:00
import me.totalfreedom.plex.admin.AdminList;
import me.totalfreedom.plex.cache.MongoPlayerData;
import me.totalfreedom.plex.cache.SQLPlayerData;
import me.totalfreedom.plex.config.Config;
import me.totalfreedom.plex.handlers.CommandHandler;
import me.totalfreedom.plex.handlers.ListenerHandler;
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;
import me.totalfreedom.plex.world.CustomWorld;
2020-10-26 03:55:49 +00:00
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
@Getter
@Setter
2020-10-26 03:55:49 +00:00
public class Plex extends JavaPlugin
{
2020-10-29 02:35:14 +00:00
private static Plex plugin;
public Config config;
public Config messages;
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-31 04:51:22 +00:00
2020-11-05 21:17:14 +00:00
private AdminList adminList;
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;
config = new Config(this, "config.yml");
messages = new Config(this, "messages.yml");
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();
messages.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();
}
new ListenerHandler(); // this doesn't need a variable.
new CommandHandler();
rankManager = new RankManager();
rankManager.generateDefaultRanks();
rankManager.importDefaultRanks();
2020-10-28 19:14:44 +00:00
PlexLog.log("Rank Manager initialized");
2020-11-05 21:17:14 +00:00
adminList = new AdminList();
2020-10-31 04:51:22 +00:00
generateWorlds();
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
}
2020-10-31 04:51:22 +00:00
private void generateWorlds()
{
PlexLog.log("Generating any worlds if needed...");
for (String key : config.getConfigurationSection("worlds").getKeys(false))
CustomWorld.generateConfigFlatWorld(key);
2020-10-31 04:51:22 +00:00
PlexLog.log("Finished with world generation!");
}
2020-10-26 03:55:49 +00:00
}