mirror of
https://github.com/songoda/UltimateModeration.git
synced 2024-11-22 02:08:47 +01:00
Heavy code style changes and slight refactoring
This commit is contained in:
parent
9c011f1ccb
commit
ab27ca52d3
@ -11,10 +11,37 @@ import com.songoda.core.database.DatabaseConnector;
|
||||
import com.songoda.core.database.MySQLConnector;
|
||||
import com.songoda.core.database.SQLiteConnector;
|
||||
import com.songoda.core.gui.GuiManager;
|
||||
import com.songoda.ultimatemoderation.commands.*;
|
||||
import com.songoda.ultimatemoderation.commands.CommandBan;
|
||||
import com.songoda.ultimatemoderation.commands.CommandClearChat;
|
||||
import com.songoda.ultimatemoderation.commands.CommandHelp;
|
||||
import com.songoda.ultimatemoderation.commands.CommandKick;
|
||||
import com.songoda.ultimatemoderation.commands.CommandMute;
|
||||
import com.songoda.ultimatemoderation.commands.CommandRandomPlayer;
|
||||
import com.songoda.ultimatemoderation.commands.CommandReload;
|
||||
import com.songoda.ultimatemoderation.commands.CommandRunTemplate;
|
||||
import com.songoda.ultimatemoderation.commands.CommandSettings;
|
||||
import com.songoda.ultimatemoderation.commands.CommandSlowMode;
|
||||
import com.songoda.ultimatemoderation.commands.CommandStaffChat;
|
||||
import com.songoda.ultimatemoderation.commands.CommandTicket;
|
||||
import com.songoda.ultimatemoderation.commands.CommandToggleChat;
|
||||
import com.songoda.ultimatemoderation.commands.CommandUltimateModeration;
|
||||
import com.songoda.ultimatemoderation.commands.CommandUnBan;
|
||||
import com.songoda.ultimatemoderation.commands.CommandUnMute;
|
||||
import com.songoda.ultimatemoderation.commands.CommandVanish;
|
||||
import com.songoda.ultimatemoderation.commands.CommandWarn;
|
||||
import com.songoda.ultimatemoderation.database.DataManager;
|
||||
import com.songoda.ultimatemoderation.database.migrations._1_InitialMigration;
|
||||
import com.songoda.ultimatemoderation.listeners.*;
|
||||
import com.songoda.ultimatemoderation.listeners.BlockListener;
|
||||
import com.songoda.ultimatemoderation.listeners.ChatListener;
|
||||
import com.songoda.ultimatemoderation.listeners.CommandListener;
|
||||
import com.songoda.ultimatemoderation.listeners.DeathListener;
|
||||
import com.songoda.ultimatemoderation.listeners.DropListener;
|
||||
import com.songoda.ultimatemoderation.listeners.InventoryListener;
|
||||
import com.songoda.ultimatemoderation.listeners.LoginListener;
|
||||
import com.songoda.ultimatemoderation.listeners.MobTargetLister;
|
||||
import com.songoda.ultimatemoderation.listeners.MoveListener;
|
||||
import com.songoda.ultimatemoderation.listeners.SkyBlockListener;
|
||||
import com.songoda.ultimatemoderation.listeners.SpyingDismountListener;
|
||||
import com.songoda.ultimatemoderation.moderate.ModerationManager;
|
||||
import com.songoda.ultimatemoderation.punish.AppliedPunishment;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentNote;
|
||||
@ -28,12 +55,11 @@ import com.songoda.ultimatemoderation.tickets.Ticket;
|
||||
import com.songoda.ultimatemoderation.tickets.TicketManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class UltimateModeration extends SongodaPlugin {
|
||||
private static UltimateModeration INSTANCE;
|
||||
|
||||
private final GuiManager guiManager = new GuiManager(this);
|
||||
private TicketManager ticketManager;
|
||||
private TemplateManager templateManager;
|
||||
@ -45,13 +71,16 @@ public class UltimateModeration extends SongodaPlugin {
|
||||
private DatabaseConnector databaseConnector;
|
||||
private DataManager dataManager;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link JavaPlugin#getPlugin(Class)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public static UltimateModeration getInstance() {
|
||||
return INSTANCE;
|
||||
return getPlugin(UltimateModeration.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPluginLoad() {
|
||||
INSTANCE = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -72,7 +101,7 @@ public class UltimateModeration extends SongodaPlugin {
|
||||
this.commandManager.addCommand(new CommandUltimateModeration(this))
|
||||
.addSubCommands(
|
||||
new CommandReload(this),
|
||||
new CommandSettings(this, guiManager),
|
||||
new CommandSettings(this, this.guiManager),
|
||||
new CommandHelp(this)
|
||||
);
|
||||
this.commandManager.addCommand(new CommandBan(this));
|
||||
@ -83,7 +112,7 @@ 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, guiManager));
|
||||
this.commandManager.addCommand(new CommandTicket(this, this.guiManager));
|
||||
this.commandManager.addCommand(new CommandToggleChat(this));
|
||||
this.commandManager.addCommand(new CommandUnBan(this));
|
||||
this.commandManager.addCommand(new CommandUnMute(this));
|
||||
@ -116,8 +145,7 @@ public class UltimateModeration extends SongodaPlugin {
|
||||
}
|
||||
|
||||
this.dataManager = new DataManager(this.databaseConnector, this);
|
||||
DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager,
|
||||
new _1_InitialMigration());
|
||||
DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager, new _1_InitialMigration(this));
|
||||
dataMigrationManager.runMigrations();
|
||||
|
||||
} catch (Exception ex) {
|
||||
@ -128,10 +156,10 @@ public class UltimateModeration extends SongodaPlugin {
|
||||
}
|
||||
|
||||
// Register Listeners
|
||||
guiManager.init();
|
||||
this.guiManager.init();
|
||||
PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
pluginManager.registerEvents(new CommandListener(this), this);
|
||||
pluginManager.registerEvents(new DeathListener(this), this);
|
||||
pluginManager.registerEvents(new DeathListener(), this);
|
||||
pluginManager.registerEvents(new MoveListener(this), this);
|
||||
pluginManager.registerEvents(new DropListener(this), this);
|
||||
pluginManager.registerEvents(new InventoryListener(this), this);
|
||||
@ -139,11 +167,13 @@ public class UltimateModeration extends SongodaPlugin {
|
||||
pluginManager.registerEvents(new LoginListener(this), this);
|
||||
pluginManager.registerEvents(new MobTargetLister(), this);
|
||||
pluginManager.registerEvents(new BlockListener(this), this);
|
||||
if (pluginManager.isPluginEnabled("FabledSkyBlock"))
|
||||
pluginManager.registerEvents(new SkyBlockListener(this), this);
|
||||
if (pluginManager.isPluginEnabled("FabledSkyBlock")) {
|
||||
pluginManager.registerEvents(new SkyBlockListener(), this);
|
||||
}
|
||||
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13))
|
||||
pluginManager.registerEvents(new SpyingDismountListener(), this);
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13)) {
|
||||
pluginManager.registerEvents(new SpyingDismountListener(this), this);
|
||||
}
|
||||
|
||||
// Start tasks
|
||||
SlowModeTask.startTask(this);
|
||||
@ -159,16 +189,19 @@ public class UltimateModeration extends SongodaPlugin {
|
||||
}
|
||||
});
|
||||
this.dataManager.getAppliedPunishments((appliedPunishments) -> {
|
||||
for (AppliedPunishment punishment : appliedPunishments)
|
||||
for (AppliedPunishment punishment : appliedPunishments) {
|
||||
this.punishmentManager.getPlayer(punishment.getVictim()).addPunishment(punishment);
|
||||
}
|
||||
});
|
||||
this.dataManager.getNotes((notes) -> {
|
||||
for (PunishmentNote note : notes)
|
||||
for (PunishmentNote note : notes) {
|
||||
this.punishmentManager.getPlayer(note.getSubject()).addNotes(note);
|
||||
}
|
||||
});
|
||||
this.dataManager.getTickets((tickets) -> {
|
||||
for (Ticket ticket : tickets.values())
|
||||
for (Ticket ticket : tickets.values()) {
|
||||
this.ticketManager.addTicket(ticket);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
@ -185,38 +218,38 @@ public class UltimateModeration extends SongodaPlugin {
|
||||
}
|
||||
|
||||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
return this.commandManager;
|
||||
}
|
||||
|
||||
public TemplateManager getTemplateManager() {
|
||||
return templateManager;
|
||||
return this.templateManager;
|
||||
}
|
||||
|
||||
public PunishmentManager getPunishmentManager() {
|
||||
return punishmentManager;
|
||||
return this.punishmentManager;
|
||||
}
|
||||
|
||||
public TicketManager getTicketManager() {
|
||||
return ticketManager;
|
||||
return this.ticketManager;
|
||||
}
|
||||
|
||||
public StaffChatManager getStaffChatManager() {
|
||||
return staffChatManager;
|
||||
return this.staffChatManager;
|
||||
}
|
||||
|
||||
public DataManager getDataManager() {
|
||||
return dataManager;
|
||||
return this.dataManager;
|
||||
}
|
||||
|
||||
public DatabaseConnector getDatabaseConnector() {
|
||||
return databaseConnector;
|
||||
return this.databaseConnector;
|
||||
}
|
||||
|
||||
public GuiManager getGuiManager() {
|
||||
return guiManager;
|
||||
return this.guiManager;
|
||||
}
|
||||
|
||||
public ModerationManager getModerationManager() {
|
||||
return moderationManager;
|
||||
return this.moderationManager;
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.songoda.ultimatemoderation.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.utils.TimeUtils;
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.punish.Punishment;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import com.songoda.ultimatemoderation.utils.VaultPermissions;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -17,7 +17,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandBan extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public CommandBan(UltimateModeration plugin) {
|
||||
@ -27,21 +26,23 @@ public class CommandBan extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length < 1)
|
||||
if (args.length < 1) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
// I dream of the day where someone creates a ticket because
|
||||
// they can't ban someone for the reason "Stole me 2h sword".
|
||||
// I dream of the day when someone creates a ticket because
|
||||
// they can't ban someone for the reason "Stole me 2h sword"
|
||||
long duration = 0;
|
||||
StringBuilder reasonBuilder = new StringBuilder();
|
||||
if (args.length > 1) {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
String line = args[i];
|
||||
long time = Methods.parseTime(line);
|
||||
if (time != 0)
|
||||
long time = TimeUtils.parseTime(line);
|
||||
if (time != 0) {
|
||||
duration += time;
|
||||
else
|
||||
} else {
|
||||
reasonBuilder.append(line).append(" ");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -49,21 +50,21 @@ public class CommandBan extends AbstractCommand {
|
||||
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
||||
|
||||
if (plugin.getPunishmentManager().getPlayer(player).getActivePunishments()
|
||||
if (this.plugin.getPunishmentManager().getPlayer(player).getActivePunishments()
|
||||
.stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.BAN)) {
|
||||
plugin.getLocale().newMessage("That player is already banned.").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().newMessage("That player is already banned.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (duration == 0 && !sender.hasPermission("um.ban.permanent")) {
|
||||
plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
long durationFinal = duration;
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
if (sender instanceof Player && VaultPermissions.hasPermission(player, "um.ban.exempt")) {
|
||||
plugin.getLocale().newMessage("You cannot ban this player.").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().newMessage("You cannot ban this player.").sendPrefixedMessage(sender);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandClearChat extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public CommandClearChat(UltimateModeration plugin) {
|
||||
@ -21,9 +20,9 @@ public class CommandClearChat extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
|
||||
if (args.length != 0 && !args[0].equalsIgnoreCase("force"))
|
||||
if (args.length != 0 && !args[0].equalsIgnoreCase("force")) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!player.hasPermission("um.clearchat.bypass") || isForced(args)) {
|
||||
@ -32,13 +31,14 @@ public class CommandClearChat extends AbstractCommand {
|
||||
player.sendMessage(toSend);
|
||||
}
|
||||
|
||||
plugin.getLocale().getMessage("command.clearchat.cleared")
|
||||
this.plugin.getLocale().getMessage("command.clearchat.cleared")
|
||||
.processPlaceholder("player", sender.getName()).sendPrefixedMessage(player);
|
||||
|
||||
if (player.hasPermission("um.clearchat.bypass") && !isForced(args)) {
|
||||
plugin.getLocale().getMessage("command.clearchat.immune").sendMessage(player);
|
||||
this.plugin.getLocale().getMessage("command.clearchat.immune").sendMessage(player);
|
||||
}
|
||||
}
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,13 @@
|
||||
package com.songoda.ultimatemoderation.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandHelp extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public CommandHelp(UltimateModeration plugin) {
|
||||
@ -19,15 +18,15 @@ public class CommandHelp extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
plugin.getLocale().getMessage("&7Version " + plugin.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda")
|
||||
this.plugin.getLocale().getMessage("&7Version " + this.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(TextUtils.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 : plugin.getCommandManager().getAllCommands()) {
|
||||
sender.sendMessage(TextUtils.formatText("&6Commands:"));
|
||||
for (AbstractCommand command : this.plugin.getCommandManager().getAllCommands()) {
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
|
||||
sender.sendMessage(TextUtils.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
|
||||
}
|
||||
}
|
||||
sender.sendMessage("");
|
||||
|
@ -14,7 +14,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandKick extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public CommandKick(UltimateModeration plugin) {
|
||||
@ -24,8 +23,9 @@ public class CommandKick extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length < 1)
|
||||
if (args.length < 1) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
StringBuilder reasonBuilder = new StringBuilder();
|
||||
if (args.length > 1) {
|
||||
@ -40,7 +40,7 @@ public class CommandKick extends AbstractCommand {
|
||||
OfflinePlayer player = Bukkit.getPlayer(args[0]);
|
||||
|
||||
if (sender instanceof Player && player.getPlayer().hasPermission("um.kick.exempt")) {
|
||||
plugin.getLocale().newMessage("You cannot kick this player.").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().newMessage("You cannot kick this player.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.songoda.ultimatemoderation.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.utils.TimeUtils;
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.punish.Punishment;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import com.songoda.ultimatemoderation.utils.VaultPermissions;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -17,7 +17,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandMute extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public CommandMute(UltimateModeration plugin) {
|
||||
@ -27,21 +26,23 @@ public class CommandMute extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length < 1)
|
||||
if (args.length < 1) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
// I dream of the day where someone creates a ticket because
|
||||
// I dream of the day when someone creates a ticket because
|
||||
// they can't ban someone for the reason "Stole me 2h sword".
|
||||
long duration = 0;
|
||||
StringBuilder reasonBuilder = new StringBuilder();
|
||||
if (args.length > 1) {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
String line = args[i];
|
||||
long time = Methods.parseTime(line);
|
||||
if (time != 0)
|
||||
long time = TimeUtils.parseTime(line);
|
||||
if (time != 0) {
|
||||
duration += time;
|
||||
else
|
||||
} else {
|
||||
reasonBuilder.append(line).append(" ");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -50,13 +51,13 @@ public class CommandMute extends AbstractCommand {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
||||
|
||||
if (sender instanceof Player && VaultPermissions.hasPermission(player, "um.mute.exempt")) {
|
||||
plugin.getLocale().newMessage("You cannot mute that player.").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().newMessage("You cannot mute that player.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (plugin.getPunishmentManager().getPlayer(player).getActivePunishments()
|
||||
if (this.plugin.getPunishmentManager().getPlayer(player).getActivePunishments()
|
||||
.stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.MUTE)) {
|
||||
plugin.getLocale().newMessage("That player is already muted.").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().newMessage("That player is already muted.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandRandomPlayer extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public CommandRandomPlayer(UltimateModeration plugin) {
|
||||
@ -26,7 +25,7 @@ public class CommandRandomPlayer extends AbstractCommand {
|
||||
players.remove(sender);
|
||||
|
||||
if (players.size() == 0) {
|
||||
plugin.getLocale().newMessage("&cYou are the only one online!").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().newMessage("&cYou are the only one online!").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ import org.bukkit.command.CommandSender;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandReload extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public CommandReload(UltimateModeration plugin) {
|
||||
@ -17,8 +16,8 @@ public class CommandReload extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
plugin.reloadConfig();
|
||||
plugin.getLocale().newMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
|
||||
this.plugin.reloadConfig();
|
||||
this.plugin.getLocale().newMessage("&7Configuration and Language files reloaded.").sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandRunTemplate extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public CommandRunTemplate(UltimateModeration plugin) {
|
||||
@ -34,7 +33,7 @@ public class CommandRunTemplate extends AbstractCommand {
|
||||
}
|
||||
String templateStr = templateBuilder.toString().trim();
|
||||
|
||||
Template template = plugin.getTemplateManager().getTemplate(templateStr);
|
||||
Template template = this.plugin.getTemplateManager().getTemplate(templateStr);
|
||||
|
||||
if (template == null) {
|
||||
sender.sendMessage("That template does not exist...");
|
||||
@ -56,7 +55,7 @@ public class CommandRunTemplate extends AbstractCommand {
|
||||
return players;
|
||||
} else if (args.length == 2) {
|
||||
List<String> lines = new ArrayList<>();
|
||||
for (Template template : plugin.getTemplateManager().getTemplates()) {
|
||||
for (Template template : this.plugin.getTemplateManager().getTemplates()) {
|
||||
lines.add(template.getName());
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import org.bukkit.entity.Player;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandSettings extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
private final GuiManager guiManager;
|
||||
|
||||
@ -22,8 +21,7 @@ public class CommandSettings extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player player = (Player) sender;
|
||||
guiManager.showGUI((Player) sender, new PluginConfigGui(plugin));
|
||||
this.guiManager.showGUI((Player) sender, new PluginConfigGui(this.plugin));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.songoda.ultimatemoderation.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.utils.TimeUtils;
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.listeners.ChatListener;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -12,7 +12,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandSlowMode extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public CommandSlowMode(UltimateModeration plugin) {
|
||||
@ -24,18 +23,19 @@ public class CommandSlowMode extends AbstractCommand {
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length == 0) {
|
||||
ChatListener.setSlowModeOverride(0);
|
||||
plugin.getLocale().getMessage("event.slowmode.disabled").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().getMessage("event.slowmode.disabled").sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
} else if (args.length != 1)
|
||||
} else if (args.length != 1) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
long delay = Methods.parseTime(args[0]);
|
||||
long delay = TimeUtils.parseTime(args[0]);
|
||||
|
||||
ChatListener.setSlowModeOverride(delay);
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(player ->
|
||||
plugin.getLocale().getMessage("event.slowmode.enabled")
|
||||
.processPlaceholder("delay", Methods.makeReadable(delay)).sendPrefixedMessage(player));
|
||||
this.plugin.getLocale().getMessage("event.slowmode.enabled")
|
||||
.processPlaceholder("delay", TimeUtils.makeReadable(delay)).sendPrefixedMessage(player));
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandStaffChat extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public CommandStaffChat(UltimateModeration plugin) {
|
||||
@ -20,33 +19,36 @@ public class CommandStaffChat extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length != 1)
|
||||
if (args.length != 1) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
String channelName = args[0];
|
||||
Player player = (Player) sender;
|
||||
|
||||
if (channelName.trim().equalsIgnoreCase("leave")) {
|
||||
for (StaffChannel channel : plugin.getStaffChatManager().getChats().values()) {
|
||||
if (!channel.listMembers().contains(player.getUniqueId())) continue;
|
||||
for (StaffChannel channel : this.plugin.getStaffChatManager().getChats().values()) {
|
||||
if (!channel.listMembers().contains(player.getUniqueId())) {
|
||||
continue;
|
||||
}
|
||||
channel.removeMember(player);
|
||||
plugin.getLocale().getMessage("event.staffchat.leave")
|
||||
this.plugin.getLocale().getMessage("event.staffchat.leave")
|
||||
.processPlaceholder("channel", channel.getChannelName()).sendPrefixedMessage(player);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
plugin.getLocale().getMessage("event.staffchat.nochannels").sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().getMessage("event.staffchat.nochannels").sendPrefixedMessage(player);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
plugin.getLocale().getMessage("event.staffchat.join")
|
||||
this.plugin.getLocale().getMessage("event.staffchat.join")
|
||||
.processPlaceholder("channel", channelName).sendPrefixedMessage(player);
|
||||
plugin.getStaffChatManager().getChat(channelName).addMember(player);
|
||||
this.plugin.getStaffChatManager().getChat(channelName).addMember(player);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(CommandSender sender, String... args) {
|
||||
return new ArrayList<>(plugin.getStaffChatManager().getChats().keySet());
|
||||
return new ArrayList<>(this.plugin.getStaffChatManager().getChats().keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -10,7 +10,6 @@ import org.bukkit.entity.Player;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandTicket extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
private final GuiManager guiManager;
|
||||
|
||||
@ -23,7 +22,7 @@ public class CommandTicket extends AbstractCommand {
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
Player senderP = ((Player) sender);
|
||||
guiManager.showGUI(senderP, new TicketManagerGui(plugin, senderP, senderP));
|
||||
this.guiManager.showGUI(senderP, new TicketManagerGui(this.plugin, senderP, senderP));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@ -46,5 +45,4 @@ public class CommandTicket extends AbstractCommand {
|
||||
public String getDescription() {
|
||||
return "Opens the ticket interface.";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import org.bukkit.entity.Player;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandToggleChat extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
/*
|
||||
@ -26,25 +25,25 @@ public class CommandToggleChat extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
toggled = !toggled;
|
||||
this.toggled = !this.toggled;
|
||||
|
||||
Message message = toggled ? plugin.getLocale().getMessage("command.togglechat.toggledOn")
|
||||
: plugin.getLocale().getMessage("command.togglechat.toggledOff");
|
||||
Message message = this.toggled ? this.plugin.getLocale().getMessage("command.togglechat.toggledOn")
|
||||
: this.plugin.getLocale().getMessage("command.togglechat.toggledOff");
|
||||
|
||||
ChatListener.setChatToggled(toggled);
|
||||
ChatListener.setChatToggled(this.toggled);
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
|
||||
message.sendPrefixedMessage(player);
|
||||
|
||||
if (!player.hasPermission(getPermissionNode() + ".bypass"))
|
||||
if (!player.hasPermission(getPermissionNode() + ".bypass")) {
|
||||
continue;
|
||||
|
||||
plugin.getLocale().getMessage("command.togglechat.bypass").sendMessage(player);
|
||||
}
|
||||
this.plugin.getLocale().getMessage("command.togglechat.bypass").sendMessage(player);
|
||||
}
|
||||
|
||||
if (!(sender instanceof Player))
|
||||
if (!(sender instanceof Player)) {
|
||||
message.sendPrefixedMessage(sender);
|
||||
}
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import org.bukkit.entity.Player;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandUltimateModeration extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public CommandUltimateModeration(UltimateModeration plugin) {
|
||||
@ -19,7 +18,7 @@ public class CommandUltimateModeration extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
plugin.getGuiManager().showGUI((Player) sender, new MainGui(plugin, (Player) sender));
|
||||
this.plugin.getGuiManager().showGUI((Player) sender, new MainGui(this.plugin, (Player) sender));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandUnBan extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public CommandUnBan(UltimateModeration plugin) {
|
||||
@ -23,22 +22,23 @@ public class CommandUnBan extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length != 1)
|
||||
if (args.length != 1) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
||||
|
||||
if (!plugin.getPunishmentManager().getPlayer(player).getActivePunishments()
|
||||
if (!this.plugin.getPunishmentManager().getPlayer(player).getActivePunishments()
|
||||
.stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.BAN)) {
|
||||
plugin.getLocale().newMessage("That player isn't banned.").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().newMessage("That player isn't banned.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(player);
|
||||
PlayerPunishData playerPunishData = this.plugin.getPunishmentManager().getPlayer(player);
|
||||
|
||||
playerPunishData.expirePunishments(PunishmentType.BAN);
|
||||
|
||||
plugin.getLocale().getMessage("event.unban.success")
|
||||
this.plugin.getLocale().getMessage("event.unban.success")
|
||||
.processPlaceholder("player", player.getName()).sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandUnMute extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public CommandUnMute(UltimateModeration plugin) {
|
||||
@ -28,17 +27,17 @@ public class CommandUnMute extends AbstractCommand {
|
||||
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
||||
|
||||
if (!plugin.getPunishmentManager().getPlayer(player).getActivePunishments()
|
||||
if (!this.plugin.getPunishmentManager().getPlayer(player).getActivePunishments()
|
||||
.stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.MUTE)) {
|
||||
plugin.getLocale().newMessage("That player isn't muted.").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().newMessage("That player isn't muted.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(player);
|
||||
PlayerPunishData playerPunishData = this.plugin.getPunishmentManager().getPlayer(player);
|
||||
|
||||
playerPunishData.expirePunishments(PunishmentType.MUTE);
|
||||
|
||||
plugin.getLocale().newMessage(plugin.getLocale().getMessage("event.unmute.success")
|
||||
this.plugin.getLocale().newMessage(this.plugin.getLocale().getMessage("event.unmute.success")
|
||||
.processPlaceholder("player", player.getName()).getMessage()).sendPrefixedMessage(sender);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
@ -18,7 +18,6 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CommandVanish extends AbstractCommand {
|
||||
|
||||
private static final List<UUID> inVanish = new ArrayList<>();
|
||||
|
||||
public CommandVanish() {
|
||||
@ -28,7 +27,9 @@ public class CommandVanish extends AbstractCommand {
|
||||
public static void registerVanishedPlayers(Player player) {
|
||||
for (UUID uuid : inVanish) {
|
||||
Player vanished = Bukkit.getPlayer(uuid);
|
||||
if (vanished == null) continue;
|
||||
if (vanished == null) {
|
||||
continue;
|
||||
}
|
||||
if (player.hasPermission("um.vanish.bypass")) {
|
||||
player.showPlayer(vanished);
|
||||
} else {
|
||||
@ -44,15 +45,17 @@ public class CommandVanish extends AbstractCommand {
|
||||
|
||||
if (inVanish.contains(uuid)) {
|
||||
inVanish.remove(uuid);
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
|
||||
player.setInvulnerable(false);
|
||||
}
|
||||
player.setCanPickupItems(true);
|
||||
instance.getLocale().getMessage("command.vanish.toggledOff").sendPrefixedMessage(player);
|
||||
} else {
|
||||
inVanish.add(uuid);
|
||||
player.setCanPickupItems(false);
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
|
||||
player.setInvulnerable(true);
|
||||
}
|
||||
instance.getLocale().getMessage("command.vanish.toggledOn").sendPrefixedMessage(player);
|
||||
|
||||
}
|
||||
@ -74,15 +77,17 @@ public class CommandVanish extends AbstractCommand {
|
||||
float xx = (float) (0 + (Math.random() * 1));
|
||||
float yy = (float) (0 + (Math.random() * 2));
|
||||
float zz = (float) (0 + (Math.random() * 1));
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12))
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_12)) {
|
||||
player.getWorld().spawnParticle(Particle.valueOf(Settings.VANISH_PARTICLE.getString()), player.getLocation().add(0, 1, 0), 35, xx, yy, zz, 0);
|
||||
}
|
||||
}
|
||||
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (inVanish.contains(uuid))
|
||||
if (inVanish.contains(uuid)) {
|
||||
registerVanishedPlayers(p);
|
||||
else
|
||||
} else {
|
||||
p.showPlayer(player);
|
||||
}
|
||||
}
|
||||
for (Entity e : player.getNearbyEntities(30, 30, 30)) {
|
||||
if (e instanceof Monster) {
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.songoda.ultimatemoderation.commands;
|
||||
|
||||
import com.songoda.core.commands.AbstractCommand;
|
||||
import com.songoda.core.utils.TimeUtils;
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.punish.Punishment;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import com.songoda.ultimatemoderation.utils.VaultPermissions;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -17,7 +17,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandWarn extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public CommandWarn(UltimateModeration plugin) {
|
||||
@ -27,21 +26,23 @@ public class CommandWarn extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length < 1)
|
||||
if (args.length < 1) {
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
}
|
||||
|
||||
// I dream of the day where someone creates a ticket because
|
||||
// I dream of the day when someone creates a ticket because
|
||||
// they can't ban someone for the reason "Stole me 2h sword".
|
||||
long duration = 0;
|
||||
StringBuilder reasonBuilder = new StringBuilder();
|
||||
if (args.length > 1) {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
String line = args[i];
|
||||
long time = Methods.parseTime(line);
|
||||
if (time != 0)
|
||||
long time = TimeUtils.parseTime(line);
|
||||
if (time != 0) {
|
||||
duration += time;
|
||||
else
|
||||
} else {
|
||||
reasonBuilder.append(line).append(" ");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -50,7 +51,7 @@ public class CommandWarn extends AbstractCommand {
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
||||
|
||||
if (sender instanceof Player && VaultPermissions.hasPermission(player, "um.warning.exempt")) {
|
||||
plugin.getLocale().newMessage("You cannot warn that player.").sendPrefixedMessage(sender);
|
||||
this.plugin.getLocale().newMessage("You cannot warn that player.").sendPrefixedMessage(sender);
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,6 @@ import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class DataManager extends DataManagerAbstract {
|
||||
|
||||
public DataManager(DatabaseConnector databaseConnector, Plugin plugin) {
|
||||
super(databaseConnector, plugin);
|
||||
}
|
||||
|
@ -9,14 +9,16 @@ import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
public class _1_InitialMigration extends DataMigration {
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public _1_InitialMigration() {
|
||||
public _1_InitialMigration(UltimateModeration plugin) {
|
||||
super(1);
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void migrate(Connection connection, String tablePrefix) throws SQLException {
|
||||
String autoIncrement = UltimateModeration.getInstance().getDatabaseConnector() instanceof MySQLConnector ? " AUTO_INCREMENT" : "";
|
||||
String autoIncrement = this.plugin.getDatabaseConnector() instanceof MySQLConnector ? " AUTO_INCREMENT" : "";
|
||||
|
||||
// Create templates table
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
|
@ -24,7 +24,6 @@ import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MainGui extends Gui {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
private Online currentOnline = Online.ONLINE;
|
||||
@ -38,11 +37,14 @@ public class MainGui extends Gui {
|
||||
setDefaultItem(null);
|
||||
this.viewer = viewer;
|
||||
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
players.add(player.getUniqueId());
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
this.players.add(player.getUniqueId());
|
||||
}
|
||||
for (UUID uuid : plugin.getPunishmentManager().getPunishments().keySet()) {
|
||||
if (Bukkit.getOfflinePlayer(uuid).isOnline()) continue;
|
||||
players.add(uuid);
|
||||
if (Bukkit.getOfflinePlayer(uuid).isOnline()) {
|
||||
continue;
|
||||
}
|
||||
this.players.add(uuid);
|
||||
}
|
||||
|
||||
setTitle(plugin.getLocale().getMessage("gui.players.title").getMessage());
|
||||
@ -51,8 +53,9 @@ public class MainGui extends Gui {
|
||||
}
|
||||
|
||||
private void showPage() {
|
||||
if (inventory != null)
|
||||
inventory.clear();
|
||||
if (this.inventory != null) {
|
||||
this.inventory.clear();
|
||||
}
|
||||
setActionForRange(0, 53, null);
|
||||
|
||||
// decorate the edges
|
||||
@ -69,14 +72,16 @@ public class MainGui extends Gui {
|
||||
mirrorFill(0, 1, true, true, glass2);
|
||||
|
||||
setButton(5, 2, GuiUtils.createButtonItem(CompatibleMaterial.ENDER_PEARL,
|
||||
plugin.getLocale().getMessage("gui.players.search").getMessage()),
|
||||
this.plugin.getLocale().getMessage("gui.players.search").getMessage()),
|
||||
(event) -> {
|
||||
AnvilGui gui = new AnvilGui(event.player, this);
|
||||
gui.setAction(event2 -> {
|
||||
List<UUID> players = new ArrayList<>(plugin.getPunishmentManager().getPunishments().keySet());
|
||||
List<UUID> players = new ArrayList<>(this.plugin.getPunishmentManager().getPunishments().keySet());
|
||||
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
if (players.contains(p.getUniqueId())) continue;
|
||||
if (players.contains(p.getUniqueId())) {
|
||||
continue;
|
||||
}
|
||||
players.add(p.getUniqueId());
|
||||
}
|
||||
|
||||
@ -87,115 +92,118 @@ public class MainGui extends Gui {
|
||||
this.players.addAll(found);
|
||||
showPage();
|
||||
} else {
|
||||
plugin.getLocale().getMessage("gui.players.nonefound").sendMessage(event.player);
|
||||
this.plugin.getLocale().getMessage("gui.players.nonefound").sendMessage(event.player);
|
||||
}
|
||||
event2.player.closeInventory();
|
||||
});
|
||||
|
||||
ItemStack item = new ItemStack(Material.PAPER);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(plugin.getLocale().getMessage("gui.players.name").getMessage());
|
||||
meta.setDisplayName(this.plugin.getLocale().getMessage("gui.players.name").getMessage());
|
||||
item.setItemMeta(meta);
|
||||
|
||||
gui.setInput(item);
|
||||
guiManager.showGUI(event.player, gui);
|
||||
this.guiManager.showGUI(event.player, gui);
|
||||
});
|
||||
|
||||
setButton(5, 3, GuiUtils.createButtonItem(CompatibleMaterial.HOPPER, TextUtils.formatText("&6" + currentOnline.getTranslation())),
|
||||
setButton(5, 3, GuiUtils.createButtonItem(CompatibleMaterial.HOPPER, TextUtils.formatText("&6" + this.currentOnline.getTranslation())),
|
||||
(event) -> {
|
||||
this.currentOnline = currentOnline.next();
|
||||
this.currentOnline = this.currentOnline.next();
|
||||
this.page = 1;
|
||||
showPage();
|
||||
});
|
||||
|
||||
|
||||
if (viewer.hasPermission("um.tickets"))
|
||||
if (this.viewer.hasPermission("um.tickets")) {
|
||||
setButton(5, 5, GuiUtils.createButtonItem(CompatibleMaterial.CHEST,
|
||||
plugin.getLocale().getMessage("gui.players.button.tickets").getMessage()),
|
||||
(event) -> guiManager.showGUI(event.player, new TicketManagerGui(plugin, null, viewer)));
|
||||
this.plugin.getLocale().getMessage("gui.players.button.tickets").getMessage()),
|
||||
(event) -> this.guiManager.showGUI(event.player, new TicketManagerGui(this.plugin, null, this.viewer)));
|
||||
}
|
||||
|
||||
if (viewer.hasPermission("um.templates"))
|
||||
if (this.viewer.hasPermission("um.templates")) {
|
||||
setButton(5, 6, GuiUtils.createButtonItem(CompatibleMaterial.MAP,
|
||||
plugin.getLocale().getMessage("gui.players.button.templatemanager").getMessage()),
|
||||
(events) -> guiManager.showGUI(events.player, new TemplateManagerGui(plugin, viewer)));
|
||||
this.plugin.getLocale().getMessage("gui.players.button.templatemanager").getMessage()),
|
||||
(events) -> this.guiManager.showGUI(events.player, new TemplateManagerGui(this.plugin, this.viewer)));
|
||||
}
|
||||
|
||||
|
||||
List<UUID> toUse = players.stream()
|
||||
.filter(u -> currentOnline == Online.BOTH
|
||||
|| currentOnline == Online.ONLINE && Bukkit.getOfflinePlayer(u).isOnline()
|
||||
|| currentOnline == Online.OFFLINE && !Bukkit.getOfflinePlayer(u).isOnline()).collect(Collectors.toList());
|
||||
List<UUID> toUse = this.players.stream()
|
||||
.filter(u -> this.currentOnline == Online.BOTH
|
||||
|| this.currentOnline == Online.ONLINE && Bukkit.getOfflinePlayer(u).isOnline()
|
||||
|| this.currentOnline == Online.OFFLINE && !Bukkit.getOfflinePlayer(u).isOnline()).collect(Collectors.toList());
|
||||
|
||||
this.pages = (int) Math.max(1, Math.ceil(toUse.size() / ((double) 28)));
|
||||
|
||||
final List<UUID> toUseFinal = toUse.stream().skip((page - 1) * 28).limit(28).collect(Collectors.toList());
|
||||
final List<UUID> toUseFinal = toUse.stream().skip((this.page - 1) * 28).limit(28).collect(Collectors.toList());
|
||||
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
int num = 11;
|
||||
for (UUID uuid : toUseFinal) {
|
||||
if (num == 16 || num == 36)
|
||||
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 = this.plugin.getPunishmentManager().getPlayer(pl);
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add(plugin.getLocale().getMessage("gui.players.click").getMessage());
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.players.click").getMessage());
|
||||
lore.add("");
|
||||
|
||||
int ticketAmt = (int) plugin.getTicketManager().getTicketsAbout(pl).stream()
|
||||
int ticketAmt = (int) this.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")
|
||||
if (ticketAmt == 0) {
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.players.notickets").getMessage());
|
||||
} else {
|
||||
if (ticketAmt == 1) {
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.players.ticketsone").getMessage());
|
||||
} else {
|
||||
lore.add(this.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")
|
||||
if (warningAmt == 0) {
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.players.nowarnings").getMessage());
|
||||
} else {
|
||||
if (warningAmt == 1) {
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.players.warningsone").getMessage());
|
||||
} else {
|
||||
lore.add(this.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)));
|
||||
(event) -> this.guiManager.showGUI(event.player, new PlayerGui(this.plugin, pl, this.viewer)));
|
||||
|
||||
num++;
|
||||
}
|
||||
});
|
||||
|
||||
// enable page events
|
||||
setNextPage(4, 7, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()));
|
||||
setPrevPage(4, 1, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.back").getMessage()));
|
||||
setNextPage(4, 7, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, this.plugin.getLocale().getMessage("gui.general.next").getMessage()));
|
||||
setPrevPage(4, 1, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, this.plugin.getLocale().getMessage("gui.general.back").getMessage()));
|
||||
setOnPage((event) -> showPage());
|
||||
}
|
||||
|
||||
private enum Online {
|
||||
|
||||
ONLINE, OFFLINE, BOTH;
|
||||
|
||||
private static Online[] vals = values();
|
||||
|
||||
public Online next() {
|
||||
return vals[(this.ordinal() != vals.length - 1 ? this.ordinal() + 1 : 0)];
|
||||
return values()[(this.ordinal() != values().length - 1 ? this.ordinal() + 1 : 0)];
|
||||
}
|
||||
|
||||
public String getTranslation() {
|
||||
return UltimateModeration.getInstance().getLocale()
|
||||
.getMessage("gui.players.online." + this.name().toLowerCase()).getMessage();
|
||||
return UltimateModeration.getPlugin(UltimateModeration.class)
|
||||
.getLocale()
|
||||
.getMessage("gui.players.online." + this.name().toLowerCase())
|
||||
.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ModerateGui extends Gui {
|
||||
|
||||
public ModerateGui(UltimateModeration plugin, OfflinePlayer toModerate, Player player) {
|
||||
super(5);
|
||||
setDefaultItem(null);
|
||||
@ -38,8 +37,8 @@ public class ModerateGui extends Gui {
|
||||
mirrorFill(0, 1, true, true, glass2);
|
||||
|
||||
setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR,
|
||||
plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
(event) -> guiManager.showGUI(event.player, new PlayerGui(plugin, toModerate, event.player)));
|
||||
plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
(event) -> this.guiManager.showGUI(event.player, new PlayerGui(plugin, toModerate, event.player)));
|
||||
|
||||
int[] slots = new int[]{11, 13, 15, 29, 31, 33};
|
||||
|
||||
@ -47,11 +46,14 @@ public class ModerateGui extends Gui {
|
||||
|
||||
int i = 0;
|
||||
for (AbstractModeration moderation : moderations) {
|
||||
if (!moderation.hasPermission(player) || moderation.isExempt(toModerate)) continue;
|
||||
if (!moderation.hasPermission(player) || moderation.isExempt(toModerate)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int slot = slots[i];
|
||||
setButton(slot, GuiUtils.createButtonItem(moderation.getIcon(),
|
||||
TextUtils.formatText("&6&l" + moderation.getProper()),
|
||||
TextUtils.formatText("&7" + moderation.getDescription())),
|
||||
TextUtils.formatText("&6&l" + moderation.getProper()),
|
||||
TextUtils.formatText("&7" + moderation.getDescription())),
|
||||
(event) -> moderation.runPreModeration(player, toModerate));
|
||||
i++;
|
||||
}
|
||||
|
@ -20,7 +20,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class NotesManagerGui extends Gui {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
private final OfflinePlayer toModerate;
|
||||
@ -42,19 +41,20 @@ public class NotesManagerGui extends Gui {
|
||||
}
|
||||
|
||||
private void showPage() {
|
||||
if (inventory != null)
|
||||
inventory.clear();
|
||||
if (this.inventory != null) {
|
||||
this.inventory.clear();
|
||||
}
|
||||
setActionForRange(0, 53, null);
|
||||
|
||||
int numNotes = plugin.getPunishmentManager().getPlayer(toModerate).getNotes().size();
|
||||
int numNotes = this.plugin.getPunishmentManager().getPlayer(this.toModerate).getNotes().size();
|
||||
this.pages = (int) Math.max(1, Math.ceil(numNotes / ((double) 28)));
|
||||
|
||||
List<PunishmentNote> notes = plugin.getPunishmentManager().getPlayer(toModerate).getNotes().stream()
|
||||
.skip((page - 1) * 28).limit(28).collect(Collectors.toList());
|
||||
List<PunishmentNote> notes = this.plugin.getPunishmentManager().getPlayer(this.toModerate).getNotes().stream()
|
||||
.skip((this.page - 1) * 28).limit(28).collect(Collectors.toList());
|
||||
|
||||
// enable page events
|
||||
setNextPage(0, 1, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()));
|
||||
setPrevPage(0, 3, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.back").getMessage()));
|
||||
setNextPage(0, 1, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, this.plugin.getLocale().getMessage("gui.general.next").getMessage()));
|
||||
setPrevPage(0, 3, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, this.plugin.getLocale().getMessage("gui.general.back").getMessage()));
|
||||
setOnPage((event) -> showPage());
|
||||
|
||||
// decorate the edges
|
||||
@ -71,37 +71,40 @@ public class NotesManagerGui extends Gui {
|
||||
mirrorFill(0, 1, true, true, glass2);
|
||||
|
||||
setButton(5, 5, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR,
|
||||
plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
(event) -> guiManager.showGUI(event.player, new PlayerGui(plugin, toModerate, event.player)));
|
||||
this.plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
(event) -> this.guiManager.showGUI(event.player, new PlayerGui(this.plugin, this.toModerate, event.player)));
|
||||
|
||||
if (create)
|
||||
if (this.create) {
|
||||
setButton(5, 3, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE,
|
||||
plugin.getLocale().getMessage("gui.notes.create").getMessage()),
|
||||
this.plugin.getLocale().getMessage("gui.notes.create").getMessage()),
|
||||
(event) -> {
|
||||
ChatPrompt.showPrompt(plugin, event.player,
|
||||
plugin.getLocale().getMessage("gui.notes.type").getMessage(),
|
||||
ChatPrompt.showPrompt(this.plugin, event.player,
|
||||
this.plugin.getLocale().getMessage("gui.notes.type").getMessage(),
|
||||
(response) -> {
|
||||
PunishmentNote note = new PunishmentNote(response.getMessage(),
|
||||
event.player.getUniqueId(), toModerate.getUniqueId(),
|
||||
event.player.getUniqueId(), this.toModerate.getUniqueId(),
|
||||
System.currentTimeMillis());
|
||||
plugin.getPunishmentManager().getPlayer(toModerate).addNotes(note);
|
||||
plugin.getDataManager().createNote(note);
|
||||
this.plugin.getPunishmentManager().getPlayer(this.toModerate).addNotes(note);
|
||||
this.plugin.getDataManager().createNote(note);
|
||||
|
||||
showPage();
|
||||
}).setOnClose(() -> guiManager.showGUI(event.player, new NotesManagerGui(plugin, toModerate, event.player)));
|
||||
}).setOnClose(() -> this.guiManager.showGUI(event.player, new NotesManagerGui(this.plugin, this.toModerate, event.player)));
|
||||
});
|
||||
}
|
||||
|
||||
int num = 11;
|
||||
for (PunishmentNote note : notes) {
|
||||
if (num == 16 || num == 36)
|
||||
if (num == 16 || num == 36) {
|
||||
num = num + 2;
|
||||
}
|
||||
String noteStr = note.getNote();
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
int lastIndex = 0;
|
||||
for (int n = 0; n < noteStr.length(); n++) {
|
||||
if (n - lastIndex < 20)
|
||||
if (n - lastIndex < 20) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (noteStr.charAt(n) == ' ') {
|
||||
lore.add("&6" + noteStr.substring(lastIndex, n).trim());
|
||||
@ -109,8 +112,9 @@ public class NotesManagerGui extends Gui {
|
||||
}
|
||||
}
|
||||
|
||||
if (lastIndex - noteStr.length() < 20)
|
||||
if (lastIndex - noteStr.length() < 20) {
|
||||
lore.add("&6" + noteStr.substring(lastIndex).trim());
|
||||
}
|
||||
|
||||
String name = lore.get(0);
|
||||
lore.remove(0);
|
||||
@ -119,25 +123,26 @@ public class NotesManagerGui extends Gui {
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy");
|
||||
|
||||
lore.add(plugin.getLocale().getMessage("gui.notes.createdby")
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.notes.createdby")
|
||||
.processPlaceholder("player", Bukkit.getOfflinePlayer(note.getAuthor()).getName())
|
||||
.getMessage());
|
||||
lore.add(plugin.getLocale().getMessage("gui.notes.createdon")
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.notes.createdon")
|
||||
.processPlaceholder("sent", format.format(new Date(note.getCreationDate())))
|
||||
.getMessage());
|
||||
if (delete) lore.add(plugin.getLocale().getMessage("gui.notes.remove").getMessage());
|
||||
if (this.delete) {
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.notes.remove").getMessage());
|
||||
}
|
||||
|
||||
setButton(num, GuiUtils.createButtonItem(CompatibleMaterial.MAP, TextUtils.formatText(name), TextUtils.formatText(lore)),
|
||||
(event) -> {
|
||||
if (delete) {
|
||||
plugin.getPunishmentManager().getPlayer(toModerate).removeNotes(note);
|
||||
plugin.getDataManager().deleteNote(note);
|
||||
if (this.delete) {
|
||||
this.plugin.getPunishmentManager().getPlayer(this.toModerate).removeNotes(note);
|
||||
this.plugin.getDataManager().deleteNote(note);
|
||||
showPage();
|
||||
}
|
||||
});
|
||||
|
||||
num++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class PlayerGui extends Gui {
|
||||
|
||||
public PlayerGui(UltimateModeration plugin, OfflinePlayer toModerate, Player player) {
|
||||
super(6);
|
||||
setDefaultItem(null);
|
||||
@ -48,35 +47,40 @@ public class PlayerGui extends Gui {
|
||||
: "&c" + plugin.getLocale().getMessage("gui.players.online.offline").getMessage())));
|
||||
|
||||
setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR,
|
||||
plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
(event) -> guiManager.showGUI(event.player, new MainGui(plugin, event.player)));
|
||||
plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
(event) -> this.guiManager.showGUI(event.player, new MainGui(plugin, event.player)));
|
||||
|
||||
if (punish)
|
||||
if (punish) {
|
||||
setButton(38, GuiUtils.createButtonItem(CompatibleMaterial.ANVIL,
|
||||
plugin.getLocale().getMessage("gui.player.punish").getMessage()),
|
||||
plugin.getLocale().getMessage("gui.player.punish").getMessage()),
|
||||
(event) -> plugin.getGuiManager().showGUI(player,
|
||||
new PunishGui(plugin, toModerate, null, event.player)));
|
||||
}
|
||||
|
||||
if (tickets)
|
||||
if (tickets) {
|
||||
setButton(30, GuiUtils.createButtonItem(CompatibleMaterial.CHEST,
|
||||
plugin.getLocale().getMessage("gui.player.tickets").getMessage()),
|
||||
plugin.getLocale().getMessage("gui.player.tickets").getMessage()),
|
||||
(event) -> plugin.getGuiManager().showGUI(player,
|
||||
new TicketManagerGui(plugin, toModerate, event.player)));
|
||||
}
|
||||
|
||||
if (toModerate.isOnline() && punishments)
|
||||
if (toModerate.isOnline() && punishments) {
|
||||
setButton(32, GuiUtils.createButtonItem(CompatibleMaterial.DIAMOND_SWORD,
|
||||
plugin.getLocale().getMessage("gui.player.punishments").getMessage()),
|
||||
plugin.getLocale().getMessage("gui.player.punishments").getMessage()),
|
||||
(event) -> plugin.getGuiManager().showGUI(player, new PunishmentsGui(plugin, toModerate)));
|
||||
}
|
||||
|
||||
if (notes)
|
||||
if (notes) {
|
||||
setButton(42, GuiUtils.createButtonItem(CompatibleMaterial.MAP,
|
||||
plugin.getLocale().getMessage("gui.player.notes").getMessage()),
|
||||
plugin.getLocale().getMessage("gui.player.notes").getMessage()),
|
||||
(event) -> plugin.getGuiManager().showGUI(player,
|
||||
new NotesManagerGui(plugin, toModerate, event.player)));
|
||||
}
|
||||
|
||||
if (moderate)
|
||||
if (moderate) {
|
||||
setButton(40, GuiUtils.createButtonItem(CompatibleMaterial.DIAMOND_CHESTPLATE,
|
||||
plugin.getLocale().getMessage("gui.player.moderate").getMessage()),
|
||||
(event) -> guiManager.showGUI(player, new ModerateGui(plugin, toModerate, event.player)));
|
||||
plugin.getLocale().getMessage("gui.player.moderate").getMessage()),
|
||||
(event) -> this.guiManager.showGUI(player, new ModerateGui(plugin, toModerate, event.player)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,12 +6,12 @@ import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.core.utils.ItemUtils;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.core.utils.TimeUtils;
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.punish.Punishment;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.punish.template.Template;
|
||||
import com.songoda.ultimatemoderation.settings.Settings;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
@ -23,7 +23,6 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PunishGui extends Gui {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
private final Player player;
|
||||
private final OfflinePlayer toModerate;
|
||||
@ -56,15 +55,18 @@ public class PunishGui extends Gui {
|
||||
setTitle(toModerate == null ? plugin.getLocale().getMessage("gui.punish.title.template").getMessage()
|
||||
: plugin.getLocale().getMessage("gui.punish.title")
|
||||
.processPlaceholder("toModerate", toModerate.getName()).getMessage());
|
||||
if (toModerate != null) runTask();
|
||||
if (toModerate != null) {
|
||||
runTask();
|
||||
}
|
||||
|
||||
setOnClose((event) -> Bukkit.getScheduler().cancelTask(task));
|
||||
setOnClose((event) -> Bukkit.getScheduler().cancelTask(this.task));
|
||||
paint();
|
||||
}
|
||||
|
||||
public void paint() {
|
||||
if (inventory != null)
|
||||
inventory.clear();
|
||||
if (this.inventory != null) {
|
||||
this.inventory.clear();
|
||||
}
|
||||
setActionForRange(0, 53, null);
|
||||
|
||||
// decorate the edges
|
||||
@ -81,180 +83,197 @@ public class PunishGui extends Gui {
|
||||
mirrorFill(2, 0, false, true, glass2);
|
||||
mirrorFill(0, 1, true, true, glass2);
|
||||
|
||||
if (toModerate != null)
|
||||
setItem(13, GuiUtils.createButtonItem(ItemUtils.getPlayerSkull(toModerate),
|
||||
TextUtils.formatText("&6&l" + toModerate.getName())));
|
||||
if (this.toModerate != null) {
|
||||
setItem(13, GuiUtils.createButtonItem(ItemUtils.getPlayerSkull(this.toModerate),
|
||||
TextUtils.formatText("&6&l" + this.toModerate.getName())));
|
||||
}
|
||||
|
||||
if (player.hasPermission("um." + type.toString().toLowerCase()))
|
||||
if (this.player.hasPermission("um." + this.type.toString().toLowerCase())) {
|
||||
setButton(22, GuiUtils.createButtonItem(CompatibleMaterial.EMERALD_BLOCK,
|
||||
plugin.getLocale().getMessage("gui.punish.submit").getMessage()),
|
||||
this.plugin.getLocale().getMessage("gui.punish.submit").getMessage()),
|
||||
(event) -> {
|
||||
if (!player.hasPermission("um." + type.toString().toLowerCase())) return;
|
||||
if (duration == -1 && type == PunishmentType.BAN && !player.hasPermission("um.ban.permanent"))
|
||||
if (!this.player.hasPermission("um." + this.type.toString().toLowerCase())) {
|
||||
return;
|
||||
}
|
||||
if (this.duration == -1 && this.type == PunishmentType.BAN && !this.player.hasPermission("um.ban.permanent")) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (toModerate == null) {
|
||||
if (reason == null || templateName == null) return;
|
||||
if (this.toModerate == null) {
|
||||
if (this.reason == null || this.templateName == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (template == null)
|
||||
if (this.template == null) {
|
||||
finishTemplate();
|
||||
else
|
||||
} else {
|
||||
updateTemplate();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
switch (type) {
|
||||
switch (this.type) {
|
||||
case BAN:
|
||||
case MUTE:
|
||||
case WARNING:
|
||||
new Punishment(type, duration, reason).execute(player, toModerate);
|
||||
new Punishment(this.type, this.duration, this.reason).execute(this.player, this.toModerate);
|
||||
break;
|
||||
case KICK:
|
||||
new Punishment(type, reason).execute(player, toModerate);
|
||||
new Punishment(this.type, this.reason).execute(this.player, this.toModerate);
|
||||
break;
|
||||
}
|
||||
player.closeInventory();
|
||||
this.player.closeInventory();
|
||||
});
|
||||
}
|
||||
|
||||
setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR,
|
||||
plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
this.plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
(event) -> {
|
||||
if (toModerate != null)
|
||||
guiManager.showGUI(player, new PlayerGui(plugin, toModerate, player));
|
||||
else
|
||||
guiManager.showGUI(player, new TemplateManagerGui(plugin, player));
|
||||
if (this.toModerate != null) {
|
||||
this.guiManager.showGUI(this.player, new PlayerGui(this.plugin, this.toModerate, this.player));
|
||||
} else {
|
||||
this.guiManager.showGUI(this.player, new TemplateManagerGui(this.plugin, this.player));
|
||||
}
|
||||
});
|
||||
|
||||
setButton(28, GuiUtils.createButtonItem(CompatibleMaterial.ANVIL,
|
||||
plugin.getLocale().getMessage("gui.punish.type.punishment").getMessage(),
|
||||
TextUtils.formatText("&7" + type.getTranslation()),
|
||||
"",
|
||||
plugin.getLocale().getMessage("gui.punish.type.punishment.click").getMessage()),
|
||||
this.plugin.getLocale().getMessage("gui.punish.type.punishment").getMessage(),
|
||||
TextUtils.formatText("&7" + this.type.getTranslation()),
|
||||
"",
|
||||
this.plugin.getLocale().getMessage("gui.punish.type.punishment.click").getMessage()),
|
||||
(event) -> {
|
||||
this.type = this.type.next();
|
||||
justSaved = false;
|
||||
this.justSaved = false;
|
||||
paint();
|
||||
});
|
||||
|
||||
ItemStack templateItem = toModerate != null ? GuiUtils.createButtonItem(CompatibleMaterial.MAP,
|
||||
plugin.getLocale().getMessage("gui.punish.type.template").getMessage(),
|
||||
plugin.getLocale().getMessage("gui.punish.type.template.current")
|
||||
ItemStack templateItem = this.toModerate != null ? GuiUtils.createButtonItem(CompatibleMaterial.MAP,
|
||||
this.plugin.getLocale().getMessage("gui.punish.type.template").getMessage(),
|
||||
this.plugin.getLocale().getMessage("gui.punish.type.template.current")
|
||||
.processPlaceholder("template",
|
||||
template == null
|
||||
? plugin.getLocale().getMessage("gui.general.none").getMessage()
|
||||
: template.getName()).getMessage(),
|
||||
this.template == null
|
||||
? this.plugin.getLocale().getMessage("gui.general.none").getMessage()
|
||||
: this.template.getName()).getMessage(),
|
||||
"",
|
||||
plugin.getLocale().getMessage(plugin.getTemplateManager().getTemplates().size() == 0
|
||||
this.plugin.getLocale().getMessage(this.plugin.getTemplateManager().getTemplates().size() == 0
|
||||
? "gui.punish.type.template.none"
|
||||
: "gui.punish.type.template.click").getMessage())
|
||||
: GuiUtils.createButtonItem(CompatibleMaterial.MAP,
|
||||
plugin.getLocale().getMessage("gui.punish.type.name").getMessage(),
|
||||
plugin.getLocale().getMessage("gui.punish.type.name.current")
|
||||
this.plugin.getLocale().getMessage("gui.punish.type.name").getMessage(),
|
||||
this.plugin.getLocale().getMessage("gui.punish.type.name.current")
|
||||
.processPlaceholder("name",
|
||||
templateName == null
|
||||
? plugin.getLocale().getMessage("gui.punish.type.name.current").getMessage()
|
||||
: templateName).getMessage(),
|
||||
this.templateName == null
|
||||
? this.plugin.getLocale().getMessage("gui.punish.type.name.current").getMessage()
|
||||
: this.templateName).getMessage(),
|
||||
"",
|
||||
plugin.getLocale().getMessage("gui.punish.type.name.current.click").getMessage());
|
||||
this.plugin.getLocale().getMessage("gui.punish.type.name.current.click").getMessage());
|
||||
|
||||
setButton(30, templateItem, (event) -> {
|
||||
if (toModerate == null) {
|
||||
if (this.toModerate == null) {
|
||||
nameTemplate();
|
||||
return;
|
||||
}
|
||||
if (plugin.getTemplateManager().getTemplates().size() == 0) return;
|
||||
if (this.plugin.getTemplateManager().getTemplates().size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (player.hasPermission("um.templates.use"))
|
||||
guiManager.showGUI(player, new TemplateSelectorGui(plugin, this, player));
|
||||
if (this.player.hasPermission("um.templates.use")) {
|
||||
this.guiManager.showGUI(this.player, new TemplateSelectorGui(this.plugin, this, this.player));
|
||||
}
|
||||
});
|
||||
|
||||
if (type != PunishmentType.KICK) {
|
||||
if (this.type != PunishmentType.KICK) {
|
||||
setButton(32, GuiUtils.createButtonItem(CompatibleMaterial.CLOCK,
|
||||
plugin.getLocale().getMessage("gui.punish.type.duration").getMessage(),
|
||||
plugin.getLocale().getMessage("gui.punish.type.duration.leftclick").getMessage(),
|
||||
plugin.getLocale().getMessage("gui.punish.type.duration.rightclick").getMessage(),
|
||||
"",
|
||||
plugin.getLocale().getMessage("gui.punish.type.duration.current").getMessage(),
|
||||
TextUtils.formatText("&6" + (duration == -1 ? plugin.getLocale().getMessage("gui.general.permanent").getMessage()
|
||||
: Methods.makeReadable(duration)))),
|
||||
this.plugin.getLocale().getMessage("gui.punish.type.duration").getMessage(),
|
||||
this.plugin.getLocale().getMessage("gui.punish.type.duration.leftclick").getMessage(),
|
||||
this.plugin.getLocale().getMessage("gui.punish.type.duration.rightclick").getMessage(),
|
||||
"",
|
||||
this.plugin.getLocale().getMessage("gui.punish.type.duration.current").getMessage(),
|
||||
TextUtils.formatText("&6" + (this.duration == -1 ? this.plugin.getLocale().getMessage("gui.general.permanent").getMessage()
|
||||
: TimeUtils.makeReadable(this.duration)))),
|
||||
(event) -> {
|
||||
if (this.type == PunishmentType.KICK) return;
|
||||
if (this.type == PunishmentType.KICK) {
|
||||
return;
|
||||
}
|
||||
if (event.clickType == ClickType.LEFT) {
|
||||
AnvilGui gui = new AnvilGui(player, this);
|
||||
AnvilGui gui = new AnvilGui(this.player, this);
|
||||
gui.setAction(evt -> {
|
||||
this.duration = Methods.parseTime(gui.getInputText());
|
||||
justSaved = false;
|
||||
guiManager.showGUI(player, this);
|
||||
this.duration = TimeUtils.parseTime(gui.getInputText());
|
||||
this.justSaved = false;
|
||||
this.guiManager.showGUI(this.player, this);
|
||||
paint();
|
||||
});
|
||||
|
||||
ItemStack item = new ItemStack(Material.PAPER);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
meta.setDisplayName(duration == -1 || duration == 0 ? "1d 1h 1m" : Methods.makeReadable(duration));
|
||||
meta.setDisplayName(this.duration == -1 || this.duration == 0 ? "1d 1h 1m" : TimeUtils.makeReadable(this.duration));
|
||||
item.setItemMeta(meta);
|
||||
|
||||
gui.setInput(item);
|
||||
guiManager.showGUI(player, gui);
|
||||
this.guiManager.showGUI(this.player, gui);
|
||||
} else {
|
||||
duration = -1;
|
||||
this.duration = -1;
|
||||
paint();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setButton(34, GuiUtils.createButtonItem(CompatibleMaterial.PAPER,
|
||||
plugin.getLocale().getMessage("gui.punish.type.reason").getMessage(),
|
||||
plugin.getLocale().getMessage("gui.punish.type.reason.click").getMessage(),
|
||||
this.plugin.getLocale().getMessage("gui.punish.type.reason").getMessage(),
|
||||
this.plugin.getLocale().getMessage("gui.punish.type.reason.click").getMessage(),
|
||||
"",
|
||||
plugin.getLocale().getMessage("gui.punish.type.reason.current").getMessage(),
|
||||
TextUtils.formatText("&6" + reason)), (event) -> {
|
||||
this.plugin.getLocale().getMessage("gui.punish.type.reason.current").getMessage(),
|
||||
TextUtils.formatText("&6" + this.reason)), (event) -> {
|
||||
|
||||
AnvilGui gui = new AnvilGui(player, this);
|
||||
AnvilGui gui = new AnvilGui(this.player, this);
|
||||
gui.setAction(evnt -> {
|
||||
this.reason = gui.getInputText();
|
||||
justSaved = false;
|
||||
guiManager.showGUI(player, this);
|
||||
this.justSaved = false;
|
||||
this.guiManager.showGUI(this.player, this);
|
||||
paint();
|
||||
});
|
||||
|
||||
ItemStack item = GuiUtils.createButtonItem(CompatibleMaterial.PAPER,
|
||||
reason == null ? plugin.getLocale().getMessage("gui.general.reason").getMessage() : reason);
|
||||
this.reason == null ? this.plugin.getLocale().getMessage("gui.general.reason").getMessage() : this.reason);
|
||||
|
||||
gui.setInput(item);
|
||||
guiManager.showGUI(player, gui);
|
||||
this.guiManager.showGUI(this.player, gui);
|
||||
});
|
||||
}
|
||||
|
||||
private void notifyTemplate() {
|
||||
if (reason == null || (justSaved && template != null)) {
|
||||
inventory.setItem(4, null);
|
||||
if (this.reason == null || (this.justSaved && this.template != null)) {
|
||||
this.inventory.setItem(4, null);
|
||||
return;
|
||||
}
|
||||
|
||||
CompatibleMaterial material = CompatibleMaterial.WHITE_WOOL;
|
||||
String name = plugin.getLocale().getMessage("gui.punish.template.create").getMessage();
|
||||
String name = this.plugin.getLocale().getMessage("gui.punish.template.create").getMessage();
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add(plugin.getLocale().getMessage("gui.punish.template.create2").getMessage());
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.punish.template.create2").getMessage());
|
||||
|
||||
if (!justSaved && template != null) {
|
||||
name = plugin.getLocale().getMessage("gui.punish.template.leftclick").getMessage();
|
||||
if (!this.justSaved && this.template != null) {
|
||||
name = this.plugin.getLocale().getMessage("gui.punish.template.leftclick").getMessage();
|
||||
lore.clear();
|
||||
lore.add(plugin.getLocale().getMessage("gui.punish.template.leftclick2")
|
||||
.processPlaceholder("template", template.getName()).getMessage());
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.punish.template.leftclick2")
|
||||
.processPlaceholder("template", this.template.getName()).getMessage());
|
||||
lore.add("");
|
||||
lore.add(plugin.getLocale().getMessage("gui.punish.template.rightclick").getMessage());
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.punish.template.rightclick").getMessage());
|
||||
}
|
||||
|
||||
if (getItem(4) != null && CompatibleMaterial.getMaterial(getItem(4)) == CompatibleMaterial.WHITE_WOOL)
|
||||
if (getItem(4) != null && CompatibleMaterial.getMaterial(getItem(4)) == CompatibleMaterial.WHITE_WOOL) {
|
||||
material = CompatibleMaterial.YELLOW_WOOL;
|
||||
}
|
||||
|
||||
setButton(4, GuiUtils.createButtonItem(material, name, lore), (event) -> {
|
||||
|
||||
if (reason == null || duration == 0) return;
|
||||
if (this.reason == null || this.duration == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (template != null && event.clickType == ClickType.LEFT) {
|
||||
if (this.template != null && event.clickType == ClickType.LEFT) {
|
||||
updateTemplate();
|
||||
return;
|
||||
}
|
||||
@ -263,51 +282,54 @@ public class PunishGui extends Gui {
|
||||
}
|
||||
|
||||
public void runTask() {
|
||||
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this::notifyTemplate, 10L, 10L);
|
||||
this.task = Bukkit.getScheduler().scheduleSyncRepeatingTask(this.plugin, this::notifyTemplate, 10L, 10L);
|
||||
}
|
||||
|
||||
private void nameTemplate() {
|
||||
AnvilGui gui = new AnvilGui(player, this);
|
||||
AnvilGui gui = new AnvilGui(this.player, this);
|
||||
gui.setAction(event -> {
|
||||
this.templateName = gui.getInputText();
|
||||
|
||||
if (reason != null && templateName != null) {
|
||||
if (template == null)
|
||||
if (this.reason != null && this.templateName != null) {
|
||||
if (this.template == null) {
|
||||
finishTemplate();
|
||||
else
|
||||
} else {
|
||||
updateTemplate();
|
||||
}
|
||||
}
|
||||
|
||||
justSaved = true;
|
||||
guiManager.showGUI(player, this);
|
||||
this.justSaved = true;
|
||||
this.guiManager.showGUI(this.player, this);
|
||||
paint();
|
||||
});
|
||||
|
||||
ItemStack item = GuiUtils.createButtonItem(CompatibleMaterial.PAPER,
|
||||
template == null ? plugin.getLocale().getMessage("gui.general.templatename").getMessage() : template.getName());
|
||||
this.template == null ? this.plugin.getLocale().getMessage("gui.general.templatename").getMessage() : this.template.getName());
|
||||
|
||||
gui.setInput(item);
|
||||
guiManager.showGUI(player, gui);
|
||||
this.guiManager.showGUI(this.player, gui);
|
||||
}
|
||||
|
||||
private void updateTemplate() {
|
||||
Template template = new Template(this.type, this.duration, this.reason, this.template.getCreator(), this.templateName);
|
||||
plugin.getTemplateManager().removeTemplate(this.template);
|
||||
plugin.getTemplateManager().addTemplate(template);
|
||||
plugin.getDataManager().deleteTemplate(this.template);
|
||||
plugin.getDataManager().createTemplate(template);
|
||||
justSaved = true;
|
||||
if (toModerate == null)
|
||||
guiManager.showGUI(player, new TemplateManagerGui(plugin, player));
|
||||
this.plugin.getTemplateManager().removeTemplate(this.template);
|
||||
this.plugin.getTemplateManager().addTemplate(template);
|
||||
this.plugin.getDataManager().deleteTemplate(this.template);
|
||||
this.plugin.getDataManager().createTemplate(template);
|
||||
this.justSaved = true;
|
||||
if (this.toModerate == null) {
|
||||
this.guiManager.showGUI(this.player, new TemplateManagerGui(this.plugin, this.player));
|
||||
}
|
||||
}
|
||||
|
||||
private void finishTemplate() {
|
||||
Template template = new Template(this.type, this.duration, this.reason, player, templateName);
|
||||
plugin.getTemplateManager().addTemplate(template);
|
||||
plugin.getDataManager().createTemplate(template);
|
||||
Template template = new Template(this.type, this.duration, this.reason, this.player, this.templateName);
|
||||
this.plugin.getTemplateManager().addTemplate(template);
|
||||
this.plugin.getDataManager().createTemplate(template);
|
||||
this.template = template;
|
||||
if (toModerate == null)
|
||||
guiManager.showGUI(player, new TemplateManagerGui(plugin, player));
|
||||
if (this.toModerate == null) {
|
||||
this.guiManager.showGUI(this.player, new TemplateManagerGui(this.plugin, this.player));
|
||||
}
|
||||
}
|
||||
|
||||
public void setTemplate(Template template) {
|
||||
|
@ -4,12 +4,12 @@ import com.songoda.core.compatibility.CompatibleMaterial;
|
||||
import com.songoda.core.gui.Gui;
|
||||
import com.songoda.core.gui.GuiUtils;
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.core.utils.TimeUtils;
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.punish.AppliedPunishment;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
|
||||
import com.songoda.ultimatemoderation.settings.Settings;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -19,7 +19,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PunishmentsGui extends Gui {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
private final OfflinePlayer toModerate;
|
||||
|
||||
@ -39,13 +38,14 @@ public class PunishmentsGui extends Gui {
|
||||
}
|
||||
|
||||
protected void showPage() {
|
||||
if (inventory != null)
|
||||
inventory.clear();
|
||||
if (this.inventory != null) {
|
||||
this.inventory.clear();
|
||||
}
|
||||
setActionForRange(0, 53, null);
|
||||
|
||||
|
||||
setNextPage(0, 5, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()));
|
||||
setPrevPage(0, 1, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.back").getMessage()));
|
||||
setNextPage(0, 5, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, this.plugin.getLocale().getMessage("gui.general.next").getMessage()));
|
||||
setPrevPage(0, 1, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, this.plugin.getLocale().getMessage("gui.general.back").getMessage()));
|
||||
setOnPage((event) -> showPage());
|
||||
|
||||
// decorate the edges
|
||||
@ -61,25 +61,27 @@ public class PunishmentsGui extends Gui {
|
||||
mirrorFill(1, 0, true, true, glass2);
|
||||
mirrorFill(0, 1, true, true, glass2);
|
||||
|
||||
PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(toModerate);
|
||||
PlayerPunishData playerPunishData = this.plugin.getPunishmentManager().getPlayer(this.toModerate);
|
||||
|
||||
List<PunishmentHolder> punishments = new ArrayList<>();
|
||||
|
||||
if (currentActivity == Activity.ACTIVE || currentActivity == Activity.BOTH) {
|
||||
if (this.currentActivity == Activity.ACTIVE || this.currentActivity == Activity.BOTH) {
|
||||
for (AppliedPunishment punishment : playerPunishData.getActivePunishments()) {
|
||||
if (punishmentType != PunishmentType.ALL) {
|
||||
if (punishment.getPunishmentType() != punishmentType)
|
||||
if (this.punishmentType != PunishmentType.ALL) {
|
||||
if (punishment.getPunishmentType() != this.punishmentType) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
punishments.add(new PunishmentHolder(Activity.ACTIVE, punishment));
|
||||
}
|
||||
}
|
||||
|
||||
if (currentActivity == Activity.EXPIRED || currentActivity == Activity.BOTH) {
|
||||
if (this.currentActivity == Activity.EXPIRED || this.currentActivity == Activity.BOTH) {
|
||||
for (AppliedPunishment punishment : playerPunishData.getExpiredPunishments()) {
|
||||
if (punishmentType != PunishmentType.ALL) {
|
||||
if (punishment.getPunishmentType() != punishmentType)
|
||||
if (this.punishmentType != PunishmentType.ALL) {
|
||||
if (punishment.getPunishmentType() != this.punishmentType) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
punishments.add(new PunishmentHolder(Activity.EXPIRED, punishment));
|
||||
}
|
||||
@ -88,66 +90,67 @@ public class PunishmentsGui extends Gui {
|
||||
int numNotes = punishments.size();
|
||||
this.pages = (int) Math.floor(numNotes / 28.0);
|
||||
|
||||
punishments = punishments.stream().skip((page - 1) * 28).limit(28)
|
||||
punishments = punishments.stream().skip((this.page - 1) * 28).limit(28)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
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)));
|
||||
this.plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
(event) -> this.guiManager.showGUI(event.player, new PlayerGui(this.plugin, this.toModerate, event.player)));
|
||||
|
||||
setButton(5, 3, GuiUtils.createButtonItem(CompatibleMaterial.APPLE, Methods.formatText("&6" + currentActivity.getTranslation())),
|
||||
setButton(5, 3, GuiUtils.createButtonItem(CompatibleMaterial.APPLE, TextUtils.formatText("&6" + this.currentActivity.getTranslation())),
|
||||
(event) -> {
|
||||
this.currentActivity = currentActivity.next();
|
||||
this.currentActivity = this.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, TextUtils.formatText("&6" + this.punishmentType.name())),
|
||||
(event) -> {
|
||||
this.punishmentType = punishmentType.nextFilter();
|
||||
this.punishmentType = this.punishmentType.nextFilter();
|
||||
this.page = 1;
|
||||
showPage();
|
||||
});
|
||||
|
||||
int num = 11;
|
||||
for (PunishmentHolder punishmentHolder : punishments) {
|
||||
if (num == 16 || num == 36)
|
||||
if (num == 16 || num == 36) {
|
||||
num = num + 2;
|
||||
}
|
||||
AppliedPunishment appliedPunishment = punishmentHolder.getAppliedPunishment();
|
||||
Activity activity = punishmentHolder.getActivity();
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add("");
|
||||
lore.add(plugin.getLocale().getMessage("gui.punishments.reason").getMessage());
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.punishments.reason").getMessage());
|
||||
lore.add("&7" + appliedPunishment.getReason());
|
||||
if (appliedPunishment.getPunishmentType() != PunishmentType.KICK) {
|
||||
lore.add("");
|
||||
lore.add(plugin.getLocale().getMessage("gui.punishments.duration").getMessage());
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.punishments.duration").getMessage());
|
||||
lore.add("&7" + (appliedPunishment.getDuration() != -1
|
||||
? Methods.makeReadable(appliedPunishment.getDuration())
|
||||
: plugin.getLocale().getMessage("gui.general.permanent").getMessage()));
|
||||
? TimeUtils.makeReadable(appliedPunishment.getDuration())
|
||||
: this.plugin.getLocale().getMessage("gui.general.permanent").getMessage()));
|
||||
lore.add("");
|
||||
lore.add(plugin.getLocale().getMessage("gui.punishments.punisher").getMessage());
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.punishments.punisher").getMessage());
|
||||
lore.add("&7" + (appliedPunishment.getPunisher() == null ? "Console" : Bukkit.getOfflinePlayer(appliedPunishment.getPunisher()).getName()));
|
||||
if (activity == Activity.ACTIVE) {
|
||||
lore.add("");
|
||||
if (appliedPunishment.getDuration() != -1) {
|
||||
lore.add(plugin.getLocale().getMessage("gui.punishments.remaining").getMessage());
|
||||
lore.add("&7" + Methods.makeReadable(appliedPunishment.getTimeRemaining()));
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.punishments.remaining").getMessage());
|
||||
lore.add("&7" + TimeUtils.makeReadable(appliedPunishment.getTimeRemaining()));
|
||||
lore.add("");
|
||||
}
|
||||
lore.add(plugin.getLocale().getMessage("gui.punishments.click").getMessage());
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.punishments.click").getMessage());
|
||||
}
|
||||
}
|
||||
lore.add("");
|
||||
setButton(num, GuiUtils.createButtonItem(CompatibleMaterial.MAP,
|
||||
TextUtils.formatText("&6&l" + appliedPunishment.getPunishmentType().getTranslation() + " - &7&l" + activity.getTranslation()),
|
||||
TextUtils.formatText(lore)),
|
||||
TextUtils.formatText("&6&l" + appliedPunishment.getPunishmentType().getTranslation() + " - &7&l" + activity.getTranslation()),
|
||||
TextUtils.formatText(lore)),
|
||||
(event) -> {
|
||||
if (appliedPunishment.getPunishmentType() != PunishmentType.KICK
|
||||
&& activity == Activity.ACTIVE) {
|
||||
appliedPunishment.expire();
|
||||
plugin.getDataManager().updateAppliedPunishment(appliedPunishment);
|
||||
this.plugin.getDataManager().updateAppliedPunishment(appliedPunishment);
|
||||
showPage();
|
||||
}
|
||||
});
|
||||
@ -158,8 +161,7 @@ public class PunishmentsGui extends Gui {
|
||||
}
|
||||
|
||||
|
||||
private class PunishmentHolder {
|
||||
|
||||
private static class PunishmentHolder {
|
||||
private final Activity activity;
|
||||
private final AppliedPunishment appliedPunishment;
|
||||
|
||||
@ -169,26 +171,26 @@ public class PunishmentsGui extends Gui {
|
||||
}
|
||||
|
||||
public Activity getActivity() {
|
||||
return activity;
|
||||
return this.activity;
|
||||
}
|
||||
|
||||
public AppliedPunishment getAppliedPunishment() {
|
||||
return appliedPunishment;
|
||||
return this.appliedPunishment;
|
||||
}
|
||||
}
|
||||
|
||||
private enum Activity {
|
||||
|
||||
BOTH, ACTIVE, EXPIRED;
|
||||
|
||||
private static Activity[] vals = values();
|
||||
|
||||
public Activity next() {
|
||||
return vals[(this.ordinal() != vals.length - 1 ? this.ordinal() + 1 : 0)];
|
||||
return values()[(this.ordinal() != values().length - 1 ? this.ordinal() + 1 : 0)];
|
||||
}
|
||||
|
||||
public String getTranslation() {
|
||||
return UltimateModeration.getInstance().getLocale().getMessage("gui.punishments.activity." + this.name().toLowerCase()).getMessage();
|
||||
return UltimateModeration.getPlugin(UltimateModeration.class)
|
||||
.getLocale()
|
||||
.getMessage("gui.punishments.activity." + this.name().toLowerCase())
|
||||
.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.punish.template.Template;
|
||||
import com.songoda.ultimatemoderation.settings.Settings;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -17,7 +16,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TemplateManagerGui extends Gui {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
private PunishmentType punishmentType = PunishmentType.ALL;
|
||||
@ -52,13 +50,13 @@ public class TemplateManagerGui extends Gui {
|
||||
}
|
||||
|
||||
private void toCurrentPage() {
|
||||
if (inventory != null) {
|
||||
inventory.clear();
|
||||
if (this.inventory != null) {
|
||||
this.inventory.clear();
|
||||
}
|
||||
|
||||
setActionForRange(0, 53, null);
|
||||
|
||||
int numTemplates = plugin.getTemplateManager().getTemplates().size();
|
||||
int numTemplates = this.plugin.getTemplateManager().getTemplates().size();
|
||||
this.pages = (int) Math.floor(numTemplates / 28.0);
|
||||
|
||||
// decorate the edges
|
||||
@ -74,21 +72,21 @@ public class TemplateManagerGui extends Gui {
|
||||
mirrorFill(1, 0, true, true, glass2);
|
||||
mirrorFill(0, 1, true, true, glass2);
|
||||
|
||||
setButton(5, 3, GuiUtils.createButtonItem(CompatibleMaterial.DIAMOND_SWORD, Methods.formatText("&6" + punishmentType.name())),
|
||||
setButton(5, 3, GuiUtils.createButtonItem(CompatibleMaterial.DIAMOND_SWORD, TextUtils.formatText("&6" + this.punishmentType.name())),
|
||||
(event) -> {
|
||||
this.punishmentType = punishmentType.nextFilter();
|
||||
this.punishmentType = this.punishmentType.nextFilter();
|
||||
this.page = 1;
|
||||
toCurrentPage();
|
||||
});
|
||||
|
||||
setButton(5, 4, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR,
|
||||
plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
(event) -> guiManager.showGUI(event.player, new MainGui(plugin, event.player)));
|
||||
this.plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
(event) -> this.guiManager.showGUI(event.player, new MainGui(this.plugin, event.player)));
|
||||
|
||||
if (player.hasPermission("um.templates.create")) {
|
||||
if (this.player.hasPermission("um.templates.create")) {
|
||||
setButton(5, 5, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE,
|
||||
plugin.getLocale().getMessage("gui.templatemanager.create").getMessage()),
|
||||
(event) -> guiManager.showGUI(event.player, new PunishGui(plugin, null, null, player)));
|
||||
this.plugin.getLocale().getMessage("gui.templatemanager.create").getMessage()),
|
||||
(event) -> this.guiManager.showGUI(event.player, new PunishGui(this.plugin, null, null, this.player)));
|
||||
}
|
||||
|
||||
List<Template> templates = findTemplates(this.page, this.punishmentType);
|
||||
@ -100,16 +98,16 @@ public class TemplateManagerGui extends Gui {
|
||||
}
|
||||
|
||||
setButton(num, GuiUtils.createButtonItem(CompatibleMaterial.MAP, TextUtils.formatText("&6&l" + template.getName()),
|
||||
plugin.getLocale().getMessage("gui.templatemanager.leftclick").getMessage(),
|
||||
plugin.getLocale().getMessage("gui.templatemanager.rightclick").getMessage()),
|
||||
this.plugin.getLocale().getMessage("gui.templatemanager.leftclick").getMessage(),
|
||||
this.plugin.getLocale().getMessage("gui.templatemanager.rightclick").getMessage()),
|
||||
(event) -> {
|
||||
if (event.clickType == ClickType.LEFT) {
|
||||
if (player.hasPermission("um.templates.edit"))
|
||||
guiManager.showGUI(player, new PunishGui(plugin, null, template, player));
|
||||
if (this.player.hasPermission("um.templates.edit"))
|
||||
this.guiManager.showGUI(this.player, new PunishGui(this.plugin, null, template, this.player));
|
||||
} else if (event.clickType == ClickType.RIGHT) {
|
||||
if (player.hasPermission("um.templates.destroy")) {
|
||||
plugin.getTemplateManager().removeTemplate(template);
|
||||
plugin.getDataManager().deleteTemplate(template);
|
||||
if (this.player.hasPermission("um.templates.destroy")) {
|
||||
this.plugin.getTemplateManager().removeTemplate(template);
|
||||
this.plugin.getDataManager().deleteTemplate(template);
|
||||
}
|
||||
|
||||
toCurrentPage();
|
||||
@ -119,12 +117,12 @@ public class TemplateManagerGui extends Gui {
|
||||
++num;
|
||||
}
|
||||
|
||||
setButton(0, 3, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.back").getMessage()), (event) -> toPrevPage());
|
||||
setButton(0, 5, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()), (event) -> toNextPage());
|
||||
setButton(0, 3, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, this.plugin.getLocale().getMessage("gui.general.back").getMessage()), (event) -> toPrevPage());
|
||||
setButton(0, 5, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, this.plugin.getLocale().getMessage("gui.general.next").getMessage()), (event) -> toNextPage());
|
||||
}
|
||||
|
||||
private List<Template> findTemplates(int page, PunishmentType punishmentType) {
|
||||
return plugin.getTemplateManager().getTemplates().stream()
|
||||
return this.plugin.getTemplateManager().getTemplates().stream()
|
||||
.filter(template -> punishmentType == PunishmentType.ALL || template.getPunishmentType() == punishmentType)
|
||||
.skip((page - 1) * 28L)
|
||||
.limit(28)
|
||||
|
@ -11,7 +11,6 @@ import org.bukkit.entity.Player;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TemplateSelectorGui extends Gui {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
private final PunishGui punish;
|
||||
|
||||
@ -27,27 +26,26 @@ public class TemplateSelectorGui extends Gui {
|
||||
|
||||
private void paint() {
|
||||
setButton(8, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR,
|
||||
plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
this.plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
(event) -> {
|
||||
guiManager.showGUI(event.player, punish);
|
||||
punish.runTask();
|
||||
this.guiManager.showGUI(event.player, this.punish);
|
||||
this.punish.runTask();
|
||||
});
|
||||
|
||||
ArrayList<Template> templates = new ArrayList<>(plugin.getTemplateManager().getTemplates());
|
||||
ArrayList<Template> templates = new ArrayList<>(this.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()),
|
||||
plugin.getLocale().getMessage("gui.templateselector.click").getMessage()),
|
||||
this.plugin.getLocale().getMessage("gui.templateselector.click").getMessage()),
|
||||
(event) -> {
|
||||
punish.setType(template.getPunishmentType());
|
||||
punish.setDuration(template.getDuration());
|
||||
punish.setReason(template.getReason());
|
||||
punish.setTemplate(template);
|
||||
punish.runTask();
|
||||
punish.paint();
|
||||
guiManager.showGUI(event.player, punish);
|
||||
this.punish.setType(template.getPunishmentType());
|
||||
this.punish.setDuration(template.getDuration());
|
||||
this.punish.setReason(template.getReason());
|
||||
this.punish.setTemplate(template);
|
||||
this.punish.runTask();
|
||||
this.punish.paint();
|
||||
this.guiManager.showGUI(event.player, this.punish);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -23,9 +23,8 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TicketGui extends Gui {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
private final StaffChatManager chatManager = UltimateModeration.getInstance().getStaffChatManager();
|
||||
private final StaffChatManager chatManager;
|
||||
|
||||
private final Ticket ticket;
|
||||
|
||||
@ -38,6 +37,7 @@ public class TicketGui extends Gui {
|
||||
setDefaultItem(null);
|
||||
this.ticket = ticket;
|
||||
this.plugin = plugin;
|
||||
this.chatManager = plugin.getStaffChatManager();
|
||||
this.player = player;
|
||||
this.toModerate = toModerate;
|
||||
|
||||
@ -49,14 +49,15 @@ public class TicketGui extends Gui {
|
||||
}
|
||||
|
||||
private void showPage() {
|
||||
if (inventory != null)
|
||||
inventory.clear();
|
||||
if (this.inventory != null) {
|
||||
this.inventory.clear();
|
||||
}
|
||||
setActionForRange(0, 53, null);
|
||||
|
||||
int numNotes = ticket.getResponses().size();
|
||||
int numNotes = this.ticket.getResponses().size();
|
||||
this.pages = (int) Math.floor(numNotes / 28.0);
|
||||
|
||||
List<TicketResponse> responses = ticket.getResponses().stream().skip((page - 1) * 28).limit(28)
|
||||
List<TicketResponse> responses = this.ticket.getResponses().stream().skip((this.page - 1) * 28).limit(28)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// decorate the edges
|
||||
@ -73,56 +74,61 @@ public class TicketGui extends Gui {
|
||||
mirrorFill(0, 1, true, true, glass2);
|
||||
|
||||
// enable page event
|
||||
setNextPage(4, 7, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()));
|
||||
setPrevPage(4, 1, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.back").getMessage()));
|
||||
setNextPage(4, 7, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, this.plugin.getLocale().getMessage("gui.general.next").getMessage()));
|
||||
setPrevPage(4, 1, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, this.plugin.getLocale().getMessage("gui.general.back").getMessage()));
|
||||
setOnPage((event) -> showPage());
|
||||
|
||||
if (player.hasPermission("um.tickets.openclose"))
|
||||
setButton(5, 3, GuiUtils.createButtonItem(CompatibleMaterial.LEVER, TextUtils.formatText("&6" + ticket.getStatus().getStatus())),
|
||||
if (this.player.hasPermission("um.tickets.openclose")) {
|
||||
setButton(5, 3, GuiUtils.createButtonItem(CompatibleMaterial.LEVER, TextUtils.formatText("&6" + this.ticket.getStatus().getStatus())),
|
||||
(event) -> {
|
||||
ticket.setStatus(ticket.getStatus() == TicketStatus.OPEN ? TicketStatus.CLOSED : TicketStatus.OPEN);
|
||||
plugin.getDataManager().updateTicket(ticket);
|
||||
this.ticket.setStatus(this.ticket.getStatus() == TicketStatus.OPEN ? TicketStatus.CLOSED : TicketStatus.OPEN);
|
||||
this.plugin.getDataManager().updateTicket(this.ticket);
|
||||
// Notify staff of ticket status
|
||||
chatManager.getChat("ticket").messageAll(UltimateModeration.getInstance().getLocale().getMessage("notify.ticket.status").getMessage().replace("%tid%", "" + ticket.getId()).replace("%type%", ticket.getType()).replace("%player%", Bukkit.getPlayer(ticket.getVictim()).getDisplayName()).replace("%status%", ticket.getStatus().toString()));
|
||||
this.chatManager.getChat("ticket").messageAll(this.plugin.getLocale().getMessage("notify.ticket.status").getMessage().replace("%tid%", String.valueOf(this.ticket.getId())).replace("%type%", this.ticket.getType()).replace("%player%", Bukkit.getPlayer(this.ticket.getVictim()).getDisplayName()).replace("%status%", this.ticket.getStatus().toString()));
|
||||
showPage();
|
||||
});
|
||||
}
|
||||
|
||||
setButton(4, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR,
|
||||
plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
this.plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
(event) -> {
|
||||
plugin.getGuiManager().showGUI(event.player, new TicketManagerGui(plugin, toModerate, event.player));
|
||||
this.plugin.getGuiManager().showGUI(event.player, new TicketManagerGui(this.plugin, this.toModerate, event.player));
|
||||
});
|
||||
|
||||
if (player.hasPermission("um.ticket.clicktotele") && ticket.getLocation() != null)
|
||||
if (this.player.hasPermission("um.ticket.clicktotele") && this.ticket.getLocation() != null) {
|
||||
setButton(5, 5, GuiUtils.createButtonItem(CompatibleMaterial.ENDER_PEARL,
|
||||
plugin.getLocale().getMessage("gui.ticket.clicktotele").getMessage()),
|
||||
(event) -> player.teleport(ticket.getLocation()));
|
||||
this.plugin.getLocale().getMessage("gui.ticket.clicktotele").getMessage()),
|
||||
(event) -> this.player.teleport(this.ticket.getLocation()));
|
||||
}
|
||||
|
||||
if (player.hasPermission("um.tickets.respond"))
|
||||
setButton(5, 4, GuiUtils.createButtonItem(CompatibleMaterial.WRITABLE_BOOK, plugin.getLocale().getMessage("gui.ticket.respond").getMessage()),
|
||||
if (this.player.hasPermission("um.tickets.respond")) {
|
||||
setButton(5, 4, GuiUtils.createButtonItem(CompatibleMaterial.WRITABLE_BOOK, this.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()));
|
||||
plugin.getDataManager().createTicketResponse(response);
|
||||
ChatPrompt.showPrompt(this.plugin, this.player, this.plugin.getLocale().getMessage("gui.ticket.what").getMessage(), (evnt) -> {
|
||||
TicketResponse response = this.ticket.addResponse(new TicketResponse(this.player, evnt.getMessage(), System.currentTimeMillis()));
|
||||
this.plugin.getDataManager().createTicketResponse(response);
|
||||
// Notify staff of ticket response.
|
||||
chatManager.getChat("ticket").messageAll(UltimateModeration.getInstance().getLocale().getMessage("notify.ticket.response").getMessage().replace("%tid%", "" + ticket.getId()).replace("%type%", ticket.getType()).replace("%player%", Bukkit.getPlayer(ticket.getVictim()).getDisplayName()));
|
||||
this.chatManager.getChat("ticket").messageAll(this.plugin.getLocale().getMessage("notify.ticket.response").getMessage().replace("%tid%", "" + this.ticket.getId()).replace("%type%", this.ticket.getType()).replace("%player%", Bukkit.getPlayer(this.ticket.getVictim()).getDisplayName()));
|
||||
showPage();
|
||||
}).setOnClose(() -> guiManager.showGUI(event.player, this));
|
||||
}).setOnClose(() -> this.guiManager.showGUI(event.player, this));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
int num = 11;
|
||||
for (TicketResponse ticketResponse : responses) {
|
||||
if (num == 16 || num == 36)
|
||||
if (num == 16 || num == 36) {
|
||||
num = num + 2;
|
||||
}
|
||||
|
||||
String subjectStr = ticketResponse.getMessage();
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
int lastIndex = 0;
|
||||
for (int n = 0; n < subjectStr.length(); n++) {
|
||||
if (n - lastIndex < 20)
|
||||
if (n - lastIndex < 20) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (subjectStr.charAt(n) == ' ') {
|
||||
lore.add(TextUtils.formatText("&6" + subjectStr.substring(lastIndex, n).trim()));
|
||||
@ -130,8 +136,9 @@ public class TicketGui extends Gui {
|
||||
}
|
||||
}
|
||||
|
||||
if (lastIndex - subjectStr.length() < 20)
|
||||
if (lastIndex - subjectStr.length() < 20) {
|
||||
lore.add(TextUtils.formatText("&6" + subjectStr.substring(lastIndex).trim()));
|
||||
}
|
||||
|
||||
String name = lore.get(0);
|
||||
lore.remove(0);
|
||||
@ -141,9 +148,9 @@ public class TicketGui extends Gui {
|
||||
SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy");
|
||||
|
||||
|
||||
lore.add(plugin.getLocale().getMessage("gui.ticket.postedby")
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.ticket.postedby")
|
||||
.processPlaceholder("player", Bukkit.getOfflinePlayer(ticketResponse.getAuthor()).getName()).getMessage());
|
||||
lore.add(plugin.getLocale().getMessage("gui.ticket.createdon")
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.ticket.createdon")
|
||||
.processPlaceholder("sent", format.format(new Date(ticketResponse.getPostedDate()))).getMessage());
|
||||
|
||||
setItem(num, GuiUtils.createButtonItem(CompatibleMaterial.MAP, TextUtils.formatText(name), lore));
|
||||
|
@ -22,7 +22,6 @@ import java.util.stream.Collectors;
|
||||
|
||||
// FIXME: Pagination not working (probably in other GUIs too) (copy own one from TemplateManagerGui)
|
||||
public class TicketManagerGui extends Gui {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
private final OfflinePlayer toModerate;
|
||||
@ -44,18 +43,19 @@ public class TicketManagerGui extends Gui {
|
||||
}
|
||||
|
||||
private void showPage() {
|
||||
if (inventory != null)
|
||||
inventory.clear();
|
||||
if (this.inventory != null) {
|
||||
this.inventory.clear();
|
||||
}
|
||||
setActionForRange(0, 53, null);
|
||||
|
||||
List<Ticket> tickets = toModerate != null
|
||||
? plugin.getTicketManager().getTicketsAbout(toModerate, status)
|
||||
: plugin.getTicketManager().getTickets(status);
|
||||
List<Ticket> tickets = this.toModerate != null
|
||||
? this.plugin.getTicketManager().getTicketsAbout(this.toModerate, this.status)
|
||||
: this.plugin.getTicketManager().getTickets(this.status);
|
||||
|
||||
int numTickets = tickets.size();
|
||||
this.pages = (int) Math.floor(numTickets / 28.0);
|
||||
|
||||
tickets = tickets.stream().skip((page - 1) * 28).limit(28).collect(Collectors.toList());
|
||||
tickets = tickets.stream().skip((this.page - 1) * 28).limit(28).collect(Collectors.toList());
|
||||
|
||||
// decorate the edges
|
||||
ItemStack glass2 = GuiUtils.getBorderItem(Settings.GLASS_TYPE_2.getMaterial(CompatibleMaterial.BLUE_STAINED_GLASS_PANE));
|
||||
@ -71,44 +71,49 @@ public class TicketManagerGui extends Gui {
|
||||
mirrorFill(0, 1, true, true, glass2);
|
||||
|
||||
// enable page event
|
||||
setNextPage(4, 7, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.next").getMessage()));
|
||||
setPrevPage(4, 1, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, plugin.getLocale().getMessage("gui.general.back").getMessage()));
|
||||
setNextPage(4, 7, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, this.plugin.getLocale().getMessage("gui.general.next").getMessage()));
|
||||
setPrevPage(4, 1, GuiUtils.createButtonItem(CompatibleMaterial.ARROW, this.plugin.getLocale().getMessage("gui.general.back").getMessage()));
|
||||
setOnPage((event) -> showPage());
|
||||
|
||||
setButton(5, 3, GuiUtils.createButtonItem(CompatibleMaterial.LEVER, TextUtils.formatText("&6" + status.getStatus())),
|
||||
setButton(5, 3, GuiUtils.createButtonItem(CompatibleMaterial.LEVER, TextUtils.formatText("&6" + this.status.getStatus())),
|
||||
(event) -> {
|
||||
this.status = status == TicketStatus.OPEN ? TicketStatus.CLOSED : TicketStatus.OPEN;
|
||||
this.status = this.status == TicketStatus.OPEN ? TicketStatus.CLOSED : TicketStatus.OPEN;
|
||||
this.page = 1;
|
||||
showPage();
|
||||
});
|
||||
|
||||
if (toModerate != null && player.hasPermission("um.tickets.create"))
|
||||
if (this.toModerate != null && this.player.hasPermission("um.tickets.create")) {
|
||||
setButton(5, 5, GuiUtils.createButtonItem(CompatibleMaterial.REDSTONE,
|
||||
plugin.getLocale().getMessage("gui.tickets.create").getMessage()),
|
||||
(event) -> createNew(player, toModerate));
|
||||
this.plugin.getLocale().getMessage("gui.tickets.create").getMessage()),
|
||||
(event) -> createNew(this.player, this.toModerate));
|
||||
}
|
||||
|
||||
if (player.hasPermission("um.ticket"))
|
||||
if (this.player.hasPermission("um.ticket")) {
|
||||
setButton(5, 4, GuiUtils.createButtonItem(CompatibleMaterial.OAK_DOOR,
|
||||
plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
this.plugin.getLocale().getMessage("gui.general.back").getMessage()),
|
||||
(event) -> {
|
||||
if (toModerate == null)
|
||||
plugin.getGuiManager().showGUI(player, new MainGui(plugin, player));
|
||||
else
|
||||
plugin.getGuiManager().showGUI(event.player, new PlayerGui(plugin, toModerate, event.player));
|
||||
if (this.toModerate == null) {
|
||||
this.plugin.getGuiManager().showGUI(this.player, new MainGui(this.plugin, this.player));
|
||||
} else {
|
||||
this.plugin.getGuiManager().showGUI(event.player, new PlayerGui(this.plugin, this.toModerate, event.player));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
int num = 11;
|
||||
for (Ticket ticket : tickets) {
|
||||
if (num == 16 || num == 36)
|
||||
if (num == 16 || num == 36) {
|
||||
num = num + 2;
|
||||
}
|
||||
|
||||
String subjectStr = ticket.getSubject();
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
int lastIndex = 0;
|
||||
for (int n = 0; n < subjectStr.length(); n++) {
|
||||
if (n - lastIndex < 20)
|
||||
if (n - lastIndex < 20) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (subjectStr.charAt(n) == ' ') {
|
||||
lore.add("&6" + subjectStr.substring(lastIndex, n).trim());
|
||||
@ -116,8 +121,9 @@ public class TicketManagerGui extends Gui {
|
||||
}
|
||||
}
|
||||
|
||||
if (lastIndex - subjectStr.length() < 20)
|
||||
if (lastIndex - subjectStr.length() < 20) {
|
||||
lore.add("&6" + subjectStr.substring(lastIndex).trim() + " &7- " + ticket.getId());
|
||||
}
|
||||
|
||||
String name = lore.get(0);
|
||||
lore.remove(0);
|
||||
@ -126,27 +132,28 @@ public class TicketManagerGui extends Gui {
|
||||
|
||||
SimpleDateFormat format = new SimpleDateFormat("MM-dd-yyyy");
|
||||
|
||||
lore.add(plugin.getLocale().getMessage("gui.ticket.status")
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.ticket.status")
|
||||
.processPlaceholder("status", ticket.getStatus().getStatus()).getMessage());
|
||||
|
||||
if (toModerate != null)
|
||||
lore.add(plugin.getLocale().getMessage("gui.tickets.player")
|
||||
if (this.toModerate != null) {
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.tickets.player")
|
||||
.processPlaceholder("player", Bukkit.getOfflinePlayer(ticket.getVictim()).getName()).getMessage());
|
||||
lore.add(plugin.getLocale().getMessage("gui.ticket.type")
|
||||
}
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.ticket.type")
|
||||
.processPlaceholder("type", ticket.getType()).getMessage());
|
||||
lore.add(plugin.getLocale().getMessage("gui.ticket.createdon")
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.ticket.createdon")
|
||||
.processPlaceholder("sent", format.format(new Date(ticket.getCreationDate()))).getMessage());
|
||||
lore.add(plugin.getLocale().getMessage("gui.tickets.click").getMessage());
|
||||
lore.add(this.plugin.getLocale().getMessage("gui.tickets.click").getMessage());
|
||||
|
||||
setButton(num, GuiUtils.createButtonItem(CompatibleMaterial.MAP,
|
||||
TextUtils.formatText(name), TextUtils.formatText(lore)),
|
||||
(event) -> guiManager.showGUI(player, new TicketGui(plugin, ticket, toModerate, player)));
|
||||
TextUtils.formatText(name), TextUtils.formatText(lore)),
|
||||
(event) -> this.guiManager.showGUI(this.player, new TicketGui(this.plugin, ticket, this.toModerate, this.player)));
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
public static void createNew(Player player, OfflinePlayer toModerate) {
|
||||
UltimateModeration plugin = UltimateModeration.getInstance();
|
||||
UltimateModeration plugin = UltimateModeration.getPlugin(UltimateModeration.class);
|
||||
|
||||
AnvilGui gui = new AnvilGui(player);
|
||||
gui.setAction((event) ->
|
||||
|
@ -16,16 +16,15 @@ import org.bukkit.entity.Player;
|
||||
import java.util.List;
|
||||
|
||||
public class TicketTypeGui extends Gui {
|
||||
|
||||
private final StaffChatManager chatManager = UltimateModeration.getInstance().getStaffChatManager();
|
||||
private final StaffChatManager chatManager;
|
||||
|
||||
public TicketTypeGui(UltimateModeration plugin, OfflinePlayer toModerate, Player player, String subject) {
|
||||
super(3);
|
||||
this.chatManager = plugin.getStaffChatManager();
|
||||
|
||||
setDefaultItem(null);
|
||||
|
||||
setTitle(plugin.getLocale().getMessage("gui.ticket.picktype").getMessage());
|
||||
|
||||
|
||||
List<String> types = Settings.TICKET_TYPES.getStringList();
|
||||
|
||||
for (int i = 0; i < types.size(); i++) {
|
||||
@ -39,13 +38,14 @@ public class TicketTypeGui extends Gui {
|
||||
plugin.getTicketManager().addTicket(ticket);
|
||||
|
||||
// Notify staff
|
||||
chatManager.getChat("ticket").messageAll(UltimateModeration.getInstance().getLocale().getMessage("notify.ticket.created").getMessage().replace("%tid%", "" + ticket.getId()).replace("%type%", ticket.getType()).replace("%player%", Bukkit.getPlayer(ticket.getVictim()).getDisplayName()));
|
||||
if (player == toModerate)
|
||||
this.chatManager.getChat("ticket").messageAll(plugin.getLocale().getMessage("notify.ticket.created").getMessage().replace("%tid%", String.valueOf(ticket.getId())).replace("%type%", ticket.getType()).replace("%player%", Bukkit.getPlayer(ticket.getVictim()).getDisplayName()));
|
||||
if (player == toModerate) {
|
||||
ticket.setLocation(player.getLocation());
|
||||
}
|
||||
ticket.addResponse(new TicketResponse(player, event2.getMessage(), System.currentTimeMillis()));
|
||||
plugin.getDataManager().createTicket(ticket);
|
||||
}).setOnClose(() ->
|
||||
guiManager.showGUI(event.player, new TicketGui(plugin, ticket, toModerate, player)));
|
||||
this.guiManager.showGUI(event.player, new TicketGui(plugin, ticket, toModerate, player)));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -13,29 +13,35 @@ import org.bukkit.event.block.BlockBreakEvent;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockListener implements Listener {
|
||||
|
||||
private UltimateModeration instance;
|
||||
private StaffChatManager chat = UltimateModeration.getInstance().getStaffChatManager();
|
||||
private final UltimateModeration instance;
|
||||
private final StaffChatManager chat;
|
||||
|
||||
public BlockListener(UltimateModeration ultimateModeration) {
|
||||
this.instance = ultimateModeration;
|
||||
this.chat = ultimateModeration.getStaffChatManager();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
Material material = block.getType();
|
||||
|
||||
List<String> blocks = instance.getConfig().getStringList("Main.Notify Blocks List");
|
||||
List<String> blocks = this.instance.getConfig().getStringList("Main.Notify Blocks List");
|
||||
|
||||
for (String broken : blocks) {
|
||||
if (!broken.equalsIgnoreCase(material.name())) continue;
|
||||
if (!broken.equalsIgnoreCase(material.name())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (player.hasPermission("um.trackblockbreaks") && instance.getConfig().getBoolean("Main.Notify Blocks")) {
|
||||
chat.getChat("notify").messageAll("&7[UM] &a" + Bukkit.getPlayer(player.getUniqueId()).getDisplayName()
|
||||
+ UltimateModeration.getInstance().getLocale().getMessage("notify.block.main").getMessage().replace("%material%", material.name()) + "(" + block.getX() + ", " + block.getY() + ", " + block.getZ() + ")&a!");
|
||||
if (player.hasPermission("um.trackblockbreaks") && this.instance.getConfig().getBoolean("Main.Notify Blocks")) {
|
||||
this.chat.getChat("notify").messageAll("&7[UM] &a" + Bukkit.getPlayer(player.getUniqueId()).getDisplayName()
|
||||
+ this.instance
|
||||
.getLocale()
|
||||
.getMessage("notify.block.main")
|
||||
.getMessage()
|
||||
.replace("%material%", material.name())
|
||||
+ "(" + block.getX() + ", " + block.getY() + ", " + block.getZ() + ")&a!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.songoda.ultimatemoderation.listeners;
|
||||
|
||||
import com.songoda.core.utils.TimeUtils;
|
||||
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 org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@ -18,7 +18,6 @@ import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ChatListener implements Listener {
|
||||
|
||||
private static long slowModeOverride = 0;
|
||||
|
||||
private static boolean isChatToggled = true; // true means people can talk, false means muted
|
||||
@ -32,7 +31,7 @@ public class ChatListener implements Listener {
|
||||
isChatToggled = toggled;
|
||||
}
|
||||
|
||||
private static List<Log> chatLog = new ArrayList<>();
|
||||
private static final List<Log> chatLog = new ArrayList<>();
|
||||
|
||||
public static long getSlowModeOverride() {
|
||||
return slowModeOverride;
|
||||
@ -41,14 +40,15 @@ public class ChatListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onChat(AsyncPlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (!onChat(player, event.getMessage()))
|
||||
if (!onChat(player, event.getMessage())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean onChat(Player player, String message) {
|
||||
UltimateModeration instance = UltimateModeration.getInstance();
|
||||
|
||||
long slowmode = slowModeOverride == 0 ? Methods.parseTime(Settings.SLOW_MODE.getString()) : slowModeOverride;
|
||||
long slowmode = slowModeOverride == 0 ? TimeUtils.parseTime(Settings.SLOW_MODE.getString()) : slowModeOverride;
|
||||
|
||||
if (!player.hasPermission("um.slowmode.bypass") && slowmode != 0) {
|
||||
List<Log> chats = chatLog.stream().filter(log -> log.player == player.getUniqueId()).collect(Collectors.toList());
|
||||
@ -63,7 +63,9 @@ public class ChatListener implements Listener {
|
||||
boolean isCancelled = false;
|
||||
|
||||
for (StaffChannel channel : instance.getStaffChatManager().getChats().values()) {
|
||||
if (!channel.listMembers().contains(player.getUniqueId())) continue;
|
||||
if (!channel.listMembers().contains(player.getUniqueId())) {
|
||||
continue;
|
||||
}
|
||||
isCancelled = true;
|
||||
channel.processMessage(message, player);
|
||||
}
|
||||
@ -95,10 +97,9 @@ public class ChatListener implements Listener {
|
||||
}
|
||||
|
||||
public static class Log {
|
||||
|
||||
private UUID player;
|
||||
private long sent;
|
||||
private String message;
|
||||
private final UUID player;
|
||||
private final long sent;
|
||||
private final String message;
|
||||
|
||||
Log(UUID player, long sent, String message) {
|
||||
this.player = player;
|
||||
@ -107,16 +108,15 @@ public class ChatListener implements Listener {
|
||||
}
|
||||
|
||||
public UUID getPlayer() {
|
||||
return player;
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public long getSent() {
|
||||
return sent;
|
||||
return this.sent;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
return this.message;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -14,8 +14,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandListener implements Listener {
|
||||
|
||||
private UltimateModeration instance;
|
||||
private final UltimateModeration instance;
|
||||
|
||||
public CommandListener(UltimateModeration ultimateModeration) {
|
||||
this.instance = ultimateModeration;
|
||||
@ -24,36 +23,34 @@ public class CommandListener implements Listener {
|
||||
@EventHandler
|
||||
public void onCommand(PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
||||
String command = event.getMessage();
|
||||
|
||||
List<AppliedPunishment> appliedPunishments = instance.getPunishmentManager().getPlayer(player).getActivePunishments(PunishmentType.MUTE);
|
||||
List<AppliedPunishment> appliedPunishments = this.instance.getPunishmentManager().getPlayer(player).getActivePunishments(PunishmentType.MUTE);
|
||||
if (!appliedPunishments.isEmpty()) {
|
||||
if (Settings.MUTE_DISABLED_COMMANDS.getStringList().stream()
|
||||
.anyMatch(s -> command.toUpperCase().startsWith("/" + s.toUpperCase())))
|
||||
if (Settings.MUTE_DISABLED_COMMANDS.getStringList().stream().anyMatch(s -> command.toUpperCase().startsWith("/" + s.toUpperCase()))) {
|
||||
event.setCancelled(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
List<String> blockedCommands = Settings.BLOCKED_COMMANDS.getStringList();
|
||||
|
||||
for (String cmd : blockedCommands) {
|
||||
if (command.toUpperCase().startsWith("/" + cmd.toUpperCase())
|
||||
&& (command.toUpperCase().endsWith(cmd.toUpperCase()) || (command.contains(" ") && command.split(" ")[0].toUpperCase().endsWith(cmd.toUpperCase())))
|
||||
&& !player.hasPermission("um.commandblock.bypass")) {
|
||||
event.setCancelled(true);
|
||||
event.setMessage("-");
|
||||
instance.getLocale().getMessage("event.command.blocked").sendPrefixedMessage(player);
|
||||
this.instance.getLocale().getMessage("event.command.blocked").sendPrefixedMessage(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (!player.hasPermission("um.commandspy.immune")) {
|
||||
for (Player pl : Bukkit.getOnlinePlayers()) {
|
||||
if (pl != player && pl.hasPermission("um.commandspy") && SpyModeration.isSpying(pl))
|
||||
instance.getLocale().getMessage("command.commandspy.deny")
|
||||
if (pl != player && pl.hasPermission("um.commandspy") && SpyModeration.isSpying(pl)) {
|
||||
this.instance.getLocale().getMessage("command.commandspy.deny")
|
||||
.processPlaceholder("player", player.getName())
|
||||
.processPlaceholder("command", command)
|
||||
.sendPrefixedMessage(pl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.songoda.ultimatemoderation.listeners;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -13,14 +12,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class DeathListener implements Listener {
|
||||
|
||||
private static Map<UUID, List<ItemStack>> playerDrops = new HashMap<>();
|
||||
|
||||
private UltimateModeration instance;
|
||||
|
||||
public DeathListener(UltimateModeration ultimateModeration) {
|
||||
this.instance = ultimateModeration;
|
||||
}
|
||||
private static final Map<UUID, List<ItemStack>> playerDrops = new HashMap<>();
|
||||
|
||||
public static List<ItemStack> getLastDrop(Player player) {
|
||||
return playerDrops.get(player.getUniqueId());
|
||||
|
@ -8,8 +8,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
|
||||
public class DropListener implements Listener {
|
||||
|
||||
private UltimateModeration instance;
|
||||
private final UltimateModeration instance;
|
||||
|
||||
public DropListener(UltimateModeration ultimateModeration) {
|
||||
this.instance = ultimateModeration;
|
||||
@ -20,7 +19,7 @@ public class DropListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
if (FreezeModeration.isFrozen(player)) {
|
||||
event.setCancelled(true);
|
||||
instance.getLocale().getMessage("command.freeze.nope").sendPrefixedMessage(player);
|
||||
this.instance.getLocale().getMessage("command.freeze.nope").sendPrefixedMessage(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
|
||||
public class InventoryListener implements Listener {
|
||||
|
||||
private UltimateModeration plugin;
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public InventoryListener(UltimateModeration ultimateModeration) {
|
||||
this.plugin = ultimateModeration;
|
||||
@ -17,11 +16,14 @@ public class InventoryListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onMove(InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player)) return;
|
||||
if (!(event.getWhoClicked() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (FreezeModeration.isFrozen(player)) {
|
||||
event.setCancelled(true);
|
||||
plugin.getLocale().getMessage("command.freeze.nope").sendPrefixedMessage(player);
|
||||
this.plugin.getLocale().getMessage("command.freeze.nope").sendPrefixedMessage(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.songoda.ultimatemoderation.listeners;
|
||||
|
||||
import com.songoda.core.utils.TimeUtils;
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.commands.CommandVanish;
|
||||
import com.songoda.ultimatemoderation.punish.AppliedPunishment;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -15,8 +15,7 @@ import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import java.util.List;
|
||||
|
||||
public class LoginListener implements Listener {
|
||||
|
||||
private UltimateModeration instance;
|
||||
private final UltimateModeration instance;
|
||||
|
||||
public LoginListener(UltimateModeration ultimateModeration) {
|
||||
this.instance = ultimateModeration;
|
||||
@ -24,17 +23,19 @@ public class LoginListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPreLogin(AsyncPlayerPreLoginEvent event) {
|
||||
PlayerPunishData playerPunishData = instance.getPunishmentManager().getPlayer(event.getUniqueId());
|
||||
PlayerPunishData playerPunishData = this.instance.getPunishmentManager().getPlayer(event.getUniqueId());
|
||||
|
||||
List<AppliedPunishment> appliedPunishments = playerPunishData.getActivePunishments(PunishmentType.BAN);
|
||||
|
||||
if (appliedPunishments.isEmpty()) return;
|
||||
if (appliedPunishments.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
AppliedPunishment appliedPunishment = playerPunishData.getActivePunishments(PunishmentType.BAN).get(0);
|
||||
|
||||
event.setKickMessage(instance.getLocale().getMessage("event.ban.message")
|
||||
event.setKickMessage(this.instance.getLocale().getMessage("event.ban.message")
|
||||
.processPlaceholder("reason", appliedPunishment.getReason() == null ? "" : appliedPunishment.getReason())
|
||||
.processPlaceholder("duration", Methods.makeReadable(appliedPunishment.getTimeRemaining())).getMessage());
|
||||
.processPlaceholder("duration", TimeUtils.makeReadable(appliedPunishment.getTimeRemaining())).getMessage());
|
||||
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_BANNED);
|
||||
|
||||
|
@ -9,15 +9,17 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
|
||||
|
||||
public class MobTargetLister implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onMobTagetEvent(EntityTargetLivingEntityEvent e) {
|
||||
if (!(e.getTarget() instanceof Player)) return;
|
||||
if (!(e.getEntity() instanceof Monster)) return;
|
||||
if (!(e.getTarget() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
if (!(e.getEntity() instanceof Monster)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (CommandVanish.isVanished(((Player) e.getTarget()).getPlayer())) {
|
||||
e.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -8,8 +8,7 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public class MoveListener implements Listener {
|
||||
|
||||
private UltimateModeration instance;
|
||||
private final UltimateModeration instance;
|
||||
|
||||
public MoveListener(UltimateModeration ultimateModeration) {
|
||||
this.instance = ultimateModeration;
|
||||
@ -20,7 +19,7 @@ public class MoveListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
if (FreezeModeration.isFrozen(player)) {
|
||||
event.setCancelled(true);
|
||||
instance.getLocale().getMessage("command.freeze.nope").sendPrefixedMessage(player);
|
||||
this.instance.getLocale().getMessage("command.freeze.nope").sendPrefixedMessage(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,14 @@
|
||||
package com.songoda.ultimatemoderation.listeners;
|
||||
|
||||
import com.songoda.skyblock.api.event.player.PlayerIslandChatEvent;
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class SkyBlockListener implements Listener {
|
||||
|
||||
private UltimateModeration instance;
|
||||
|
||||
public SkyBlockListener(UltimateModeration ultimateModeration) {
|
||||
this.instance = ultimateModeration;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onIslandChat(PlayerIslandChatEvent event) {
|
||||
if (!ChatListener.onChat(event.getPlayer(), event.getMessage()))
|
||||
if (!ChatListener.onChat(event.getPlayer(), event.getMessage())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,21 +17,31 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SpyingDismountListener implements Listener {
|
||||
private static final Map<UUID, GameMode> gamemodes = new HashMap<>();
|
||||
|
||||
private static Map<UUID, GameMode> gamemodes = new HashMap<>();
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public SpyingDismountListener(UltimateModeration plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||
public void onEntityDismountEvent(EntityDismountEvent event) {
|
||||
if (!(event.getDismounted() instanceof Player)) return;
|
||||
if (!(event.getEntity() instanceof Player)) return;
|
||||
if (!(event.getDismounted() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
if (!(event.getEntity() instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SpyModeration.isSpying((((Player) event.getEntity()).getPlayer()))) {
|
||||
Player player = (Player) event.getEntity();
|
||||
gamemodes.put(player.getUniqueId(), player.getGameMode());
|
||||
player.setGameMode(GameMode.SPECTATOR);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateModeration.getInstance(), () -> {
|
||||
|
||||
if (player.getGameMode() == GameMode.SPECTATOR)
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(this.plugin, () -> {
|
||||
if (player.getGameMode() == GameMode.SPECTATOR) {
|
||||
player.setSpectatorTarget(event.getDismounted());
|
||||
}
|
||||
}, 5L);
|
||||
}
|
||||
}
|
||||
@ -39,8 +49,10 @@ 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)
|
||||
if (player.isSneaking() || !SpyModeration.isSpying(player) || player.getGameMode() != GameMode.SPECTATOR) {
|
||||
return;
|
||||
}
|
||||
|
||||
SpyModeration.spy(null, player);
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public abstract class AbstractModeration {
|
||||
|
||||
protected final UltimateModeration plugin;
|
||||
private final boolean requireOnline, allowConsole;
|
||||
|
||||
@ -43,12 +42,12 @@ public abstract class AbstractModeration {
|
||||
}
|
||||
|
||||
public boolean runPreModeration(CommandSender runner, OfflinePlayer toModerate) {
|
||||
if (requireOnline && !toModerate.isOnline()) {
|
||||
plugin.getLocale().newMessage(toModerate.getName() + " must be online for this moderation.").sendPrefixedMessage(runner);
|
||||
if (this.requireOnline && !toModerate.isOnline()) {
|
||||
this.plugin.getLocale().newMessage(toModerate.getName() + " must be online for this moderation.").sendPrefixedMessage(runner);
|
||||
}
|
||||
|
||||
if (isExempt(toModerate)) {
|
||||
plugin.getLocale().newMessage(toModerate.getName() + " is exempt from this moderation.").sendPrefixedMessage(runner);
|
||||
this.plugin.getLocale().newMessage(toModerate.getName() + " is exempt from this moderation.").sendPrefixedMessage(runner);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -58,10 +57,10 @@ public abstract class AbstractModeration {
|
||||
protected abstract boolean runModeration(CommandSender runner, OfflinePlayer toModerate);
|
||||
|
||||
public boolean isRequireOnline() {
|
||||
return requireOnline;
|
||||
return this.requireOnline;
|
||||
}
|
||||
|
||||
public boolean isAllowConsole() {
|
||||
return allowConsole;
|
||||
return this.allowConsole;
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GenericModerationCommand extends AbstractCommand {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
private final AbstractModeration moderation;
|
||||
|
||||
@ -23,17 +22,18 @@ public class GenericModerationCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(CommandSender sender, String... args) {
|
||||
if (args.length != 1)
|
||||
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...");
|
||||
this.plugin.getLocale().newMessage("&cThis player has never played this server before...");
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
moderation.runPreModeration(sender, player);
|
||||
this.moderation.runPreModeration(sender, player);
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
@ -52,16 +52,16 @@ public class GenericModerationCommand extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return moderation.getPermission();
|
||||
return this.moderation.getPermission();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/" + moderation.getProper() + " <player>";
|
||||
return "/" + this.moderation.getProper() + " <player>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return moderation.getDescription();
|
||||
return this.moderation.getDescription();
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class ModerationManager {
|
||||
|
||||
private static final Map<ModerationType, AbstractModeration> moderations = new TreeMap<>();
|
||||
|
||||
public ModerationManager(UltimateModeration plugin) {
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.songoda.ultimatemoderation.moderate;
|
||||
|
||||
public enum ModerationType {
|
||||
|
||||
FREEZE, SPY, INV_SEE, ENDER_VIEW, REVIVE
|
||||
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FreezeModeration extends AbstractModeration {
|
||||
|
||||
private static final List<UUID> frozen = new ArrayList<>();
|
||||
|
||||
public FreezeModeration(UltimateModeration plugin) {
|
||||
@ -44,16 +43,18 @@ public class FreezeModeration extends AbstractModeration {
|
||||
protected boolean runModeration(CommandSender runner, OfflinePlayer toModerate) {
|
||||
if (frozen.contains(toModerate.getUniqueId())) {
|
||||
frozen.remove(toModerate.getUniqueId());
|
||||
plugin.getLocale().getMessage("command.freeze.remove")
|
||||
this.plugin.getLocale().getMessage("command.freeze.remove")
|
||||
.processPlaceholder("player", toModerate.getPlayer().getDisplayName()).sendPrefixedMessage(runner);
|
||||
if (toModerate.isOnline())
|
||||
plugin.getLocale().getMessage("command.freeze.alertremove").sendPrefixedMessage(toModerate.getPlayer());
|
||||
if (toModerate.isOnline()) {
|
||||
this.plugin.getLocale().getMessage("command.freeze.alertremove").sendPrefixedMessage(toModerate.getPlayer());
|
||||
}
|
||||
} else {
|
||||
frozen.add(toModerate.getUniqueId());
|
||||
plugin.getLocale().getMessage("command.freeze.add")
|
||||
this.plugin.getLocale().getMessage("command.freeze.add")
|
||||
.processPlaceholder("player", toModerate.getPlayer().getDisplayName()).sendPrefixedMessage(runner);
|
||||
if (toModerate.isOnline())
|
||||
plugin.getLocale().getMessage("command.freeze.alertadd").sendPrefixedMessage(toModerate.getPlayer());
|
||||
if (toModerate.isOnline()) {
|
||||
this.plugin.getLocale().getMessage("command.freeze.alertadd").sendPrefixedMessage(toModerate.getPlayer());
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class InvSeeModeration extends AbstractModeration {
|
||||
|
||||
public InvSeeModeration(UltimateModeration plugin) {
|
||||
super(plugin, true, false);
|
||||
registerCommand(plugin);
|
||||
|
@ -14,9 +14,12 @@ import org.bukkit.inventory.ItemStack;
|
||||
import java.util.List;
|
||||
|
||||
public class ReviveModeration extends AbstractModeration {
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
public ReviveModeration(UltimateModeration plugin) {
|
||||
super(plugin, true, true);
|
||||
this.plugin = plugin;
|
||||
|
||||
registerCommand(plugin);
|
||||
}
|
||||
|
||||
@ -43,11 +46,10 @@ public class ReviveModeration extends AbstractModeration {
|
||||
@Override
|
||||
protected boolean runModeration(CommandSender runner, OfflinePlayer toModerate) {
|
||||
Player toModeratePlayer = (Player) toModerate;
|
||||
UltimateModeration instance = UltimateModeration.getInstance();
|
||||
List<ItemStack> drops = DeathListener.getLastDrop(toModeratePlayer);
|
||||
|
||||
if (drops == null) {
|
||||
instance.getLocale().getMessage("command.revive.noloot").sendPrefixedMessage(runner);
|
||||
this.plugin.getLocale().getMessage("command.revive.noloot").sendPrefixedMessage(runner);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -56,8 +58,8 @@ public class ReviveModeration extends AbstractModeration {
|
||||
|
||||
PlayerUtils.giveItem(toModeratePlayer, dropArr);
|
||||
|
||||
instance.getLocale().getMessage("command.revive.revived").sendPrefixedMessage(toModeratePlayer);
|
||||
instance.getLocale().getMessage("command.revive.success")
|
||||
this.plugin.getLocale().getMessage("command.revive.revived").sendPrefixedMessage(toModeratePlayer);
|
||||
this.plugin.getLocale().getMessage("command.revive.success")
|
||||
.processPlaceholder("player", toModerate.getName()).sendPrefixedMessage(runner);
|
||||
return true;
|
||||
}
|
||||
|
@ -17,8 +17,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class SpyModeration extends AbstractModeration {
|
||||
|
||||
private static Map<UUID, Spy> spying = new HashMap<>();
|
||||
private static final Map<UUID, Spy> spying = new HashMap<>();
|
||||
|
||||
public SpyModeration(UltimateModeration plugin) {
|
||||
super(plugin, true, false);
|
||||
@ -53,10 +52,11 @@ public class SpyModeration extends AbstractModeration {
|
||||
if (spying.containsKey(runnerPlayer.getUniqueId())) {
|
||||
Spy spyingEntry = spying.remove(runnerPlayer.getUniqueId());
|
||||
runnerPlayer.teleport(spyingEntry.getLastLocation());
|
||||
if (spyingEntry.isVanishApplied() && CommandVanish.isVanished(runnerPlayer))
|
||||
if (spyingEntry.isVanishApplied() && CommandVanish.isVanished(runnerPlayer)) {
|
||||
CommandVanish.vanish(runnerPlayer);
|
||||
}
|
||||
|
||||
plugin.getLocale().getMessage("command.spy.returned").sendPrefixedMessage(runner);
|
||||
this.plugin.getLocale().getMessage("command.spy.returned").sendPrefixedMessage(runner);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -74,8 +74,9 @@ public class SpyModeration extends AbstractModeration {
|
||||
if (spying.containsKey(senderP) && oPlayer == null) {
|
||||
Spy spyingEntry = spying.remove(senderP.getUniqueId());
|
||||
senderP.teleport(spyingEntry.getLastLocation());
|
||||
if (spyingEntry.isVanishApplied() && CommandVanish.isVanished(senderP))
|
||||
if (spyingEntry.isVanishApplied() && CommandVanish.isVanished(senderP)) {
|
||||
CommandVanish.vanish(senderP);
|
||||
}
|
||||
senderP.setGameMode(SpyingDismountListener.getGamemodes().get(senderP.getUniqueId()));
|
||||
|
||||
UltimateModeration.getInstance().getLocale().getMessage("command.spy.returned").sendPrefixedMessage(senderP);
|
||||
@ -114,8 +115,8 @@ public class SpyModeration extends AbstractModeration {
|
||||
}
|
||||
|
||||
public static class Spy {
|
||||
private Location lastLocation;
|
||||
private boolean vanishApplied;
|
||||
private final Location lastLocation;
|
||||
private final boolean vanishApplied;
|
||||
|
||||
public Spy(Location lastLocation, boolean vanishApplied) {
|
||||
this.lastLocation = lastLocation;
|
||||
@ -123,11 +124,11 @@ public class SpyModeration extends AbstractModeration {
|
||||
}
|
||||
|
||||
public Location getLastLocation() {
|
||||
return lastLocation;
|
||||
return this.lastLocation;
|
||||
}
|
||||
|
||||
public boolean isVanishApplied() {
|
||||
return vanishApplied;
|
||||
return this.vanishApplied;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class ViewEnderChestModeration extends AbstractModeration {
|
||||
|
||||
public ViewEnderChestModeration(UltimateModeration plugin) {
|
||||
super(plugin, true, false);
|
||||
registerCommand(plugin);
|
||||
|
@ -3,7 +3,6 @@ package com.songoda.ultimatemoderation.punish;
|
||||
import java.util.UUID;
|
||||
|
||||
public class AppliedPunishment extends Punishment {
|
||||
|
||||
private final UUID victim;
|
||||
private final UUID punisher;
|
||||
private long expiration;
|
||||
@ -30,15 +29,15 @@ public class AppliedPunishment extends Punishment {
|
||||
}
|
||||
|
||||
public UUID getVictim() {
|
||||
return victim;
|
||||
return this.victim;
|
||||
}
|
||||
|
||||
public UUID getPunisher() {
|
||||
return punisher;
|
||||
return this.punisher;
|
||||
}
|
||||
|
||||
public long getExpiration() {
|
||||
return expiration;
|
||||
return this.expiration;
|
||||
}
|
||||
|
||||
public void expire() {
|
||||
@ -46,6 +45,6 @@ public class AppliedPunishment extends Punishment {
|
||||
}
|
||||
|
||||
public long getTimeRemaining() {
|
||||
return expiration - System.currentTimeMillis();
|
||||
return this.expiration - System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
package com.songoda.ultimatemoderation.punish;
|
||||
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.core.utils.TimeUtils;
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Punishment {
|
||||
|
||||
private int id;
|
||||
|
||||
private final PunishmentType punishmentType;
|
||||
@ -44,23 +44,24 @@ public class Punishment {
|
||||
public void execute(CommandSender punisher, OfflinePlayer victim) {
|
||||
UltimateModeration plugin = UltimateModeration.getInstance();
|
||||
|
||||
if (!punisher.hasPermission("Um." + punishmentType)) {
|
||||
if (!punisher.hasPermission("Um." + this.punishmentType)) {
|
||||
plugin.getLocale().getMessage("event.general.nopermission").sendPrefixedMessage(punisher);
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(victim);
|
||||
switch (punishmentType) {
|
||||
switch (this.punishmentType) {
|
||||
case BAN:
|
||||
if (!playerPunishData.getActivePunishments(PunishmentType.BAN).isEmpty()) {
|
||||
plugin.getLocale().getMessage("event.ban.already").sendPrefixedMessage(punisher);
|
||||
return;
|
||||
}
|
||||
if (victim.isOnline())
|
||||
if (victim.isOnline()) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> victim.getPlayer().kickPlayer(plugin.getLocale()
|
||||
.getMessage("event.ban.message")
|
||||
.processPlaceholder("reason", reason == null ? "" : reason)
|
||||
.processPlaceholder("duration", Methods.makeReadable(duration)).getMessage()));
|
||||
.processPlaceholder("reason", this.reason == null ? "" : this.reason)
|
||||
.processPlaceholder("duration", TimeUtils.makeReadable(this.duration)).getMessage()));
|
||||
}
|
||||
break;
|
||||
case MUTE:
|
||||
if (!playerPunishData.getActivePunishments(PunishmentType.MUTE).isEmpty()) {
|
||||
@ -70,10 +71,11 @@ public class Punishment {
|
||||
sendMessage(victim);
|
||||
break;
|
||||
case KICK:
|
||||
if (victim.isOnline())
|
||||
if (victim.isOnline()) {
|
||||
Bukkit.getScheduler().runTask(plugin, () -> victim.getPlayer().kickPlayer(plugin.getLocale()
|
||||
.getMessage("event.kick.message")
|
||||
.processPlaceholder("reason", reason == null ? "" : reason).getMessage()));
|
||||
.processPlaceholder("reason", this.reason == null ? "" : this.reason).getMessage()));
|
||||
}
|
||||
break;
|
||||
case WARNING:
|
||||
sendMessage(victim);
|
||||
@ -81,22 +83,24 @@ public class Punishment {
|
||||
}
|
||||
|
||||
String punishSuccess = plugin.getLocale()
|
||||
.getMessage("event." + punishmentType.name().toLowerCase() + ".success")
|
||||
.getMessage("event." + this.punishmentType.name().toLowerCase() + ".success")
|
||||
.processPlaceholder("player", victim.getName())
|
||||
.getPrefixedMessage();
|
||||
|
||||
if (reason != null)
|
||||
if (this.reason != null) {
|
||||
punishSuccess += plugin.getLocale().getMessage("event.punish.reason")
|
||||
.processPlaceholder("reason", reason).getMessage();
|
||||
.processPlaceholder("reason", this.reason).getMessage();
|
||||
}
|
||||
|
||||
if (duration != -1 && duration != 0)
|
||||
if (this.duration != -1 && this.duration != 0) {
|
||||
punishSuccess += plugin.getLocale().getMessage("event.punish.theirduration")
|
||||
.processPlaceholder("duration", Methods.makeReadable(duration)).getMessage();
|
||||
.processPlaceholder("duration", TimeUtils.makeReadable(this.duration)).getMessage();
|
||||
}
|
||||
|
||||
punisher.sendMessage(punishSuccess + Methods.formatText("&7."));
|
||||
punisher.sendMessage(punishSuccess + TextUtils.formatText("&7."));
|
||||
|
||||
AppliedPunishment appliedPunishment = apply(victim, punisher);
|
||||
if (duration != 0) {
|
||||
if (this.duration != 0) {
|
||||
playerPunishData.addPunishment(appliedPunishment);
|
||||
} else {
|
||||
appliedPunishment.expire();
|
||||
@ -106,26 +110,30 @@ public class Punishment {
|
||||
}
|
||||
|
||||
public void sendMessage(OfflinePlayer offlineVictim) {
|
||||
if (!offlineVictim.isOnline()) return;
|
||||
if (!offlineVictim.isOnline()) {
|
||||
return;
|
||||
}
|
||||
Player victim = offlineVictim.getPlayer();
|
||||
UltimateModeration plugin = UltimateModeration.getInstance();
|
||||
|
||||
String punishSuccess = plugin.getLocale()
|
||||
.getMessage("event." + punishmentType.name().toLowerCase() + ".message").getPrefixedMessage();
|
||||
.getMessage("event." + this.punishmentType.name().toLowerCase() + ".message").getPrefixedMessage();
|
||||
|
||||
if (reason != null)
|
||||
if (this.reason != null) {
|
||||
punishSuccess += plugin.getLocale().getMessage("event.punish.reason")
|
||||
.processPlaceholder("reason", reason).getMessage();
|
||||
.processPlaceholder("reason", this.reason).getMessage();
|
||||
}
|
||||
|
||||
if (duration != -1)
|
||||
if (this.duration != -1) {
|
||||
punishSuccess += plugin.getLocale().getMessage("event.punish.yourduration")
|
||||
.processPlaceholder("duration", Methods.makeReadable(duration)).getMessage();
|
||||
.processPlaceholder("duration", TimeUtils.makeReadable(this.duration)).getMessage();
|
||||
}
|
||||
|
||||
victim.sendMessage(punishSuccess + Methods.formatText("&7."));
|
||||
victim.sendMessage(punishSuccess + TextUtils.formatText("&7."));
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
|
@ -3,7 +3,6 @@ package com.songoda.ultimatemoderation.punish;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PunishmentNote {
|
||||
|
||||
private int id;
|
||||
|
||||
private final String note;
|
||||
@ -27,7 +26,7 @@ public class PunishmentNote {
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
@ -35,18 +34,18 @@ public class PunishmentNote {
|
||||
}
|
||||
|
||||
public String getNote() {
|
||||
return note;
|
||||
return this.note;
|
||||
}
|
||||
|
||||
public UUID getAuthor() {
|
||||
return author;
|
||||
return this.author;
|
||||
}
|
||||
|
||||
public UUID getSubject() {
|
||||
return subject;
|
||||
return this.subject;
|
||||
}
|
||||
|
||||
public long getCreationDate() {
|
||||
return creationDate;
|
||||
return this.creationDate;
|
||||
}
|
||||
}
|
||||
|
@ -3,25 +3,26 @@ package com.songoda.ultimatemoderation.punish;
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
|
||||
public enum PunishmentType {
|
||||
|
||||
ALL, BAN, KICK, WARNING, MUTE;
|
||||
|
||||
private static PunishmentType[] vals = values();
|
||||
|
||||
public PunishmentType next() {
|
||||
PunishmentType next = vals[(this.ordinal() != vals.length - 1 ? this.ordinal() + 1 : 0)];
|
||||
PunishmentType next = values()[(this.ordinal() != values().length - 1 ? this.ordinal() + 1 : 0)];
|
||||
|
||||
if (next == ALL)
|
||||
if (next == ALL) {
|
||||
next = next.next();
|
||||
}
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
public PunishmentType nextFilter() {
|
||||
return vals[(this.ordinal() != vals.length - 1 ? this.ordinal() + 1 : 0)];
|
||||
return values()[(this.ordinal() != values().length - 1 ? this.ordinal() + 1 : 0)];
|
||||
}
|
||||
|
||||
public String getTranslation() {
|
||||
return UltimateModeration.getInstance().getLocale().getMessage("gui.punishmenttypes." + this.name().toLowerCase()).getMessage();
|
||||
return UltimateModeration.getPlugin(UltimateModeration.class)
|
||||
.getLocale()
|
||||
.getMessage("gui.punishmenttypes." + this.name().toLowerCase())
|
||||
.getMessage();
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PlayerPunishData {
|
||||
|
||||
private final UUID player;
|
||||
|
||||
private final List<AppliedPunishment> activePunishments = new ArrayList<>();
|
||||
@ -30,27 +29,27 @@ public class PlayerPunishData {
|
||||
}
|
||||
|
||||
public UUID getPlayer() {
|
||||
return player;
|
||||
return this.player;
|
||||
}
|
||||
|
||||
public List<AppliedPunishment> getActivePunishments() {
|
||||
audit();
|
||||
return new ArrayList<>(activePunishments);
|
||||
return new ArrayList<>(this.activePunishments);
|
||||
}
|
||||
|
||||
public List<AppliedPunishment> getActivePunishments(PunishmentType type) {
|
||||
audit();
|
||||
return activePunishments.stream().filter(punishment -> punishment.getPunishmentType() == type).collect(Collectors.toList());
|
||||
return this.activePunishments.stream().filter(punishment -> punishment.getPunishmentType() == type).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<AppliedPunishment> getExpiredPunishments() {
|
||||
audit();
|
||||
return new ArrayList<>(expiredPunishments);
|
||||
return new ArrayList<>(this.expiredPunishments);
|
||||
}
|
||||
|
||||
public List<AppliedPunishment> getExpiredPunishments(PunishmentType type) {
|
||||
audit();
|
||||
return expiredPunishments.stream().filter(punishment -> punishment.getPunishmentType() == type).collect(Collectors.toList());
|
||||
return this.expiredPunishments.stream().filter(punishment -> punishment.getPunishmentType() == type).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public AppliedPunishment[] addPunishment(AppliedPunishment... appliedPunishments) {
|
||||
@ -74,7 +73,7 @@ public class PlayerPunishData {
|
||||
}
|
||||
|
||||
public List<PunishmentNote> getNotes() {
|
||||
return new ArrayList<>(punishmentNotes);
|
||||
return new ArrayList<>(this.punishmentNotes);
|
||||
}
|
||||
|
||||
public PunishmentNote[] addNotes(PunishmentNote... notes) {
|
||||
@ -92,7 +91,7 @@ public class PlayerPunishData {
|
||||
}
|
||||
|
||||
private void audit(boolean forced, PunishmentType punishmentType) {
|
||||
List<AppliedPunishment> expired = activePunishments.stream().filter(appliedPunishment ->
|
||||
List<AppliedPunishment> expired = this.activePunishments.stream().filter(appliedPunishment ->
|
||||
(appliedPunishment.getDuration() != -1 || forced || appliedPunishment.getExpiration() == -1)
|
||||
&& (appliedPunishment.getPunishmentType() == punishmentType || punishmentType == PunishmentType.ALL)
|
||||
&& appliedPunishment.getExpiration() <= System.currentTimeMillis()).collect(Collectors.toList());
|
||||
@ -103,7 +102,7 @@ public class PlayerPunishData {
|
||||
|
||||
public void expirePunishments(PunishmentType type) {
|
||||
List<AppliedPunishment> toAudit = new ArrayList<>();
|
||||
activePunishments.stream().filter(appliedPunishment ->
|
||||
this.activePunishments.stream().filter(appliedPunishment ->
|
||||
type == appliedPunishment.getPunishmentType()).forEach(appliedPunishment -> {
|
||||
appliedPunishment.expire();
|
||||
UltimateModeration.getInstance().getDataManager().updateAppliedPunishment(appliedPunishment);
|
||||
|
@ -8,11 +8,10 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PunishmentManager {
|
||||
|
||||
private Map<UUID, PlayerPunishData> punishments = new HashMap<>();
|
||||
private final Map<UUID, PlayerPunishData> punishments = new HashMap<>();
|
||||
|
||||
public Map<UUID, PlayerPunishData> getPunishments() {
|
||||
return Collections.unmodifiableMap(punishments);
|
||||
return Collections.unmodifiableMap(this.punishments);
|
||||
}
|
||||
|
||||
public PlayerPunishData getPlayer(OfflinePlayer player) {
|
||||
@ -20,6 +19,6 @@ public class PunishmentManager {
|
||||
}
|
||||
|
||||
public PlayerPunishData getPlayer(UUID player) {
|
||||
return punishments.computeIfAbsent(player, PlayerPunishData::new);
|
||||
return this.punishments.computeIfAbsent(player, PlayerPunishData::new);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import org.bukkit.entity.Player;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Template extends Punishment {
|
||||
|
||||
private final String templateName;
|
||||
private final UUID creator;
|
||||
|
||||
@ -30,10 +29,10 @@ public class Template extends Punishment {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return templateName;
|
||||
return this.templateName;
|
||||
}
|
||||
|
||||
public UUID getCreator() {
|
||||
return creator;
|
||||
return this.creator;
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,17 @@
|
||||
package com.songoda.ultimatemoderation.punish.template;
|
||||
|
||||
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 List<Template> templates = new LinkedList<>();
|
||||
|
||||
public Template getTemplate(String name) {
|
||||
for (Template template : templates) {
|
||||
if (formatName(template.getName()).equals(formatName(name)))
|
||||
if (formatName(template.getName()).equals(formatName(name))) {
|
||||
return template;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -33,7 +31,9 @@ public class TemplateManager {
|
||||
}
|
||||
|
||||
private String formatName(String name) {
|
||||
if (name == null) return null;
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
name = name.toUpperCase().trim();
|
||||
name = name.replace(" ", "_");
|
||||
return name;
|
||||
|
@ -8,80 +8,79 @@ import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class Settings {
|
||||
static final Config CONFIG = UltimateModeration.getPlugin(UltimateModeration.class).getCoreConfig();
|
||||
|
||||
static final Config config = UltimateModeration.getInstance().getCoreConfig();
|
||||
|
||||
public static final ConfigSetting VANISH_EFFECTS = new ConfigSetting(config, "Main.Enable Vanish Effects", true,
|
||||
public static final ConfigSetting VANISH_EFFECTS = new ConfigSetting(CONFIG, "Main.Enable Vanish Effects", true,
|
||||
"Show particles and play sound when going in and out of vanish.");
|
||||
|
||||
public static final ConfigSetting VANISH_SOUND = new ConfigSetting(config, "Main.Vanish Sound", "ENTITY_GENERIC_EXPLODE",
|
||||
public static final ConfigSetting VANISH_SOUND = new ConfigSetting(CONFIG, "Main.Vanish Sound", "ENTITY_GENERIC_EXPLODE",
|
||||
"Sound to be played when going into vanish.");
|
||||
|
||||
public static final ConfigSetting VANISH_BATS = new ConfigSetting(config, "Main.Release Bats On Vanish", true,
|
||||
public static final ConfigSetting VANISH_BATS = new ConfigSetting(CONFIG, "Main.Release Bats On Vanish", true,
|
||||
"Shows bats when entering vanish.");
|
||||
|
||||
public static final ConfigSetting VANISH_PARTICLE = new ConfigSetting(config, "Main.Vanish Particle", "EXPLOSION_NORMAL",
|
||||
public static final ConfigSetting VANISH_PARTICLE = new ConfigSetting(CONFIG, "Main.Vanish Particle", "EXPLOSION_NORMAL",
|
||||
"Show particles when entering vanish.");
|
||||
|
||||
public static final ConfigSetting SLOW_MODE = new ConfigSetting(config, "Main.SLOW_MODE", "0s",
|
||||
public static final ConfigSetting SLOW_MODE = new ConfigSetting(CONFIG, "Main.SLOW_MODE", "0s",
|
||||
"Limits how often a player can send a chat message by the corresponding amount.");
|
||||
|
||||
public static final ConfigSetting BLOCKED_COMMANDS = new ConfigSetting(config, "Main.Blocked Commands", Arrays.asList("Fly", "Op", "Plugins", "Pl"),
|
||||
public static final ConfigSetting BLOCKED_COMMANDS = new ConfigSetting(CONFIG, "Main.Blocked Commands", Arrays.asList("Fly", "Op", "Plugins", "Pl"),
|
||||
"Prevents players from running the specified commands.");
|
||||
|
||||
public static final ConfigSetting AUTOSAVE = new ConfigSetting(config, "Main.Auto Save Interval In Seconds", 15,
|
||||
public static final ConfigSetting AUTOSAVE = new ConfigSetting(CONFIG, "Main.Auto Save Interval In Seconds", 15,
|
||||
"The amount of time in between saving to file.",
|
||||
"This is purely a safety function to prevent against unplanned crashes or",
|
||||
"restarts. With that said it is advised to keep this enabled.",
|
||||
"If however you enjoy living on the edge, feel free to turn it off.");
|
||||
|
||||
public static final ConfigSetting STAFFCHAT_COLOR_CODE = new ConfigSetting(config, "Main.Staff Chat Color Code", 'b',
|
||||
public static final ConfigSetting STAFFCHAT_COLOR_CODE = new ConfigSetting(CONFIG, "Main.Staff Chat Color Code", 'b',
|
||||
"Color of messages sent in staff chat.");
|
||||
|
||||
public static final ConfigSetting TICKET_TYPES = new ConfigSetting(config, "Main.Ticket Types", Arrays.asList("Grief", "Player Report", "Bug Report", "Suggestion", "Other"),
|
||||
public static final ConfigSetting TICKET_TYPES = new ConfigSetting(CONFIG, "Main.Ticket Types", Arrays.asList("Grief", "Player Report", "Bug Report", "Suggestion", "Other"),
|
||||
"Types of tickets players can open.");
|
||||
|
||||
public static final ConfigSetting MUTE_DISABLED_COMMANDS = new ConfigSetting(config, "Main.Mute Disabled Commands", Arrays.asList("minecraft:me", "minecraft:tell"),
|
||||
public static final ConfigSetting MUTE_DISABLED_COMMANDS = new ConfigSetting(CONFIG, "Main.Mute Disabled Commands", Arrays.asList("minecraft:me", "minecraft:tell"),
|
||||
"Commands disabled when a player is muted.");
|
||||
|
||||
public static final ConfigSetting GLASS_TYPE_1 = new ConfigSetting(config, "Interfaces.Glass Type 1", "GRAY_STAINED_GLASS_PANE");
|
||||
public static final ConfigSetting GLASS_TYPE_2 = new ConfigSetting(config, "Interfaces.Glass Type 2", "BLUE_STAINED_GLASS_PANE");
|
||||
public static final ConfigSetting GLASS_TYPE_3 = new ConfigSetting(config, "Interfaces.Glass Type 3", "LIGHT_BLUE_STAINED_GLASS_PANE");
|
||||
public static final ConfigSetting GLASS_TYPE_1 = new ConfigSetting(CONFIG, "Interfaces.Glass Type 1", "GRAY_STAINED_GLASS_PANE");
|
||||
public static final ConfigSetting GLASS_TYPE_2 = new ConfigSetting(CONFIG, "Interfaces.Glass Type 2", "BLUE_STAINED_GLASS_PANE");
|
||||
public static final ConfigSetting GLASS_TYPE_3 = new ConfigSetting(CONFIG, "Interfaces.Glass Type 3", "LIGHT_BLUE_STAINED_GLASS_PANE");
|
||||
|
||||
public static final ConfigSetting LANGUGE_MODE = new ConfigSetting(config, "System.Language Mode", "en_US",
|
||||
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 = 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"),
|
||||
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.");
|
||||
|
||||
public static final ConfigSetting MYSQL_ENABLED = new ConfigSetting(config, "MySQL.Enabled", false, "Set to 'true' to use MySQL instead of SQLite for data storage.");
|
||||
public static final ConfigSetting MYSQL_HOSTNAME = new ConfigSetting(config, "MySQL.Hostname", "localhost");
|
||||
public static final ConfigSetting MYSQL_PORT = new ConfigSetting(config, "MySQL.Port", 3306);
|
||||
public static final ConfigSetting MYSQL_DATABASE = new ConfigSetting(config, "MySQL.Database", "your-database");
|
||||
public static final ConfigSetting MYSQL_USERNAME = new ConfigSetting(config, "MySQL.Username", "user");
|
||||
public static final ConfigSetting MYSQL_PASSWORD = new ConfigSetting(config, "MySQL.Password", "pass");
|
||||
public static final ConfigSetting MYSQL_USE_SSL = new ConfigSetting(config, "MySQL.Use SSL", false);
|
||||
public static final ConfigSetting MYSQL_POOL_SIZE = new ConfigSetting(config, "MySQL.Pool Size", 3, "Determines the number of connections the pool is using. Increase this value if you are getting timeout errors when more players online.");
|
||||
public static final ConfigSetting MYSQL_ENABLED = new ConfigSetting(CONFIG, "MySQL.Enabled", false, "Set to 'true' to use MySQL instead of SQLite for data storage.");
|
||||
public static final ConfigSetting MYSQL_HOSTNAME = new ConfigSetting(CONFIG, "MySQL.Hostname", "localhost");
|
||||
public static final ConfigSetting MYSQL_PORT = new ConfigSetting(CONFIG, "MySQL.Port", 3306);
|
||||
public static final ConfigSetting MYSQL_DATABASE = new ConfigSetting(CONFIG, "MySQL.Database", "your-database");
|
||||
public static final ConfigSetting MYSQL_USERNAME = new ConfigSetting(CONFIG, "MySQL.Username", "user");
|
||||
public static final ConfigSetting MYSQL_PASSWORD = new ConfigSetting(CONFIG, "MySQL.Password", "pass");
|
||||
public static final ConfigSetting MYSQL_USE_SSL = new ConfigSetting(CONFIG, "MySQL.Use SSL", false);
|
||||
public static final ConfigSetting MYSQL_POOL_SIZE = new ConfigSetting(CONFIG, "MySQL.Pool Size", 3, "Determines the number of connections the pool is using. Increase this value if you are getting timeout errors when more players online.");
|
||||
|
||||
public static void setupConfig() {
|
||||
config.load();
|
||||
config.setAutoremove(true).setAutosave(true);
|
||||
CONFIG.load();
|
||||
CONFIG.setAutoremove(true).setAutosave(true);
|
||||
|
||||
// convert glass pane settings
|
||||
int color;
|
||||
if ((color = GLASS_TYPE_1.getInt(-1)) != -1) {
|
||||
config.set(GLASS_TYPE_1.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
|
||||
CONFIG.set(GLASS_TYPE_1.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
|
||||
}
|
||||
if ((color = GLASS_TYPE_2.getInt(-1)) != -1) {
|
||||
config.set(GLASS_TYPE_2.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
|
||||
CONFIG.set(GLASS_TYPE_2.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
|
||||
}
|
||||
if ((color = GLASS_TYPE_3.getInt(-1)) != -1) {
|
||||
config.set(GLASS_TYPE_3.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
|
||||
CONFIG.set(GLASS_TYPE_3.getKey(), CompatibleMaterial.getGlassPaneColor(color).name());
|
||||
}
|
||||
|
||||
config.saveChanges();
|
||||
CONFIG.saveChanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.songoda.ultimatemoderation.staffchat;
|
||||
|
||||
import com.songoda.core.utils.TextUtils;
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.settings.Settings;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -11,7 +11,6 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class StaffChannel {
|
||||
|
||||
private final String channelName;
|
||||
private char chatChar = Settings.STAFFCHAT_COLOR_CODE.getChar();
|
||||
private final List<UUID> members = new ArrayList<>();
|
||||
@ -22,28 +21,35 @@ public class StaffChannel {
|
||||
}
|
||||
|
||||
public List<UUID> listMembers() {
|
||||
return new ArrayList<>(members);
|
||||
return new ArrayList<>(this.members);
|
||||
}
|
||||
|
||||
public void addMember(Player player) {
|
||||
if (members.contains(player.getUniqueId())) return;
|
||||
if (this.members.contains(player.getUniqueId())) {
|
||||
return;
|
||||
}
|
||||
messageAll(UltimateModeration.getInstance().getLocale()
|
||||
.getMessage("event.staffchat.alljoin")
|
||||
.processPlaceholder("player", player.getName()).getMessage(), player);
|
||||
|
||||
UltimateModeration.getInstance().getStaffChatManager().getChats().values().stream().forEach(members1 -> {
|
||||
UltimateModeration.getInstance()
|
||||
.getStaffChatManager()
|
||||
.getChats()
|
||||
.values()
|
||||
.stream()
|
||||
.forEach(members1 -> {
|
||||
if (members1.listMembers().contains(player.getUniqueId())) {
|
||||
members1.removeMember(player);
|
||||
}
|
||||
});
|
||||
members.add(player.getUniqueId());
|
||||
if (chatLog.size() > 5) {
|
||||
chatLog.stream().skip(chatLog.size() - 3).forEach(message -> player.sendMessage(Methods.formatText(message)));
|
||||
this.members.add(player.getUniqueId());
|
||||
if (this.chatLog.size() > 5) {
|
||||
this.chatLog.stream().skip(this.chatLog.size() - 3).forEach(message -> player.sendMessage(TextUtils.formatText(message)));
|
||||
}
|
||||
}
|
||||
|
||||
public void removeMember(Player player) {
|
||||
members.remove(player.getUniqueId());
|
||||
this.members.remove(player.getUniqueId());
|
||||
messageAll(UltimateModeration.getInstance().getLocale()
|
||||
.getMessage("event.staffchat.allleave")
|
||||
.processPlaceholder("player", player.getName()).getMessage(), player);
|
||||
@ -52,8 +58,8 @@ 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("color", this.chatChar)
|
||||
.processPlaceholder("channel", this.channelName)
|
||||
.processPlaceholder("player", player.getDisplayName())
|
||||
.processPlaceholder("message", message).getMessage());
|
||||
}
|
||||
@ -63,20 +69,24 @@ public class StaffChannel {
|
||||
}
|
||||
|
||||
public void messageAll(String message, Player exempt) {
|
||||
chatLog.add(message);
|
||||
this.chatLog.add(message);
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (exempt != null && player == exempt) continue;
|
||||
if (!members.contains(player.getUniqueId()) && !player.hasPermission("um.staffchat.spy")) continue;
|
||||
player.sendMessage(Methods.formatText(message));
|
||||
if (exempt != null && player == exempt) {
|
||||
continue;
|
||||
}
|
||||
if (!this.members.contains(player.getUniqueId()) && !player.hasPermission("um.staffchat.spy")) {
|
||||
continue;
|
||||
}
|
||||
player.sendMessage(TextUtils.formatText(message));
|
||||
}
|
||||
}
|
||||
|
||||
public String getChannelName() {
|
||||
return channelName;
|
||||
return this.channelName;
|
||||
}
|
||||
|
||||
public char getChatChar() {
|
||||
return chatChar;
|
||||
return this.chatChar;
|
||||
}
|
||||
|
||||
public void setChatChar(char chatChar) {
|
||||
|
@ -5,23 +5,24 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class StaffChatManager {
|
||||
|
||||
private final Map<String, StaffChannel> chats = new HashMap<>();
|
||||
|
||||
public Map<String, StaffChannel> getChats() {
|
||||
return Collections.unmodifiableMap(chats);
|
||||
return Collections.unmodifiableMap(this.chats);
|
||||
}
|
||||
|
||||
public StaffChannel getChat(String channel) {
|
||||
return chats.computeIfAbsent(formatName(channel), k -> new StaffChannel(formatName(channel)));
|
||||
return this.chats.computeIfAbsent(formatName(channel), k -> new StaffChannel(formatName(channel)));
|
||||
}
|
||||
|
||||
public void removeChat(String channel) {
|
||||
chats.remove(formatName(channel));
|
||||
this.chats.remove(formatName(channel));
|
||||
}
|
||||
|
||||
private String formatName(String name) {
|
||||
if (name == null) return null;
|
||||
if (name == null) {
|
||||
return null;
|
||||
}
|
||||
name = name.toUpperCase().trim();
|
||||
name = name.replace(" ", "_");
|
||||
return name;
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.songoda.ultimatemoderation.tasks;
|
||||
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.core.utils.TimeUtils;
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.listeners.ChatListener;
|
||||
import com.songoda.ultimatemoderation.settings.Settings;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -14,7 +14,6 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class SlowModeTask extends BukkitRunnable {
|
||||
|
||||
private static SlowModeTask instance;
|
||||
private static UltimateModeration plugin;
|
||||
|
||||
@ -34,29 +33,33 @@ public class SlowModeTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
long slowmode = ChatListener.getSlowModeOverride() == 0 ? Methods.parseTime(Settings.SLOW_MODE.getString()) : ChatListener.getSlowModeOverride();
|
||||
long slowmode = ChatListener.getSlowModeOverride() == 0 ? TimeUtils.parseTime(Settings.SLOW_MODE.getString()) : ChatListener.getSlowModeOverride();
|
||||
|
||||
if (slowmode == 0) return;
|
||||
if (slowmode == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ChatListener.Log> logs = ChatListener.getLogs();
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(player -> {
|
||||
if (player.hasPermission("um.slowmode.bypass")) return;
|
||||
if (player.hasPermission("um.slowmode.bypass")) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<ChatListener.Log> chats = logs.stream().filter(log -> log.getPlayer() == player.getUniqueId()).collect(Collectors.toList());
|
||||
if (chats.size() == 0) return;
|
||||
if (chats.size() == 0) {
|
||||
return;
|
||||
}
|
||||
ChatListener.Log last = chats.get(chats.size() - 1);
|
||||
|
||||
if ((System.currentTimeMillis() - last.getSent()) < (slowmode + 1000)) {
|
||||
int remaining = (int) ((slowmode / 1000) - (System.currentTimeMillis() - last.getSent()) / 1000);
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9))
|
||||
if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(remaining == 0
|
||||
? plugin.getLocale().getMessage("event.slowmode.done").getMessage()
|
||||
: plugin.getLocale().getMessage("event.slowmode.wait").processPlaceholder("delay", remaining).getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class Ticket {
|
||||
|
||||
private int id;
|
||||
|
||||
private TicketStatus status = TicketStatus.OPEN;
|
||||
|
@ -9,7 +9,6 @@ import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TicketManager {
|
||||
|
||||
private final TreeMap<Integer, Ticket> registeredTickets = new TreeMap<>();
|
||||
|
||||
public Ticket addTicket(Ticket ticket) {
|
||||
|
@ -5,7 +5,6 @@ import org.bukkit.OfflinePlayer;
|
||||
import java.util.UUID;
|
||||
|
||||
public class TicketResponse {
|
||||
|
||||
private int ticketId;
|
||||
|
||||
private final UUID author;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.songoda.ultimatemoderation.tickets;
|
||||
|
||||
public enum TicketStatus {
|
||||
|
||||
OPEN("Open"),
|
||||
CLOSED("Closed");
|
||||
|
||||
|
@ -1,192 +0,0 @@
|
||||
package com.songoda.ultimatemoderation.utils;
|
||||
|
||||
import com.songoda.core.compatibility.ServerVersion;
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
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;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Methods {
|
||||
|
||||
private static Map<String, Location> serializeCache = new HashMap<>();
|
||||
|
||||
public static ItemStack getGlass() {
|
||||
UltimateModeration instance = UltimateModeration.getInstance();
|
||||
return Methods.getGlass(instance.getConfig().getBoolean("Interfaces.Replace Glass Type 1 With Rainbow Glass"), instance.getConfig().getInt("Interfaces.Glass Type 1"));
|
||||
}
|
||||
|
||||
public static ItemStack getBackgroundGlass(boolean type) {
|
||||
UltimateModeration instance = UltimateModeration.getInstance();
|
||||
if (type)
|
||||
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 2"));
|
||||
else
|
||||
return getGlass(false, instance.getConfig().getInt("Interfaces.Glass Type 3"));
|
||||
}
|
||||
|
||||
private static ItemStack getGlass(Boolean rainbow, int type) {
|
||||
int randomNum = 1 + (int) (Math.random() * 6);
|
||||
ItemStack glass;
|
||||
if (rainbow) {
|
||||
glass = new ItemStack(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ?
|
||||
Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) randomNum);
|
||||
} else {
|
||||
glass = new ItemStack(ServerVersion.isServerVersionAtLeast(ServerVersion.V1_13) ?
|
||||
Material.LEGACY_STAINED_GLASS_PANE : Material.valueOf("STAINED_GLASS_PANE"), 1, (short) type);
|
||||
}
|
||||
ItemMeta glassmeta = glass.getItemMeta();
|
||||
glassmeta.setDisplayName("§l");
|
||||
glass.setItemMeta(glassmeta);
|
||||
return glass;
|
||||
}
|
||||
|
||||
public static String formatText(String text) {
|
||||
if (text == null || text.equals(""))
|
||||
return "";
|
||||
return formatText(text, false);
|
||||
}
|
||||
|
||||
public static String formatText(String text, boolean cap) {
|
||||
if (text == null || text.equals(""))
|
||||
return "";
|
||||
if (cap)
|
||||
text = text.substring(0, 1).toUpperCase() + text.substring(1);
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
}
|
||||
|
||||
public static String formatTitle(String text) {
|
||||
if (text == null || text.equals(""))
|
||||
return "";
|
||||
if (!ServerVersion.isServerVersionAtLeast(ServerVersion.V1_9)) {
|
||||
if (text.length() > 31)
|
||||
text = text.substring(0, 29) + "...";
|
||||
}
|
||||
text = formatText(text);
|
||||
return text;
|
||||
}
|
||||
|
||||
public static String makeReadable(Long time) {
|
||||
if (time == null)
|
||||
return "";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
long days = TimeUnit.MILLISECONDS.toDays(time);
|
||||
long hours = TimeUnit.MILLISECONDS.toHours(time) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(time));
|
||||
long minutes = TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time));
|
||||
long seconds = TimeUnit.MILLISECONDS.toSeconds(time) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time));
|
||||
|
||||
if (days != 0L)
|
||||
sb.append(" ").append(days).append("d");
|
||||
if (hours != 0L)
|
||||
sb.append(" ").append(hours).append("h");
|
||||
if (minutes != 0L)
|
||||
sb.append(" ").append(minutes).append("m");
|
||||
if (seconds != 0L)
|
||||
sb.append(" ").append(seconds).append("s");
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
|
||||
public static long parseTime(String input) {
|
||||
long result = 0;
|
||||
StringBuilder number = new StringBuilder();
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
char c = input.charAt(i);
|
||||
if (Character.isDigit(c)) {
|
||||
number.append(c);
|
||||
} else if (Character.isLetter(c) && (number.length() > 0)) {
|
||||
result += convert(Integer.parseInt(number.toString()), c);
|
||||
number = new StringBuilder();
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static long convert(long value, char unit) {
|
||||
switch (unit) {
|
||||
case 'd':
|
||||
return value * 1000 * 60 * 60 * 24;
|
||||
case 'h':
|
||||
return value * 1000 * 60 * 60;
|
||||
case 'm':
|
||||
return value * 1000 * 60;
|
||||
case 's':
|
||||
return value * 1000;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
public static String convertToInvisibleString(String s) {
|
||||
if (s == null || s.equals(""))
|
||||
return "";
|
||||
StringBuilder hidden = new StringBuilder();
|
||||
for (char c : s.toCharArray()) hidden.append(ChatColor.COLOR_CHAR + "").append(c);
|
||||
return hidden.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the location of the block specified.
|
||||
*
|
||||
* @param b The block whose location is to be saved.
|
||||
* @return The serialized data.
|
||||
*/
|
||||
public static String serializeLocation(Block b) {
|
||||
if (b == null)
|
||||
return "";
|
||||
return serializeLocation(b.getLocation());
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes the location specified.
|
||||
*
|
||||
* @param location The location that is to be saved.
|
||||
* @return The serialized data.
|
||||
*/
|
||||
public static String serializeLocation(Location location) {
|
||||
if (location == null || location.getWorld() == null)
|
||||
return "";
|
||||
String w = location.getWorld().getName();
|
||||
double x = location.getX();
|
||||
double y = location.getY();
|
||||
double z = location.getZ();
|
||||
String str = w + ":" + x + ":" + y + ":" + z;
|
||||
str = str.replace(".0", "").replace("/", "");
|
||||
return str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deserializes a location from the string.
|
||||
*
|
||||
* @param str The string to parse.
|
||||
* @return The location that was serialized in the string.
|
||||
*/
|
||||
public static Location unserializeLocation(String str) {
|
||||
if (str == null || str.equals(""))
|
||||
return null;
|
||||
if (serializeCache.containsKey(str)) {
|
||||
return serializeCache.get(str).clone();
|
||||
}
|
||||
String cacheKey = str;
|
||||
str = str.replace("y:", ":").replace("z:", ":").replace("w:", "").replace("x:", ":").replace("/", ".");
|
||||
List<String> args = Arrays.asList(str.split("\\s*:\\s*"));
|
||||
|
||||
World world = Bukkit.getWorld(args.get(0));
|
||||
double x = Double.parseDouble(args.get(1)), y = Double.parseDouble(args.get(2)), z = Double.parseDouble(args.get(3));
|
||||
Location location = new Location(world, x, y, z, 0, 0);
|
||||
serializeCache.put(cacheKey, location.clone());
|
||||
return location;
|
||||
}
|
||||
|
||||
}
|
@ -6,20 +6,18 @@ import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
public class VaultPermissions {
|
||||
|
||||
// Vault
|
||||
private static Permission vaultPermission = null;
|
||||
|
||||
static {
|
||||
if (Bukkit.getServer().getPluginManager().getPlugin("Vault") != null) {
|
||||
RegisteredServiceProvider<Permission> permissionRsp = Bukkit.getServer().getServicesManager().getRegistration(Permission.class);
|
||||
if (permissionRsp != null) vaultPermission = permissionRsp.getProvider();
|
||||
if (permissionRsp != null) {
|
||||
vaultPermission = permissionRsp.getProvider();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasPermission(OfflinePlayer offlinePlayer, String perm) {
|
||||
if (vaultPermission != null)
|
||||
return vaultPermission.playerHas(Bukkit.getWorlds().get(0).getName(), offlinePlayer, perm);
|
||||
return false;
|
||||
return vaultPermission != null && vaultPermission.playerHas(Bukkit.getWorlds().get(0).getName(), offlinePlayer, perm);
|
||||
}
|
||||
}
|
||||
|
@ -4,32 +4,32 @@ main: com.songoda.ultimatemoderation.UltimateModeration
|
||||
version: maven-version-number
|
||||
author: Songoda
|
||||
api-version: 1.13
|
||||
softdepend: [Vault, FabledSkyBlock]
|
||||
softdepend: [ Vault, FabledSkyBlock ]
|
||||
commands:
|
||||
UltimateModeration:
|
||||
description: View information on this plugin.
|
||||
default: true
|
||||
aliases: [um, p]
|
||||
aliases: [ um, p ]
|
||||
usage: /um
|
||||
ClearChat:
|
||||
description: Clear the chat
|
||||
default: false
|
||||
aliases: [cc]
|
||||
aliases: [ cc ]
|
||||
usage: /cc
|
||||
ToggleChat:
|
||||
description: Toggle chat
|
||||
default: false
|
||||
aliases: [tc]
|
||||
aliases: [ tc ]
|
||||
usage: /tc
|
||||
RandomPlayer:
|
||||
description: Random Player
|
||||
default: false
|
||||
aliases: [rp]
|
||||
aliases: [ rp ]
|
||||
usage: /rp
|
||||
Vanish:
|
||||
description: Vanish
|
||||
default: false
|
||||
aliases: [v]
|
||||
aliases: [ v ]
|
||||
usage: /v
|
||||
Spy:
|
||||
description: Spy
|
||||
@ -82,15 +82,15 @@ commands:
|
||||
Ticket:
|
||||
description: Ticket
|
||||
default: false
|
||||
aliases: [tickets]
|
||||
aliases: [ tickets ]
|
||||
usage: /ticket
|
||||
StaffChat:
|
||||
description: StaffChat
|
||||
default: false
|
||||
aliases: [sc]
|
||||
aliases: [ sc ]
|
||||
usage: /staffchat
|
||||
SlowMode:
|
||||
description: SlowMode
|
||||
default: false
|
||||
aliases: [sm]
|
||||
ussage: /slowmode
|
||||
aliases: [ sm ]
|
||||
ussage: /slowmode
|
||||
|
Loading…
Reference in New Issue
Block a user