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 templates = plugin.getTemplateManager().getTemplates().values().stream().skip((page - 1) * 28).limit(28)
+ List templates = plugin.getTemplateManager().getTemplates().stream().skip((page - 1) * 28).limit(28)
.collect(Collectors.toList());
setNextPage(0, 5, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()));
@@ -92,12 +91,14 @@ public class TemplateManagerGui extends Gui {
if (player.hasPermission("um.templates.edit"))
guiManager.showGUI(player, new PunishGui(plugin, null, template, player));
} else if (event.clickType == ClickType.RIGHT) {
- if (player.hasPermission("um.templates.destroy"))
+ if (player.hasPermission("um.templates.destroy")) {
plugin.getTemplateManager().removeTemplate(template);
+ plugin.getDataManager().deleteTemplate(template);
+ }
showPage();
}
});
- num ++;
+ num++;
}
}
diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/TemplateSelectorGui.java b/src/main/java/com/songoda/ultimatemoderation/gui/TemplateSelectorGui.java
index cf1fbe3..b26de5b 100644
--- a/src/main/java/com/songoda/ultimatemoderation/gui/TemplateSelectorGui.java
+++ b/src/main/java/com/songoda/ultimatemoderation/gui/TemplateSelectorGui.java
@@ -13,7 +13,7 @@ import java.util.ArrayList;
public class TemplateSelectorGui extends Gui {
private final UltimateModeration plugin;
- private PunishGui punish;
+ private final PunishGui punish;
public TemplateSelectorGui(UltimateModeration plugin, PunishGui punish, Player player) {
super(6);
@@ -33,7 +33,7 @@ public class TemplateSelectorGui extends Gui {
punish.runTask();
});
- ArrayList templates = new ArrayList<>(plugin.getTemplateManager().getTemplates().values());
+ ArrayList templates = new ArrayList<>(plugin.getTemplateManager().getTemplates());
for (int i = 0; i < templates.size(); i++) {
Template template = templates.get(i);
setButton(18 + i, GuiUtils.createButtonItem(CompatibleMaterial.MAP, TextUtils.formatText("&6&l" + template.getName()),
diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/TicketGui.java b/src/main/java/com/songoda/ultimatemoderation/gui/TicketGui.java
index 1188c5f..d385261 100644
--- a/src/main/java/com/songoda/ultimatemoderation/gui/TicketGui.java
+++ b/src/main/java/com/songoda/ultimatemoderation/gui/TicketGui.java
@@ -25,7 +25,7 @@ import java.util.stream.Collectors;
public class TicketGui extends Gui {
private final UltimateModeration plugin;
- private StaffChatManager chatManager = UltimateModeration.getInstance().getStaffChatManager();
+ private final StaffChatManager chatManager = UltimateModeration.getInstance().getStaffChatManager();
private final Ticket ticket;
@@ -99,7 +99,7 @@ public class TicketGui extends Gui {
(event) -> player.teleport(ticket.getLocation()));
if (player.hasPermission("um.tickets.respond"))
- setButton(5,4, GuiUtils.createButtonItem(CompatibleMaterial.WRITABLE_BOOK, plugin.getLocale().getMessage("gui.ticket.respond").getMessage()),
+ setButton(5, 4, GuiUtils.createButtonItem(CompatibleMaterial.WRITABLE_BOOK, plugin.getLocale().getMessage("gui.ticket.respond").getMessage()),
(event) -> {
ChatPrompt.showPrompt(plugin, player, plugin.getLocale().getMessage("gui.ticket.what").getMessage(), (evnt) -> {
TicketResponse response = ticket.addResponse(new TicketResponse(player, evnt.getMessage(), System.currentTimeMillis()));
@@ -147,7 +147,7 @@ public class TicketGui extends Gui {
.processPlaceholder("sent", format.format(new Date(ticketResponse.getPostedDate()))).getMessage());
setItem(num, GuiUtils.createButtonItem(CompatibleMaterial.MAP, TextUtils.formatText(name), lore));
- num ++;
+ num++;
}
}
}
diff --git a/src/main/java/com/songoda/ultimatemoderation/gui/TicketManagerGui.java b/src/main/java/com/songoda/ultimatemoderation/gui/TicketManagerGui.java
index ab91c7b..fb29c91 100644
--- a/src/main/java/com/songoda/ultimatemoderation/gui/TicketManagerGui.java
+++ b/src/main/java/com/songoda/ultimatemoderation/gui/TicketManagerGui.java
@@ -9,7 +9,6 @@ import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.settings.Settings;
import com.songoda.ultimatemoderation.tickets.Ticket;
import com.songoda.ultimatemoderation.tickets.TicketStatus;
-import com.songoda.ultimatemoderation.utils.Methods;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
@@ -19,7 +18,6 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-import java.util.UUID;
import java.util.stream.Collectors;
public class TicketManagerGui extends Gui {
@@ -84,7 +82,7 @@ public class TicketManagerGui extends Gui {
});
if (toModerate != null && player.hasPermission("um.tickets.create"))
- setButton(5,5, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE,
+ setButton(5, 5, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE,
plugin.getLocale().getMessage("gui.tickets.create").getMessage()),
(event) -> createNew(player, toModerate));
@@ -142,7 +140,7 @@ public class TicketManagerGui extends Gui {
setButton(num, GuiUtils.createButtonItem(CompatibleMaterial.MAP,
TextUtils.formatText(name), TextUtils.formatText(lore)),
(event) -> guiManager.showGUI(player, new TicketGui(plugin, ticket, toModerate, player)));
- num ++;
+ num++;
}
}
diff --git a/src/main/java/com/songoda/ultimatemoderation/listeners/ChatListener.java b/src/main/java/com/songoda/ultimatemoderation/listeners/ChatListener.java
index 1514d4b..25360b2 100644
--- a/src/main/java/com/songoda/ultimatemoderation/listeners/ChatListener.java
+++ b/src/main/java/com/songoda/ultimatemoderation/listeners/ChatListener.java
@@ -3,16 +3,18 @@ package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.punish.AppliedPunishment;
import com.songoda.ultimatemoderation.punish.PunishmentType;
+import com.songoda.ultimatemoderation.settings.Settings;
import com.songoda.ultimatemoderation.staffchat.StaffChannel;
import com.songoda.ultimatemoderation.utils.Methods;
-import com.songoda.ultimatemoderation.settings.Settings;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
import java.util.stream.Collectors;
public class ChatListener implements Listener {
diff --git a/src/main/java/com/songoda/ultimatemoderation/listeners/SkyBlockListener.java b/src/main/java/com/songoda/ultimatemoderation/listeners/SkyBlockListener.java
index 588dd02..a26113f 100644
--- a/src/main/java/com/songoda/ultimatemoderation/listeners/SkyBlockListener.java
+++ b/src/main/java/com/songoda/ultimatemoderation/listeners/SkyBlockListener.java
@@ -2,16 +2,8 @@ package com.songoda.ultimatemoderation.listeners;
import com.songoda.skyblock.api.event.player.PlayerIslandChatEvent;
import com.songoda.ultimatemoderation.UltimateModeration;
-import com.songoda.ultimatemoderation.staffchat.StaffChatManager;
-import org.bukkit.Bukkit;
-import org.bukkit.Material;
-import org.bukkit.block.Block;
-import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
-import org.bukkit.event.block.BlockBreakEvent;
-
-import java.util.List;
public class SkyBlockListener implements Listener {
@@ -20,11 +12,11 @@ public class SkyBlockListener implements Listener {
public SkyBlockListener(UltimateModeration ultimateModeration) {
this.instance = ultimateModeration;
}
-
+
@EventHandler
public void onIslandChat(PlayerIslandChatEvent event) {
if (!ChatListener.onChat(event.getPlayer(), event.getMessage()))
event.setCancelled(true);
}
-
+
}
diff --git a/src/main/java/com/songoda/ultimatemoderation/listeners/SpyingDismountListener.java b/src/main/java/com/songoda/ultimatemoderation/listeners/SpyingDismountListener.java
index 985f3fe..2630e58 100644
--- a/src/main/java/com/songoda/ultimatemoderation/listeners/SpyingDismountListener.java
+++ b/src/main/java/com/songoda/ultimatemoderation/listeners/SpyingDismountListener.java
@@ -39,7 +39,8 @@ public class SpyingDismountListener implements Listener {
@EventHandler
public void onSneak(PlayerToggleSneakEvent event) {
Player player = event.getPlayer();
- if (player.isSneaking() || !SpyModeration.isSpying(player) || player.getGameMode() != GameMode.SPECTATOR) return;
+ if (player.isSneaking() || !SpyModeration.isSpying(player) || player.getGameMode() != GameMode.SPECTATOR)
+ return;
SpyModeration.spy(null, player);
}
diff --git a/src/main/java/com/songoda/ultimatemoderation/moderate/AbstractModeration.java b/src/main/java/com/songoda/ultimatemoderation/moderate/AbstractModeration.java
index 8b1ec73..789bac4 100644
--- a/src/main/java/com/songoda/ultimatemoderation/moderate/AbstractModeration.java
+++ b/src/main/java/com/songoda/ultimatemoderation/moderate/AbstractModeration.java
@@ -5,7 +5,6 @@ import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.utils.VaultPermissions;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
-import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
public abstract class AbstractModeration {
diff --git a/src/main/java/com/songoda/ultimatemoderation/moderate/GenericModerationCommand.java b/src/main/java/com/songoda/ultimatemoderation/moderate/GenericModerationCommand.java
index fa3a03d..bfddeb7 100644
--- a/src/main/java/com/songoda/ultimatemoderation/moderate/GenericModerationCommand.java
+++ b/src/main/java/com/songoda/ultimatemoderation/moderate/GenericModerationCommand.java
@@ -12,56 +12,56 @@ import java.util.List;
public class GenericModerationCommand extends AbstractCommand {
- private final UltimateModeration plugin;
- private final AbstractModeration moderation;
+ private final UltimateModeration plugin;
+ private final AbstractModeration moderation;
- public GenericModerationCommand(UltimateModeration plugin, AbstractModeration moderation) {
- super(moderation.isAllowConsole() ? CommandType.CONSOLE_OK : CommandType.PLAYER_ONLY, moderation.getProper());
- this.plugin = plugin;
- this.moderation = moderation;
- }
-
- @Override
- protected ReturnType runCommand(CommandSender sender, String... args) {
- if (args.length != 1)
- return ReturnType.SYNTAX_ERROR;
-
- OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
-
- if (!player.hasPlayedBefore()) {
- plugin.getLocale().newMessage("&cThis player has never played this server before...");
- return ReturnType.FAILURE;
- }
-
- moderation.runPreModeration(sender, player);
-
- return ReturnType.SUCCESS;
- }
-
- @Override
- protected List onTab(CommandSender sender, String... args) {
- if (args.length == 1) {
- List players = new ArrayList<>();
- for (Player player : Bukkit.getOnlinePlayers()) {
- players.add(player.getName());
- }
- return players;
- }
- return null;
- }
-
- @Override
- public String getPermissionNode() {
- return moderation.getPermission();
- }
-
- @Override
- public String getSyntax() {
- return "/" + moderation.getProper() + " ";
- }
-
- @Override
- public String getDescription() {
- return moderation.getDescription();
- }
+ public GenericModerationCommand(UltimateModeration plugin, AbstractModeration moderation) {
+ super(moderation.isAllowConsole() ? CommandType.CONSOLE_OK : CommandType.PLAYER_ONLY, moderation.getProper());
+ this.plugin = plugin;
+ this.moderation = moderation;
}
+
+ @Override
+ protected ReturnType runCommand(CommandSender sender, String... args) {
+ if (args.length != 1)
+ return ReturnType.SYNTAX_ERROR;
+
+ OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
+
+ if (!player.hasPlayedBefore()) {
+ plugin.getLocale().newMessage("&cThis player has never played this server before...");
+ return ReturnType.FAILURE;
+ }
+
+ moderation.runPreModeration(sender, player);
+
+ return ReturnType.SUCCESS;
+ }
+
+ @Override
+ protected List onTab(CommandSender sender, String... args) {
+ if (args.length == 1) {
+ List players = new ArrayList<>();
+ for (Player player : Bukkit.getOnlinePlayers()) {
+ players.add(player.getName());
+ }
+ return players;
+ }
+ return null;
+ }
+
+ @Override
+ public String getPermissionNode() {
+ return moderation.getPermission();
+ }
+
+ @Override
+ public String getSyntax() {
+ return "/" + moderation.getProper() + " ";
+ }
+
+ @Override
+ public String getDescription() {
+ return moderation.getDescription();
+ }
+}
diff --git a/src/main/java/com/songoda/ultimatemoderation/moderate/ModerationManager.java b/src/main/java/com/songoda/ultimatemoderation/moderate/ModerationManager.java
index 1b70e9a..fd8d466 100644
--- a/src/main/java/com/songoda/ultimatemoderation/moderate/ModerationManager.java
+++ b/src/main/java/com/songoda/ultimatemoderation/moderate/ModerationManager.java
@@ -1,7 +1,11 @@
package com.songoda.ultimatemoderation.moderate;
import com.songoda.ultimatemoderation.UltimateModeration;
-import com.songoda.ultimatemoderation.moderate.moderations.*;
+import com.songoda.ultimatemoderation.moderate.moderations.FreezeModeration;
+import com.songoda.ultimatemoderation.moderate.moderations.InvSeeModeration;
+import com.songoda.ultimatemoderation.moderate.moderations.ReviveModeration;
+import com.songoda.ultimatemoderation.moderate.moderations.SpyModeration;
+import com.songoda.ultimatemoderation.moderate.moderations.ViewEnderChestModeration;
import java.util.Collections;
import java.util.Map;
diff --git a/src/main/java/com/songoda/ultimatemoderation/moderate/moderations/InvSeeModeration.java b/src/main/java/com/songoda/ultimatemoderation/moderate/moderations/InvSeeModeration.java
index c62a8cf..00ad9e5 100644
--- a/src/main/java/com/songoda/ultimatemoderation/moderate/moderations/InvSeeModeration.java
+++ b/src/main/java/com/songoda/ultimatemoderation/moderate/moderations/InvSeeModeration.java
@@ -8,10 +8,6 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.UUID;
-
public class InvSeeModeration extends AbstractModeration {
public InvSeeModeration(UltimateModeration plugin) {
diff --git a/src/main/java/com/songoda/ultimatemoderation/moderate/moderations/ReviveModeration.java b/src/main/java/com/songoda/ultimatemoderation/moderate/moderations/ReviveModeration.java
index 7a9614e..7a8b2f1 100644
--- a/src/main/java/com/songoda/ultimatemoderation/moderate/moderations/ReviveModeration.java
+++ b/src/main/java/com/songoda/ultimatemoderation/moderate/moderations/ReviveModeration.java
@@ -11,10 +11,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
-import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.UUID;
public class ReviveModeration extends AbstractModeration {
diff --git a/src/main/java/com/songoda/ultimatemoderation/punish/player/PlayerPunishData.java b/src/main/java/com/songoda/ultimatemoderation/punish/player/PlayerPunishData.java
index 23e4b5e..2826f19 100644
--- a/src/main/java/com/songoda/ultimatemoderation/punish/player/PlayerPunishData.java
+++ b/src/main/java/com/songoda/ultimatemoderation/punish/player/PlayerPunishData.java
@@ -1,8 +1,8 @@
package com.songoda.ultimatemoderation.punish.player;
import com.songoda.ultimatemoderation.UltimateModeration;
-import com.songoda.ultimatemoderation.punish.PunishmentNote;
import com.songoda.ultimatemoderation.punish.AppliedPunishment;
+import com.songoda.ultimatemoderation.punish.PunishmentNote;
import com.songoda.ultimatemoderation.punish.PunishmentType;
import java.util.ArrayList;
diff --git a/src/main/java/com/songoda/ultimatemoderation/punish/template/TemplateManager.java b/src/main/java/com/songoda/ultimatemoderation/punish/template/TemplateManager.java
index 9c4cb14..32e4c95 100644
--- a/src/main/java/com/songoda/ultimatemoderation/punish/template/TemplateManager.java
+++ b/src/main/java/com/songoda/ultimatemoderation/punish/template/TemplateManager.java
@@ -1,13 +1,17 @@
package com.songoda.ultimatemoderation.punish.template;
-import java.util.*;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
public class TemplateManager {
- private static final Map templates = new HashMap<>();
+ private static final List templates = new LinkedList<>();
public Template getTemplate(String name) {
- for (Template template : templates.values()) {
+ for (Template template : templates) {
if (formatName(template.getName()).equals(formatName(name)))
return template;
}
@@ -15,20 +19,17 @@ public class TemplateManager {
}
public Template addTemplate(Template template) {
- return templates.put(template.getId(), template);
+ templates.add(template);
+ return template;
}
public Template removeTemplate(Template template) {
- return templates.remove(template.getId());
+ templates.remove(template);
+ return template;
}
- public Template updateTemplate(int id, Template template) {
- templates.remove(id);
- return addTemplate(template);
- }
-
- public Map getTemplates() {
- return Collections.unmodifiableMap(templates);
+ public List getTemplates() {
+ return Collections.unmodifiableList(templates);
}
private String formatName(String name) {
diff --git a/src/main/java/com/songoda/ultimatemoderation/settings/Settings.java b/src/main/java/com/songoda/ultimatemoderation/settings/Settings.java
index 4a4bc2d..f909204 100644
--- a/src/main/java/com/songoda/ultimatemoderation/settings/Settings.java
+++ b/src/main/java/com/songoda/ultimatemoderation/settings/Settings.java
@@ -3,11 +3,9 @@ package com.songoda.ultimatemoderation.settings;
import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.configuration.Config;
import com.songoda.core.configuration.ConfigSetting;
-import com.songoda.core.hooks.EconomyManager;
import com.songoda.ultimatemoderation.UltimateModeration;
import java.util.Arrays;
-import java.util.stream.Collectors;
public class Settings {
@@ -53,9 +51,9 @@ public class Settings {
public static final ConfigSetting LANGUGE_MODE = new ConfigSetting(config, "System.Language Mode", "en_US",
"The enabled language file.",
"More language files (if available) can be found in the plugins data folder.");
-
+
public static final ConfigSetting NOTIFY_BLOCK = new ConfigSetting(config, "Main.Notify Blocks", true, "Notify Staff on Block Break");
-
+
public static final ConfigSetting NOTIFY_BLOCK_LIST = new ConfigSetting(config, "Main.Notify Blocks List", Arrays.asList("DIAMOND_ORE", "EMERALD_ORE"),
"Blocks that will give a notification when mined.");
diff --git a/src/main/java/com/songoda/ultimatemoderation/staffchat/StaffChannel.java b/src/main/java/com/songoda/ultimatemoderation/staffchat/StaffChannel.java
index ddaacdd..3727c08 100644
--- a/src/main/java/com/songoda/ultimatemoderation/staffchat/StaffChannel.java
+++ b/src/main/java/com/songoda/ultimatemoderation/staffchat/StaffChannel.java
@@ -3,7 +3,6 @@ package com.songoda.ultimatemoderation.staffchat;
import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.settings.Settings;
import com.songoda.ultimatemoderation.utils.Methods;
-import com.songoda.ultimatemoderation.settings.Settings;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -52,11 +51,11 @@ public class StaffChannel {
public void processMessage(String message, Player player) {
messageAll(UltimateModeration.getInstance().getLocale()
- .getMessage("event.staffchat.format")
- .processPlaceholder("color", chatChar)
- .processPlaceholder("channel", channelName)
- .processPlaceholder("player", player.getDisplayName())
- .processPlaceholder("message", message).getMessage());
+ .getMessage("event.staffchat.format")
+ .processPlaceholder("color", chatChar)
+ .processPlaceholder("channel", channelName)
+ .processPlaceholder("player", player.getDisplayName())
+ .processPlaceholder("message", message).getMessage());
}
public void messageAll(String message) {
diff --git a/src/main/java/com/songoda/ultimatemoderation/staffchat/StaffChatManager.java b/src/main/java/com/songoda/ultimatemoderation/staffchat/StaffChatManager.java
index 47a81bf..d5eb671 100644
--- a/src/main/java/com/songoda/ultimatemoderation/staffchat/StaffChatManager.java
+++ b/src/main/java/com/songoda/ultimatemoderation/staffchat/StaffChatManager.java
@@ -1,6 +1,8 @@
package com.songoda.ultimatemoderation.staffchat;
-import java.util.*;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
public class StaffChatManager {
diff --git a/src/main/java/com/songoda/ultimatemoderation/storage/Storage.java b/src/main/java/com/songoda/ultimatemoderation/storage/Storage.java
deleted file mode 100644
index 63a6931..0000000
--- a/src/main/java/com/songoda/ultimatemoderation/storage/Storage.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.songoda.ultimatemoderation.storage;
-
-import com.songoda.core.configuration.Config;
-import com.songoda.ultimatemoderation.UltimateModeration;
-import com.songoda.ultimatemoderation.punish.AppliedPunishment;
-import com.songoda.ultimatemoderation.punish.PunishmentNote;
-import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
-import com.songoda.ultimatemoderation.punish.template.Template;
-import com.songoda.ultimatemoderation.tickets.Ticket;
-import com.songoda.ultimatemoderation.tickets.TicketResponse;
-import com.songoda.ultimatemoderation.utils.Methods;
-
-import java.util.List;
-
-public abstract class Storage {
-
- protected final UltimateModeration plugin;
- protected final Config dataFile;
-
- public Storage(UltimateModeration plugin) {
- this.plugin = plugin;
- this.dataFile = new Config(plugin, "data.yml");
- this.dataFile.load();
- }
-
- public abstract boolean containsGroup(String group);
-
- public abstract List getRowsByGroup(String group);
-
- public abstract void prepareSaveItem(String group, StorageItem... items);
-
- public void updateData(UltimateModeration instance) {
- }
-
- public abstract void doSave();
-
- public abstract void save();
-
- public abstract void makeBackup();
-
- public abstract void closeConnection();
-
-}
diff --git a/src/main/java/com/songoda/ultimatemoderation/storage/StorageItem.java b/src/main/java/com/songoda/ultimatemoderation/storage/StorageItem.java
deleted file mode 100644
index 0c2b261..0000000
--- a/src/main/java/com/songoda/ultimatemoderation/storage/StorageItem.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.songoda.ultimatemoderation.storage;
-
-import org.bukkit.Material;
-import org.bukkit.entity.EntityType;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-public class StorageItem {
-
- private final Object object;
- private String key = null;
-
- public StorageItem(Object object) {
- this.object = object;
- }
-
- public StorageItem(String key, Object object) {
- this.key = key;
- this.object = object;
- }
-
- public StorageItem(String key, List material) {
- String object = "";
- for (Material m : material) {
- object += m.name() + ";";
- }
- this.key = key;
- this.object = object;
- }
-
- public String getKey() {
- return key;
- }
-
- public String asString() {
- if (object == null) return null;
- return (String) object;
- }
-
- public long asLong() {
- if (object == null) return -1;
- if (object instanceof Integer) {
- return (long)((int)object);
- }
- return (long) object;
- }
-
- public boolean asBoolean() {
- if (object == null) return false;
- return (boolean) object;
- }
-
- public int asInt() {
- if (object == null) return 0;
- return (int) object;
- }
-
- public Object asObject() {
- return object;
- }
-
-}
diff --git a/src/main/java/com/songoda/ultimatemoderation/storage/StorageRow.java b/src/main/java/com/songoda/ultimatemoderation/storage/StorageRow.java
deleted file mode 100644
index 134b01f..0000000
--- a/src/main/java/com/songoda/ultimatemoderation/storage/StorageRow.java
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.songoda.ultimatemoderation.storage;
-
-import java.util.Collections;
-import java.util.Map;
-
-public class StorageRow {
-
- private final String key;
-
- private final Map items;
-
- public StorageRow(String key, Map items) {
- this.key = key;
- this.items = items;
- }
-
- public String getKey() {
- return key;
- }
-
- public Map getItems() {
- return Collections.unmodifiableMap(items);
- }
-
- public StorageItem get(String key) {
- if (!items.containsKey(key) || items.get(key).asObject().toString().equals("")) return new StorageItem(null);
- return items.get(key);
- }
-}
diff --git a/src/main/java/com/songoda/ultimatemoderation/storage/types/StorageYaml.java b/src/main/java/com/songoda/ultimatemoderation/storage/types/StorageYaml.java
deleted file mode 100644
index 2296ee4..0000000
--- a/src/main/java/com/songoda/ultimatemoderation/storage/types/StorageYaml.java
+++ /dev/null
@@ -1,148 +0,0 @@
-package com.songoda.ultimatemoderation.storage.types;
-
-import com.songoda.ultimatemoderation.UltimateModeration;
-import com.songoda.ultimatemoderation.storage.Storage;
-import com.songoda.ultimatemoderation.storage.StorageItem;
-import com.songoda.ultimatemoderation.storage.StorageRow;
-import org.bukkit.configuration.ConfigurationSection;
-import org.bukkit.configuration.MemorySection;
-
-import java.io.*;
-import java.util.*;
-
-public class StorageYaml extends Storage {
-
- private final Map toSave = new HashMap<>();
- private Map lastSave = null;
-
- public StorageYaml(UltimateModeration plugin) {
- super(plugin);
- }
-
- @Override
- public boolean containsGroup(String group) {
- return dataFile.contains("data." + group);
- }
-
- @Override
- public List getRowsByGroup(String group) {
- List rows = new ArrayList<>();
- ConfigurationSection currentSection = dataFile.getConfigurationSection("data." + group);
- for (String key : currentSection.getKeys(false)) {
-
- Map items = new HashMap<>();
- ConfigurationSection currentSection2 = dataFile.getConfigurationSection("data." + group + "." + key);
- for (String key2 : currentSection2.getKeys(false)) {
- String path = "data." + group + "." + key + "." + key2;
- items.put(key2, new StorageItem(dataFile.get(path) instanceof MemorySection
- ? convertToInLineList(path) : dataFile.get(path)));
- }
- if (items.isEmpty()) continue;
- StorageRow row = new StorageRow(key, items);
- rows.add(row);
- }
- return rows;
- }
-
- private String convertToInLineList(String path) {
- StringBuilder converted = new StringBuilder();
- for (String key : dataFile.getConfigurationSection(path).getKeys(false)) {
- converted.append(key).append(":").append(dataFile.getInt(path + "." + key)).append(";");
- }
- return converted.toString();
- }
-
- @Override
- public void prepareSaveItem(String group, StorageItem... items) {
- for (StorageItem item : items) {
- if (item == null || item.asObject() == null) continue;
- toSave.put("data." + group + "." + items[0].asString() + "." + item.getKey(), item.asObject());
- }
- }
-
- @Override
- public void doSave() {
- this.updateData(plugin);
-
- if (lastSave == null)
- lastSave = new HashMap<>(toSave);
-
- if (toSave.isEmpty()) return;
- Map nextSave = new HashMap<>(toSave);
-
- this.makeBackup();
- this.save();
-
- toSave.clear();
- lastSave.clear();
- lastSave.putAll(nextSave);
- }
-
- @Override
- public void save() {
- try {
- for (Map.Entry entry : lastSave.entrySet()) {
- if (toSave.containsKey(entry.getKey())) {
- Object newValue = toSave.get(entry.getKey());
- if (!entry.getValue().equals(newValue)) {
- dataFile.set(entry.getKey(), newValue);
- }
- toSave.remove(entry.getKey());
- } else {
- dataFile.set(entry.getKey(), null);
- }
- }
-
- for (Map.Entry entry : toSave.entrySet()) {
- dataFile.set(entry.getKey(), entry.getValue());
- }
-
- dataFile.save();
- } catch (NullPointerException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void makeBackup() {
- File data = new File(plugin.getDataFolder(), "data.yml");
- File dataClone = new File(plugin.getDataFolder(), "data-backup-" + System.currentTimeMillis() + ".yml");
- try {
- if (data.exists())
- copyFile(data, dataClone);
- } catch (IOException e) {
- e.printStackTrace();
- }
- Deque backups = new ArrayDeque<>();
- for (File file : Objects.requireNonNull(plugin.getDataFolder().listFiles())) {
- if (file.getName().toLowerCase().contains("data-backup")) {
- backups.add(file);
- }
- }
- if (backups.size() > 3) {
- backups.getFirst().delete();
- }
- }
-
- @Override
- public void closeConnection() {
- dataFile.save();
- }
-
- private static void copyFile(File source, File dest) throws IOException {
- InputStream is = null;
- OutputStream os = null;
- try {
- is = new FileInputStream(source);
- os = new FileOutputStream(dest);
- byte[] buffer = new byte[1024];
- int length;
- while ((length = is.read(buffer)) > 0) {
- os.write(buffer, 0, length);
- }
- } finally {
- is.close();
- os.close();
- }
- }
-}
diff --git a/src/main/java/com/songoda/ultimatemoderation/tickets/TicketManager.java b/src/main/java/com/songoda/ultimatemoderation/tickets/TicketManager.java
index 406530f..0a718ed 100644
--- a/src/main/java/com/songoda/ultimatemoderation/tickets/TicketManager.java
+++ b/src/main/java/com/songoda/ultimatemoderation/tickets/TicketManager.java
@@ -2,7 +2,10 @@ package com.songoda.ultimatemoderation.tickets;
import org.bukkit.OfflinePlayer;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.TreeMap;
+import java.util.UUID;
import java.util.stream.Collectors;
public class TicketManager {
diff --git a/src/main/java/com/songoda/ultimatemoderation/utils/Methods.java b/src/main/java/com/songoda/ultimatemoderation/utils/Methods.java
index 3286470..ee46cc8 100644
--- a/src/main/java/com/songoda/ultimatemoderation/utils/Methods.java
+++ b/src/main/java/com/songoda/ultimatemoderation/utils/Methods.java
@@ -2,7 +2,11 @@ package com.songoda.ultimatemoderation.utils;
import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration;
-import org.bukkit.*;
+import org.bukkit.Bukkit;
+import org.bukkit.ChatColor;
+import org.bukkit.Location;
+import org.bukkit.Material;
+import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
diff --git a/src/main/java/com/songoda/ultimatemoderation/utils/VaultPermissions.java b/src/main/java/com/songoda/ultimatemoderation/utils/VaultPermissions.java
index b3d0dee..b024e8d 100644
--- a/src/main/java/com/songoda/ultimatemoderation/utils/VaultPermissions.java
+++ b/src/main/java/com/songoda/ultimatemoderation/utils/VaultPermissions.java
@@ -18,7 +18,8 @@ public class VaultPermissions {
}
public static boolean hasPermission(OfflinePlayer offlinePlayer, String perm) {
- if (vaultPermission != null) return vaultPermission.playerHas(Bukkit.getWorlds().get(0).getName(), offlinePlayer, perm);
+ if (vaultPermission != null)
+ return vaultPermission.playerHas(Bukkit.getWorlds().get(0).getName(), offlinePlayer, perm);
return false;
}
}