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

229 lines
9.3 KiB
Java
Raw Normal View History

2023-08-02 18:57:10 +02:00
package com.craftaro.ultimatemoderation;
2019-02-27 02:50:18 +01:00
import com.craftaro.core.SongodaCore;
import com.craftaro.core.SongodaPlugin;
import com.craftaro.core.commands.CommandManager;
import com.craftaro.core.compatibility.ServerVersion;
import com.craftaro.core.configuration.Config;
import com.craftaro.core.gui.GuiManager;
import com.craftaro.core.third_party.com.cryptomorin.xseries.XMaterial;
2023-08-02 18:57:10 +02:00
import com.craftaro.ultimatemoderation.commands.CommandBan;
import com.craftaro.ultimatemoderation.commands.CommandClearChat;
import com.craftaro.ultimatemoderation.commands.CommandHelp;
import com.craftaro.ultimatemoderation.commands.CommandKick;
import com.craftaro.ultimatemoderation.commands.CommandMute;
import com.craftaro.ultimatemoderation.commands.CommandRandomPlayer;
import com.craftaro.ultimatemoderation.commands.CommandReload;
import com.craftaro.ultimatemoderation.commands.CommandRunTemplate;
import com.craftaro.ultimatemoderation.commands.CommandSettings;
import com.craftaro.ultimatemoderation.commands.CommandSlowMode;
import com.craftaro.ultimatemoderation.commands.CommandStaffChat;
import com.craftaro.ultimatemoderation.commands.CommandTicket;
import com.craftaro.ultimatemoderation.commands.CommandToggleChat;
import com.craftaro.ultimatemoderation.commands.CommandUltimateModeration;
import com.craftaro.ultimatemoderation.commands.CommandUnBan;
import com.craftaro.ultimatemoderation.commands.CommandUnMute;
import com.craftaro.ultimatemoderation.commands.CommandVanish;
import com.craftaro.ultimatemoderation.commands.CommandWarn;
import com.craftaro.ultimatemoderation.database.DataHelper;
import com.craftaro.ultimatemoderation.database.migrations._1_InitialMigration;
import com.craftaro.ultimatemoderation.listeners.BlockListener;
import com.craftaro.ultimatemoderation.listeners.ChatListener;
import com.craftaro.ultimatemoderation.listeners.CommandListener;
import com.craftaro.ultimatemoderation.listeners.DeathListener;
import com.craftaro.ultimatemoderation.listeners.DropListener;
import com.craftaro.ultimatemoderation.listeners.InventoryListener;
import com.craftaro.ultimatemoderation.listeners.LoginListener;
import com.craftaro.ultimatemoderation.listeners.MobTargetLister;
import com.craftaro.ultimatemoderation.listeners.MoveListener;
import com.craftaro.ultimatemoderation.listeners.SkyBlockListener;
import com.craftaro.ultimatemoderation.listeners.SpyingDismountListener;
import com.craftaro.ultimatemoderation.moderate.ModerationManager;
import com.craftaro.ultimatemoderation.punish.AppliedPunishment;
import com.craftaro.ultimatemoderation.punish.PunishmentNote;
import com.craftaro.ultimatemoderation.punish.player.PunishmentManager;
import com.craftaro.ultimatemoderation.punish.template.Template;
import com.craftaro.ultimatemoderation.punish.template.TemplateManager;
2023-08-15 23:24:07 +02:00
import com.craftaro.ultimatemoderation.settings.Settings;
2023-08-02 18:57:10 +02:00
import com.craftaro.ultimatemoderation.staffchat.StaffChatManager;
import com.craftaro.ultimatemoderation.tasks.SlowModeTask;
import com.craftaro.ultimatemoderation.tickets.Ticket;
import com.craftaro.ultimatemoderation.tickets.TicketManager;
2019-02-27 02:50:18 +01:00
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
2019-02-27 02:50:18 +01:00
2023-08-02 18:57:10 +02:00
import java.util.Arrays;
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 {
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;
2023-08-02 18:57:10 +02:00
private DataHelper dataHelper;
2019-02-27 02:50:18 +01:00
/**
* @deprecated Use {@link JavaPlugin#getPlugin(Class)} instead.
*/
@Deprecated
2019-02-27 02:50:18 +01:00
public static UltimateModeration getInstance() {
return getPlugin(UltimateModeration.class);
2019-02-27 02:50:18 +01:00
}
@Override
2019-10-19 19:29:46 +02:00
public void onPluginLoad() {
}
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, XMaterial.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, this.guiManager),
2019-10-19 19:29:46 +02:00
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, 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);
try {
2023-08-15 23:24:07 +02:00
initDatabase(Arrays.asList(new _1_InitialMigration()));
2023-08-02 18:58:48 +02:00
this.dataHelper = new DataHelper(getDataManager(), this);
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
this.guiManager.init();
PluginManager pluginManager = Bukkit.getPluginManager();
pluginManager.registerEvents(new CommandListener(this), this);
pluginManager.registerEvents(new DeathListener(), 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);
}
2019-10-13 18:49:11 +02:00
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
pluginManager.registerEvents(new SpyingDismountListener(this), 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() {
2023-08-02 18:57:10 +02:00
getDataManager().getAsyncPool().execute(() -> {
2020-09-08 22:31:23 +02:00
// Load data from DB
2023-08-02 18:57:10 +02:00
this.dataHelper.getTemplates((templates) -> {
2020-09-08 22:31:23 +02:00
for (Template template : templates) {
this.templateManager.addTemplate(template);
}
});
2023-08-02 18:57:10 +02:00
this.dataHelper.getAppliedPunishments((appliedPunishments) -> {
for (AppliedPunishment punishment : appliedPunishments) {
2020-09-08 22:31:23 +02:00
this.punishmentManager.getPlayer(punishment.getVictim()).addPunishment(punishment);
}
2020-09-08 22:31:23 +02:00
});
2023-08-02 18:57:10 +02:00
this.dataHelper.getNotes((notes) -> {
for (PunishmentNote note : notes) {
2020-09-08 22:31:23 +02:00
this.punishmentManager.getPlayer(note.getSubject()).addNotes(note);
}
2020-09-08 22:31:23 +02:00
});
2023-08-02 18:57:10 +02:00
this.dataHelper.getTickets((tickets) -> {
for (Ticket ticket : tickets.values()) {
2020-09-08 22:31:23 +02:00
this.ticketManager.addTicket(ticket);
}
2020-09-08 22:31:23 +02:00
});
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 this.commandManager;
2019-02-27 02:50:18 +01:00
}
2019-03-03 22:33:44 +01:00
public TemplateManager getTemplateManager() {
return this.templateManager;
2019-03-03 22:33:44 +01:00
}
2019-02-27 02:50:18 +01:00
2019-03-03 22:33:44 +01:00
public PunishmentManager getPunishmentManager() {
return this.punishmentManager;
2019-03-03 22:33:44 +01:00
}
2019-03-07 05:31:30 +01:00
public TicketManager getTicketManager() {
return this.ticketManager;
2019-03-07 05:31:30 +01:00
}
2019-03-08 17:24:47 +01:00
public StaffChatManager getStaffChatManager() {
return this.staffChatManager;
2019-03-08 17:24:47 +01:00
}
2020-06-04 18:20:35 +02:00
public GuiManager getGuiManager() {
return this.guiManager;
2020-06-04 18:20:35 +02:00
}
2020-08-05 00:20:25 +02:00
public ModerationManager getModerationManager() {
return this.moderationManager;
2020-08-05 00:20:25 +02:00
}
2023-08-02 18:57:10 +02:00
public DataHelper getDataHelper() {
2023-08-15 23:24:07 +02:00
return this.dataHelper;
2023-08-02 18:57:10 +02:00
}
2019-02-27 02:50:18 +01:00
}