diff --git a/pom.xml b/pom.xml index 54f9b9d..673aaa8 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ com.songoda UltimateModeration 4.0.0 - 2.0.1 + 2.0.2 clean install UltimateModeration-${project.version} diff --git a/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java b/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java index ee4235b..cbefe40 100644 --- a/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java +++ b/src/main/java/com/songoda/ultimatemoderation/UltimateModeration.java @@ -18,30 +18,18 @@ import com.songoda.ultimatemoderation.listeners.*; import com.songoda.ultimatemoderation.moderate.ModerationManager; import com.songoda.ultimatemoderation.punish.AppliedPunishment; import com.songoda.ultimatemoderation.punish.PunishmentNote; -import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.player.PunishmentManager; import com.songoda.ultimatemoderation.punish.template.Template; import com.songoda.ultimatemoderation.punish.template.TemplateManager; import com.songoda.ultimatemoderation.settings.Settings; import com.songoda.ultimatemoderation.staffchat.StaffChatManager; -import com.songoda.ultimatemoderation.storage.Storage; -import com.songoda.ultimatemoderation.storage.StorageRow; -import com.songoda.ultimatemoderation.storage.types.StorageYaml; import com.songoda.ultimatemoderation.tasks.SlowModeTask; import com.songoda.ultimatemoderation.tickets.Ticket; import com.songoda.ultimatemoderation.tickets.TicketManager; -import com.songoda.ultimatemoderation.tickets.TicketResponse; -import com.songoda.ultimatemoderation.tickets.TicketStatus; -import com.songoda.ultimatemoderation.utils.Methods; import org.bukkit.Bukkit; -import org.bukkit.ChatColor; import org.bukkit.plugin.PluginManager; -import java.io.File; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.UUID; public class UltimateModeration extends SongodaPlugin { private static UltimateModeration INSTANCE; @@ -55,7 +43,6 @@ public class UltimateModeration extends SongodaPlugin { private ModerationManager moderationManager; private DatabaseConnector databaseConnector; - private DataMigrationManager dataMigrationManager; private DataManager dataManager; public static UltimateModeration getInstance() { @@ -96,11 +83,11 @@ public class UltimateModeration extends SongodaPlugin { 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.commandManager.addCommand(new CommandTicket(this, guiManager)); 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 CommandVanish()); this.commandManager.addCommand(new CommandWarn(this)); // Setup Managers @@ -128,9 +115,9 @@ public class UltimateModeration extends SongodaPlugin { } this.dataManager = new DataManager(this.databaseConnector, this); - this.dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager, + DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager, new _1_InitialMigration()); - this.dataMigrationManager.runMigrations(); + dataMigrationManager.runMigrations(); } catch (Exception ex) { this.getLogger().severe("Fatal error trying to connect to database. " + @@ -139,108 +126,6 @@ public class UltimateModeration extends SongodaPlugin { return; } - Bukkit.getScheduler().runTaskLaterAsynchronously(this, () -> { - // Legacy Data - File folder = getDataFolder(); - File dataFile = new File(folder, "data.yml"); - - boolean converted = false; - if (dataFile.exists()) { - converted = true; - Storage storage = new StorageYaml(this); - console.sendMessage("[" + getDescription().getName() + "] " + ChatColor.RED + "Conversion process starting DO NOT turn off your server... " + - "UltimateModeration hasn't fully loaded yet so its best users don't interact with the plugin until conversion completes."); - 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()); - dataManager.createTemplate(template); - } - } - - if (storage.containsGroup("punishments")) { - for (StorageRow row : storage.getRowsByGroup("punishments")) { - AppliedPunishment appliedPunishment = new AppliedPunishment(PunishmentType.valueOf(row.get("type").asString()), - row.get("duration").asLong(), - row.get("reason").asString(), - UUID.fromString(row.get("victim").asString()), - row.get("punisher").asObject() == null ? null : UUID.fromString(row.get("punisher").asString()), - row.get("expiration").asLong()); - dataManager.createAppliedPunishment(appliedPunishment); - } - } - - if (storage.containsGroup("notes")) { - for (StorageRow row : storage.getRowsByGroup("notes")) { - PunishmentNote note = new PunishmentNote(row.get("note").asString(), - UUID.fromString(row.get("author").asString()), - UUID.fromString(row.get("subject").asString()), - row.get("creation").asLong()); - dataManager.createNote(note); - } - } - - Map tickets = new HashMap<>(); - if (storage.containsGroup("tickets")) { - for (StorageRow row : storage.getRowsByGroup("tickets")) { - - int id = Integer.parseInt(row.get("id").asString()); - Ticket ticket = new Ticket( - UUID.fromString(row.get("player").asString()), - row.get("subject").asString(), - row.get("type").asString()); - ticket.setId(id); - ticket.setLocation(Methods.unserializeLocation(row.get("location").asString())); - ticket.setStatus(TicketStatus.valueOf(row.get("status").asString())); - tickets.put(id, ticket); - } - } - - 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()), - row.get("message").asString(), - Long.parseLong(row.get("posted").asString())); - - tickets.get(id).addResponse(ticketResponse); - ticketResponse.setTicketId(id); - } - } - for (Ticket ticket : tickets.values()) - dataManager.createTicket(ticket); - } - dataFile.delete(); - - final boolean convrted = converted; - getDataManager().queueAsync(() -> { - if (convrted) - console.sendMessage("[" + getDescription().getName() + "] " + ChatColor.GREEN + "Conversion complete :)"); - // 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); - }); - }, "create"); - }, 20); - // Register Listeners guiManager.init(); PluginManager pluginManager = Bukkit.getPluginManager(); @@ -263,6 +148,30 @@ public class UltimateModeration extends SongodaPlugin { SlowModeTask.startTask(this); } + @Override + public void onDataLoad() { + getDataManager().queueAsync(() -> { + // 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); + }); + }, "create"); + } + @Override public void onConfigReload() { this.setLocale(getConfig().getString("System.Language Mode"), true); diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandBan.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandBan.java index 57c3a3e..fed62b4 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandBan.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandBan.java @@ -18,11 +18,11 @@ import java.util.List; public class CommandBan extends AbstractCommand { - private UltimateModeration instance; + private final UltimateModeration plugin; - public CommandBan(UltimateModeration instance) { + public CommandBan(UltimateModeration plugin) { super(CommandType.CONSOLE_OK, "Ban"); - this.instance = instance; + this.plugin = plugin; } @Override @@ -50,25 +50,25 @@ public class CommandBan extends AbstractCommand { OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); if (!player.hasPlayedBefore()) { - instance.getLocale().newMessage("That player does not exist.").sendMessage(sender); + plugin.getLocale().newMessage("That player does not exist.").sendMessage(sender); return ReturnType.FAILURE; } - if (instance.getPunishmentManager().getPlayer(player).getActivePunishments() + if (plugin.getPunishmentManager().getPlayer(player).getActivePunishments() .stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.BAN)) { - instance.getLocale().newMessage("That player is already banned.").sendPrefixedMessage(sender); + plugin.getLocale().newMessage("That player is already banned.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } if (duration == 0 && !sender.hasPermission("um.ban.permanent")) { - instance.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender); + plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender); return ReturnType.FAILURE; } long durationFinal = duration; - Bukkit.getScheduler().runTaskAsynchronously(instance, () -> { + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { if (sender instanceof Player && VaultPermissions.hasPermission(player, "um.ban.exempt")) { - instance.getLocale().newMessage("You cannot ban this player.").sendPrefixedMessage(sender); + plugin.getLocale().newMessage("You cannot ban this player.").sendPrefixedMessage(sender); return; } diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandClearChat.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandClearChat.java index 594ae98..a31bd28 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandClearChat.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandClearChat.java @@ -12,11 +12,11 @@ import java.util.List; public class CommandClearChat extends AbstractCommand { - private UltimateModeration instance; + private final UltimateModeration plugin; - public CommandClearChat(UltimateModeration instance) { + public CommandClearChat(UltimateModeration plugin) { super(CommandType.PLAYER_ONLY, "ClearChat"); - this.instance = instance; + this.plugin = plugin; } @Override @@ -32,11 +32,11 @@ public class CommandClearChat extends AbstractCommand { player.sendMessage(toSend); } - instance.getLocale().getMessage("command.clearchat.cleared") + plugin.getLocale().getMessage("command.clearchat.cleared") .processPlaceholder("player", sender.getName()).sendPrefixedMessage(player); if (player.hasPermission("um.clearchat.bypass") && !isForced(args)) { - instance.getLocale().getMessage("command.clearchat.immune").sendMessage(player); + plugin.getLocale().getMessage("command.clearchat.immune").sendMessage(player); } } return ReturnType.SUCCESS; diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandHelp.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandHelp.java index 9a3fc56..5997404 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandHelp.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandHelp.java @@ -9,23 +9,23 @@ import java.util.List; public class CommandHelp extends AbstractCommand { - private UltimateModeration instance; + private final UltimateModeration plugin; - public CommandHelp(UltimateModeration instance) { + public CommandHelp(UltimateModeration plugin) { super(CommandType.CONSOLE_OK, "help"); - this.instance = instance; + this.plugin = plugin; } @Override protected ReturnType runCommand(CommandSender sender, String... args) { sender.sendMessage(""); - instance.getLocale().getMessage("&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda") + plugin.getLocale().getMessage("&7Version " + plugin.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda") .sendPrefixedMessage(sender); sender.sendMessage(""); sender.sendMessage(Methods.formatText("&7Welcome to UltimateModeration! To get started try using the /um command to access the moderation panel.")); sender.sendMessage(""); sender.sendMessage(Methods.formatText("&6Commands:")); - for (AbstractCommand command : instance.getCommandManager().getAllCommands()) { + for (AbstractCommand command : plugin.getCommandManager().getAllCommands()) { if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) { sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription())); } diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandKick.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandKick.java index 28ff94a..dea19a3 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandKick.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandKick.java @@ -13,13 +13,13 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -public class CommandKick extends AbstractCommand { +public class CommandKick extends AbstractCommand { - private UltimateModeration instance; + private final UltimateModeration plugin; - public CommandKick(UltimateModeration instance) { + public CommandKick(UltimateModeration plugin) { super(CommandType.CONSOLE_OK, "Kick"); - this.instance = instance; + this.plugin = plugin; } @Override @@ -40,12 +40,12 @@ public class CommandKick extends AbstractCommand { OfflinePlayer player = Bukkit.getPlayer(args[0]); if (player == null) { - instance.getLocale().newMessage("That player does not exist or is not online.").sendPrefixedMessage(sender); + plugin.getLocale().newMessage("That player does not exist or is not online.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } if (sender instanceof Player && player.getPlayer().hasPermission("um.kick.exempt")) { - instance.getLocale().newMessage("You cannot kick this player.").sendPrefixedMessage(sender); + plugin.getLocale().newMessage("You cannot kick this player.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandMute.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandMute.java index 6675ca4..6682e7c 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandMute.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandMute.java @@ -18,11 +18,11 @@ import java.util.List; public class CommandMute extends AbstractCommand { - private UltimateModeration instance; + private final UltimateModeration plugin; - public CommandMute(UltimateModeration instance) { + public CommandMute(UltimateModeration plugin) { super(CommandType.CONSOLE_OK, "Mute"); - this.instance = instance; + this.plugin = plugin; } @Override @@ -50,18 +50,18 @@ public class CommandMute extends AbstractCommand { OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); if (!player.hasPlayedBefore()) { - instance.getLocale().newMessage("That player does not exist.").sendPrefixedMessage(sender); + plugin.getLocale().newMessage("That player does not exist.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } if (sender instanceof Player && VaultPermissions.hasPermission(player, "um.mute.exempt")) { - instance.getLocale().newMessage("You cannot mute that player.").sendPrefixedMessage(sender); + plugin.getLocale().newMessage("You cannot mute that player.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } - if (instance.getPunishmentManager().getPlayer(player).getActivePunishments() + if (plugin.getPunishmentManager().getPlayer(player).getActivePunishments() .stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.MUTE)) { - instance.getLocale().newMessage("That player is already muted.").sendPrefixedMessage(sender); + plugin.getLocale().newMessage("That player is already muted.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandRandomPlayer.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandRandomPlayer.java index f3398fd..10c2238 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandRandomPlayer.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandRandomPlayer.java @@ -12,11 +12,11 @@ import java.util.List; public class CommandRandomPlayer extends AbstractCommand { - private UltimateModeration instance; + private final UltimateModeration plugin; - public CommandRandomPlayer(UltimateModeration instance) { + public CommandRandomPlayer(UltimateModeration plugin) { super(CommandType.PLAYER_ONLY, "RandomPlayer"); - this.instance = instance; + this.plugin = plugin; } @Override @@ -26,7 +26,7 @@ public class CommandRandomPlayer extends AbstractCommand { players.remove(sender); if (players.size() == 0) { - instance.getLocale().newMessage("&cYou are the only one online!").sendPrefixedMessage(sender); + plugin.getLocale().newMessage("&cYou are the only one online!").sendPrefixedMessage(sender); return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandReload.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandReload.java index dff2ec2..b755739 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandReload.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandReload.java @@ -8,17 +8,17 @@ import java.util.List; public class CommandReload extends AbstractCommand { - private UltimateModeration instance; + private final UltimateModeration plugin; - public CommandReload(UltimateModeration instance) { + public CommandReload(UltimateModeration plugin) { super(CommandType.CONSOLE_OK, "reload"); - this.instance = instance; + this.plugin = plugin; } @Override protected ReturnType runCommand(CommandSender sender, String... args) { - instance.reloadConfig(); - instance.getLocale().newMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender); + plugin.reloadConfig(); + plugin.getLocale().newMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender); return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandRunTemplate.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandRunTemplate.java index e5283a4..72ebf25 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandRunTemplate.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandRunTemplate.java @@ -13,11 +13,11 @@ import java.util.List; public class CommandRunTemplate extends AbstractCommand { - private UltimateModeration instance; + private final UltimateModeration plugin; - public CommandRunTemplate(UltimateModeration instance) { + public CommandRunTemplate(UltimateModeration plugin) { super(CommandType.CONSOLE_OK, "RunTemplate"); - this.instance = instance; + this.plugin = plugin; } @Override @@ -27,8 +27,8 @@ public class CommandRunTemplate extends AbstractCommand { OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); - if (player == null) { - instance.getLocale().newMessage("That player does not exist.").sendPrefixedMessage(sender); + if (!player.hasPlayedBefore()) { + plugin.getLocale().newMessage("That player does not exist.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } @@ -39,7 +39,7 @@ public class CommandRunTemplate extends AbstractCommand { } String templateStr = templateBuilder.toString().trim(); - Template template = instance.getTemplateManager().getTemplate(templateStr); + Template template = plugin.getTemplateManager().getTemplate(templateStr); if (template == null) { sender.sendMessage("That template does not exist..."); @@ -61,7 +61,7 @@ public class CommandRunTemplate extends AbstractCommand { return players; } else if (args.length == 2) { List lines = new ArrayList<>(); - for (Template template : instance.getTemplateManager().getTemplates().values()) { + for (Template template : plugin.getTemplateManager().getTemplates()) { lines.add(template.getName()); } } diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandSettings.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandSettings.java index 2f4799b..1cadbde 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandSettings.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandSettings.java @@ -11,19 +11,19 @@ import java.util.List; public class CommandSettings extends AbstractCommand { - final UltimateModeration instance; - final GuiManager guiManager; + private final UltimateModeration plugin; + private final GuiManager guiManager; - public CommandSettings(UltimateModeration instance, GuiManager manager) { + public CommandSettings(UltimateModeration plugin, GuiManager manager) { super(CommandType.PLAYER_ONLY, "settings"); - this.instance = instance; + this.plugin = plugin; this.guiManager = manager; } @Override protected ReturnType runCommand(CommandSender sender, String... args) { Player player = (Player) sender; - guiManager.showGUI((Player) sender, new PluginConfigGui(instance)); + guiManager.showGUI((Player) sender, new PluginConfigGui(plugin)); return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandSlowMode.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandSlowMode.java index d55c92b..c1d6ece 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandSlowMode.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandSlowMode.java @@ -13,18 +13,18 @@ import java.util.List; public class CommandSlowMode extends AbstractCommand { - private UltimateModeration instance; + private final UltimateModeration plugin; - public CommandSlowMode(UltimateModeration instance) { + public CommandSlowMode(UltimateModeration plugin) { super(CommandType.CONSOLE_OK, "Slowmode"); - this.instance = instance; + this.plugin = plugin; } @Override protected ReturnType runCommand(CommandSender sender, String... args) { if (args.length == 0) { ChatListener.setSlowModeOverride(0); - instance.getLocale().getMessage("event.slowmode.disabled").sendPrefixedMessage(sender); + plugin.getLocale().getMessage("event.slowmode.disabled").sendPrefixedMessage(sender); return ReturnType.SUCCESS; } else if (args.length != 1) return ReturnType.SYNTAX_ERROR; @@ -34,7 +34,7 @@ public class CommandSlowMode extends AbstractCommand { ChatListener.setSlowModeOverride(delay); Bukkit.getOnlinePlayers().forEach(player -> - instance.getLocale().getMessage("event.slowmode.enabled") + plugin.getLocale().getMessage("event.slowmode.enabled") .processPlaceholder("delay", Methods.makeReadable(delay)).sendPrefixedMessage(player)); return ReturnType.SUCCESS; diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandStaffChat.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandStaffChat.java index 6ff006f..d8a7ba9 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandStaffChat.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandStaffChat.java @@ -11,11 +11,11 @@ import java.util.List; public class CommandStaffChat extends AbstractCommand { - private UltimateModeration instance; + private final UltimateModeration plugin; - public CommandStaffChat(UltimateModeration instance) { + public CommandStaffChat(UltimateModeration plugin) { super(CommandType.PLAYER_ONLY, "StaffChat"); - this.instance = instance; + this.plugin = plugin; } @Override @@ -27,26 +27,26 @@ public class CommandStaffChat extends AbstractCommand { Player player = (Player) sender; if (channelName.trim().equalsIgnoreCase("leave")) { - for (StaffChannel channel : instance.getStaffChatManager().getChats().values()) { + for (StaffChannel channel : plugin.getStaffChatManager().getChats().values()) { if (!channel.listMembers().contains(player.getUniqueId())) continue; channel.removeMember(player); - instance.getLocale().getMessage("event.staffchat.leave") + plugin.getLocale().getMessage("event.staffchat.leave") .processPlaceholder("channel", channel.getChannelName()).sendPrefixedMessage(player); return ReturnType.SUCCESS; } - instance.getLocale().getMessage("event.staffchat.nochannels").sendPrefixedMessage(player); + plugin.getLocale().getMessage("event.staffchat.nochannels").sendPrefixedMessage(player); return ReturnType.FAILURE; } - instance.getLocale().getMessage("event.staffchat.join") + plugin.getLocale().getMessage("event.staffchat.join") .processPlaceholder("channel", channelName).sendPrefixedMessage(player); - instance.getStaffChatManager().getChat(channelName).addMember(player); + plugin.getStaffChatManager().getChat(channelName).addMember(player); return ReturnType.SUCCESS; } @Override protected List onTab(CommandSender sender, String... args) { - return new ArrayList<>(instance.getStaffChatManager().getChats().keySet()); + return new ArrayList<>(plugin.getStaffChatManager().getChats().keySet()); } @Override diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandTicket.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandTicket.java index fe4d873..41d1eec 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandTicket.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandTicket.java @@ -1,6 +1,7 @@ package com.songoda.ultimatemoderation.commands; import com.songoda.core.commands.AbstractCommand; +import com.songoda.core.gui.GuiManager; import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.gui.TicketManagerGui; import org.bukkit.command.CommandSender; @@ -10,18 +11,19 @@ import java.util.List; public class CommandTicket extends AbstractCommand { - private UltimateModeration instance; + private final UltimateModeration plugin; + private final GuiManager guiManager; - public CommandTicket(UltimateModeration instance) { + public CommandTicket(UltimateModeration plugin, GuiManager guiManager) { super(CommandType.PLAYER_ONLY, "Ticket"); - this.instance = instance; + this.plugin = plugin; + this.guiManager = guiManager; } @Override protected ReturnType runCommand(CommandSender sender, String... args) { Player senderP = ((Player) sender); - - new TicketManagerGui(instance, senderP, senderP); + guiManager.showGUI(senderP, new TicketManagerGui(plugin, senderP, senderP)); return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandToggleChat.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandToggleChat.java index c84fe36..7967f1e 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandToggleChat.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandToggleChat.java @@ -12,24 +12,24 @@ import java.util.List; public class CommandToggleChat extends AbstractCommand { - private UltimateModeration instance; + private final UltimateModeration plugin; /* * Chat is enabled by default ;) */ private boolean toggled = true; - public CommandToggleChat(UltimateModeration instance) { + public CommandToggleChat(UltimateModeration plugin) { super(CommandType.PLAYER_ONLY, "togglechat"); - this.instance = instance; + this.plugin = plugin; } @Override protected ReturnType runCommand(CommandSender sender, String... args) { toggled = !toggled; - Message message = toggled ? instance.getLocale().getMessage("command.togglechat.toggledOn") - : instance.getLocale().getMessage("command.togglechat.toggledOff"); + Message message = toggled ? plugin.getLocale().getMessage("command.togglechat.toggledOn") + : plugin.getLocale().getMessage("command.togglechat.toggledOff"); ChatListener.setChatToggled(toggled); @@ -40,7 +40,7 @@ public class CommandToggleChat extends AbstractCommand { if (!player.hasPermission(getPermissionNode() + ".bypass")) continue; - instance.getLocale().getMessage("command.togglechat.bypass").sendMessage(player); + plugin.getLocale().getMessage("command.togglechat.bypass").sendMessage(player); } if (!(sender instanceof Player)) diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandUltimateModeration.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandUltimateModeration.java index 710f0c3..b077705 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandUltimateModeration.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandUltimateModeration.java @@ -10,16 +10,16 @@ import java.util.List; public class CommandUltimateModeration extends AbstractCommand { - private UltimateModeration instance; + private final UltimateModeration plugin; - public CommandUltimateModeration(UltimateModeration instance) { + public CommandUltimateModeration(UltimateModeration plugin) { super(CommandType.PLAYER_ONLY, "UltimateModeration"); - this.instance = instance; + this.plugin = plugin; } @Override protected ReturnType runCommand(CommandSender sender, String... args) { - instance.getGuiManager().showGUI((Player) sender, new MainGui(instance, (Player) sender)); + plugin.getGuiManager().showGUI((Player) sender, new MainGui(plugin, (Player) sender)); return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandUnBan.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandUnBan.java index 3aa7845..97338b7 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandUnBan.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandUnBan.java @@ -14,11 +14,11 @@ import java.util.List; public class CommandUnBan extends AbstractCommand { - private UltimateModeration instance; + private final UltimateModeration plugin; - public CommandUnBan(UltimateModeration instance) { + public CommandUnBan(UltimateModeration plugin) { super(CommandType.CONSOLE_OK, "UnBan"); - this.instance = instance; + this.plugin = plugin; } @Override @@ -29,21 +29,21 @@ public class CommandUnBan extends AbstractCommand { OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); if (!player.hasPlayedBefore()) { - instance.getLocale().newMessage("That player does not exist.").sendPrefixedMessage(sender); + plugin.getLocale().newMessage("That player does not exist.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } - if (!instance.getPunishmentManager().getPlayer(player).getActivePunishments() + if (!plugin.getPunishmentManager().getPlayer(player).getActivePunishments() .stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.BAN)) { - instance.getLocale().newMessage("That player isn't banned.").sendPrefixedMessage(sender); + plugin.getLocale().newMessage("That player isn't banned.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } - PlayerPunishData playerPunishData = instance.getPunishmentManager().getPlayer(player); + PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(player); playerPunishData.expirePunishments(PunishmentType.BAN); - instance.getLocale().getMessage("event.unban.success") + plugin.getLocale().getMessage("event.unban.success") .processPlaceholder("player", player.getName()).sendPrefixedMessage(sender); return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandUnMute.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandUnMute.java index 17fcd4b..ee3bb21 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandUnMute.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandUnMute.java @@ -14,11 +14,11 @@ import java.util.List; public class CommandUnMute extends AbstractCommand { - private UltimateModeration instance; + private final UltimateModeration plugin; - public CommandUnMute(UltimateModeration instance) { + public CommandUnMute(UltimateModeration plugin) { super(CommandType.CONSOLE_OK, "UnMute"); - this.instance = instance; + this.plugin = plugin; } @Override @@ -28,22 +28,22 @@ public class CommandUnMute extends AbstractCommand { OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); - if (player == null) { - instance.getLocale().newMessage("That player does not exist.").sendPrefixedMessage(sender); + if (!player.hasPlayedBefore()) { + plugin.getLocale().newMessage("That player does not exist.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } - if (!instance.getPunishmentManager().getPlayer(player).getActivePunishments() + if (!plugin.getPunishmentManager().getPlayer(player).getActivePunishments() .stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.MUTE)) { - instance.getLocale().newMessage("That player isn't muted.").sendPrefixedMessage(sender); + plugin.getLocale().newMessage("That player isn't muted.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } - PlayerPunishData playerPunishData = instance.getPunishmentManager().getPlayer(player); + PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(player); playerPunishData.expirePunishments(PunishmentType.MUTE); - instance.getLocale().newMessage(instance.getLocale().getMessage("event.unmute.success") + plugin.getLocale().newMessage(plugin.getLocale().getMessage("event.unmute.success") .processPlaceholder("player", player.getName()).getMessage()).sendPrefixedMessage(sender); return ReturnType.SUCCESS; } diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandVanish.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandVanish.java index d5f1a83..bc30f21 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandVanish.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandVanish.java @@ -19,13 +19,10 @@ import java.util.UUID; public class CommandVanish extends AbstractCommand { - private UltimateModeration instance; + private static final List inVanish = new ArrayList<>(); - private static List inVanish = new ArrayList<>(); - - public CommandVanish(UltimateModeration instance) { + public CommandVanish() { super(CommandType.PLAYER_ONLY, "Vanish"); - this.instance = instance; } public static void registerVanishedPlayers(Player player) { diff --git a/src/main/java/com/songoda/ultimatemoderation/commands/CommandWarn.java b/src/main/java/com/songoda/ultimatemoderation/commands/CommandWarn.java index 596c6c2..c8c8ef7 100644 --- a/src/main/java/com/songoda/ultimatemoderation/commands/CommandWarn.java +++ b/src/main/java/com/songoda/ultimatemoderation/commands/CommandWarn.java @@ -18,11 +18,11 @@ import java.util.List; public class CommandWarn extends AbstractCommand { - private UltimateModeration instance; + private final UltimateModeration plugin; - public CommandWarn(UltimateModeration instance) { + public CommandWarn(UltimateModeration plugin) { super(CommandType.CONSOLE_OK, "Warn"); - this.instance = instance; + this.plugin = plugin; } @Override @@ -50,12 +50,12 @@ public class CommandWarn extends AbstractCommand { OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); if (!player.hasPlayedBefore()) { - instance.getLocale().newMessage("That player does not exist.").sendPrefixedMessage(sender); + plugin.getLocale().newMessage("That player does not exist.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } if (sender instanceof Player && VaultPermissions.hasPermission(player, "um.warning.exempt")) { - instance.getLocale().newMessage("You cannot warn that player.").sendPrefixedMessage(sender); + plugin.getLocale().newMessage("You cannot warn that player.").sendPrefixedMessage(sender); return ReturnType.FAILURE; } diff --git a/src/main/java/com/songoda/ultimatemoderation/database/DataManager.java b/src/main/java/com/songoda/ultimatemoderation/database/DataManager.java index 7c0458e..7985009 100644 --- a/src/main/java/com/songoda/ultimatemoderation/database/DataManager.java +++ b/src/main/java/com/songoda/ultimatemoderation/database/DataManager.java @@ -12,10 +12,15 @@ import com.songoda.ultimatemoderation.tickets.TicketStatus; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.plugin.Plugin; + import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.Statement; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.UUID; import java.util.function.Consumer; public class DataManager extends DataManagerAbstract { diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/MainGui.java b/src/main/java/com/songoda/ultimatemoderation/gui/MainGui.java index 9ce8a83..648918a 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/MainGui.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/MainGui.java @@ -29,7 +29,7 @@ public class MainGui extends Gui { private Online currentOnline = Online.ONLINE; - private List players = new ArrayList<>(); + private final List players = new ArrayList<>(); private final Player viewer; public MainGui(UltimateModeration plugin, Player viewer) { @@ -83,7 +83,8 @@ public class MainGui extends Gui { List found = players.stream().filter(uuid -> Bukkit.getOfflinePlayer(uuid).getName().toLowerCase().contains(gui.getInputText().toLowerCase())).collect(Collectors.toList()); if (found.size() >= 1) { - this.players = found; + this.players.clear(); + this.players.addAll(found); showPage(); } else { plugin.getLocale().getMessage("gui.players.nonefound").sendMessage(event.player); @@ -126,52 +127,54 @@ public class MainGui extends Gui { this.pages = (int) Math.max(1, Math.ceil(toUse.size() / ((double) 28))); - toUse = toUse.stream().skip((page - 1) * 28).limit(28).collect(Collectors.toList()); + final List toUseFinal = toUse.stream().skip((page - 1) * 28).limit(28).collect(Collectors.toList()); - int num = 11; - for (UUID uuid : toUse) { - if (num == 16 || num == 36) - num = num + 2; - OfflinePlayer pl = Bukkit.getOfflinePlayer(uuid); - ItemStack skull = ItemUtils.getPlayerSkull(pl); - setItem(num, skull); + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + int num = 11; + for (UUID uuid : toUseFinal) { + if (num == 16 || num == 36) + num = num + 2; + OfflinePlayer pl = Bukkit.getOfflinePlayer(uuid); + ItemStack skull = ItemUtils.getPlayerSkull(pl); + setItem(num, skull); - PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(pl); + PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(pl); - ArrayList lore = new ArrayList<>(); - lore.add(plugin.getLocale().getMessage("gui.players.click").getMessage()); - lore.add(""); + ArrayList lore = new ArrayList<>(); + lore.add(plugin.getLocale().getMessage("gui.players.click").getMessage()); + lore.add(""); - int ticketAmt = (int) plugin.getTicketManager().getTicketsAbout(pl).stream() - .filter(t -> t.getStatus() == TicketStatus.OPEN).count(); + int ticketAmt = (int) plugin.getTicketManager().getTicketsAbout(pl).stream() + .filter(t -> t.getStatus() == TicketStatus.OPEN).count(); - if (ticketAmt == 0) - lore.add(plugin.getLocale().getMessage("gui.players.notickets").getMessage()); - else { - if (ticketAmt == 1) - lore.add(plugin.getLocale().getMessage("gui.players.ticketsone").getMessage()); - else - lore.add(plugin.getLocale().getMessage("gui.players.tickets") - .processPlaceholder("amount", ticketAmt).getMessage()); + if (ticketAmt == 0) + lore.add(plugin.getLocale().getMessage("gui.players.notickets").getMessage()); + else { + if (ticketAmt == 1) + lore.add(plugin.getLocale().getMessage("gui.players.ticketsone").getMessage()); + else + lore.add(plugin.getLocale().getMessage("gui.players.tickets") + .processPlaceholder("amount", ticketAmt).getMessage()); + } + + int warningAmt = playerPunishData.getActivePunishments(PunishmentType.WARNING).size(); + + if (warningAmt == 0) + lore.add(plugin.getLocale().getMessage("gui.players.nowarnings").getMessage()); + else { + if (warningAmt == 1) + lore.add(plugin.getLocale().getMessage("gui.players.warningsone").getMessage()); + else + lore.add(plugin.getLocale().getMessage("gui.players.warnings") + .processPlaceholder("amount", warningAmt).getMessage()); + } + + setButton(num, GuiUtils.createButtonItem(skull, TextUtils.formatText("&7&l" + pl.getName()), lore), + (event) -> guiManager.showGUI(event.player, new PlayerGui(plugin, pl, viewer))); + + num++; } - - int warningAmt = playerPunishData.getActivePunishments(PunishmentType.WARNING).size(); - - if (warningAmt == 0) - lore.add(plugin.getLocale().getMessage("gui.players.nowarnings").getMessage()); - else { - if (warningAmt == 1) - lore.add(plugin.getLocale().getMessage("gui.players.warningsone").getMessage()); - else - lore.add(plugin.getLocale().getMessage("gui.players.warnings") - .processPlaceholder("amount", warningAmt).getMessage()); - } - - setButton(num, GuiUtils.createButtonItem(skull, TextUtils.formatText("&7&l" + pl.getName()), lore), - (event) -> guiManager.showGUI(event.player, new PlayerGui(plugin, pl, viewer))); - - num++; - } + }); // enable page events setNextPage(4, 7, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage())); diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/PunishGui.java b/src/main/java/com/songoda/ultimatemoderation/gui/PunishGui.java index 48b5d1a..27a05ab 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/PunishGui.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/PunishGui.java @@ -292,7 +292,8 @@ public class PunishGui extends Gui { private void updateTemplate() { Template template = new Template(this.type, this.duration, this.reason, this.template.getCreator(), this.templateName); - plugin.getTemplateManager().updateTemplate(this.template.getId(), template); + plugin.getTemplateManager().removeTemplate(this.template); + plugin.getTemplateManager().addTemplate(template); plugin.getDataManager().deleteTemplate(this.template); plugin.getDataManager().createTemplate(template); justSaved = true; diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/PunishmentsGui.java b/src/main/java/com/songoda/ultimatemoderation/gui/PunishmentsGui.java index fb27f32..4e0cc7a 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/PunishmentsGui.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/PunishmentsGui.java @@ -91,18 +91,18 @@ public class PunishmentsGui extends Gui { punishments = punishments.stream().skip((page - 1) * 28).limit(28) .collect(Collectors.toList()); - setButton(5,4, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, + setButton(5, 4, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR, plugin.getLocale().getMessage("gui.general.back").getMessage()), (event) -> guiManager.showGUI(event.player, new PlayerGui(plugin, toModerate, event.player))); - setButton(5,3, GuiUtils.createButtonItem(CompatibleMaterial.APPLE, Methods.formatText("&6" + currentActivity.getTranslation())), + setButton(5, 3, GuiUtils.createButtonItem(CompatibleMaterial.APPLE, Methods.formatText("&6" + currentActivity.getTranslation())), (event) -> { this.currentActivity = currentActivity.next(); this.page = 1; showPage(); }); - setButton(5,5, GuiUtils.createButtonItem(CompatibleMaterial.DIAMOND_SWORD, Methods.formatText("&6" + punishmentType.name())), + setButton(5, 5, GuiUtils.createButtonItem(CompatibleMaterial.DIAMOND_SWORD, Methods.formatText("&6" + punishmentType.name())), (event) -> { this.punishmentType = punishmentType.nextFilter(); this.page = 1; @@ -152,7 +152,7 @@ public class PunishmentsGui extends Gui { } }); - num ++; + num++; } } diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/TemplateManagerGui.java b/src/main/java/com/songoda/ultimatemoderation/gui/TemplateManagerGui.java index 7102f82..a1de8bf 100644 --- a/src/main/java/com/songoda/ultimatemoderation/gui/TemplateManagerGui.java +++ b/src/main/java/com/songoda/ultimatemoderation/gui/TemplateManagerGui.java @@ -5,7 +5,6 @@ import com.songoda.core.gui.Gui; import com.songoda.core.gui.GuiUtils; import com.songoda.core.utils.TextUtils; import com.songoda.ultimatemoderation.UltimateModeration; -import com.songoda.ultimatemoderation.punish.PunishmentNote; import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.template.Template; import com.songoda.ultimatemoderation.settings.Settings; @@ -42,7 +41,7 @@ public class TemplateManagerGui extends Gui { int numTemplates = plugin.getTemplateManager().getTemplates().size(); this.pages = (int) Math.floor(numTemplates / 28.0); - List