Merge branch 'development'

This commit is contained in:
Brianna 2020-09-08 16:32:14 -05:00
commit ac0844d34b
48 changed files with 305 additions and 674 deletions

View File

@ -2,7 +2,7 @@
<groupId>com.songoda</groupId> <groupId>com.songoda</groupId>
<artifactId>UltimateModeration</artifactId> <artifactId>UltimateModeration</artifactId>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<version>2.0.1</version> <version>2.0.2</version>
<build> <build>
<defaultGoal>clean install</defaultGoal> <defaultGoal>clean install</defaultGoal>
<finalName>UltimateModeration-${project.version}</finalName> <finalName>UltimateModeration-${project.version}</finalName>

View File

@ -18,30 +18,18 @@ import com.songoda.ultimatemoderation.listeners.*;
import com.songoda.ultimatemoderation.moderate.ModerationManager; import com.songoda.ultimatemoderation.moderate.ModerationManager;
import com.songoda.ultimatemoderation.punish.AppliedPunishment; import com.songoda.ultimatemoderation.punish.AppliedPunishment;
import com.songoda.ultimatemoderation.punish.PunishmentNote; import com.songoda.ultimatemoderation.punish.PunishmentNote;
import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.punish.player.PunishmentManager; import com.songoda.ultimatemoderation.punish.player.PunishmentManager;
import com.songoda.ultimatemoderation.punish.template.Template; import com.songoda.ultimatemoderation.punish.template.Template;
import com.songoda.ultimatemoderation.punish.template.TemplateManager; import com.songoda.ultimatemoderation.punish.template.TemplateManager;
import com.songoda.ultimatemoderation.settings.Settings; import com.songoda.ultimatemoderation.settings.Settings;
import com.songoda.ultimatemoderation.staffchat.StaffChatManager; 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.tasks.SlowModeTask;
import com.songoda.ultimatemoderation.tickets.Ticket; import com.songoda.ultimatemoderation.tickets.Ticket;
import com.songoda.ultimatemoderation.tickets.TicketManager; 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.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import java.io.File;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.UUID;
public class UltimateModeration extends SongodaPlugin { public class UltimateModeration extends SongodaPlugin {
private static UltimateModeration INSTANCE; private static UltimateModeration INSTANCE;
@ -55,7 +43,6 @@ public class UltimateModeration extends SongodaPlugin {
private ModerationManager moderationManager; private ModerationManager moderationManager;
private DatabaseConnector databaseConnector; private DatabaseConnector databaseConnector;
private DataMigrationManager dataMigrationManager;
private DataManager dataManager; private DataManager dataManager;
public static UltimateModeration getInstance() { public static UltimateModeration getInstance() {
@ -96,11 +83,11 @@ public class UltimateModeration extends SongodaPlugin {
this.commandManager.addCommand(new CommandRunTemplate(this)); this.commandManager.addCommand(new CommandRunTemplate(this));
this.commandManager.addCommand(new CommandSlowMode(this)); this.commandManager.addCommand(new CommandSlowMode(this));
this.commandManager.addCommand(new CommandStaffChat(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 CommandToggleChat(this));
this.commandManager.addCommand(new CommandUnBan(this)); this.commandManager.addCommand(new CommandUnBan(this));
this.commandManager.addCommand(new CommandUnMute(this)); this.commandManager.addCommand(new CommandUnMute(this));
this.commandManager.addCommand(new CommandVanish(this)); this.commandManager.addCommand(new CommandVanish());
this.commandManager.addCommand(new CommandWarn(this)); this.commandManager.addCommand(new CommandWarn(this));
// Setup Managers // Setup Managers
@ -128,9 +115,9 @@ public class UltimateModeration extends SongodaPlugin {
} }
this.dataManager = new DataManager(this.databaseConnector, this); 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()); new _1_InitialMigration());
this.dataMigrationManager.runMigrations(); dataMigrationManager.runMigrations();
} catch (Exception ex) { } catch (Exception ex) {
this.getLogger().severe("Fatal error trying to connect to database. " + this.getLogger().severe("Fatal error trying to connect to database. " +
@ -139,108 +126,6 @@ public class UltimateModeration extends SongodaPlugin {
return; 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<Integer, Ticket> 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 // Register Listeners
guiManager.init(); guiManager.init();
PluginManager pluginManager = Bukkit.getPluginManager(); PluginManager pluginManager = Bukkit.getPluginManager();
@ -263,6 +148,30 @@ public class UltimateModeration extends SongodaPlugin {
SlowModeTask.startTask(this); 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 @Override
public void onConfigReload() { public void onConfigReload() {
this.setLocale(getConfig().getString("System.Language Mode"), true); this.setLocale(getConfig().getString("System.Language Mode"), true);

View File

@ -18,11 +18,11 @@ import java.util.List;
public class CommandBan extends AbstractCommand { 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"); super(CommandType.CONSOLE_OK, "Ban");
this.instance = instance; this.plugin = plugin;
} }
@Override @Override
@ -50,25 +50,25 @@ public class CommandBan extends AbstractCommand {
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
if (!player.hasPlayedBefore()) { 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; return ReturnType.FAILURE;
} }
if (instance.getPunishmentManager().getPlayer(player).getActivePunishments() if (plugin.getPunishmentManager().getPlayer(player).getActivePunishments()
.stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.BAN)) { .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; return ReturnType.FAILURE;
} }
if (duration == 0 && !sender.hasPermission("um.ban.permanent")) { 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; return ReturnType.FAILURE;
} }
long durationFinal = duration; long durationFinal = duration;
Bukkit.getScheduler().runTaskAsynchronously(instance, () -> { Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
if (sender instanceof Player && VaultPermissions.hasPermission(player, "um.ban.exempt")) { 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; return;
} }

View File

@ -12,11 +12,11 @@ import java.util.List;
public class CommandClearChat extends AbstractCommand { 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"); super(CommandType.PLAYER_ONLY, "ClearChat");
this.instance = instance; this.plugin = plugin;
} }
@Override @Override
@ -32,11 +32,11 @@ public class CommandClearChat extends AbstractCommand {
player.sendMessage(toSend); player.sendMessage(toSend);
} }
instance.getLocale().getMessage("command.clearchat.cleared") plugin.getLocale().getMessage("command.clearchat.cleared")
.processPlaceholder("player", sender.getName()).sendPrefixedMessage(player); .processPlaceholder("player", sender.getName()).sendPrefixedMessage(player);
if (player.hasPermission("um.clearchat.bypass") && !isForced(args)) { 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; return ReturnType.SUCCESS;

View File

@ -9,23 +9,23 @@ import java.util.List;
public class CommandHelp extends AbstractCommand { 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"); super(CommandType.CONSOLE_OK, "help");
this.instance = instance; this.plugin = plugin;
} }
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
sender.sendMessage(""); 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); .sendPrefixedMessage(sender);
sender.sendMessage(""); sender.sendMessage("");
sender.sendMessage(Methods.formatText("&7Welcome to UltimateModeration! To get started try using the /um command to access the moderation panel.")); sender.sendMessage(Methods.formatText("&7Welcome to UltimateModeration! To get started try using the /um command to access the moderation panel."));
sender.sendMessage(""); sender.sendMessage("");
sender.sendMessage(Methods.formatText("&6Commands:")); 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())) { if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription())); sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
} }

View File

@ -13,13 +13,13 @@ import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; 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"); super(CommandType.CONSOLE_OK, "Kick");
this.instance = instance; this.plugin = plugin;
} }
@Override @Override
@ -40,12 +40,12 @@ public class CommandKick extends AbstractCommand {
OfflinePlayer player = Bukkit.getPlayer(args[0]); OfflinePlayer player = Bukkit.getPlayer(args[0]);
if (player == null) { 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; return ReturnType.FAILURE;
} }
if (sender instanceof Player && player.getPlayer().hasPermission("um.kick.exempt")) { 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; return ReturnType.FAILURE;
} }

View File

@ -18,11 +18,11 @@ import java.util.List;
public class CommandMute extends AbstractCommand { 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"); super(CommandType.CONSOLE_OK, "Mute");
this.instance = instance; this.plugin = plugin;
} }
@Override @Override
@ -50,18 +50,18 @@ public class CommandMute extends AbstractCommand {
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
if (!player.hasPlayedBefore()) { 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; return ReturnType.FAILURE;
} }
if (sender instanceof Player && VaultPermissions.hasPermission(player, "um.mute.exempt")) { 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; return ReturnType.FAILURE;
} }
if (instance.getPunishmentManager().getPlayer(player).getActivePunishments() if (plugin.getPunishmentManager().getPlayer(player).getActivePunishments()
.stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.MUTE)) { .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; return ReturnType.FAILURE;
} }

View File

@ -12,11 +12,11 @@ import java.util.List;
public class CommandRandomPlayer extends AbstractCommand { 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"); super(CommandType.PLAYER_ONLY, "RandomPlayer");
this.instance = instance; this.plugin = plugin;
} }
@Override @Override
@ -26,7 +26,7 @@ public class CommandRandomPlayer extends AbstractCommand {
players.remove(sender); players.remove(sender);
if (players.size() == 0) { 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; return ReturnType.FAILURE;
} }

View File

@ -8,17 +8,17 @@ import java.util.List;
public class CommandReload extends AbstractCommand { 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"); super(CommandType.CONSOLE_OK, "reload");
this.instance = instance; this.plugin = plugin;
} }
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
instance.reloadConfig(); plugin.reloadConfig();
instance.getLocale().newMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender); plugin.getLocale().newMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} }

View File

@ -13,11 +13,11 @@ import java.util.List;
public class CommandRunTemplate extends AbstractCommand { 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"); super(CommandType.CONSOLE_OK, "RunTemplate");
this.instance = instance; this.plugin = plugin;
} }
@Override @Override
@ -27,8 +27,8 @@ public class CommandRunTemplate extends AbstractCommand {
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
if (player == null) { 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; return ReturnType.FAILURE;
} }
@ -39,7 +39,7 @@ public class CommandRunTemplate extends AbstractCommand {
} }
String templateStr = templateBuilder.toString().trim(); String templateStr = templateBuilder.toString().trim();
Template template = instance.getTemplateManager().getTemplate(templateStr); Template template = plugin.getTemplateManager().getTemplate(templateStr);
if (template == null) { if (template == null) {
sender.sendMessage("That template does not exist..."); sender.sendMessage("That template does not exist...");
@ -61,7 +61,7 @@ public class CommandRunTemplate extends AbstractCommand {
return players; return players;
} else if (args.length == 2) { } else if (args.length == 2) {
List<String> lines = new ArrayList<>(); List<String> lines = new ArrayList<>();
for (Template template : instance.getTemplateManager().getTemplates().values()) { for (Template template : plugin.getTemplateManager().getTemplates()) {
lines.add(template.getName()); lines.add(template.getName());
} }
} }

View File

@ -11,19 +11,19 @@ import java.util.List;
public class CommandSettings extends AbstractCommand { public class CommandSettings extends AbstractCommand {
final UltimateModeration instance; private final UltimateModeration plugin;
final GuiManager guiManager; private final GuiManager guiManager;
public CommandSettings(UltimateModeration instance, GuiManager manager) { public CommandSettings(UltimateModeration plugin, GuiManager manager) {
super(CommandType.PLAYER_ONLY, "settings"); super(CommandType.PLAYER_ONLY, "settings");
this.instance = instance; this.plugin = plugin;
this.guiManager = manager; this.guiManager = manager;
} }
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
Player player = (Player) sender; Player player = (Player) sender;
guiManager.showGUI((Player) sender, new PluginConfigGui(instance)); guiManager.showGUI((Player) sender, new PluginConfigGui(plugin));
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} }

View File

@ -13,18 +13,18 @@ import java.util.List;
public class CommandSlowMode extends AbstractCommand { 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"); super(CommandType.CONSOLE_OK, "Slowmode");
this.instance = instance; this.plugin = plugin;
} }
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
if (args.length == 0) { if (args.length == 0) {
ChatListener.setSlowModeOverride(0); ChatListener.setSlowModeOverride(0);
instance.getLocale().getMessage("event.slowmode.disabled").sendPrefixedMessage(sender); plugin.getLocale().getMessage("event.slowmode.disabled").sendPrefixedMessage(sender);
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} else if (args.length != 1) } else if (args.length != 1)
return ReturnType.SYNTAX_ERROR; return ReturnType.SYNTAX_ERROR;
@ -34,7 +34,7 @@ public class CommandSlowMode extends AbstractCommand {
ChatListener.setSlowModeOverride(delay); ChatListener.setSlowModeOverride(delay);
Bukkit.getOnlinePlayers().forEach(player -> Bukkit.getOnlinePlayers().forEach(player ->
instance.getLocale().getMessage("event.slowmode.enabled") plugin.getLocale().getMessage("event.slowmode.enabled")
.processPlaceholder("delay", Methods.makeReadable(delay)).sendPrefixedMessage(player)); .processPlaceholder("delay", Methods.makeReadable(delay)).sendPrefixedMessage(player));
return ReturnType.SUCCESS; return ReturnType.SUCCESS;

View File

@ -11,11 +11,11 @@ import java.util.List;
public class CommandStaffChat extends AbstractCommand { 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"); super(CommandType.PLAYER_ONLY, "StaffChat");
this.instance = instance; this.plugin = plugin;
} }
@Override @Override
@ -27,26 +27,26 @@ public class CommandStaffChat extends AbstractCommand {
Player player = (Player) sender; Player player = (Player) sender;
if (channelName.trim().equalsIgnoreCase("leave")) { 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; if (!channel.listMembers().contains(player.getUniqueId())) continue;
channel.removeMember(player); channel.removeMember(player);
instance.getLocale().getMessage("event.staffchat.leave") plugin.getLocale().getMessage("event.staffchat.leave")
.processPlaceholder("channel", channel.getChannelName()).sendPrefixedMessage(player); .processPlaceholder("channel", channel.getChannelName()).sendPrefixedMessage(player);
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} }
instance.getLocale().getMessage("event.staffchat.nochannels").sendPrefixedMessage(player); plugin.getLocale().getMessage("event.staffchat.nochannels").sendPrefixedMessage(player);
return ReturnType.FAILURE; return ReturnType.FAILURE;
} }
instance.getLocale().getMessage("event.staffchat.join") plugin.getLocale().getMessage("event.staffchat.join")
.processPlaceholder("channel", channelName).sendPrefixedMessage(player); .processPlaceholder("channel", channelName).sendPrefixedMessage(player);
instance.getStaffChatManager().getChat(channelName).addMember(player); plugin.getStaffChatManager().getChat(channelName).addMember(player);
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} }
@Override @Override
protected List<String> onTab(CommandSender sender, String... args) { protected List<String> onTab(CommandSender sender, String... args) {
return new ArrayList<>(instance.getStaffChatManager().getChats().keySet()); return new ArrayList<>(plugin.getStaffChatManager().getChats().keySet());
} }
@Override @Override

View File

@ -1,6 +1,7 @@
package com.songoda.ultimatemoderation.commands; package com.songoda.ultimatemoderation.commands;
import com.songoda.core.commands.AbstractCommand; import com.songoda.core.commands.AbstractCommand;
import com.songoda.core.gui.GuiManager;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.gui.TicketManagerGui; import com.songoda.ultimatemoderation.gui.TicketManagerGui;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -10,18 +11,19 @@ import java.util.List;
public class CommandTicket extends AbstractCommand { 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"); super(CommandType.PLAYER_ONLY, "Ticket");
this.instance = instance; this.plugin = plugin;
this.guiManager = guiManager;
} }
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
Player senderP = ((Player) sender); Player senderP = ((Player) sender);
guiManager.showGUI(senderP, new TicketManagerGui(plugin, senderP, senderP));
new TicketManagerGui(instance, senderP, senderP);
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} }

View File

@ -12,24 +12,24 @@ import java.util.List;
public class CommandToggleChat extends AbstractCommand { public class CommandToggleChat extends AbstractCommand {
private UltimateModeration instance; private final UltimateModeration plugin;
/* /*
* Chat is enabled by default ;) * Chat is enabled by default ;)
*/ */
private boolean toggled = true; private boolean toggled = true;
public CommandToggleChat(UltimateModeration instance) { public CommandToggleChat(UltimateModeration plugin) {
super(CommandType.PLAYER_ONLY, "togglechat"); super(CommandType.PLAYER_ONLY, "togglechat");
this.instance = instance; this.plugin = plugin;
} }
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { protected ReturnType runCommand(CommandSender sender, String... args) {
toggled = !toggled; toggled = !toggled;
Message message = toggled ? instance.getLocale().getMessage("command.togglechat.toggledOn") Message message = toggled ? plugin.getLocale().getMessage("command.togglechat.toggledOn")
: instance.getLocale().getMessage("command.togglechat.toggledOff"); : plugin.getLocale().getMessage("command.togglechat.toggledOff");
ChatListener.setChatToggled(toggled); ChatListener.setChatToggled(toggled);
@ -40,7 +40,7 @@ public class CommandToggleChat extends AbstractCommand {
if (!player.hasPermission(getPermissionNode() + ".bypass")) if (!player.hasPermission(getPermissionNode() + ".bypass"))
continue; continue;
instance.getLocale().getMessage("command.togglechat.bypass").sendMessage(player); plugin.getLocale().getMessage("command.togglechat.bypass").sendMessage(player);
} }
if (!(sender instanceof Player)) if (!(sender instanceof Player))

View File

@ -10,16 +10,16 @@ import java.util.List;
public class CommandUltimateModeration extends AbstractCommand { 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"); super(CommandType.PLAYER_ONLY, "UltimateModeration");
this.instance = instance; this.plugin = plugin;
} }
@Override @Override
protected ReturnType runCommand(CommandSender sender, String... args) { 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; return ReturnType.SUCCESS;
} }

View File

@ -14,11 +14,11 @@ import java.util.List;
public class CommandUnBan extends AbstractCommand { 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"); super(CommandType.CONSOLE_OK, "UnBan");
this.instance = instance; this.plugin = plugin;
} }
@Override @Override
@ -29,21 +29,21 @@ public class CommandUnBan extends AbstractCommand {
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
if (!player.hasPlayedBefore()) { 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; return ReturnType.FAILURE;
} }
if (!instance.getPunishmentManager().getPlayer(player).getActivePunishments() if (!plugin.getPunishmentManager().getPlayer(player).getActivePunishments()
.stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.BAN)) { .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; return ReturnType.FAILURE;
} }
PlayerPunishData playerPunishData = instance.getPunishmentManager().getPlayer(player); PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(player);
playerPunishData.expirePunishments(PunishmentType.BAN); playerPunishData.expirePunishments(PunishmentType.BAN);
instance.getLocale().getMessage("event.unban.success") plugin.getLocale().getMessage("event.unban.success")
.processPlaceholder("player", player.getName()).sendPrefixedMessage(sender); .processPlaceholder("player", player.getName()).sendPrefixedMessage(sender);
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} }

View File

@ -14,11 +14,11 @@ import java.util.List;
public class CommandUnMute extends AbstractCommand { 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"); super(CommandType.CONSOLE_OK, "UnMute");
this.instance = instance; this.plugin = plugin;
} }
@Override @Override
@ -28,22 +28,22 @@ public class CommandUnMute extends AbstractCommand {
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
if (player == null) { 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; return ReturnType.FAILURE;
} }
if (!instance.getPunishmentManager().getPlayer(player).getActivePunishments() if (!plugin.getPunishmentManager().getPlayer(player).getActivePunishments()
.stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.MUTE)) { .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; return ReturnType.FAILURE;
} }
PlayerPunishData playerPunishData = instance.getPunishmentManager().getPlayer(player); PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(player);
playerPunishData.expirePunishments(PunishmentType.MUTE); 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); .processPlaceholder("player", player.getName()).getMessage()).sendPrefixedMessage(sender);
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} }

View File

@ -19,13 +19,10 @@ import java.util.UUID;
public class CommandVanish extends AbstractCommand { public class CommandVanish extends AbstractCommand {
private UltimateModeration instance; private static final List<UUID> inVanish = new ArrayList<>();
private static List<UUID> inVanish = new ArrayList<>(); public CommandVanish() {
public CommandVanish(UltimateModeration instance) {
super(CommandType.PLAYER_ONLY, "Vanish"); super(CommandType.PLAYER_ONLY, "Vanish");
this.instance = instance;
} }
public static void registerVanishedPlayers(Player player) { public static void registerVanishedPlayers(Player player) {

View File

@ -18,11 +18,11 @@ import java.util.List;
public class CommandWarn extends AbstractCommand { 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"); super(CommandType.CONSOLE_OK, "Warn");
this.instance = instance; this.plugin = plugin;
} }
@Override @Override
@ -50,12 +50,12 @@ public class CommandWarn extends AbstractCommand {
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]); OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
if (!player.hasPlayedBefore()) { 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; return ReturnType.FAILURE;
} }
if (sender instanceof Player && VaultPermissions.hasPermission(player, "um.warning.exempt")) { 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; return ReturnType.FAILURE;
} }

View File

@ -12,10 +12,15 @@ import com.songoda.ultimatemoderation.tickets.TicketStatus;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.Statement; 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; import java.util.function.Consumer;
public class DataManager extends DataManagerAbstract { public class DataManager extends DataManagerAbstract {

View File

@ -29,7 +29,7 @@ public class MainGui extends Gui {
private Online currentOnline = Online.ONLINE; private Online currentOnline = Online.ONLINE;
private List<UUID> players = new ArrayList<>(); private final List<UUID> players = new ArrayList<>();
private final Player viewer; private final Player viewer;
public MainGui(UltimateModeration plugin, Player viewer) { public MainGui(UltimateModeration plugin, Player viewer) {
@ -83,7 +83,8 @@ public class MainGui extends Gui {
List<UUID> found = players.stream().filter(uuid -> Bukkit.getOfflinePlayer(uuid).getName().toLowerCase().contains(gui.getInputText().toLowerCase())).collect(Collectors.toList()); List<UUID> found = players.stream().filter(uuid -> Bukkit.getOfflinePlayer(uuid).getName().toLowerCase().contains(gui.getInputText().toLowerCase())).collect(Collectors.toList());
if (found.size() >= 1) { if (found.size() >= 1) {
this.players = found; this.players.clear();
this.players.addAll(found);
showPage(); showPage();
} else { } else {
plugin.getLocale().getMessage("gui.players.nonefound").sendMessage(event.player); 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))); 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<UUID> toUseFinal = toUse.stream().skip((page - 1) * 28).limit(28).collect(Collectors.toList());
int num = 11; Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
for (UUID uuid : toUse) { int num = 11;
if (num == 16 || num == 36) for (UUID uuid : toUseFinal) {
num = num + 2; if (num == 16 || num == 36)
OfflinePlayer pl = Bukkit.getOfflinePlayer(uuid); num = num + 2;
ItemStack skull = ItemUtils.getPlayerSkull(pl); OfflinePlayer pl = Bukkit.getOfflinePlayer(uuid);
setItem(num, skull); ItemStack skull = ItemUtils.getPlayerSkull(pl);
setItem(num, skull);
PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(pl); PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(pl);
ArrayList<String> lore = new ArrayList<>(); ArrayList<String> lore = new ArrayList<>();
lore.add(plugin.getLocale().getMessage("gui.players.click").getMessage()); lore.add(plugin.getLocale().getMessage("gui.players.click").getMessage());
lore.add(""); lore.add("");
int ticketAmt = (int) plugin.getTicketManager().getTicketsAbout(pl).stream() int ticketAmt = (int) plugin.getTicketManager().getTicketsAbout(pl).stream()
.filter(t -> t.getStatus() == TicketStatus.OPEN).count(); .filter(t -> t.getStatus() == TicketStatus.OPEN).count();
if (ticketAmt == 0) if (ticketAmt == 0)
lore.add(plugin.getLocale().getMessage("gui.players.notickets").getMessage()); lore.add(plugin.getLocale().getMessage("gui.players.notickets").getMessage());
else { else {
if (ticketAmt == 1) if (ticketAmt == 1)
lore.add(plugin.getLocale().getMessage("gui.players.ticketsone").getMessage()); lore.add(plugin.getLocale().getMessage("gui.players.ticketsone").getMessage());
else else
lore.add(plugin.getLocale().getMessage("gui.players.tickets") lore.add(plugin.getLocale().getMessage("gui.players.tickets")
.processPlaceholder("amount", ticketAmt).getMessage()); .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 // enable page events
setNextPage(4, 7, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage())); setNextPage(4, 7, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()));

View File

@ -292,7 +292,8 @@ public class PunishGui extends Gui {
private void updateTemplate() { private void updateTemplate() {
Template template = new Template(this.type, this.duration, this.reason, this.template.getCreator(), this.templateName); 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().deleteTemplate(this.template);
plugin.getDataManager().createTemplate(template); plugin.getDataManager().createTemplate(template);
justSaved = true; justSaved = true;

View File

@ -91,18 +91,18 @@ public class PunishmentsGui extends Gui {
punishments = punishments.stream().skip((page - 1) * 28).limit(28) punishments = punishments.stream().skip((page - 1) * 28).limit(28)
.collect(Collectors.toList()); .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()), plugin.getLocale().getMessage("gui.general.back").getMessage()),
(event) -> guiManager.showGUI(event.player, new PlayerGui(plugin, toModerate, event.player))); (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) -> { (event) -> {
this.currentActivity = currentActivity.next(); this.currentActivity = currentActivity.next();
this.page = 1; this.page = 1;
showPage(); 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) -> { (event) -> {
this.punishmentType = punishmentType.nextFilter(); this.punishmentType = punishmentType.nextFilter();
this.page = 1; this.page = 1;
@ -152,7 +152,7 @@ public class PunishmentsGui extends Gui {
} }
}); });
num ++; num++;
} }
} }

View File

@ -5,7 +5,6 @@ import com.songoda.core.gui.Gui;
import com.songoda.core.gui.GuiUtils; import com.songoda.core.gui.GuiUtils;
import com.songoda.core.utils.TextUtils; import com.songoda.core.utils.TextUtils;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.punish.PunishmentNote;
import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.punish.template.Template; import com.songoda.ultimatemoderation.punish.template.Template;
import com.songoda.ultimatemoderation.settings.Settings; import com.songoda.ultimatemoderation.settings.Settings;
@ -42,7 +41,7 @@ public class TemplateManagerGui extends Gui {
int numTemplates = plugin.getTemplateManager().getTemplates().size(); int numTemplates = plugin.getTemplateManager().getTemplates().size();
this.pages = (int) Math.floor(numTemplates / 28.0); this.pages = (int) Math.floor(numTemplates / 28.0);
List<Template> templates = plugin.getTemplateManager().getTemplates().values().stream().skip((page - 1) * 28).limit(28) List<Template> templates = plugin.getTemplateManager().getTemplates().stream().skip((page - 1) * 28).limit(28)
.collect(Collectors.toList()); .collect(Collectors.toList());
setNextPage(0, 5, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage())); 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")) if (player.hasPermission("um.templates.edit"))
guiManager.showGUI(player, new PunishGui(plugin, null, template, player)); guiManager.showGUI(player, new PunishGui(plugin, null, template, player));
} else if (event.clickType == ClickType.RIGHT) { } else if (event.clickType == ClickType.RIGHT) {
if (player.hasPermission("um.templates.destroy")) if (player.hasPermission("um.templates.destroy")) {
plugin.getTemplateManager().removeTemplate(template); plugin.getTemplateManager().removeTemplate(template);
plugin.getDataManager().deleteTemplate(template);
}
showPage(); showPage();
} }
}); });
num ++; num++;
} }
} }

View File

@ -13,7 +13,7 @@ import java.util.ArrayList;
public class TemplateSelectorGui extends Gui { public class TemplateSelectorGui extends Gui {
private final UltimateModeration plugin; private final UltimateModeration plugin;
private PunishGui punish; private final PunishGui punish;
public TemplateSelectorGui(UltimateModeration plugin, PunishGui punish, Player player) { public TemplateSelectorGui(UltimateModeration plugin, PunishGui punish, Player player) {
super(6); super(6);
@ -33,7 +33,7 @@ public class TemplateSelectorGui extends Gui {
punish.runTask(); punish.runTask();
}); });
ArrayList<Template> templates = new ArrayList<>(plugin.getTemplateManager().getTemplates().values()); ArrayList<Template> templates = new ArrayList<>(plugin.getTemplateManager().getTemplates());
for (int i = 0; i < templates.size(); i++) { for (int i = 0; i < templates.size(); i++) {
Template template = templates.get(i); Template template = templates.get(i);
setButton(18 + i, GuiUtils.createButtonItem(CompatibleMaterial.MAP, TextUtils.formatText("&6&l" + template.getName()), setButton(18 + i, GuiUtils.createButtonItem(CompatibleMaterial.MAP, TextUtils.formatText("&6&l" + template.getName()),

View File

@ -25,7 +25,7 @@ import java.util.stream.Collectors;
public class TicketGui extends Gui { public class TicketGui extends Gui {
private final UltimateModeration plugin; private final UltimateModeration plugin;
private StaffChatManager chatManager = UltimateModeration.getInstance().getStaffChatManager(); private final StaffChatManager chatManager = UltimateModeration.getInstance().getStaffChatManager();
private final Ticket ticket; private final Ticket ticket;
@ -99,7 +99,7 @@ public class TicketGui extends Gui {
(event) -> player.teleport(ticket.getLocation())); (event) -> player.teleport(ticket.getLocation()));
if (player.hasPermission("um.tickets.respond")) 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) -> { (event) -> {
ChatPrompt.showPrompt(plugin, player, plugin.getLocale().getMessage("gui.ticket.what").getMessage(), (evnt) -> { ChatPrompt.showPrompt(plugin, player, plugin.getLocale().getMessage("gui.ticket.what").getMessage(), (evnt) -> {
TicketResponse response = ticket.addResponse(new TicketResponse(player, evnt.getMessage(), System.currentTimeMillis())); 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()); .processPlaceholder("sent", format.format(new Date(ticketResponse.getPostedDate()))).getMessage());
setItem(num, GuiUtils.createButtonItem(CompatibleMaterial.MAP, TextUtils.formatText(name), lore)); setItem(num, GuiUtils.createButtonItem(CompatibleMaterial.MAP, TextUtils.formatText(name), lore));
num ++; num++;
} }
} }
} }

View File

@ -9,7 +9,6 @@ import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.settings.Settings; import com.songoda.ultimatemoderation.settings.Settings;
import com.songoda.ultimatemoderation.tickets.Ticket; import com.songoda.ultimatemoderation.tickets.Ticket;
import com.songoda.ultimatemoderation.tickets.TicketStatus; import com.songoda.ultimatemoderation.tickets.TicketStatus;
import com.songoda.ultimatemoderation.utils.Methods;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -19,7 +18,6 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class TicketManagerGui extends Gui { public class TicketManagerGui extends Gui {
@ -84,7 +82,7 @@ public class TicketManagerGui extends Gui {
}); });
if (toModerate != null && player.hasPermission("um.tickets.create")) 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()), plugin.getLocale().getMessage("gui.tickets.create").getMessage()),
(event) -> createNew(player, toModerate)); (event) -> createNew(player, toModerate));
@ -142,7 +140,7 @@ public class TicketManagerGui extends Gui {
setButton(num, GuiUtils.createButtonItem(CompatibleMaterial.MAP, setButton(num, GuiUtils.createButtonItem(CompatibleMaterial.MAP,
TextUtils.formatText(name), TextUtils.formatText(lore)), TextUtils.formatText(name), TextUtils.formatText(lore)),
(event) -> guiManager.showGUI(player, new TicketGui(plugin, ticket, toModerate, player))); (event) -> guiManager.showGUI(player, new TicketGui(plugin, ticket, toModerate, player)));
num ++; num++;
} }
} }

View File

@ -3,16 +3,18 @@ package com.songoda.ultimatemoderation.listeners;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.punish.AppliedPunishment; import com.songoda.ultimatemoderation.punish.AppliedPunishment;
import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.PunishmentType;
import com.songoda.ultimatemoderation.settings.Settings;
import com.songoda.ultimatemoderation.staffchat.StaffChannel; import com.songoda.ultimatemoderation.staffchat.StaffChannel;
import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.settings.Settings;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.AsyncPlayerChatEvent; 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; import java.util.stream.Collectors;
public class ChatListener implements Listener { public class ChatListener implements Listener {

View File

@ -2,16 +2,8 @@ package com.songoda.ultimatemoderation.listeners;
import com.songoda.skyblock.api.event.player.PlayerIslandChatEvent; import com.songoda.skyblock.api.event.player.PlayerIslandChatEvent;
import com.songoda.ultimatemoderation.UltimateModeration; 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.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import java.util.List;
public class SkyBlockListener implements Listener { public class SkyBlockListener implements Listener {

View File

@ -39,7 +39,8 @@ public class SpyingDismountListener implements Listener {
@EventHandler @EventHandler
public void onSneak(PlayerToggleSneakEvent event) { public void onSneak(PlayerToggleSneakEvent event) {
Player player = event.getPlayer(); 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); SpyModeration.spy(null, player);
} }

View File

@ -5,7 +5,6 @@ import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.utils.VaultPermissions; import com.songoda.ultimatemoderation.utils.VaultPermissions;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public abstract class AbstractModeration { public abstract class AbstractModeration {

View File

@ -12,56 +12,56 @@ import java.util.List;
public class GenericModerationCommand extends AbstractCommand { public class GenericModerationCommand extends AbstractCommand {
private final UltimateModeration plugin; private final UltimateModeration plugin;
private final AbstractModeration moderation; private final AbstractModeration moderation;
public GenericModerationCommand(UltimateModeration plugin, AbstractModeration moderation) { public GenericModerationCommand(UltimateModeration plugin, AbstractModeration moderation) {
super(moderation.isAllowConsole() ? CommandType.CONSOLE_OK : CommandType.PLAYER_ONLY, moderation.getProper()); super(moderation.isAllowConsole() ? CommandType.CONSOLE_OK : CommandType.PLAYER_ONLY, moderation.getProper());
this.plugin = plugin; this.plugin = plugin;
this.moderation = moderation; 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<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) {
List<String> 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() + " <player>";
}
@Override
public String getDescription() {
return moderation.getDescription();
}
} }
@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<String> onTab(CommandSender sender, String... args) {
if (args.length == 1) {
List<String> 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() + " <player>";
}
@Override
public String getDescription() {
return moderation.getDescription();
}
}

View File

@ -1,7 +1,11 @@
package com.songoda.ultimatemoderation.moderate; package com.songoda.ultimatemoderation.moderate;
import com.songoda.ultimatemoderation.UltimateModeration; 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.Collections;
import java.util.Map; import java.util.Map;

View File

@ -8,10 +8,6 @@ import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class InvSeeModeration extends AbstractModeration { public class InvSeeModeration extends AbstractModeration {
public InvSeeModeration(UltimateModeration plugin) { public InvSeeModeration(UltimateModeration plugin) {

View File

@ -11,10 +11,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.UUID;
public class ReviveModeration extends AbstractModeration { public class ReviveModeration extends AbstractModeration {

View File

@ -1,8 +1,8 @@
package com.songoda.ultimatemoderation.punish.player; package com.songoda.ultimatemoderation.punish.player;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.punish.PunishmentNote;
import com.songoda.ultimatemoderation.punish.AppliedPunishment; import com.songoda.ultimatemoderation.punish.AppliedPunishment;
import com.songoda.ultimatemoderation.punish.PunishmentNote;
import com.songoda.ultimatemoderation.punish.PunishmentType; import com.songoda.ultimatemoderation.punish.PunishmentType;
import java.util.ArrayList; import java.util.ArrayList;

View File

@ -1,13 +1,17 @@
package com.songoda.ultimatemoderation.punish.template; 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 { public class TemplateManager {
private static final Map<Integer, Template> templates = new HashMap<>(); private static final List<Template> templates = new LinkedList<>();
public Template getTemplate(String name) { public Template getTemplate(String name) {
for (Template template : templates.values()) { for (Template template : templates) {
if (formatName(template.getName()).equals(formatName(name))) if (formatName(template.getName()).equals(formatName(name)))
return template; return template;
} }
@ -15,20 +19,17 @@ public class TemplateManager {
} }
public Template addTemplate(Template template) { public Template addTemplate(Template template) {
return templates.put(template.getId(), template); templates.add(template);
return template;
} }
public Template removeTemplate(Template template) { public Template removeTemplate(Template template) {
return templates.remove(template.getId()); templates.remove(template);
return template;
} }
public Template updateTemplate(int id, Template template) { public List<Template> getTemplates() {
templates.remove(id); return Collections.unmodifiableList(templates);
return addTemplate(template);
}
public Map<Integer, Template> getTemplates() {
return Collections.unmodifiableMap(templates);
} }
private String formatName(String name) { private String formatName(String name) {

View File

@ -3,11 +3,9 @@ package com.songoda.ultimatemoderation.settings;
import com.songoda.core.compatibility.CompatibleMaterial; import com.songoda.core.compatibility.CompatibleMaterial;
import com.songoda.core.configuration.Config; import com.songoda.core.configuration.Config;
import com.songoda.core.configuration.ConfigSetting; import com.songoda.core.configuration.ConfigSetting;
import com.songoda.core.hooks.EconomyManager;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import java.util.Arrays; import java.util.Arrays;
import java.util.stream.Collectors;
public class Settings { public class Settings {

View File

@ -3,7 +3,6 @@ package com.songoda.ultimatemoderation.staffchat;
import com.songoda.ultimatemoderation.UltimateModeration; import com.songoda.ultimatemoderation.UltimateModeration;
import com.songoda.ultimatemoderation.settings.Settings; import com.songoda.ultimatemoderation.settings.Settings;
import com.songoda.ultimatemoderation.utils.Methods; import com.songoda.ultimatemoderation.utils.Methods;
import com.songoda.ultimatemoderation.settings.Settings;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -52,11 +51,11 @@ public class StaffChannel {
public void processMessage(String message, Player player) { public void processMessage(String message, Player player) {
messageAll(UltimateModeration.getInstance().getLocale() messageAll(UltimateModeration.getInstance().getLocale()
.getMessage("event.staffchat.format") .getMessage("event.staffchat.format")
.processPlaceholder("color", chatChar) .processPlaceholder("color", chatChar)
.processPlaceholder("channel", channelName) .processPlaceholder("channel", channelName)
.processPlaceholder("player", player.getDisplayName()) .processPlaceholder("player", player.getDisplayName())
.processPlaceholder("message", message).getMessage()); .processPlaceholder("message", message).getMessage());
} }
public void messageAll(String message) { public void messageAll(String message) {

View File

@ -1,6 +1,8 @@
package com.songoda.ultimatemoderation.staffchat; package com.songoda.ultimatemoderation.staffchat;
import java.util.*; import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class StaffChatManager { public class StaffChatManager {

View File

@ -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<StorageRow> 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();
}

View File

@ -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> 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;
}
}

View File

@ -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<String, StorageItem> items;
public StorageRow(String key, Map<String, StorageItem> items) {
this.key = key;
this.items = items;
}
public String getKey() {
return key;
}
public Map<String, StorageItem> 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);
}
}

View File

@ -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<String, Object> toSave = new HashMap<>();
private Map<String, Object> lastSave = null;
public StorageYaml(UltimateModeration plugin) {
super(plugin);
}
@Override
public boolean containsGroup(String group) {
return dataFile.contains("data." + group);
}
@Override
public List<StorageRow> getRowsByGroup(String group) {
List<StorageRow> rows = new ArrayList<>();
ConfigurationSection currentSection = dataFile.getConfigurationSection("data." + group);
for (String key : currentSection.getKeys(false)) {
Map<String, StorageItem> 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<String, Object> nextSave = new HashMap<>(toSave);
this.makeBackup();
this.save();
toSave.clear();
lastSave.clear();
lastSave.putAll(nextSave);
}
@Override
public void save() {
try {
for (Map.Entry<String, Object> 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<String, Object> 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<File> 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();
}
}
}

View File

@ -2,7 +2,10 @@ package com.songoda.ultimatemoderation.tickets;
import org.bukkit.OfflinePlayer; 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; import java.util.stream.Collectors;
public class TicketManager { public class TicketManager {

View File

@ -2,7 +2,11 @@ package com.songoda.ultimatemoderation.utils;
import com.songoda.core.compatibility.ServerVersion; import com.songoda.core.compatibility.ServerVersion;
import com.songoda.ultimatemoderation.UltimateModeration; 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.block.Block;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;

View File

@ -18,7 +18,8 @@ public class VaultPermissions {
} }
public static boolean hasPermission(OfflinePlayer offlinePlayer, String perm) { 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; return false;
} }
} }