mirror of
https://github.com/songoda/UltimateModeration.git
synced 2025-03-12 14:39:12 +01:00
Added GUI System.
This commit is contained in:
parent
11c58ba673
commit
9a32add117
@ -1,7 +1,10 @@
|
||||
package com.songoda.ultimatemoderation;
|
||||
|
||||
import com.songoda.epicspawners.utils.gui.AbstractGUI;
|
||||
import com.songoda.ultimatemoderation.command.CommandManager;
|
||||
import com.songoda.ultimatemoderation.listeners.*;
|
||||
import com.songoda.ultimatemoderation.punish.player.PunishmentManager;
|
||||
import com.songoda.ultimatemoderation.punish.template.TemplateManager;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import com.songoda.ultimatemoderation.utils.SettingsManager;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -13,8 +16,12 @@ public class UltimateModeration extends JavaPlugin {
|
||||
private static CommandSender console = Bukkit.getConsoleSender();
|
||||
private static UltimateModeration INSTANCE;
|
||||
private References references;
|
||||
|
||||
private TemplateManager templateManager;
|
||||
private SettingsManager settingsManager;
|
||||
private CommandManager commandManager;
|
||||
private PunishmentManager punishmentManager;
|
||||
|
||||
private Locale locale;
|
||||
|
||||
public static UltimateModeration getInstance() {
|
||||
@ -60,7 +67,12 @@ public class UltimateModeration extends JavaPlugin {
|
||||
|
||||
this.references = new References();
|
||||
|
||||
//Setup Managers
|
||||
this.templateManager = new TemplateManager();
|
||||
this.commandManager = new CommandManager(this);
|
||||
this.punishmentManager = new PunishmentManager();
|
||||
|
||||
AbstractGUI.initializeListeners(this);
|
||||
|
||||
// Register Listeners
|
||||
Bukkit.getPluginManager().registerEvents(new CommandListener(this), this);
|
||||
@ -110,5 +122,11 @@ public class UltimateModeration extends JavaPlugin {
|
||||
return references;
|
||||
}
|
||||
|
||||
public TemplateManager getTemplateManager() {
|
||||
return templateManager;
|
||||
}
|
||||
|
||||
public PunishmentManager getPunishmentManager() {
|
||||
return punishmentManager;
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,8 @@ import java.util.List;
|
||||
|
||||
public abstract class AbstractCommand {
|
||||
|
||||
private AbstractCommand parent = null;
|
||||
private final boolean noConsole;
|
||||
private AbstractCommand parent = null;
|
||||
private boolean hasArgs = false;
|
||||
private String command;
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
package com.songoda.ultimatemoderation.command;
|
||||
|
||||
import com.songoda.epicspawners.References;
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.commands.*;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -36,6 +34,13 @@ public class CommandManager implements CommandExecutor {
|
||||
instance.getCommand("Revive").setExecutor(this);
|
||||
instance.getCommand("Spy").setExecutor(this);
|
||||
instance.getCommand("CommandSpy").setExecutor(this);
|
||||
instance.getCommand("Ban").setExecutor(this);
|
||||
instance.getCommand("UnBan").setExecutor(this);
|
||||
instance.getCommand("Kick").setExecutor(this);
|
||||
instance.getCommand("Mute").setExecutor(this);
|
||||
instance.getCommand("UnMute").setExecutor(this);
|
||||
instance.getCommand("Warn").setExecutor(this);
|
||||
instance.getCommand("RunTemplate").setExecutor(this);
|
||||
|
||||
AbstractCommand commandUltimateModeration = addCommand(new CommandUltimateModeration());
|
||||
addCommand(new CommandClearChat());
|
||||
@ -48,8 +53,16 @@ public class CommandManager implements CommandExecutor {
|
||||
addCommand(new CommandRevive());
|
||||
addCommand(new CommandSpy());
|
||||
addCommand(new CommandCommandSpy());
|
||||
addCommand(new CommandBan());
|
||||
addCommand(new CommandUnBan());
|
||||
addCommand(new CommandKick());
|
||||
addCommand(new CommandMute());
|
||||
addCommand(new CommandUnMute());
|
||||
addCommand(new CommandWarn());
|
||||
addCommand(new CommandRunTemplate());
|
||||
|
||||
addCommand(new CommandSettings(commandUltimateModeration));
|
||||
addCommand(new CommandHelp(commandUltimateModeration));
|
||||
addCommand(new CommandReload(commandUltimateModeration));
|
||||
|
||||
for (AbstractCommand abstractCommand : commands) {
|
||||
|
@ -0,0 +1,75 @@
|
||||
package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.punish.Punishment;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandBan extends AbstractCommand {
|
||||
|
||||
public CommandBan() {
|
||||
super(false, true, "Ban");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
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".
|
||||
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)
|
||||
duration += time;
|
||||
else
|
||||
reasonBuilder.append(line).append(" ");
|
||||
|
||||
}
|
||||
}
|
||||
String reason = reasonBuilder.toString().trim();
|
||||
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist.");
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
new Punishment(PunishmentType.BAN, duration == 0 ? -1 : duration, reason.equals("") ? null : reason)
|
||||
.execute(sender, player);
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "um.ban";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/Ban <player> [duration] [reason]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Allows you to ban players.";
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ import java.util.List;
|
||||
public class CommandClearChat extends AbstractCommand {
|
||||
|
||||
public CommandClearChat() {
|
||||
super(true, true,"ClearChat");
|
||||
super(true, true, "ClearChat");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -14,12 +14,16 @@ public class CommandCommandSpy extends AbstractCommand {
|
||||
private static List<UUID> inSpy = new ArrayList<>();
|
||||
|
||||
public CommandCommandSpy() {
|
||||
super(true, false,"CommandSpy");
|
||||
super(true, false, "CommandSpy");
|
||||
}
|
||||
|
||||
public static boolean isSpying(Player player) {
|
||||
return !inSpy.contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
Player player = ((Player)sender);
|
||||
Player player = ((Player) sender);
|
||||
|
||||
if (inSpy.contains(player.getUniqueId())) {
|
||||
inSpy.remove(player.getUniqueId());
|
||||
@ -36,10 +40,6 @@ public class CommandCommandSpy extends AbstractCommand {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isSpying(Player player) {
|
||||
return !inSpy.contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "Um.commandspy";
|
||||
|
@ -2,7 +2,6 @@ package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -16,7 +15,24 @@ public class CommandFreeze extends AbstractCommand {
|
||||
private static List<UUID> frozen = new ArrayList<>();
|
||||
|
||||
public CommandFreeze() {
|
||||
super(true, true,"Freeze");
|
||||
super(true, true, "Freeze");
|
||||
}
|
||||
|
||||
public static void freeze(Player player, Player sender) {
|
||||
UltimateModeration instance = UltimateModeration.getInstance();
|
||||
if (frozen.contains(player.getUniqueId())) {
|
||||
frozen.remove(player.getUniqueId());
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.remove", player.getDisplayName()));
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.alertremove"));
|
||||
} else {
|
||||
frozen.add(player.getUniqueId());
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.add", player.getDisplayName()));
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.alertadd"));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isFrozen(Player player) {
|
||||
return frozen.contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -31,23 +47,11 @@ public class CommandFreeze extends AbstractCommand {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
if (frozen.contains(player.getUniqueId())) {
|
||||
frozen.remove(player.getUniqueId());
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.remove", player.getDisplayName()));
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.alertremove"));
|
||||
} else {
|
||||
frozen.add(player.getUniqueId());
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.add", player.getDisplayName()));
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.alertadd"));
|
||||
}
|
||||
freeze(player, (Player) sender);
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
public static boolean isFrozen(Player player) {
|
||||
return frozen.contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
|
@ -0,0 +1,50 @@
|
||||
package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandHelp extends AbstractCommand {
|
||||
|
||||
public CommandHelp(AbstractCommand parent) {
|
||||
super(parent, false, "help");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda"));
|
||||
|
||||
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
|
||||
}
|
||||
}
|
||||
sender.sendMessage("");
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/um help";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Displays this page.";
|
||||
}
|
||||
}
|
@ -11,7 +11,7 @@ import java.util.List;
|
||||
public class CommandInvSee extends AbstractCommand {
|
||||
|
||||
public CommandInvSee() {
|
||||
super(true, true,"InvSee");
|
||||
super(true, true, "InvSee");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -26,7 +26,7 @@ public class CommandInvSee extends AbstractCommand {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
((Player)sender).openInventory(player.getInventory());
|
||||
((Player) sender).openInventory(player.getInventory());
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,67 @@
|
||||
package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.punish.Punishment;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandKick extends AbstractCommand {
|
||||
|
||||
public CommandKick() {
|
||||
super(false, true, "Kick");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
if (args.length < 1)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
StringBuilder reasonBuilder = new StringBuilder();
|
||||
if (args.length > 1) {
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
String line = args[i];
|
||||
reasonBuilder.append(line).append(" ");
|
||||
|
||||
}
|
||||
}
|
||||
String reason = reasonBuilder.toString().trim();
|
||||
|
||||
OfflinePlayer player = Bukkit.getPlayer(args[0]);
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist or is not online.");
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
new Punishment(PunishmentType.KICK, reason.equals("") ? null : reason)
|
||||
.execute(sender, player);
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "um.kick";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/Kick <player> [reason]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Allows you to kick players.";
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.punish.Punishment;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandMute extends AbstractCommand {
|
||||
|
||||
public CommandMute() {
|
||||
super(false, true, "Mute");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
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".
|
||||
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)
|
||||
duration += time;
|
||||
else
|
||||
reasonBuilder.append(line).append(" ");
|
||||
|
||||
}
|
||||
}
|
||||
String reason = reasonBuilder.toString().trim();
|
||||
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist.");
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
new Punishment(PunishmentType.MUTE, duration == 0 ? -1 : duration, reason.equals("") ? null : reason)
|
||||
.execute(sender, player);
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "um.mute";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/Mute <player> [duration] [reason]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Allows you to mute players.";
|
||||
}
|
||||
}
|
@ -7,12 +7,14 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandRandomPlayer extends AbstractCommand {
|
||||
|
||||
public CommandRandomPlayer() {
|
||||
super(true, false,"RandomPlayer");
|
||||
super(true, false, "RandomPlayer");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -26,7 +28,7 @@ public class CommandRandomPlayer extends AbstractCommand {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
((Player)sender).teleport(players.get(0).getLocation());
|
||||
((Player) sender).teleport(players.get(0).getLocation());
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@ public class CommandRevive extends AbstractCommand {
|
||||
private static List<UUID> frozen = new ArrayList<>();
|
||||
|
||||
public CommandRevive() {
|
||||
super(true, true,"Revive");
|
||||
super(true, true, "Revive");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,71 @@
|
||||
package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.punish.Punishment;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.punish.template.Template;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandRunTemplate extends AbstractCommand {
|
||||
|
||||
public CommandRunTemplate() {
|
||||
super(false, true, "RunTemplate");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
if (args.length < 2)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist.");
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
StringBuilder templateBuilder = new StringBuilder();
|
||||
for (int i = 1; i < args.length; i++) {
|
||||
String line = args[i];
|
||||
templateBuilder.append(line).append(" ");
|
||||
}
|
||||
String templateStr = templateBuilder.toString().trim();
|
||||
|
||||
Template template = instance.getTemplateManager().getTemplate(templateStr);
|
||||
|
||||
if (template == null) {
|
||||
sender.sendMessage("That template does not exist...");
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
template.execute(sender, player);
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "um.template";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/RunTemplate <player> <template>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Allows you to use templates on players.";
|
||||
}
|
||||
}
|
@ -2,21 +2,36 @@ package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.listeners.DeathListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CommandSpy extends AbstractCommand {
|
||||
|
||||
private static Map<UUID, Spy> spying = new HashMap<>();
|
||||
|
||||
public CommandSpy() {
|
||||
super(true, true,"Spy");
|
||||
super(true, true, "Spy");
|
||||
}
|
||||
|
||||
public static void spy(Player player, Player senderP) {
|
||||
UltimateModeration instance = UltimateModeration.getInstance();
|
||||
boolean didVanish = false;
|
||||
if (!CommandVanish.isVanished(senderP)) {
|
||||
didVanish = true;
|
||||
CommandVanish.vanish(senderP);
|
||||
}
|
||||
|
||||
spying.put(senderP.getUniqueId(), new Spy(senderP.getLocation(), didVanish));
|
||||
player.addPassenger(senderP);
|
||||
|
||||
senderP.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.spy.success", player.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -24,7 +39,7 @@ public class CommandSpy extends AbstractCommand {
|
||||
if (args.length > 1)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
Player senderP = ((Player)sender);
|
||||
Player senderP = ((Player) sender);
|
||||
|
||||
if (args.length == 0) {
|
||||
if (!spying.containsKey(senderP.getUniqueId()))
|
||||
@ -50,16 +65,8 @@ public class CommandSpy extends AbstractCommand {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
boolean didVanish = false;
|
||||
if (!CommandVanish.isVanished(senderP)) {
|
||||
didVanish = true;
|
||||
CommandVanish.vanish(senderP);
|
||||
}
|
||||
spy(player, senderP);
|
||||
|
||||
spying.put(senderP.getUniqueId(), new Spy(senderP.getLocation(), didVanish));
|
||||
player.addPassenger(senderP);
|
||||
|
||||
senderP.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.spy.success", player.getName()));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@ -83,7 +90,7 @@ public class CommandSpy extends AbstractCommand {
|
||||
return "Allows you to spy on a player.";
|
||||
}
|
||||
|
||||
public class Spy {
|
||||
public static class Spy {
|
||||
private Location lastLocation;
|
||||
private boolean vanishApplied;
|
||||
|
||||
|
@ -2,28 +2,21 @@ package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import com.songoda.ultimatemoderation.gui.GUIPlayers;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandUltimateModeration extends AbstractCommand {
|
||||
|
||||
public CommandUltimateModeration() {
|
||||
super(false, false, "UltimateModeration");
|
||||
super(true, false, "UltimateModeration");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
sender.sendMessage("");
|
||||
sender.sendMessage(Methods.formatText(instance.getReferences().getPrefix() + "&7Version " + instance.getDescription().getVersion() + " Created with <3 by &5&l&oSongoda"));
|
||||
|
||||
for (AbstractCommand command : instance.getCommandManager().getCommands()) {
|
||||
if (command.getPermissionNode() == null || sender.hasPermission(command.getPermissionNode())) {
|
||||
sender.sendMessage(Methods.formatText("&8 - &a" + command.getSyntax() + "&7 - " + command.getDescription()));
|
||||
}
|
||||
}
|
||||
sender.sendMessage("");
|
||||
new GUIPlayers(instance, (Player) sender);
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
@ -35,7 +28,7 @@ public class CommandUltimateModeration extends AbstractCommand {
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return null;
|
||||
return "um.moderate";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,59 @@
|
||||
package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.punish.AppliedPunishment;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandUnBan extends AbstractCommand {
|
||||
|
||||
public CommandUnBan() {
|
||||
super(false, true, "UnBan");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
if (args.length != 1)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist.");
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
PlayerPunishData playerPunishData = instance.getPunishmentManager().getPlayer(player);
|
||||
|
||||
playerPunishData.expirePunishments(PunishmentType.BAN);
|
||||
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.unban.success"));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "um.ban";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/UnBan <player>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Allows you to ban players.";
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandUnMute extends AbstractCommand {
|
||||
|
||||
public CommandUnMute() {
|
||||
super(false, true, "UnMute");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
if (args.length != 1)
|
||||
return ReturnType.SYNTAX_ERROR;
|
||||
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist.");
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
PlayerPunishData playerPunishData = instance.getPunishmentManager().getPlayer(player);
|
||||
|
||||
playerPunishData.expirePunishments(PunishmentType.MUTE);
|
||||
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.unmute.success"));
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "um.mute";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/UnMute <player>";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Allows you to unmute players.";
|
||||
}
|
||||
}
|
@ -13,7 +13,6 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -25,23 +24,11 @@ public class CommandVanish extends AbstractCommand {
|
||||
super(true, false, "Vanish");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
Player player = ((Player)sender);
|
||||
vanish(player);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void registerVanishedPlayers(Player player) {
|
||||
for (UUID uuid : inVanish) {
|
||||
Player vanished = Bukkit.getPlayer(uuid);
|
||||
if (vanished == null) continue;
|
||||
if(player.hasPermission("um.vanish.bypass")) {
|
||||
if (player.hasPermission("um.vanish.bypass")) {
|
||||
player.showPlayer(vanished);
|
||||
} else {
|
||||
player.hidePlayer(vanished);
|
||||
@ -79,7 +66,7 @@ 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));
|
||||
player.getWorld().spawnParticle(Particle.valueOf(SettingsManager.Setting.VANISH_PARTICLE.getString()), player.getLocation().add(0,1,0), 35, xx, yy, zz, 0);
|
||||
player.getWorld().spawnParticle(Particle.valueOf(SettingsManager.Setting.VANISH_PARTICLE.getString()), player.getLocation().add(0, 1, 0), 35, xx, yy, zz, 0);
|
||||
}
|
||||
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
@ -94,6 +81,18 @@ public class CommandVanish extends AbstractCommand {
|
||||
return inVanish.contains(player.getUniqueId());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
Player player = ((Player) sender);
|
||||
vanish(player);
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "um.vanish";
|
||||
|
@ -2,18 +2,16 @@ package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandViewEnderChest extends AbstractCommand {
|
||||
|
||||
public CommandViewEnderChest() {
|
||||
super(true, true,"ViewEnderChest");
|
||||
super(true, true, "ViewEnderChest");
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -29,7 +27,7 @@ public class CommandViewEnderChest extends AbstractCommand {
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
((Player)sender).openInventory(player.getEnderChest());
|
||||
((Player) sender).openInventory(player.getEnderChest());
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,74 @@
|
||||
package com.songoda.ultimatemoderation.command.commands;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.AbstractCommand;
|
||||
import com.songoda.ultimatemoderation.punish.Punishment;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CommandWarn extends AbstractCommand {
|
||||
|
||||
public CommandWarn() {
|
||||
super(false, true, "Warn");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
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".
|
||||
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)
|
||||
duration += time;
|
||||
else
|
||||
reasonBuilder.append(line).append(" ");
|
||||
|
||||
}
|
||||
}
|
||||
String reason = reasonBuilder.toString().trim();
|
||||
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage(instance.getReferences().getPrefix() + "That player does not exist.");
|
||||
return ReturnType.FAILURE;
|
||||
}
|
||||
|
||||
new Punishment(PunishmentType.WARNING, duration == 0 ? -1 : duration, reason.equals("") ? null : reason)
|
||||
.execute(sender, player);
|
||||
|
||||
return ReturnType.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<String> onTab(UltimateModeration instance, CommandSender sender, String... args) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPermissionNode() {
|
||||
return "um.warning";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSyntax() {
|
||||
return "/Warn <player> [duration] [reason]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Allows you to warn players.";
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package com.songoda.ultimatemoderation.gui;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.commands.CommandFreeze;
|
||||
import com.songoda.ultimatemoderation.command.commands.CommandSpy;
|
||||
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
public class GUIModerate extends AbstractGUI {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
private final Player toModerate;
|
||||
|
||||
public GUIModerate(UltimateModeration plugin, Player toModerate, Player player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.toModerate = toModerate;
|
||||
|
||||
init(plugin.getLocale().getMessage("gui.moderate.title", toModerate.getName()), 45);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void constructGUI() {
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = ((SkullMeta) head.getItemMeta());
|
||||
meta.setOwningPlayer(toModerate);
|
||||
head.setItemMeta(meta);
|
||||
|
||||
createButton(13, head, "&7&l" + toModerate.getName());
|
||||
|
||||
createButton(8, Material.OAK_DOOR, "Back");
|
||||
|
||||
createButton(28, Material.BLUE_ICE, "&6&lFreeze", "&7Stop a player from moving.", "", "&7Currently:&6 " + (CommandFreeze.isFrozen(toModerate) ? "Frozen" : "Unfrozen"));
|
||||
createButton(30, Material.SADDLE, "&6&lSpy", "&7Spy on a player");
|
||||
createButton(32, Material.CHEST, "&c&lInventory", "&7Access this users Inventory.");
|
||||
createButton(34, Material.ENDER_CHEST, "&a&lEnderchest", "&7Access this users Enderchest");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerClickables() {
|
||||
registerClickable(8, ((player1, inventory1, cursor, slot, type) -> {
|
||||
new GUIPlayer(plugin, toModerate, player1);
|
||||
}));
|
||||
|
||||
registerClickable(28, ((player1, inventory1, cursor, slot, type) -> {
|
||||
CommandFreeze.freeze(toModerate, player);
|
||||
constructGUI();
|
||||
}));
|
||||
|
||||
registerClickable(30, ((player1, inventory1, cursor, slot, type) -> {
|
||||
CommandSpy.spy(toModerate, player);
|
||||
player.closeInventory();
|
||||
}));
|
||||
|
||||
registerClickable(32, ((player1, inventory1, cursor, slot, type) -> {
|
||||
player.openInventory(player.getInventory());
|
||||
}));
|
||||
|
||||
registerClickable(34, ((player1, inventory1, cursor, slot, type) -> {
|
||||
player.openInventory(player.getEnderChest());
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
}
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.songoda.ultimatemoderation.gui;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
public class GUIPlayer extends AbstractGUI {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
private final Player toModerate;
|
||||
|
||||
public GUIPlayer(UltimateModeration plugin, Player toModerate, Player player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.toModerate = toModerate;
|
||||
|
||||
init(plugin.getLocale().getMessage("gui.player.title", toModerate.getName()), 45);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void constructGUI() {
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = ((SkullMeta) head.getItemMeta());
|
||||
meta.setOwningPlayer(toModerate);
|
||||
head.setItemMeta(meta);
|
||||
|
||||
createButton(13, head, "&7&l" + toModerate.getName());
|
||||
|
||||
createButton(8, Material.OAK_DOOR, plugin.getLocale().getMessage("gui.general.back"));
|
||||
|
||||
createButton(28, Material.ANVIL, plugin.getLocale().getMessage("gui.player.punish"));
|
||||
createButton(30, Material.DIAMOND_CHESTPLATE, plugin.getLocale().getMessage("gui.player.moderate"));
|
||||
createButton(32, Material.DIAMOND_SWORD, plugin.getLocale().getMessage("gui.player.punishments"));
|
||||
createButton(34, Material.STONE, "BUTT");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerClickables() {
|
||||
registerClickable(8, ((player1, inventory1, cursor, slot, type) -> {
|
||||
new GUIPlayers(plugin, player1);
|
||||
}));
|
||||
|
||||
registerClickable(28, ((player1, inventory1, cursor, slot, type) -> {
|
||||
new GUIPunish(plugin, toModerate, null, player1);
|
||||
}));
|
||||
|
||||
registerClickable(30, ((player1, inventory1, cursor, slot, type) -> {
|
||||
new GUIModerate(plugin, toModerate, player1);
|
||||
}));
|
||||
|
||||
registerClickable(32, ((player1, inventory1, cursor, slot, type) -> {
|
||||
new GUIPunishments(plugin, toModerate, player1);
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
package com.songoda.ultimatemoderation.gui;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
|
||||
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GUIPlayers extends AbstractGUI {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
private int task;
|
||||
|
||||
public GUIPlayers(UltimateModeration plugin, Player player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
|
||||
init(plugin.getLocale().getMessage("gui.players.title"), 54);
|
||||
runTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void constructGUI() {
|
||||
inventory.clear();
|
||||
resetClickables();
|
||||
registerClickables();
|
||||
ArrayList<Player> players = new ArrayList<>(Bukkit.getOnlinePlayers());
|
||||
for (int i = 0; i < players.size(); i++) {
|
||||
Player pl = players.get(i);
|
||||
|
||||
PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(pl);
|
||||
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = ((SkullMeta) head.getItemMeta());
|
||||
meta.setOwningPlayer(pl);
|
||||
head.setItemMeta(meta);
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add(plugin.getLocale().getMessage("gui.players.click"));
|
||||
lore.add("");
|
||||
|
||||
lore.add(plugin.getLocale().getMessage("gui.players.noreports"));
|
||||
|
||||
int warningAmt = playerPunishData.getActivePunishments(PunishmentType.WARNING).size();
|
||||
|
||||
if (warningAmt == 0)
|
||||
lore.add(plugin.getLocale().getMessage("gui.players.nowarnings"));
|
||||
else {
|
||||
if (warningAmt == 1)
|
||||
lore.add(plugin.getLocale().getMessage("gui.players.warningsone"));
|
||||
else
|
||||
lore.add(plugin.getLocale().getMessage("gui.players.warnings",warningAmt));
|
||||
}
|
||||
|
||||
|
||||
createButton(i, head, "&7&l" + pl.getName(), lore);
|
||||
registerClickable(i, (player1, inventory1, cursor, slot, type) -> new GUIPlayer(plugin, pl, player));
|
||||
}
|
||||
|
||||
for (int i = 0; i < 9; i++)
|
||||
createButton(36 + i, Material.GRAY_STAINED_GLASS_PANE, "&1");
|
||||
|
||||
|
||||
createButton(46, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous"));
|
||||
createButton(48, Material.ARROW, plugin.getLocale().getMessage("gui.general.next"));
|
||||
|
||||
|
||||
createButton(52, Material.MAP, plugin.getLocale().getMessage("gui.players.button.templatemanager"));
|
||||
}
|
||||
|
||||
private void runTask() {
|
||||
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this::constructGUI, 5L, 5L);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerClickables() {
|
||||
registerClickable(52, ((player1, inventory1, cursor, slot, type) ->
|
||||
new GUITemplateManager(plugin, player)));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
registerOnClose(((player1, inventory1) -> Bukkit.getScheduler().cancelTask(task)));
|
||||
}
|
||||
}
|
291
src/main/java/com/songoda/ultimatemoderation/gui/GUIPunish.java
Normal file
291
src/main/java/com/songoda/ultimatemoderation/gui/GUIPunish.java
Normal file
@ -0,0 +1,291 @@
|
||||
package com.songoda.ultimatemoderation.gui;
|
||||
|
||||
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.utils.Methods;
|
||||
import com.songoda.ultimatemoderation.utils.gui.AbstractAnvilGUI;
|
||||
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GUIPunish extends AbstractGUI {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
private final Player toModerate;
|
||||
|
||||
private Template template;
|
||||
private boolean justSaved = false;
|
||||
|
||||
private PunishmentType type = PunishmentType.BAN;
|
||||
private long duration = Long.MAX_VALUE;
|
||||
private String reason = null;
|
||||
|
||||
private String templateName = null;
|
||||
|
||||
private int task;
|
||||
|
||||
public GUIPunish(UltimateModeration plugin, Player toModerate, Template template, Player player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.toModerate = toModerate;
|
||||
if (template != null) {
|
||||
this.template = template;
|
||||
this.type = template.getPunishmentType();
|
||||
this.duration = template.getDuration();
|
||||
this.reason = template.getReason();
|
||||
this.templateName = template.getTemplateName();
|
||||
}
|
||||
|
||||
init(toModerate == null ? plugin.getLocale().getMessage("gui.punish.title.template")
|
||||
: plugin.getLocale().getMessage("gui.punish.title", toModerate.getName()), 45);
|
||||
if (toModerate != null) runTask();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void constructGUI() {
|
||||
inventory.clear();
|
||||
ItemStack head = new ItemStack(Material.PLAYER_HEAD);
|
||||
SkullMeta meta = ((SkullMeta) head.getItemMeta());
|
||||
meta.setOwningPlayer(toModerate);
|
||||
head.setItemMeta(meta);
|
||||
|
||||
if (toModerate != null)
|
||||
createButton(13, head, "&7&l" + toModerate.getName());
|
||||
|
||||
createButton(22, Material.EMERALD_BLOCK, plugin.getLocale().getMessage("gui.punish.submit"));
|
||||
|
||||
createButton(8, Material.OAK_DOOR, plugin.getLocale().getMessage("gui.general.back"));
|
||||
|
||||
createButton(28, Material.ANVIL, plugin.getLocale().getMessage("gui.punish.type.punishment"),
|
||||
"&7" + type.getTranslation(),
|
||||
"",
|
||||
plugin.getLocale().getMessage("gui.punish.type.punishment.click"));
|
||||
|
||||
if (toModerate != null) {
|
||||
createButton(30, Material.MAP, plugin.getLocale().getMessage("gui.punish.type.template"),
|
||||
plugin.getLocale().getMessage("gui.punish.type.template.current",
|
||||
(template == null ? plugin.getLocale().getMessage("gui.general.none") : template.getTemplateName())),
|
||||
"",
|
||||
plugin.getLocale().getMessage(plugin.getTemplateManager().getTemplates().size() == 0 ? "gui.punish.type.template.none" : "gui.punish.type.template.click"));
|
||||
} else {
|
||||
createButton(30, Material.MAP, plugin.getLocale().getMessage("gui.punish.type.name"),
|
||||
plugin.getLocale().getMessage("gui.punish.type.name.current",
|
||||
(templateName == null ? plugin.getLocale().getMessage("gui.general.none") : templateName)),
|
||||
"",
|
||||
plugin.getLocale().getMessage("gui.punish.type.name.current.click"));
|
||||
}
|
||||
|
||||
if (type != PunishmentType.KICK) {
|
||||
createButton(32, Material.CLOCK, plugin.getLocale().getMessage("gui.punish.type.duration"),
|
||||
plugin.getLocale().getMessage("gui.punish.type.duration.leftclick"),
|
||||
plugin.getLocale().getMessage("gui.punish.type.duration.rightclick"),
|
||||
"",
|
||||
plugin.getLocale().getMessage("gui.punish.type.duration.current"),
|
||||
"&6" + (duration == Long.MAX_VALUE ? plugin.getLocale().getMessage("gui.general.permanent") : Methods.makeReadable(duration)));
|
||||
}
|
||||
|
||||
createButton(34, Material.PAPER, plugin.getLocale().getMessage("gui.punish.type.reason"),
|
||||
plugin.getLocale().getMessage("gui.punish.type.reason.click"),
|
||||
"",
|
||||
plugin.getLocale().getMessage("gui.punish.type.reason.current"), "&6" + reason);
|
||||
}
|
||||
|
||||
private void notifyTemplate() {
|
||||
if (reason == null || duration == 0 || (justSaved && template != null)) {
|
||||
inventory.setItem(4, null);
|
||||
return;
|
||||
}
|
||||
|
||||
Material material = Material.WHITE_WOOL;
|
||||
String name = plugin.getLocale().getMessage("gui.punish.template.create");
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add(plugin.getLocale().getMessage("gui.punish.template.create2"));
|
||||
|
||||
if (!justSaved && template != null) {
|
||||
name = plugin.getLocale().getMessage("gui.punish.template.leftclick");
|
||||
lore.clear();
|
||||
lore.add(plugin.getLocale().getMessage("gui.punish.template.leftclick2", template.getTemplateName()));
|
||||
lore.add("");
|
||||
lore.add(plugin.getLocale().getMessage("gui.punish.template.rightclick"));
|
||||
}
|
||||
|
||||
if (inventory.getItem(4) != null && inventory.getItem(4).getType() == Material.WHITE_WOOL)
|
||||
material = Material.YELLOW_WOOL;
|
||||
|
||||
createButton(4, material, name, lore);
|
||||
}
|
||||
|
||||
public void runTask() {
|
||||
task = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, this::notifyTemplate, 10L, 10L);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerClickables() {
|
||||
registerClickable(8, ((player1, inventory1, cursor, slot, type) -> {
|
||||
if (toModerate != null)
|
||||
new GUIPlayer(plugin, toModerate, player);
|
||||
else
|
||||
new GUITemplateManager(plugin, player);
|
||||
}));
|
||||
|
||||
registerClickable(28, ((player1, inventory1, cursor, slot, type) -> {
|
||||
this.type = this.type.next();
|
||||
justSaved = false;
|
||||
constructGUI();
|
||||
}));
|
||||
|
||||
registerClickable(4, ((player1, inventory1, cursor, slot, type) -> {
|
||||
if (reason == null || duration == 0) return;
|
||||
|
||||
if (template != null && type == ClickType.LEFT) {
|
||||
updateTemplate();
|
||||
return;
|
||||
}
|
||||
nameTemplate();
|
||||
}));
|
||||
|
||||
registerClickable(30, ((player1, inventory1, cursor, slot, type) -> {
|
||||
if (toModerate == null) {
|
||||
nameTemplate();
|
||||
return;
|
||||
}
|
||||
if (plugin.getTemplateManager().getTemplates().size() == 0) return;
|
||||
|
||||
new GUITemplateSelector(plugin, this, player);
|
||||
}));
|
||||
registerClickable(32, ((player1, inventory1, cursor, slot, type) -> {
|
||||
if (this.type == PunishmentType.KICK) return;
|
||||
if (type == ClickType.LEFT) {
|
||||
AbstractAnvilGUI gui = new AbstractAnvilGUI(player, event -> {
|
||||
this.duration = Methods.parseTime(event.getName());
|
||||
justSaved = false;
|
||||
});
|
||||
|
||||
gui.setOnClose((player2, inventory3) -> init(inventory.getTitle(), inventory.getSize()));
|
||||
|
||||
ItemStack item = new ItemStack(Material.PAPER);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
meta.setDisplayName(duration == Long.MAX_VALUE || duration == 0 ? "1d 1h 1m" : Methods.makeReadable(duration));
|
||||
item.setItemMeta(meta);
|
||||
|
||||
gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, item);
|
||||
gui.open();
|
||||
} else {
|
||||
duration = Long.MAX_VALUE;
|
||||
constructGUI();
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
registerClickable(34, ((player1, inventory1, cursor, slot, type) -> {
|
||||
AbstractAnvilGUI gui = new AbstractAnvilGUI(player, event -> {
|
||||
this.reason = event.getName();
|
||||
justSaved = false;
|
||||
});
|
||||
|
||||
gui.setOnClose((player2, inventory3) -> init(inventory.getTitle(), inventory.getSize()));
|
||||
|
||||
ItemStack item = new ItemStack(Material.PAPER);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(reason == null ? plugin.getLocale().getMessage("gui.general.reason") : reason);
|
||||
item.setItemMeta(meta);
|
||||
|
||||
gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, item);
|
||||
gui.open();
|
||||
}));
|
||||
|
||||
registerClickable(22, ((player1, inventory1, cursor, slot, type1) -> {
|
||||
if (toModerate == null) {
|
||||
if (reason == null || duration == 0 || templateName == null) return;
|
||||
|
||||
if (template == null)
|
||||
finishTemplate();
|
||||
else
|
||||
updateTemplate();
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case BAN:
|
||||
case MUTE:
|
||||
case WARNING:
|
||||
new Punishment(type, duration, reason).execute(player, toModerate);
|
||||
break;
|
||||
case KICK:
|
||||
new Punishment(type, reason).execute(player, toModerate);
|
||||
break;
|
||||
}
|
||||
new GUIPlayer(plugin, toModerate, player);
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
registerOnClose(((player1, inventory1) -> Bukkit.getScheduler().cancelTask(task)));
|
||||
}
|
||||
|
||||
private void nameTemplate() {
|
||||
AbstractAnvilGUI gui = new AbstractAnvilGUI(player, event -> {
|
||||
this.templateName = event.getName();
|
||||
|
||||
if (toModerate != null)
|
||||
finishTemplate();
|
||||
|
||||
justSaved = true;
|
||||
});
|
||||
|
||||
gui.setOnClose((player2, inventory3) ->
|
||||
init(inventory.getTitle(), inventory.getSize()));
|
||||
|
||||
ItemStack item = new ItemStack(Material.PAPER);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(plugin.getLocale().getMessage("gui.general.templatename"));
|
||||
item.setItemMeta(meta);
|
||||
|
||||
gui.setSlot(AbstractAnvilGUI.AnvilSlot.INPUT_LEFT, item);
|
||||
gui.open();
|
||||
}
|
||||
|
||||
private void updateTemplate() {
|
||||
Template template = new Template(this.type, this.duration, this.reason, this.template.getCreator(), this.templateName);
|
||||
plugin.getTemplateManager().updateTemplate(template);
|
||||
justSaved = true;
|
||||
if (toModerate == null)
|
||||
new GUITemplateManager(plugin, player);
|
||||
}
|
||||
|
||||
private void finishTemplate() {
|
||||
Template template = new Template(this.type, this.duration, this.reason, player, templateName);
|
||||
plugin.getTemplateManager().addTemplate(template);
|
||||
this.template = template;
|
||||
if (toModerate == null)
|
||||
new GUITemplateManager(plugin, player);
|
||||
}
|
||||
|
||||
public void setTemplate(Template template) {
|
||||
this.justSaved = true;
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
public void setType(PunishmentType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public void setDuration(long duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public void setReason(String reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
package com.songoda.ultimatemoderation.gui;
|
||||
|
||||
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.utils.Methods;
|
||||
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class GUIPunishments extends AbstractGUI {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
private final Player toModerate;
|
||||
|
||||
private Activity currentActivity = Activity.BOTH;
|
||||
private PunishmentType punishmentType = PunishmentType.ALL;
|
||||
|
||||
public GUIPunishments(UltimateModeration plugin, Player toModerate, Player player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.toModerate = toModerate;
|
||||
|
||||
init(plugin.getLocale().getMessage("gui.punishments.title", toModerate.getName()), 54);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void constructGUI() {
|
||||
inventory.clear();
|
||||
resetClickables();
|
||||
registerClickables();
|
||||
|
||||
createButton(8, Material.OAK_DOOR, plugin.getLocale().getMessage("gui.general.back"));
|
||||
|
||||
createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous"));
|
||||
|
||||
createButton(3, Material.APPLE, Methods.formatText("&6" + currentActivity.getTranslation()));
|
||||
createButton(4, Material.DIAMOND_SWORD, Methods.formatText("&6" + punishmentType.name()));
|
||||
|
||||
createButton(6, Material.ARROW, plugin.getLocale().getMessage("gui.general.next"));
|
||||
|
||||
for (int i = 0; i < 9; i++)
|
||||
createButton(9 + i, Material.GRAY_STAINED_GLASS_PANE, "&1");
|
||||
|
||||
PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(toModerate);
|
||||
|
||||
Map<AppliedPunishment, Activity> punishments = new HashMap<>();
|
||||
|
||||
if (currentActivity == Activity.ACTIVE || currentActivity == Activity.BOTH) {
|
||||
for (AppliedPunishment punishment : playerPunishData.getActivePunishments()) {
|
||||
if (punishmentType != PunishmentType.ALL) {
|
||||
if (punishment.getPunishmentType() != punishmentType)
|
||||
continue;
|
||||
}
|
||||
punishments.put(punishment, Activity.ACTIVE);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentActivity == Activity.EXPIRED || currentActivity == Activity.BOTH) {
|
||||
for (AppliedPunishment punishment : playerPunishData.getExpiredPunishments()) {
|
||||
if (punishmentType != PunishmentType.ALL) {
|
||||
if (punishment.getPunishmentType() != punishmentType)
|
||||
continue;
|
||||
}
|
||||
punishments.put(punishment, Activity.EXPIRED);
|
||||
}
|
||||
}
|
||||
|
||||
int currentSlot = 18;
|
||||
for (Map.Entry<AppliedPunishment, Activity> entry : punishments.entrySet()) {
|
||||
AppliedPunishment appliedPunishment = entry.getKey();
|
||||
Activity activity = entry.getValue();
|
||||
|
||||
ArrayList<String> lore = new ArrayList<>();
|
||||
lore.add("");
|
||||
lore.add(plugin.getLocale().getMessage("gui.punishments.reason"));
|
||||
lore.add("&7" + appliedPunishment.getReason());
|
||||
if (appliedPunishment.getPunishmentType() != PunishmentType.KICK) {
|
||||
lore.add("");
|
||||
lore.add(plugin.getLocale().getMessage("gui.punishments.duration"));
|
||||
lore.add("&7" + Methods.makeReadable(appliedPunishment.getDuration()));
|
||||
lore.add("");
|
||||
lore.add(plugin.getLocale().getMessage("gui.punishments.punisher"));
|
||||
lore.add("&7" + (appliedPunishment.getPunisher() == null ? "Console" : Bukkit.getOfflinePlayer(appliedPunishment.getPunisher()).getName()));
|
||||
if (activity == Activity.ACTIVE) {
|
||||
lore.add("");
|
||||
lore.add(plugin.getLocale().getMessage("gui.punishments.remaining"));
|
||||
lore.add("&7" + Methods.makeReadable(appliedPunishment.getTimeRemaining()));
|
||||
lore.add("");
|
||||
lore.add(plugin.getLocale().getMessage("gui.punishments.click"));
|
||||
|
||||
registerClickable(currentSlot, ((player1, inventory1, cursor, slot, type) -> {
|
||||
appliedPunishment.expire();
|
||||
constructGUI();
|
||||
}));
|
||||
}
|
||||
}
|
||||
lore.add("");
|
||||
createButton(currentSlot, Material.MAP,
|
||||
"&6&l" + appliedPunishment.getPunishmentType().getTranslation() + " - &7&l" + activity.getTranslation(), lore);
|
||||
|
||||
currentSlot++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerClickables() {
|
||||
registerClickable(8, ((player1, inventory1, cursor, slot, type) ->
|
||||
new GUIPlayer(plugin, toModerate, player)));
|
||||
|
||||
registerClickable(3, ((player1, inventory1, cursor, slot, type) -> {
|
||||
this.currentActivity = currentActivity.next();
|
||||
constructGUI();
|
||||
}));
|
||||
|
||||
registerClickable(4, ((player1, inventory1, cursor, slot, type) -> {
|
||||
this.punishmentType = punishmentType.nextFilter();
|
||||
constructGUI();
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
}
|
||||
|
||||
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)];
|
||||
}
|
||||
|
||||
public String getTranslation() {
|
||||
return UltimateModeration.getInstance().getLocale().getMessage("gui.punishments.activity." + this.name().toLowerCase());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package com.songoda.ultimatemoderation.gui;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.punish.template.Template;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GUITemplateManager extends AbstractGUI {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
|
||||
private PunishmentType punishmentType = PunishmentType.ALL;
|
||||
|
||||
public GUITemplateManager(UltimateModeration plugin, Player player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
|
||||
init(plugin.getLocale().getMessage("gui.templatemanager.title"), 54);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void constructGUI() {
|
||||
inventory.clear();
|
||||
|
||||
createButton(1, Material.ARROW, plugin.getLocale().getMessage("gui.general.previous"));
|
||||
|
||||
createButton(3 ,Material.DIAMOND_SWORD, Methods.formatText("&6" + punishmentType.name()));
|
||||
|
||||
createButton(5, Material.ARROW, plugin.getLocale().getMessage("gui.general.next"));
|
||||
|
||||
createButton(8, Material.OAK_DOOR, plugin.getLocale().getMessage("gui.general.back"));
|
||||
|
||||
createButton(7, Material.REDSTONE, plugin.getLocale().getMessage("gui.templatemanager.create"));
|
||||
|
||||
for (int i = 0; i < 9; i++)
|
||||
createButton(9 + i, Material.GRAY_STAINED_GLASS_PANE, "&1");
|
||||
|
||||
ArrayList<Template> templates = new ArrayList<>(plugin.getTemplateManager().getTemplates().values());
|
||||
templates.removeIf(template -> template.getPunishmentType() != punishmentType);
|
||||
for (int i = 0; i < templates.size(); i++) {
|
||||
Template template = templates.get(i);
|
||||
createButton(18 + i, Material.MAP, "&6&l" + template.getTemplateName(),
|
||||
plugin.getLocale().getMessage("gui.templatemanager.leftclick"),
|
||||
plugin.getLocale().getMessage("gui.templatemanager.rightclick"));
|
||||
|
||||
registerClickable(18 + i, ((player1, inventory1, cursor, slot, type) -> {
|
||||
if (type == ClickType.LEFT) {
|
||||
new GUIPunish(plugin, null, template, player);
|
||||
} else if (type == ClickType.RIGHT) {
|
||||
plugin.getTemplateManager().removeTemplate(template.getTemplateName());
|
||||
constructGUI();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerClickables() {
|
||||
registerClickable(8, ((player1, inventory1, cursor, slot, type) ->
|
||||
new GUIPlayers(plugin, player)));
|
||||
|
||||
registerClickable(7, ((player1, inventory1, cursor, slot, type) ->
|
||||
new GUIPunish(plugin, null, null, player)));
|
||||
|
||||
registerClickable(3, ((player1, inventory1, cursor, slot, type) -> {
|
||||
this.punishmentType = punishmentType.nextFilter();
|
||||
constructGUI();
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.songoda.ultimatemoderation.gui;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.punish.template.Template;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import com.songoda.ultimatemoderation.utils.gui.AbstractGUI;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GUITemplateSelector extends AbstractGUI {
|
||||
|
||||
private final UltimateModeration plugin;
|
||||
private GUIPunish punish;
|
||||
|
||||
public GUITemplateSelector(UltimateModeration plugin, GUIPunish punish, Player player) {
|
||||
super(player);
|
||||
this.plugin = plugin;
|
||||
this.punish = punish;
|
||||
|
||||
init(plugin.getLocale().getMessage("gui.templateselector.title"), 54);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void constructGUI() {
|
||||
createButton(8, Material.OAK_DOOR, plugin.getLocale().getMessage("gui.general.back"));
|
||||
|
||||
for (int i = 0; i < 9; i++)
|
||||
createButton(9 + i, Material.GRAY_STAINED_GLASS_PANE, "&1");
|
||||
|
||||
ArrayList<Template> templates = new ArrayList<>(plugin.getTemplateManager().getTemplates().values());
|
||||
for (int i = 0; i < templates.size(); i++) {
|
||||
Template template = templates.get(i);
|
||||
createButton(18 + i, Material.MAP, "&6&l" + template.getTemplateName(), plugin.getLocale().getMessage("gui.templateselector.click"));
|
||||
|
||||
registerClickable(18 + i, ((player1, inventory1, cursor, slot, type) -> {
|
||||
punish.setType(template.getPunishmentType());
|
||||
punish.setDuration(template.getDuration());
|
||||
punish.setReason(template.getReason());
|
||||
punish.setTemplate(template);
|
||||
punish.init(punish.getInventory().getTitle(), punish.getInventory().getSize());
|
||||
punish.runTask();
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerClickables() {
|
||||
registerClickable(8, ((player1, inventory1, cursor, slot, type) -> {
|
||||
punish.init(punish.getInventory().getTitle(), punish.getInventory().getSize());
|
||||
punish.runTask();
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerOnCloses() {
|
||||
|
||||
}
|
||||
}
|
@ -1,21 +1,29 @@
|
||||
package com.songoda.ultimatemoderation.listeners;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.punish.AppliedPunishment;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ChatListener implements Listener {
|
||||
|
||||
private UltimateModeration instance;
|
||||
private static boolean isChatToggled = true; // true means people can talk, false means muted
|
||||
private UltimateModeration instance;
|
||||
|
||||
public ChatListener(UltimateModeration ultimateModeration) {
|
||||
this.instance = ultimateModeration;
|
||||
}
|
||||
|
||||
public static void setChatToggled(boolean toggled) {
|
||||
isChatToggled = toggled;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onChat(AsyncPlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
@ -23,10 +31,13 @@ public class ChatListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(instance.getReferences().getPrefix() + Methods.formatText(instance.getLocale().getMessage("command.togglechat.muted")));
|
||||
}
|
||||
}
|
||||
|
||||
public static void setChatToggled(boolean toggled) {
|
||||
isChatToggled = toggled;
|
||||
List<AppliedPunishment> appliedPunishments = instance.getPunishmentManager().getPlayer(player).getActivePunishments(PunishmentType.MUTE);
|
||||
if (!appliedPunishments.isEmpty()) {
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.mute.message",
|
||||
appliedPunishments.get(0).getReason(), Methods.makeReadable(appliedPunishments.get(0).getTimeRemaining())));
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,16 +2,13 @@ package com.songoda.ultimatemoderation.listeners;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.commands.CommandCommandSpy;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import com.songoda.ultimatemoderation.utils.SettingsManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandListener implements Listener {
|
||||
|
@ -1,12 +1,10 @@
|
||||
package com.songoda.ultimatemoderation.listeners;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.commands.CommandFreeze;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -24,13 +22,13 @@ public class DeathListener implements Listener {
|
||||
this.instance = ultimateModeration;
|
||||
}
|
||||
|
||||
public static List<ItemStack> getLastDrop(Player player) {
|
||||
return playerDrops.get(player.getUniqueId());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onDeath(PlayerDeathEvent event) {
|
||||
Player player = event.getEntity();
|
||||
playerDrops.put(player.getUniqueId(), event.getDrops());
|
||||
}
|
||||
|
||||
public static List<ItemStack> getLastDrop(Player player) {
|
||||
return playerDrops.get(player.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public class DropListener implements Listener {
|
||||
|
||||
|
@ -6,7 +6,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
|
||||
public class InventoryListener implements Listener {
|
||||
|
||||
@ -19,7 +18,7 @@ public class InventoryListener implements Listener {
|
||||
@EventHandler
|
||||
public void onMove(InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player)) return;
|
||||
Player player = (Player)event.getWhoClicked();
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
if (CommandFreeze.isFrozen(player)) {
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.freeze.nope"));
|
||||
|
@ -2,13 +2,18 @@ package com.songoda.ultimatemoderation.listeners;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.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;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LoginListener implements Listener {
|
||||
|
||||
private UltimateModeration instance;
|
||||
@ -17,6 +22,23 @@ public class LoginListener implements Listener {
|
||||
this.instance = ultimateModeration;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPreLogin(AsyncPlayerPreLoginEvent event) {
|
||||
PlayerPunishData playerPunishData = instance.getPunishmentManager().getPlayer(event.getUniqueId());
|
||||
|
||||
List<AppliedPunishment> appliedPunishments = playerPunishData.getActivePunishments(PunishmentType.BAN);
|
||||
|
||||
if (appliedPunishments.isEmpty()) return;
|
||||
|
||||
AppliedPunishment appliedPunishment = playerPunishData.getActivePunishments(PunishmentType.BAN).get(0);
|
||||
|
||||
event.setKickMessage(instance.getLocale().getMessage("event.ban.message",
|
||||
appliedPunishment.getReason() == null ? "" : appliedPunishment.getReason(),
|
||||
Methods.makeReadable(appliedPunishment.getTimeRemaining())));
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_BANNED);
|
||||
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onLogin(PlayerLoginEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
|
@ -2,11 +2,9 @@ package com.songoda.ultimatemoderation.listeners;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.command.commands.CommandFreeze;
|
||||
import com.songoda.ultimatemoderation.command.commands.CommandVanish;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
|
||||
public class MoveListener implements Listener {
|
||||
|
@ -0,0 +1,44 @@
|
||||
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;
|
||||
|
||||
public AppliedPunishment(PunishmentType punishmentType, long duration, String reason, UUID victim, UUID punisher, long expiration) {
|
||||
super(punishmentType, duration, reason);
|
||||
this.victim = victim;
|
||||
this.punisher = punisher;
|
||||
this.expiration = expiration;
|
||||
}
|
||||
|
||||
public AppliedPunishment(Punishment punishment, UUID victim, UUID punisher, long expiration) {
|
||||
super(punishment);
|
||||
this.victim = victim;
|
||||
this.punisher = punisher;
|
||||
this.expiration = expiration;
|
||||
}
|
||||
|
||||
public UUID getVictim() {
|
||||
return victim;
|
||||
}
|
||||
|
||||
public UUID getPunisher() {
|
||||
return punisher;
|
||||
}
|
||||
|
||||
public long getExpiration() {
|
||||
return expiration;
|
||||
}
|
||||
|
||||
public void expire() {
|
||||
this.expiration = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
public long getTimeRemaining() {
|
||||
return expiration - System.currentTimeMillis();
|
||||
}
|
||||
}
|
@ -0,0 +1,114 @@
|
||||
package com.songoda.ultimatemoderation.punish;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.punish.player.PlayerPunishData;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class Punishment {
|
||||
|
||||
private final PunishmentType punishmentType;
|
||||
private final long duration;
|
||||
private final String reason;
|
||||
|
||||
public Punishment(PunishmentType punishmentType, long duration, String reason) {
|
||||
this.punishmentType = punishmentType;
|
||||
this.duration = duration;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public Punishment(PunishmentType punishmentType, String reason) {
|
||||
this.punishmentType = punishmentType;
|
||||
this.duration = -1;
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
protected Punishment(Punishment punishment) {
|
||||
this.punishmentType = punishment.getPunishmentType();
|
||||
this.duration = punishment.getDuration();
|
||||
this.reason = punishment.getReason();
|
||||
}
|
||||
|
||||
public void execute(CommandSender punisher, OfflinePlayer victim) {
|
||||
UltimateModeration plugin = UltimateModeration.getInstance();
|
||||
|
||||
if (!punisher.hasPermission("Um." + punishmentType)) {
|
||||
punisher.sendMessage(plugin.getReferences().getPrefix() + plugin.getLocale().getMessage("event.general.nopermission"));
|
||||
return;
|
||||
}
|
||||
|
||||
PlayerPunishData playerPunishData = plugin.getPunishmentManager().getPlayer(victim);
|
||||
switch (punishmentType) {
|
||||
case BAN:
|
||||
if (!playerPunishData.getActivePunishments(PunishmentType.BAN).isEmpty()) {
|
||||
punisher.sendMessage(plugin.getReferences().getPrefix()
|
||||
+ plugin.getLocale().getMessage("event.ban.already"));
|
||||
return;
|
||||
}
|
||||
sendMessage(victim);
|
||||
break;
|
||||
case MUTE:
|
||||
if (!playerPunishData.getActivePunishments(PunishmentType.MUTE).isEmpty()) {
|
||||
punisher.sendMessage(plugin.getReferences().getPrefix()
|
||||
+ plugin.getLocale().getMessage("event.mute.already"));
|
||||
return;
|
||||
}
|
||||
sendMessage(victim);
|
||||
break;
|
||||
case KICK:
|
||||
case WARNING:
|
||||
sendMessage(victim);
|
||||
break;
|
||||
}
|
||||
|
||||
String punishSuccess = plugin.getReferences().getPrefix()
|
||||
+ plugin.getLocale().getMessage("event." + punishmentType.name().toLowerCase() + ".success", victim.getName());
|
||||
|
||||
if (reason != null)
|
||||
punishSuccess += plugin.getLocale().getMessage("event.punish.reason", reason);
|
||||
|
||||
if (duration != -1)
|
||||
punishSuccess += plugin.getLocale().getMessage("event.punish.theirduration", Methods.makeReadable(duration));
|
||||
|
||||
punisher.sendMessage(punishSuccess + Methods.formatText("&7."));
|
||||
|
||||
playerPunishData.addPunishment(apply(victim, punisher));
|
||||
}
|
||||
|
||||
private void sendMessage(OfflinePlayer offlineVictim) {
|
||||
if (!offlineVictim.isOnline()) return;
|
||||
Player victim = offlineVictim.getPlayer();
|
||||
UltimateModeration plugin = UltimateModeration.getInstance();
|
||||
|
||||
String punishSuccess = plugin.getReferences().getPrefix()
|
||||
+ plugin.getLocale().getMessage("event." + punishmentType.name().toLowerCase() + ".message");
|
||||
|
||||
if (reason != null)
|
||||
punishSuccess += plugin.getLocale().getMessage("event.punish.reason", reason);
|
||||
|
||||
if (duration != -1)
|
||||
punishSuccess += plugin.getLocale().getMessage("event.punish.yourduration", Methods.makeReadable(duration));
|
||||
|
||||
victim.sendMessage(punishSuccess + Methods.formatText("&7."));
|
||||
}
|
||||
|
||||
public PunishmentType getPunishmentType() {
|
||||
return this.punishmentType;
|
||||
}
|
||||
|
||||
public long getDuration() {
|
||||
return this.duration;
|
||||
}
|
||||
|
||||
public String getReason() {
|
||||
return this.reason;
|
||||
}
|
||||
|
||||
private AppliedPunishment apply(OfflinePlayer player, CommandSender punisher) {
|
||||
return new AppliedPunishment(this, player.getUniqueId(),
|
||||
punisher == null ? null : punisher instanceof OfflinePlayer ? ((OfflinePlayer)punisher).getUniqueId() : null, System.currentTimeMillis() + this.duration);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
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)];
|
||||
|
||||
if (next == ALL)
|
||||
next = next.next();
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
public PunishmentType nextFilter() {
|
||||
return vals[(this.ordinal() != vals.length - 1 ? this.ordinal() + 1 : 0)];
|
||||
}
|
||||
|
||||
public String getTranslation() {
|
||||
return UltimateModeration.getInstance().getLocale().getMessage("gui.punishmenttypes." + this.name().toLowerCase());
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
package com.songoda.ultimatemoderation.punish.player;
|
||||
|
||||
import com.songoda.ultimatemoderation.punish.AppliedPunishment;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class PlayerPunishData {
|
||||
|
||||
private final UUID player;
|
||||
|
||||
private final List<AppliedPunishment> activePunishments = new ArrayList<>();
|
||||
private final List<AppliedPunishment> expiredPunishments = new ArrayList<>();
|
||||
|
||||
public PlayerPunishData(UUID player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public PlayerPunishData(UUID player, List<AppliedPunishment> punishments) {
|
||||
this.player = player;
|
||||
this.activePunishments.addAll(punishments);
|
||||
}
|
||||
|
||||
public UUID getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public List<AppliedPunishment> getActivePunishments() {
|
||||
audit();
|
||||
return new ArrayList<>(activePunishments);
|
||||
}
|
||||
|
||||
public List<AppliedPunishment> getActivePunishments(PunishmentType type) {
|
||||
audit();
|
||||
return activePunishments.stream().filter(punishment -> punishment.getPunishmentType() == type).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<AppliedPunishment> getExpiredPunishments() {
|
||||
audit();
|
||||
return new ArrayList<>(expiredPunishments);
|
||||
}
|
||||
|
||||
public List<AppliedPunishment> getExpiredPunishments(PunishmentType type) {
|
||||
audit();
|
||||
return expiredPunishments.stream().filter(punishment -> punishment.getPunishmentType() == type).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public AppliedPunishment[] addPunishment(AppliedPunishment... appliedPunishments) {
|
||||
this.activePunishments.addAll(Arrays.asList(appliedPunishments));
|
||||
return appliedPunishments;
|
||||
}
|
||||
|
||||
public AppliedPunishment[] removePunishment(AppliedPunishment... appliedPunishments) {
|
||||
this.activePunishments.removeAll(Arrays.asList(appliedPunishments));
|
||||
return appliedPunishments;
|
||||
}
|
||||
|
||||
public AppliedPunishment[] removeExpiredPunishment(AppliedPunishment... appliedPunishments) {
|
||||
this.activePunishments.removeAll(Arrays.asList(appliedPunishments));
|
||||
return appliedPunishments;
|
||||
}
|
||||
|
||||
private void audit() {
|
||||
audit(false, PunishmentType.ALL);
|
||||
}
|
||||
|
||||
private void audit(boolean forced, PunishmentType punishmentType) {
|
||||
List<AppliedPunishment> expired = activePunishments.stream().filter(appliedPunishment ->
|
||||
(appliedPunishment.getDuration() != -1 || forced)
|
||||
&& (appliedPunishment.getPunishmentType() == punishmentType || punishmentType == PunishmentType.ALL)
|
||||
&& appliedPunishment.getExpiration() <= System.currentTimeMillis()).collect(Collectors.toList());
|
||||
|
||||
this.expiredPunishments.addAll(expired);
|
||||
this.activePunishments.removeAll(expired);
|
||||
}
|
||||
|
||||
public void expirePunishments(PunishmentType type) {
|
||||
List<AppliedPunishment> toAudit = new ArrayList<>();
|
||||
activePunishments.stream().filter(appliedPunishment ->
|
||||
type == appliedPunishment.getPunishmentType()).forEach(appliedPunishment -> {
|
||||
appliedPunishment.expire();
|
||||
toAudit.add(appliedPunishment);
|
||||
});
|
||||
toAudit.stream().forEach(appliedPunishment -> this.audit(true, type));
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
package com.songoda.ultimatemoderation.punish.player;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PunishmentManager {
|
||||
|
||||
private Map<UUID, PlayerPunishData> punishments = new HashMap<>();
|
||||
|
||||
public Map<UUID, PlayerPunishData> getPunishments() {
|
||||
return Collections.unmodifiableMap(punishments);
|
||||
}
|
||||
|
||||
public PlayerPunishData getPlayer(OfflinePlayer player) {
|
||||
return getPlayer(player.getUniqueId());
|
||||
}
|
||||
|
||||
public PlayerPunishData getPlayer(UUID player) {
|
||||
return punishments.computeIfAbsent(player, PlayerPunishData::new);
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.songoda.ultimatemoderation.punish.template;
|
||||
|
||||
import com.songoda.ultimatemoderation.punish.Punishment;
|
||||
import com.songoda.ultimatemoderation.punish.PunishmentType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Template extends Punishment {
|
||||
|
||||
private final String templateName;
|
||||
private final UUID creator;
|
||||
|
||||
public Template(PunishmentType punishmentType, long duration, String reason, Player creator, String templateName) {
|
||||
super(punishmentType, duration, reason);
|
||||
this.creator = creator.getUniqueId();
|
||||
this.templateName = templateName;
|
||||
}
|
||||
|
||||
public Template(PunishmentType punishmentType, long duration, String reason, UUID creator, String templateName) {
|
||||
super(punishmentType, duration, reason);
|
||||
this.creator = creator;
|
||||
this.templateName = templateName;
|
||||
}
|
||||
|
||||
public String getTemplateName() {
|
||||
return templateName;
|
||||
}
|
||||
|
||||
public UUID getCreator() {
|
||||
return creator;
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.songoda.ultimatemoderation.punish.template;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class TemplateManager {
|
||||
|
||||
private static final Map<String, Template> templates = new HashMap<>();
|
||||
|
||||
public Template getTemplate(String name) {
|
||||
return templates.get(formatName(name));
|
||||
}
|
||||
|
||||
public Template addTemplate(Template template) {
|
||||
return templates.put(formatName(template.getTemplateName()), template);
|
||||
}
|
||||
|
||||
public Template removeTemplate(String name) {
|
||||
return templates.remove(formatName(name));
|
||||
}
|
||||
|
||||
public Template updateTemplate(Template template) {
|
||||
templates.remove(formatName(template.getTemplateName()));
|
||||
return addTemplate(template);
|
||||
}
|
||||
|
||||
public Map<String, Template> getTemplates() {
|
||||
return Collections.unmodifiableMap(templates);
|
||||
}
|
||||
|
||||
private String formatName(String name) {
|
||||
name = name.toUpperCase().trim();
|
||||
name = name.replace(" ", "_");
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
@ -6,6 +6,8 @@ import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class Methods {
|
||||
|
||||
public static ItemStack getGlass() {
|
||||
@ -48,4 +50,43 @@ public class Methods {
|
||||
text = text.substring(0, 1).toUpperCase() + text.substring(1);
|
||||
return ChatColor.translateAlternateColorCodes('&', text);
|
||||
}
|
||||
|
||||
public static String makeReadable(Long time) {
|
||||
if (time == null)
|
||||
return "";
|
||||
return String.format("%dd %dh %dm",
|
||||
TimeUnit.MILLISECONDS.toDays(time),
|
||||
TimeUnit.MILLISECONDS.toHours(time) - TimeUnit.DAYS.toHours(TimeUnit.MILLISECONDS.toDays(time)),
|
||||
TimeUnit.MILLISECONDS.toMinutes(time) - TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(time)));
|
||||
}
|
||||
|
||||
|
||||
public static long parseTime(String input) {
|
||||
long result = 0;
|
||||
String number = "";
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
char c = input.charAt(i);
|
||||
if (Character.isDigit(c)) {
|
||||
number += c;
|
||||
} else if (Character.isLetter(c) && !number.isEmpty()) {
|
||||
result += convert(Integer.parseInt(number), c);
|
||||
number = "";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static long convert(int 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;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,270 @@
|
||||
package com.songoda.ultimatemoderation.utils.gui;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.utils.version.NMSUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class AbstractAnvilGUI {
|
||||
|
||||
private static Class<?> BlockPosition;
|
||||
private static Class<?> PacketPlayOutOpenWindow;
|
||||
private static Class<?> ContainerAnvil;
|
||||
private static Class<?> ChatMessage;
|
||||
private static Class<?> EntityHuman;
|
||||
private static boolean loadedClasses = false;
|
||||
private Player player;
|
||||
@SuppressWarnings("unused")
|
||||
private AnvilClickEventHandler handler;
|
||||
private Map<AnvilSlot, ItemStack> items = new HashMap<>();
|
||||
private OnClose onClose = null;
|
||||
private Inventory inv;
|
||||
private Listener listener;
|
||||
|
||||
private Sound closeSound = Sound.ENTITY_PLAYER_LEVELUP;
|
||||
|
||||
public AbstractAnvilGUI(final Player player, final AnvilClickEventHandler handler) {
|
||||
loadClasses();
|
||||
this.player = player;
|
||||
this.handler = handler;
|
||||
|
||||
this.listener = new Listener() {
|
||||
@EventHandler
|
||||
public void onInventoryClick(InventoryClickEvent event) {
|
||||
if (!(event.getWhoClicked() instanceof Player) || !event.getInventory().equals(inv)) return;
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
ItemStack item = event.getCurrentItem();
|
||||
int slot = event.getRawSlot();
|
||||
String name = "";
|
||||
|
||||
if (item != null) {
|
||||
if (item.hasItemMeta()) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
|
||||
if (meta.hasDisplayName()) {
|
||||
name = meta.getDisplayName();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AnvilClickEvent clickEvent = new AnvilClickEvent(AnvilSlot.bySlot(slot), name);
|
||||
|
||||
handler.onAnvilClick(clickEvent);
|
||||
|
||||
if (clickEvent.getWillClose()) {
|
||||
event.getWhoClicked().closeInventory();
|
||||
}
|
||||
|
||||
if (clickEvent.getWillDestroy()) {
|
||||
destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventoryClose(InventoryCloseEvent event) {
|
||||
if (!(event.getPlayer() instanceof Player)) return;
|
||||
Inventory inv = event.getInventory();
|
||||
player.setLevel(player.getLevel() - 1);
|
||||
if (!inv.equals(AbstractAnvilGUI.this.inv)) return;
|
||||
inv.clear();
|
||||
OnClose onClose = getOnClose();
|
||||
player.playSound(player.getLocation(), closeSound, 1F, 1F);
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(UltimateModeration.getInstance(), () -> {
|
||||
if (onClose != null) onClose.OnClose(player, inv);
|
||||
destroy();
|
||||
}, 1L);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
if (!event.getPlayer().equals(getPlayer())) return;
|
||||
player.setLevel(player.getLevel() - 1);
|
||||
destroy();
|
||||
}
|
||||
};
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(listener, UltimateModeration.getInstance());
|
||||
}
|
||||
|
||||
private void loadClasses() {
|
||||
if (loadedClasses) return;
|
||||
BlockPosition = NMSUtil.getNMSClass("BlockPosition");
|
||||
PacketPlayOutOpenWindow = NMSUtil.getNMSClass("PacketPlayOutOpenWindow");
|
||||
ContainerAnvil = NMSUtil.getNMSClass("ContainerAnvil");
|
||||
EntityHuman = NMSUtil.getNMSClass("EntityHuman");
|
||||
ChatMessage = NMSUtil.getNMSClass("ChatMessage");
|
||||
loadedClasses = true;
|
||||
}
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public void setSlot(AnvilSlot slot, ItemStack item) {
|
||||
items.put(slot, item);
|
||||
}
|
||||
|
||||
public void open() {
|
||||
player.setLevel(player.getLevel() + 1);
|
||||
|
||||
try {
|
||||
Object craftPlayer = NMSUtil.getCraftClass("entity.CraftPlayer").cast(player);
|
||||
Method getHandleMethod = craftPlayer.getClass().getMethod("getHandle", new Class<?>[0]);
|
||||
Object entityPlayer = getHandleMethod.invoke(craftPlayer, new Object[0]);
|
||||
|
||||
Object container;
|
||||
|
||||
if (NMSUtil.getVersionNumber() == 7) {
|
||||
container = ContainerAnvil.getConstructor(new Class[]{NMSUtil.getNMSClass("PlayerInventory"), NMSUtil.getNMSClass("World"), Integer.TYPE, Integer.TYPE, Integer.TYPE, EntityHuman}).newInstance(new Object[]{NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "inventory", false)), NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "world", false)), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0), entityPlayer});
|
||||
} else {
|
||||
container = ContainerAnvil.getConstructor(NMSUtil.getNMSClass("PlayerInventory"), NMSUtil.getNMSClass("World"), BlockPosition, EntityHuman).newInstance(NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "inventory", false)), NMSUtil.getFieldObject(entityPlayer, NMSUtil.getField(entityPlayer.getClass(), "world", false)), BlockPosition.getConstructor(int.class, int.class, int.class).newInstance(0, 0, 0), entityPlayer);
|
||||
}
|
||||
|
||||
NMSUtil.getField(NMSUtil.getNMSClass("Container"), "checkReachable", true).set(container, false);
|
||||
|
||||
Method getBukkitViewMethod = container.getClass().getMethod("getBukkitView", new Class<?>[0]);
|
||||
Object bukkitView = getBukkitViewMethod.invoke(container);
|
||||
Method getTopInventoryMethod = bukkitView.getClass().getMethod("getTopInventory", new Class<?>[0]);
|
||||
inv = (Inventory) getTopInventoryMethod.invoke(bukkitView);
|
||||
|
||||
for (AnvilSlot slot : items.keySet()) {
|
||||
inv.setItem(slot.getSlot(), items.get(slot));
|
||||
}
|
||||
|
||||
Method nextContainerCounterMethod = entityPlayer.getClass().getMethod("nextContainerCounter", new Class<?>[0]);
|
||||
int c = (int) nextContainerCounterMethod.invoke(entityPlayer);
|
||||
|
||||
Constructor<?> chatMessageConstructor = ChatMessage.getConstructor(String.class, Object[].class);
|
||||
Object packet;
|
||||
|
||||
if (NMSUtil.getVersionNumber() == 7) {
|
||||
packet = PacketPlayOutOpenWindow.getConstructor(new Class[]{Integer.TYPE, Integer.TYPE, String.class, Integer.TYPE, Boolean.TYPE, Integer.TYPE}).newInstance(new Object[]{Integer.valueOf(c), Integer.valueOf(8), "Repairing", Integer.valueOf(0), Boolean.valueOf(true), Integer.valueOf(0)});
|
||||
} else {
|
||||
packet = PacketPlayOutOpenWindow.getConstructor(int.class, String.class, NMSUtil.getNMSClass("IChatBaseComponent"), int.class).newInstance(c, "minecraft:anvil", chatMessageConstructor.newInstance("Repairing", new Object[]{}), 0);
|
||||
}
|
||||
|
||||
NMSUtil.sendPacket(player, packet);
|
||||
|
||||
Field activeContainerField = NMSUtil.getField(EntityHuman, "activeContainer", true);
|
||||
|
||||
if (activeContainerField != null) {
|
||||
activeContainerField.set(entityPlayer, container);
|
||||
NMSUtil.getField(NMSUtil.getNMSClass("Container"), "windowId", true).set(activeContainerField.get(entityPlayer), c);
|
||||
|
||||
Method addSlotListenerMethod = activeContainerField.get(entityPlayer).getClass().getMethod("addSlotListener", NMSUtil.getNMSClass("ICrafting"));
|
||||
addSlotListenerMethod.invoke(activeContainerField.get(entityPlayer), entityPlayer);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
onClose = null;
|
||||
player = null;
|
||||
handler = null;
|
||||
items = null;
|
||||
|
||||
HandlerList.unregisterAll(listener);
|
||||
|
||||
listener = null;
|
||||
}
|
||||
|
||||
private OnClose getOnClose() {
|
||||
return onClose;
|
||||
}
|
||||
|
||||
public void setOnClose(OnClose onClose) {
|
||||
this.onClose = onClose;
|
||||
}
|
||||
|
||||
public void setCloseSound(Sound sound) {
|
||||
closeSound = sound;
|
||||
}
|
||||
|
||||
public enum AnvilSlot {
|
||||
INPUT_LEFT(0),
|
||||
INPUT_RIGHT(1),
|
||||
OUTPUT(2);
|
||||
|
||||
private int slot;
|
||||
|
||||
private AnvilSlot(int slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
public static AnvilSlot bySlot(int slot) {
|
||||
for (AnvilSlot anvilSlot : values()) {
|
||||
if (anvilSlot.getSlot() == slot) {
|
||||
return anvilSlot;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getSlot() {
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
|
||||
public interface AnvilClickEventHandler {
|
||||
void onAnvilClick(AnvilClickEvent event);
|
||||
}
|
||||
|
||||
public class AnvilClickEvent {
|
||||
private AnvilSlot slot;
|
||||
|
||||
private String name;
|
||||
|
||||
private boolean close = true;
|
||||
private boolean destroy = true;
|
||||
|
||||
public AnvilClickEvent(AnvilSlot slot, String name) {
|
||||
this.slot = slot;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public AnvilSlot getSlot() {
|
||||
return slot;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean getWillClose() {
|
||||
return close;
|
||||
}
|
||||
|
||||
public void setWillClose(boolean close) {
|
||||
this.close = close;
|
||||
}
|
||||
|
||||
public boolean getWillDestroy() {
|
||||
return destroy;
|
||||
}
|
||||
|
||||
public void setWillDestroy(boolean destroy) {
|
||||
this.destroy = destroy;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,225 @@
|
||||
package com.songoda.ultimatemoderation.utils.gui;
|
||||
|
||||
import com.songoda.ultimatemoderation.UltimateModeration;
|
||||
import com.songoda.ultimatemoderation.utils.Methods;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class AbstractGUI implements Listener {
|
||||
|
||||
private static boolean listenersInitialized = false;
|
||||
protected final Player player;
|
||||
protected Inventory inventory = null;
|
||||
protected boolean cancelBottom = false;
|
||||
private Map<Range, Clickable> clickables = new HashMap<>();
|
||||
private List<OnClose> onCloses = new ArrayList<>();
|
||||
private Map<Range, Boolean> draggableRanges = new HashMap<>();
|
||||
|
||||
public AbstractGUI(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public static void initializeListeners(JavaPlugin plugin) {
|
||||
if (listenersInitialized) return;
|
||||
|
||||
Bukkit.getPluginManager().registerEvents(new Listener() {
|
||||
@EventHandler
|
||||
public void onClickGUI(InventoryClickEvent event) {
|
||||
Inventory inventory = event.getClickedInventory();
|
||||
if (inventory == null) return;
|
||||
AbstractGUI gui = getGUIFromInventory(inventory);
|
||||
Player player = (Player) event.getWhoClicked();
|
||||
|
||||
boolean bottom = false;
|
||||
|
||||
InventoryType type = event.getClickedInventory().getType();
|
||||
if (type != InventoryType.CHEST && type != InventoryType.PLAYER) return;
|
||||
|
||||
if (gui == null && event.getWhoClicked().getOpenInventory().getTopInventory() != null) {
|
||||
Inventory top = event.getWhoClicked().getOpenInventory().getTopInventory();
|
||||
gui = getGUIFromInventory(top);
|
||||
|
||||
if (gui != null && gui.cancelBottom) event.setCancelled(true);
|
||||
bottom = true;
|
||||
}
|
||||
|
||||
if (gui == null) return;
|
||||
|
||||
if (!bottom) event.setCancelled(true);
|
||||
|
||||
if (!gui.draggableRanges.isEmpty() && !bottom) {
|
||||
for (Map.Entry<Range, Boolean> entry : gui.draggableRanges.entrySet()) {
|
||||
Range range = entry.getKey();
|
||||
if (range.getMax() == range.getMin() && event.getSlot() == range.getMin()
|
||||
|| event.getSlot() >= range.getMin() && event.getSlot() <= range.getMax()) {
|
||||
event.setCancelled(!entry.getValue());
|
||||
if (!entry.getValue()) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<Range, Clickable> entries = new HashMap<>(gui.clickables);
|
||||
|
||||
for (Map.Entry<Range, Clickable> entry : entries.entrySet()) {
|
||||
Range range = entry.getKey();
|
||||
if (range.isBottom() && !bottom || !range.isBottom() && bottom || range.getClickType() != null && range.getClickType() != event.getClick())
|
||||
continue;
|
||||
if (event.getSlot() >= range.getMin() && event.getSlot() <= range.getMax()) {
|
||||
entry.getValue().Clickable(player, inventory, event.getCursor(), event.getSlot(), event.getClick());
|
||||
player.playSound(player.getLocation(), entry.getKey().getOnClickSound(), 1F, 1F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCloseGUI(InventoryCloseEvent event) {
|
||||
Inventory inventory = event.getInventory();
|
||||
AbstractGUI gui = getGUIFromInventory(inventory);
|
||||
|
||||
if (gui == null || gui.inventory == null) return;
|
||||
|
||||
for (OnClose onClose : gui.onCloses) {
|
||||
onClose.OnClose((Player) event.getPlayer(), inventory);
|
||||
}
|
||||
}
|
||||
|
||||
private AbstractGUI getGUIFromInventory(Inventory inventory) {
|
||||
if (inventory.getHolder() == null) return null;
|
||||
InventoryHolder holder = inventory.getHolder();
|
||||
if (!(holder instanceof GUIHolder)) return null;
|
||||
|
||||
return ((AbstractGUI.GUIHolder) holder).getGUI();
|
||||
}
|
||||
}, plugin);
|
||||
listenersInitialized = true;
|
||||
}
|
||||
|
||||
public void init(String title, int slots) {
|
||||
if (inventory == null
|
||||
|| inventory.getSize() != slots
|
||||
|| ChatColor.translateAlternateColorCodes('&', title) != inventory.getTitle()) {
|
||||
this.inventory = Bukkit.getServer().createInventory(new GUIHolder(), slots, Methods.formatText(title));
|
||||
if (this.clickables.size() == 0)
|
||||
registerClickables();
|
||||
if (this.onCloses.size() == 0)
|
||||
registerOnCloses();
|
||||
}
|
||||
constructGUI();
|
||||
initializeListeners(UltimateModeration.getInstance());
|
||||
player.openInventory(inventory);
|
||||
}
|
||||
|
||||
protected abstract void constructGUI();
|
||||
|
||||
protected void addDraggable(Range range, boolean option) {
|
||||
this.draggableRanges.put(range, option);
|
||||
}
|
||||
|
||||
protected void removeDraggable() {
|
||||
this.draggableRanges.clear();
|
||||
}
|
||||
|
||||
protected abstract void registerClickables();
|
||||
|
||||
protected abstract void registerOnCloses();
|
||||
|
||||
protected ItemStack createButton(int slot, Inventory inventory, ItemStack item, String name, String... lore) {
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
|
||||
if (lore != null && lore.length != 0) {
|
||||
List<String> newLore = new ArrayList<>();
|
||||
for (String line : lore) newLore.add(ChatColor.translateAlternateColorCodes('&', line));
|
||||
meta.setLore(newLore);
|
||||
}
|
||||
item.setItemMeta(meta);
|
||||
inventory.setItem(slot, item);
|
||||
return item;
|
||||
}
|
||||
|
||||
protected ItemStack createButton(int slot, ItemStack item, String name, ArrayList<String> lore) {
|
||||
return createButton(slot, inventory, item, name, lore.toArray(new String[0]));
|
||||
}
|
||||
|
||||
|
||||
protected ItemStack createButton(int slot, ItemStack item, String name, String... lore) {
|
||||
return createButton(slot, inventory, item, name, lore);
|
||||
}
|
||||
|
||||
protected ItemStack createButton(int slot, Inventory inventory, Material material, String name, String... lore) {
|
||||
return createButton(slot, inventory, new ItemStack(material), name, lore);
|
||||
}
|
||||
|
||||
protected ItemStack createButton(int slot, Material material, String name, String... lore) {
|
||||
return createButton(slot, inventory, new ItemStack(material), name, lore);
|
||||
}
|
||||
|
||||
protected ItemStack createButton(int slot, Material material, String name, ArrayList<String> lore) {
|
||||
return createButton(slot, material, name, lore.toArray(new String[0]));
|
||||
}
|
||||
|
||||
protected void registerClickable(int min, int max, ClickType clickType, boolean bottom, Clickable clickable) {
|
||||
clickables.put(new Range(min, max, clickType, bottom), clickable);
|
||||
}
|
||||
|
||||
protected void registerClickable(int min, int max, ClickType clickType, Clickable clickable) {
|
||||
registerClickable(min, max, clickType, false, clickable);
|
||||
}
|
||||
|
||||
protected void registerClickable(int slot, ClickType clickType, Clickable clickable) {
|
||||
registerClickable(slot, slot, clickType, false, clickable);
|
||||
}
|
||||
|
||||
protected void registerClickable(int min, int max, Clickable clickable) {
|
||||
registerClickable(min, max, null, false, clickable);
|
||||
}
|
||||
|
||||
protected void registerClickable(int slot, boolean bottom, Clickable clickable) {
|
||||
registerClickable(slot, slot, null, bottom, clickable);
|
||||
}
|
||||
|
||||
protected void registerClickable(int slot, Clickable clickable) {
|
||||
registerClickable(slot, slot, null, false, clickable);
|
||||
}
|
||||
|
||||
protected void resetClickables() {
|
||||
clickables.clear();
|
||||
}
|
||||
|
||||
protected void registerOnClose(OnClose onClose) {
|
||||
onCloses.add(onClose);
|
||||
}
|
||||
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public class GUIHolder implements InventoryHolder {
|
||||
|
||||
@Override
|
||||
public Inventory getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
public AbstractGUI getGUI() {
|
||||
return AbstractGUI.this;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package com.songoda.ultimatemoderation.utils.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface Clickable {
|
||||
|
||||
void Clickable(Player player, Inventory inventory, ItemStack cursor, int slot, ClickType type);
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package com.songoda.ultimatemoderation.utils.gui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
public interface OnClose {
|
||||
|
||||
void OnClose(Player player, Inventory inventory);
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.songoda.ultimatemoderation.utils.gui;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
|
||||
public class Range {
|
||||
|
||||
private int min;
|
||||
private int max;
|
||||
private ClickType clickType;
|
||||
private boolean bottom;
|
||||
private Sound onClickSound = Sound.UI_BUTTON_CLICK;
|
||||
|
||||
public Range(int min, int max, ClickType clickType, boolean bottom) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.clickType = clickType;
|
||||
this.bottom = bottom;
|
||||
}
|
||||
|
||||
public Range(int min, int max, Sound onClickSound, ClickType clickType, boolean bottom) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
this.onClickSound = onClickSound;
|
||||
this.clickType = clickType;
|
||||
this.bottom = bottom;
|
||||
}
|
||||
|
||||
public int getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public int getMax() {
|
||||
return max;
|
||||
}
|
||||
|
||||
public ClickType getClickType() {
|
||||
return clickType;
|
||||
}
|
||||
|
||||
public boolean isBottom() {
|
||||
return bottom;
|
||||
}
|
||||
|
||||
public Sound getOnClickSound() {
|
||||
return onClickSound;
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package com.songoda.ultimatemoderation.utils.version;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class NMSUtil {
|
||||
|
||||
public static String getVersion() {
|
||||
String name = Bukkit.getServer().getClass().getPackage().getName();
|
||||
return name.substring(name.lastIndexOf('.') + 1) + ".";
|
||||
}
|
||||
|
||||
public static int getVersionNumber() {
|
||||
String name = getVersion().substring(3);
|
||||
return Integer.valueOf(name.substring(0, name.length() - 4));
|
||||
}
|
||||
|
||||
public static int getVersionReleaseNumber() {
|
||||
String NMSVersion = getVersion();
|
||||
return Integer.valueOf(NMSVersion.substring(NMSVersion.length() - 2).replace(".", ""));
|
||||
}
|
||||
|
||||
public static Class<?> getNMSClass(String className) {
|
||||
try {
|
||||
String fullName = "net.minecraft.server." + getVersion() + className;
|
||||
Class<?> clazz = Class.forName(fullName);
|
||||
return clazz;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<?> getCraftClass(String className) throws ClassNotFoundException {
|
||||
try {
|
||||
String fullName = "org.bukkit.craftbukkit." + getVersion() + className;
|
||||
Class<?> clazz = Class.forName(fullName);
|
||||
return clazz;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Field getField(Class<?> clazz, String name, boolean declared) {
|
||||
try {
|
||||
Field field;
|
||||
|
||||
if (declared) {
|
||||
field = clazz.getDeclaredField(name);
|
||||
} else {
|
||||
field = clazz.getField(name);
|
||||
}
|
||||
|
||||
field.setAccessible(true);
|
||||
return field;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getFieldObject(Object object, Field field) {
|
||||
try {
|
||||
return field.get(object);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setField(Object object, String fieldName, Object fieldValue, boolean declared) {
|
||||
try {
|
||||
Field field;
|
||||
|
||||
if (declared) {
|
||||
field = object.getClass().getDeclaredField(fieldName);
|
||||
} else {
|
||||
field = object.getClass().getField(fieldName);
|
||||
}
|
||||
|
||||
field.setAccessible(true);
|
||||
field.set(object, fieldValue);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendPacket(Player player, Object packet) {
|
||||
try {
|
||||
Object handle = player.getClass().getMethod("getHandle").invoke(player);
|
||||
Object playerConnection = handle.getClass().getField("playerConnection").get(handle);
|
||||
playerConnection.getClass().getMethod("sendPacket", getNMSClass("Packet")).invoke(playerConnection, packet);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -33,4 +33,98 @@ command.commandspy.toggleOff = "&7Command spy off";
|
||||
#Event Messages
|
||||
|
||||
event.general.nopermission = "&cYou do not have permission to do that."
|
||||
event.command.blocked = "&cYou cannot use that command..."
|
||||
event.command.blocked = "&cYou cannot use that command..."
|
||||
|
||||
event.punish.reason = " &7for &6%reason%"
|
||||
event.punish.theirduration = "&7. &7Their punishment will be lifted in &6%duration%"
|
||||
event.punish.yourduration = "&7. &7Your punishment will be lifted in &6%duration%"
|
||||
|
||||
event.ban.success = "&7You have banned &6%player%"
|
||||
event.unban.success = "&7You have unbanned &6%player%"
|
||||
event.ban.message = "&7You have been banned"
|
||||
event.ban.already = "&cThis user is already banned."
|
||||
|
||||
event.mute.success = "&7You have muted &6%player%"
|
||||
event.unmute.success = "&7You have unmuted &6%player%"
|
||||
event.mute.message = "&7You have been muted"
|
||||
event.mute.already = "&cThis user is already muted."
|
||||
|
||||
event.kick.success = "&7You have kicked &6%player%"
|
||||
event.kick.message = "&7You have been kicked"
|
||||
|
||||
event.warning.success = "&7You have warned &6%player%"
|
||||
event.warning.message = "&7You have been warned"
|
||||
|
||||
#GUI Messages
|
||||
|
||||
gui.general.previous = "&6Previous Page"
|
||||
gui.general.next = "&6Next Page"
|
||||
gui.general.back = "&6Back"
|
||||
gui.general.none = "None"
|
||||
gui.general.permanent = "Permanent"
|
||||
gui.general.reason = "Reason"
|
||||
gui.general.templatename = "Template Name"
|
||||
|
||||
gui.players.title = "&8Players"
|
||||
gui.players.click = "&6Click to view player."
|
||||
gui.players.noreports = "&7No reports currently opened about this player."
|
||||
gui.players.nowarnings = "&7No warnings recorded."
|
||||
gui.players.warnings = "&7This player has received &6%amount% &7warnings."
|
||||
gui.players.warningsone = "&7This player has received &61 &7warning."
|
||||
gui.players.button.templatemanager = "&6&lTemplate Manager"
|
||||
|
||||
gui.templateselector.title = "&8Select a Template"
|
||||
gui.templateselector.click = "&7Click to select this template."
|
||||
|
||||
gui.templatemanager.title = "&8Templates"
|
||||
gui.templatemanager.create = "&6&lCreate Template"
|
||||
gui.templatemanager.leftclick = "&7Left-Click to"
|
||||
gui.templatemanager.rightclick = "&7Right-Click to destroy."
|
||||
|
||||
gui.punishments.title = "&8%toModerate% > Punish"
|
||||
gui.punishments.reason = "&6Reason"
|
||||
gui.punishments.duration = "&6Initial Duration"
|
||||
gui.punishments.punisher = "&6Punisher"
|
||||
gui.punishments.remaining = "&6Time Remaining"
|
||||
gui.punishments.click = "&7Click to expire this punishment."
|
||||
gui.punishments.activity.both = "Both"
|
||||
gui.punishments.activity.active = "Active"
|
||||
gui.punishments.activity.expired = "Expired"
|
||||
|
||||
gui.punishmenttypes.all = "All"
|
||||
gui.punishmenttypes.ban = "Ban"
|
||||
gui.punishmenttypes.kick = "Kick"
|
||||
gui.punishmenttypes.warning = "Warning"
|
||||
gui.punishmenttypes.mute = "Mute"
|
||||
|
||||
gui.punish.title = "&8%toModerate% > Punish"
|
||||
gui.punish.title.template = "&8Create a Template"
|
||||
gui.punish.submit = "&a&lSubmit"
|
||||
gui.punish.type.punishment = "&6&lPunishment"
|
||||
gui.punish.type.punishment.click = "&7Click to switch type."
|
||||
gui.punish.type.template = "&6&lTemplate"
|
||||
gui.punish.type.template.current = "&7Currently selected: &6%template%&7."
|
||||
gui.punish.type.template.none = "&7No templates to choose from."
|
||||
gui.punish.type.template.click = "&7Click to choose a template."
|
||||
gui.punish.type.name = "&6&lName"
|
||||
gui.punish.type.name.current = "&7Currently set to: &6%name%&7."
|
||||
gui.punish.type.name.current.click = "&7Click to change name."
|
||||
gui.punish.type.duration = "&c&lDuration"
|
||||
gui.punish.type.duration.leftclick = "&7Left-Click to set a duration."
|
||||
gui.punish.type.duration.rightclick = "&7Right-Click Click to set to forever."
|
||||
gui.punish.type.duration.current = "&7Currently set to:"
|
||||
gui.punish.type.reason = "&b&lReason"
|
||||
gui.punish.type.reason.click = "&7Click to set a reason."
|
||||
gui.punish.type.reason.current = "&7Currently set to:"
|
||||
gui.punish.template.create = "&7Click to create a template"
|
||||
gui.punish.template.create2 = "&7from this punishment."
|
||||
gui.punish.template.leftclick = "&7Left-Click to update the"
|
||||
gui.punish.template.leftclick2 = "&7template &6%template%&7."
|
||||
gui.punish.template.rightclick = "&7Right-Click to save as a new Template."
|
||||
|
||||
gui.player.title = "&8Players > %toModerate%"
|
||||
gui.player.punish = "&6&lPunish"
|
||||
gui.player.moderate = "&b&lModerate"
|
||||
gui.player.punishments = "&c&lPunishments"
|
||||
|
||||
gui.moderate.title = "&8%toModerate% > Moderate"
|
@ -55,4 +55,32 @@ commands:
|
||||
CommandSpy:
|
||||
description: CommandSpy
|
||||
default: false
|
||||
usage: /commandspy
|
||||
usage: /commandspy
|
||||
Ban:
|
||||
description: Ban
|
||||
default: false
|
||||
usage: /ban
|
||||
Unban:
|
||||
description: Unban
|
||||
default: false
|
||||
usage: /unban
|
||||
Kick:
|
||||
description: Kick
|
||||
default: false
|
||||
usage: /kick
|
||||
Mute:
|
||||
description: Mute
|
||||
default: false
|
||||
usage: /mute
|
||||
Unmute:
|
||||
description: Unmute
|
||||
default: false
|
||||
usage: /unmute
|
||||
Warn:
|
||||
description: Warn
|
||||
default: false
|
||||
usage: /warn
|
||||
RunTemplate:
|
||||
description: RunTemplate
|
||||
defaullt: false
|
||||
usage: /runtemplate
|
Loading…
Reference in New Issue
Block a user