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

249 lines
10 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;
import com.songoda.core.gui.GuiManager;
import com.songoda.ultimatemoderation.commands.*;
2019-02-27 22:45:39 +01:00
import com.songoda.ultimatemoderation.listeners.*;
2019-03-05 06:06:02 +01:00
import com.songoda.ultimatemoderation.punish.AppliedPunishment;
import com.songoda.ultimatemoderation.punish.PunishmentNote;
import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
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-03-05 06:06:02 +01:00
import com.songoda.ultimatemoderation.storage.Storage;
import com.songoda.ultimatemoderation.storage.StorageRow;
import com.songoda.ultimatemoderation.storage.types.StorageYaml;
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;
import com.songoda.ultimatemoderation.tickets.TicketResponse;
import com.songoda.ultimatemoderation.tickets.TicketStatus;
2019-02-27 02:50:18 +01:00
import com.songoda.ultimatemoderation.utils.Methods;
2019-03-05 06:06:02 +01:00
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
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
import java.util.UUID;
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;
2019-03-03 22:33:44 +01:00
2019-03-05 06:06:02 +01:00
private Storage storage;
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() {
storage.doSave();
this.storage.closeConnection();
}
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 CommandCommandSpy(this));
this.commandManager.addCommand(new CommandFreeze(this));
this.commandManager.addCommand(new CommandInvSee(this));
this.commandManager.addCommand(new CommandKick(this));
this.commandManager.addCommand(new CommandMute(this));
this.commandManager.addCommand(new CommandRandomPlayer(this));
this.commandManager.addCommand(new CommandRevive(this));
this.commandManager.addCommand(new CommandRunTemplate(this));
this.commandManager.addCommand(new CommandSlowMode(this));
this.commandManager.addCommand(new CommandSpy(this));
this.commandManager.addCommand(new CommandStaffChat(this));
this.commandManager.addCommand(new CommandTicket(this));
this.commandManager.addCommand(new CommandToggleChat(this));
this.commandManager.addCommand(new CommandUnBan(this));
this.commandManager.addCommand(new CommandUnMute(this));
this.commandManager.addCommand(new CommandVanish(this));
this.commandManager.addCommand(new CommandViewEnderChest(this));
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();
2019-03-03 22:33:44 +01:00
2019-03-05 06:06:02 +01:00
// Load data
this.checkStorage();
2019-03-09 04:55:02 +01:00
Bukkit.getScheduler().scheduleSyncDelayedTask(this, this::loadFromFile, 1L);
2019-03-05 06:06:02 +01:00
2019-02-27 04:08:19 +01:00
// Register Listeners
2019-10-19 19:29:46 +02:00
guiManager.init();
2019-03-05 06:06:02 +01:00
AbstractGUI.initializeListeners(this);
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-10-19 19:29:46 +02:00
int timeout = Settings.AUTOSAVE.getInt() * 60 * 20;
2019-03-05 06:06:02 +01:00
Bukkit.getScheduler().runTaskTimerAsynchronously(this, () -> storage.doSave(), timeout, timeout);
2019-02-27 02:50:18 +01:00
}
2019-03-05 06:06:02 +01:00
private void checkStorage() {
2019-10-19 19:29:46 +02:00
this.storage = new StorageYaml(this);
2019-03-05 06:06:02 +01:00
}
private void loadFromFile() {
if (storage.containsGroup("templates")) {
for (StorageRow row : storage.getRowsByGroup("templates")) {
Template template = new Template(PunishmentType.valueOf(row.get("type").asString()),
row.get("duration").asLong(),
row.get("reason").asString(),
UUID.fromString(row.get("creator").asString()),
row.get("name").asString(),
UUID.fromString(row.get("uuid").asString()));
templateManager.addTemplate(template);
}
}
if (storage.containsGroup("punishments")) {
for (StorageRow row : storage.getRowsByGroup("punishments")) {
UUID playerUUID = UUID.fromString(row.get("victim").asString());
AppliedPunishment appliedPunishment = new AppliedPunishment(PunishmentType.valueOf(row.get("type").asString()),
row.get("duration").asLong(),
row.get("reason").asString(),
UUID.fromString(row.get("victim").asString()),
2020-03-12 15:15:26 +01:00
row.get("punisher").asObject() == null ? null : UUID.fromString(row.get("punisher").asString()),
2019-03-05 06:06:02 +01:00
row.get("expiration").asLong(),
playerUUID);
PlayerPunishData playerPunishData = getPunishmentManager().getPlayer(playerUUID);
playerPunishData.addPunishment(appliedPunishment);
playerPunishData.audit();
}
}
if (storage.containsGroup("notes")) {
for (StorageRow row : storage.getRowsByGroup("notes")) {
UUID playerUUID = UUID.fromString(row.get("subject").asString());
PunishmentNote note = new PunishmentNote(UUID.fromString(row.get("uuid").asString()),
row.get("note").asString(),
UUID.fromString(row.get("author").asString()),
UUID.fromString(row.get("subject").asString()),
row.get("creation").asLong());
PlayerPunishData playerPunishData = getPunishmentManager().getPlayer(playerUUID);
playerPunishData.addNotes(note);
}
}
2019-03-07 05:31:30 +01:00
if (storage.containsGroup("tickets")) {
for (StorageRow row : storage.getRowsByGroup("tickets")) {
2020-05-12 23:28:12 +02:00
int id = Integer.parseInt(row.get("id").asString());
2019-03-07 05:31:30 +01:00
Ticket ticket = new Ticket(
UUID.fromString(row.get("player").asString()),
row.get("subject").asString(),
row.get("type").asString());
2019-03-07 05:31:30 +01:00
ticket.setTicketId(id);
ticket.setLocation(Methods.unserializeLocation(row.get("location").asString()));
2019-03-07 05:31:30 +01:00
ticket.setStatus(TicketStatus.valueOf(row.get("status").asString()));
ticketManager.addTicket(ticket, id);
}
}
if (storage.containsGroup("ticketresponses")) {
for (StorageRow row : storage.getRowsByGroup("ticketresponses")) {
int id = row.get("ticketid").asInt();
TicketResponse ticketResponse = new TicketResponse(
UUID.fromString(row.get("author").asString()),
2019-10-19 19:29:46 +02:00
row.get("message").asString(),
2020-05-12 23:28:12 +02:00
Long.parseLong(row.get("posted").asString()));
2019-03-07 05:31:30 +01:00
ticketResponse.setTicketId(id);
ticketManager.getTicket(id).addResponse(ticketResponse);
}
}
2019-03-05 06:06:02 +01:00
storage.doSave();
}
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
public GuiManager getGuiManager() {
return guiManager;
}
2019-02-27 02:50:18 +01:00
}