2021-01-03 07:21:15 +00:00
|
|
|
package dev.plex;
|
2020-10-26 03:55:49 +00:00
|
|
|
|
2021-01-03 07:21:15 +00:00
|
|
|
import dev.plex.admin.AdminList;
|
|
|
|
import dev.plex.banning.BanManager;
|
|
|
|
import dev.plex.cache.MongoPlayerData;
|
|
|
|
import dev.plex.cache.SQLPlayerData;
|
|
|
|
import dev.plex.config.Config;
|
|
|
|
import dev.plex.handlers.CommandHandler;
|
|
|
|
import dev.plex.handlers.ListenerHandler;
|
|
|
|
import dev.plex.punishment.PunishmentManager;
|
|
|
|
import dev.plex.rank.RankManager;
|
|
|
|
import dev.plex.services.ServiceManager;
|
|
|
|
import dev.plex.storage.MongoConnection;
|
|
|
|
import dev.plex.storage.RedisConnection;
|
|
|
|
import dev.plex.storage.SQLConnection;
|
|
|
|
import dev.plex.storage.StorageType;
|
|
|
|
import dev.plex.util.PlexLog;
|
|
|
|
import dev.plex.util.PlexUtils;
|
|
|
|
import dev.plex.world.CustomWorld;
|
2022-01-04 03:04:39 +00:00
|
|
|
import lombok.Getter;
|
|
|
|
import lombok.Setter;
|
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-29 02:35:14 +00:00
|
|
|
private static Plex plugin;
|
2020-10-31 15:09:13 +00:00
|
|
|
public Config config;
|
2020-11-02 00:06:08 +00:00
|
|
|
public Config messages;
|
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-11-10 02:47:03 +00:00
|
|
|
private ServiceManager serviceManager;
|
2020-10-31 04:51:22 +00:00
|
|
|
|
2020-11-06 18:51:47 +00:00
|
|
|
private PunishmentManager punishmentManager;
|
2020-11-10 02:47:03 +00:00
|
|
|
private BanManager banManager;
|
2020-11-06 18:51:47 +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()
|
|
|
|
{
|
2020-10-27 18:14:34 +00:00
|
|
|
plugin = this;
|
2020-10-31 15:09:13 +00:00
|
|
|
config = new Config(this, "config.yml");
|
2020-11-02 00:06:08 +00:00
|
|
|
messages = new Config(this, "messages.yml");
|
2020-10-27 18:14:34 +00:00
|
|
|
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-28 03:49:56 +00:00
|
|
|
config.load();
|
2020-11-02 00:06:08 +00:00
|
|
|
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
|
|
|
|
2021-01-03 07:21:15 +00:00
|
|
|
if (storageType == StorageType.MONGODB)
|
2020-10-27 20:12:38 +00:00
|
|
|
{
|
|
|
|
mongoPlayerData = new MongoPlayerData();
|
2020-10-28 03:49:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-10-27 21:04:05 +00:00
|
|
|
sqlPlayerData = new SQLPlayerData();
|
2020-10-27 20:12:38 +00:00
|
|
|
}
|
|
|
|
|
2020-10-31 08:55:27 +00:00
|
|
|
new ListenerHandler(); // this doesn't need a variable.
|
|
|
|
new CommandHandler();
|
2020-10-27 21:56:05 +00:00
|
|
|
|
|
|
|
rankManager = new RankManager();
|
|
|
|
rankManager.generateDefaultRanks();
|
2020-10-28 19:07:02 +00:00
|
|
|
rankManager.importDefaultRanks();
|
2020-10-28 19:14:44 +00:00
|
|
|
PlexLog.log("Rank Manager initialized");
|
2020-10-29 02:10:47 +00:00
|
|
|
|
2020-11-06 18:51:47 +00:00
|
|
|
punishmentManager = new PunishmentManager();
|
2020-11-10 02:47:03 +00:00
|
|
|
banManager = new BanManager();
|
|
|
|
PlexLog.log("Punishment System initialized");
|
|
|
|
|
|
|
|
serviceManager = new ServiceManager();
|
|
|
|
PlexLog.log("Service Manager initialized");
|
|
|
|
|
|
|
|
serviceManager.startServices();
|
|
|
|
PlexLog.log("Started " + serviceManager.serviceCount() + " services.");
|
2020-11-06 18:51:47 +00:00
|
|
|
|
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()
|
|
|
|
{
|
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-31 04:51:22 +00:00
|
|
|
|
|
|
|
private void generateWorlds()
|
|
|
|
{
|
|
|
|
PlexLog.log("Generating any worlds if needed...");
|
2020-10-31 15:09:13 +00:00
|
|
|
for (String key : config.getConfigurationSection("worlds").getKeys(false))
|
2020-11-06 01:29:38 +00:00
|
|
|
{
|
2020-10-31 15:09:13 +00:00
|
|
|
CustomWorld.generateConfigFlatWorld(key);
|
2020-11-06 01:29:38 +00:00
|
|
|
}
|
2020-10-31 04:51:22 +00:00
|
|
|
PlexLog.log("Finished with world generation!");
|
|
|
|
}
|
2020-10-26 03:55:49 +00:00
|
|
|
}
|