UltimateModeration/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java

223 lines
8.7 KiB
Java
Raw Normal View History

2019-02-27 02:50:18 +01:00
package com.songoda.ultimatemoderation;
2019-10-19 19:29:46 +02:00
import com.songoda.core.SongodaCore;
import com.songoda.core.SongodaPlugin;
import com.songoda.core.commands.CommandManager;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.core.configuration.Config;
2020-08-05 00:20:25 +02:00
import com.songoda.core.database.DataMigrationManager;
import com.songoda.core.database.DatabaseConnector;
import com.songoda.core.database.MySQLConnector;
import com.songoda.core.database.SQLiteConnector;
2019-10-19 19:29:46 +02:00
import com.songoda.core.gui.GuiManager;
import com.songoda.ultimatemoderation.commands.*;
2020-08-05 00:20:25 +02:00
import com.songoda.ultimatemoderation.database.DataManager;
import com.songoda.ultimatemoderation.database.migrations._1_InitialMigration;
2019-02-27 22:45:39 +01:00
import com.songoda.ultimatemoderation.listeners.*;
2020-08-05 00:20:25 +02:00
import com.songoda.ultimatemoderation.moderate.ModerationManager;
2019-03-05 06:06:02 +01:00
import com.songoda.ultimatemoderation.punish.AppliedPunishment;
import com.songoda.ultimatemoderation.punish.PunishmentNote;
2019-03-03 22:33:44 +01:00
import com.songoda.ultimatemoderation.punish.player.PunishmentManager;
2019-03-05 06:06:02 +01:00
import com.songoda.ultimatemoderation.punish.template.Template;
2019-03-03 22:33:44 +01:00
import com.songoda.ultimatemoderation.punish.template.TemplateManager;
2019-10-19 19:29:46 +02:00
import com.songoda.ultimatemoderation.settings.Settings;
2019-03-08 17:24:47 +01:00
import com.songoda.ultimatemoderation.staffchat.StaffChatManager;
2019-04-04 22:29:37 +02:00
import com.songoda.ultimatemoderation.tasks.SlowModeTask;
2019-03-07 05:31:30 +01:00
import com.songoda.ultimatemoderation.tickets.Ticket;
import com.songoda.ultimatemoderation.tickets.TicketManager;
2019-02-27 02:50:18 +01:00
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
2019-02-27 02:50:18 +01:00
2019-10-19 19:29:46 +02:00
import java.util.List;
2019-03-05 06:06:02 +01:00
2019-10-19 19:29:46 +02:00
public class UltimateModeration extends SongodaPlugin {
2019-02-27 02:50:18 +01:00
private static UltimateModeration INSTANCE;
2019-03-03 22:33:44 +01:00
2019-10-19 19:29:46 +02:00
private final GuiManager guiManager = new GuiManager(this);
2019-03-07 05:31:30 +01:00
private TicketManager ticketManager;
2019-03-03 22:33:44 +01:00
private TemplateManager templateManager;
2019-02-27 02:50:18 +01:00
private CommandManager commandManager;
2019-03-03 22:33:44 +01:00
private PunishmentManager punishmentManager;
2019-03-08 17:24:47 +01:00
private StaffChatManager staffChatManager;
2020-08-05 00:20:25 +02:00
private ModerationManager moderationManager;
2019-03-03 22:33:44 +01:00
2020-08-05 00:20:25 +02:00
private DatabaseConnector databaseConnector;
private DataManager dataManager;
2019-02-27 02:50:18 +01:00
public static UltimateModeration getInstance() {
return INSTANCE;
}
@Override
2019-10-19 19:29:46 +02:00
public void onPluginLoad() {
2019-02-27 02:50:18 +01:00
INSTANCE = this;
2019-10-19 19:29:46 +02:00
}
2019-02-27 02:50:18 +01:00
2019-10-19 19:29:46 +02:00
@Override
public void onPluginDisable() {
}
2019-02-27 02:50:18 +01:00
2019-10-19 19:29:46 +02:00
@Override
public void onPluginEnable() {
// Run Songoda Updater
SongodaCore.registerPlugin(this, 29, CompatibleMaterial.DIAMOND_CHESTPLATE);
2019-02-27 02:50:18 +01:00
2019-10-19 19:29:46 +02:00
// Setup Config
Settings.setupConfig();
this.setLocale(Settings.LANGUGE_MODE.getString(), false);
2019-02-27 02:50:18 +01:00
2019-10-19 19:29:46 +02:00
// Register commands
this.commandManager = new CommandManager(this);
this.commandManager.addCommand(new CommandUltimateModeration(this))
.addSubCommands(
new CommandReload(this),
new CommandSettings(this, guiManager),
new CommandHelp(this)
);
this.commandManager.addCommand(new CommandBan(this));
this.commandManager.addCommand(new CommandClearChat(this));
this.commandManager.addCommand(new CommandKick(this));
this.commandManager.addCommand(new CommandMute(this));
this.commandManager.addCommand(new CommandRandomPlayer(this));
this.commandManager.addCommand(new CommandRunTemplate(this));
this.commandManager.addCommand(new CommandSlowMode(this));
this.commandManager.addCommand(new CommandStaffChat(this));
this.commandManager.addCommand(new CommandTicket(this, guiManager));
2019-10-19 19:29:46 +02:00
this.commandManager.addCommand(new CommandToggleChat(this));
this.commandManager.addCommand(new CommandUnBan(this));
this.commandManager.addCommand(new CommandUnMute(this));
2020-09-08 22:51:25 +02:00
this.commandManager.addCommand(new CommandVanish());
2019-10-19 19:29:46 +02:00
this.commandManager.addCommand(new CommandWarn(this));
2019-04-26 09:38:16 +02:00
2019-03-05 06:06:02 +01:00
// Setup Managers
2019-03-07 05:31:30 +01:00
this.ticketManager = new TicketManager();
2019-03-03 22:33:44 +01:00
this.templateManager = new TemplateManager();
this.punishmentManager = new PunishmentManager();
2019-03-08 17:24:47 +01:00
this.staffChatManager = new StaffChatManager();
2020-08-05 00:20:25 +02:00
this.moderationManager = new ModerationManager(this);
2020-08-13 20:19:15 +02:00
2020-08-05 00:20:25 +02:00
try {
if (Settings.MYSQL_ENABLED.getBoolean()) {
String hostname = Settings.MYSQL_HOSTNAME.getString();
int port = Settings.MYSQL_PORT.getInt();
String database = Settings.MYSQL_DATABASE.getString();
String username = Settings.MYSQL_USERNAME.getString();
String password = Settings.MYSQL_PASSWORD.getString();
boolean useSSL = Settings.MYSQL_USE_SSL.getBoolean();
2022-08-14 11:53:38 +02:00
int poolSize = Settings.MYSQL_POOL_SIZE.getInt();
2020-08-05 00:20:25 +02:00
2022-08-14 11:53:38 +02:00
this.databaseConnector = new MySQLConnector(this, hostname, port, database, username, password, useSSL, poolSize);
2020-08-05 00:20:25 +02:00
this.getLogger().info("Data handler connected using MySQL.");
} else {
this.databaseConnector = new SQLiteConnector(this);
this.getLogger().info("Data handler connected using SQLite.");
}
2020-08-13 20:19:15 +02:00
this.dataManager = new DataManager(this.databaseConnector, this);
DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager,
2020-08-13 20:19:15 +02:00
new _1_InitialMigration());
dataMigrationManager.runMigrations();
2020-08-13 20:19:15 +02:00
2020-08-05 00:20:25 +02:00
} catch (Exception ex) {
2020-08-13 20:19:15 +02:00
this.getLogger().severe("Fatal error trying to connect to database. " +
"Please make sure all your connection settings are correct and try again. Plugin has been disabled.");
emergencyStop();
return;
2020-08-05 00:20:25 +02:00
}
2019-03-03 22:33:44 +01:00
2019-02-27 04:08:19 +01:00
// Register Listeners
2019-10-19 19:29:46 +02:00
guiManager.init();
PluginManager pluginManager = Bukkit.getPluginManager();
pluginManager.registerEvents(new CommandListener(this), this);
pluginManager.registerEvents(new DeathListener(this), this);
pluginManager.registerEvents(new MoveListener(this), this);
pluginManager.registerEvents(new DropListener(this), this);
pluginManager.registerEvents(new InventoryListener(this), this);
pluginManager.registerEvents(new ChatListener(this), this);
pluginManager.registerEvents(new LoginListener(this), this);
pluginManager.registerEvents(new MobTargetLister(), this);
pluginManager.registerEvents(new BlockListener(this), this);
if (pluginManager.isPluginEnabled("FabledSkyBlock"))
pluginManager.registerEvents(new SkyBlockListener(this), this);
2019-10-13 18:49:11 +02:00
2019-10-19 19:29:46 +02:00
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13))
pluginManager.registerEvents(new SpyingDismountListener(), this);
2019-02-27 02:50:18 +01:00
2019-04-04 22:29:37 +02:00
// Start tasks
SlowModeTask.startTask(this);
2019-03-05 06:06:02 +01:00
}
2020-09-08 22:31:23 +02:00
@Override
public void onDataLoad() {
2022-08-14 11:53:38 +02:00
getDataManager().runAsync(() -> {
2020-09-08 22:31:23 +02:00
// Load data from DB
this.dataManager.getTemplates((templates) -> {
for (Template template : templates) {
this.templateManager.addTemplate(template);
}
});
this.dataManager.getAppliedPunishments((appliedPunishments) -> {
for (AppliedPunishment punishment : appliedPunishments)
this.punishmentManager.getPlayer(punishment.getVictim()).addPunishment(punishment);
});
this.dataManager.getNotes((notes) -> {
for (PunishmentNote note : notes)
this.punishmentManager.getPlayer(note.getSubject()).addNotes(note);
});
this.dataManager.getTickets((tickets) -> {
for (Ticket ticket : tickets.values())
this.ticketManager.addTicket(ticket);
});
2022-08-14 11:53:38 +02:00
});
2020-09-08 22:31:23 +02:00
}
2019-10-19 19:29:46 +02:00
@Override
public void onConfigReload() {
this.setLocale(getConfig().getString("System.Language Mode"), true);
this.locale.reloadMessages();
2019-04-05 21:24:05 +02:00
}
2019-10-19 19:29:46 +02:00
@Override
public List<Config> getExtraConfig() {
return null;
2019-02-27 02:50:18 +01:00
}
public CommandManager getCommandManager() {
return commandManager;
}
2019-03-03 22:33:44 +01:00
public TemplateManager getTemplateManager() {
return templateManager;
}
2019-02-27 02:50:18 +01:00
2019-03-03 22:33:44 +01:00
public PunishmentManager getPunishmentManager() {
return punishmentManager;
}
2019-03-07 05:31:30 +01:00
public TicketManager getTicketManager() {
return ticketManager;
}
2019-03-08 17:24:47 +01:00
public StaffChatManager getStaffChatManager() {
return staffChatManager;
}
2020-06-04 18:20:35 +02:00
2020-08-05 00:20:25 +02:00
public DataManager getDataManager() {
return dataManager;
}
public DatabaseConnector getDatabaseConnector() {
return databaseConnector;
}
2020-06-04 18:20:35 +02:00
public GuiManager getGuiManager() {
return guiManager;
}
2020-08-05 00:20:25 +02:00
public ModerationManager getModerationManager() {
return moderationManager;
}
2019-02-27 02:50:18 +01:00
}