From 322d9b371faccc6e1e600df1873f4119ef23878c Mon Sep 17 00:00:00 2001 From: Brianna O'Keefe Date: Thu, 28 Feb 2019 18:00:22 -0500 Subject: [PATCH] Added CommandSpy --- .../command/CommandManager.java | 2 + .../command/commands/CommandCommandSpy.java | 57 +++++++++++++++++++ .../listeners/CommandListener.java | 15 ++++- src/main/resources/en_US.lang | 9 ++- src/main/resources/plugin.yml | 6 +- 5 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/songoda/ultimatemoderation/command/commands/CommandCommandSpy.java diff --git a/src/main/java/com/songoda/ultimatemoderation/command/CommandManager.java b/src/main/java/com/songoda/ultimatemoderation/command/CommandManager.java index d509e94..f4473c6 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/CommandManager.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/CommandManager.java @@ -35,6 +35,7 @@ public class CommandManager implements CommandExecutor { instance.getCommand("Freeze").setExecutor(this); instance.getCommand("Revive").setExecutor(this); instance.getCommand("Spy").setExecutor(this); + instance.getCommand("CommandSpy").setExecutor(this); AbstractCommand commandUltimateModeration = addCommand(new CommandUltimateModeration()); addCommand(new CommandClearChat()); @@ -46,6 +47,7 @@ public class CommandManager implements CommandExecutor { addCommand(new CommandFreeze()); addCommand(new CommandRevive()); addCommand(new CommandSpy()); + addCommand(new CommandCommandSpy()); addCommand(new CommandSettings(commandUltimateModeration)); addCommand(new CommandReload(commandUltimateModeration)); diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandCommandSpy.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandCommandSpy.java new file mode 100644 index 0000000..b7cf1e6 --- /dev/null +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandCommandSpy.java @@ -0,0 +1,57 @@ +package com.songoda.ultimatemoderation.command.commands; + +import com.songoda.ultimatemoderation.UltimateModeration; +import com.songoda.ultimatemoderation.command.AbstractCommand; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class CommandCommandSpy extends AbstractCommand { + + private static List inSpy = new ArrayList<>(); + + public CommandCommandSpy() { + super(true, false,"CommandSpy"); + } + + @Override + protected ReturnType runCommand(UltimateModeration instance, CommandSender sender, String... args) { + Player player = ((Player)sender); + + if (inSpy.contains(player.getUniqueId())) { + inSpy.remove(player.getUniqueId()); + player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.commandspy.toggleOn")); + } else { + inSpy.add(player.getUniqueId()); + player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.commandspy.toggleOff")); + } + return ReturnType.SUCCESS; + } + + @Override + protected List onTab(UltimateModeration instance, CommandSender sender, String... args) { + return null; + } + + public static boolean isSpying(Player player) { + return !inSpy.contains(player.getUniqueId()); + } + + @Override + public String getPermissionNode() { + return "Um.commandspy"; + } + + @Override + public String getSyntax() { + return "/Commandspy"; + } + + @Override + public String getDescription() { + return "Allows you to see inside of a players enderchest."; + } +} diff --git a/src/main/java/com/songoda/ultimatemoderation/listeners/CommandListener.java b/src/main/java/com/songoda/ultimatemoderation/listeners/CommandListener.java index 4d2746f..d282096 100644 --- a/src/main/java/com/songoda/ultimatemoderation/listeners/CommandListener.java +++ b/src/main/java/com/songoda/ultimatemoderation/listeners/CommandListener.java @@ -1,6 +1,7 @@ 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; @@ -25,14 +26,24 @@ public class CommandListener implements Listener { public void onCommand(PlayerCommandPreprocessEvent event) { Player player = event.getPlayer(); + String command = event.getMessage(); + List blockedCommands = SettingsManager.Setting.BLOCKED_COMMANDS.getStringList(); for (String cmd : blockedCommands) { - if (event.getMessage().toUpperCase().startsWith("/" + cmd.toUpperCase()) + if (command.toUpperCase().startsWith("/" + cmd.toUpperCase()) + && (command.toUpperCase().endsWith(cmd.toUpperCase()) || (command.contains(" ") && command.split(" ")[0].toUpperCase().endsWith(cmd.toUpperCase()))) && !player.hasPermission("um.commandblock.bypass")) { event.setCancelled(true); event.setMessage("-"); - player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.blocked")); + player.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("event.command.blocked")); + } + } + + if (!player.hasPermission("um.commandspy.immune")) { + for (Player pl : Bukkit.getOnlinePlayers()) { + if (pl.hasPermission("um.commandspy") && CommandCommandSpy.isSpying(pl)) + pl.sendMessage(instance.getReferences().getPrefix() + instance.getLocale().getMessage("command.commandspy.deny", player.getName(), command)); } } } diff --git a/src/main/resources/en_US.lang b/src/main/resources/en_US.lang index bf8dbb5..4625a7e 100644 --- a/src/main/resources/en_US.lang +++ b/src/main/resources/en_US.lang @@ -26,4 +26,11 @@ command.revive.revived = "&7You have been revived." command.spy.returned = "&7You were returned to your previous location" command.spy.success = "&7You are now spying on &6%player%&7. Use the command &6/spy &7to return to your previous location&7" -command.blocked = "&cYou cannot use that command..." \ No newline at end of file +command.commandspy.deny = "&6%player%&7: %command%&7." +command.commandspy.toggleOn = "&7Command spy on"; +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..." \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fd8b38b..e0d92c9 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -51,4 +51,8 @@ commands: Spy: description: Spy default: false - usage: /spy \ No newline at end of file + usage: /spy + CommandSpy: + description: CommandSpy + default: false + usage: /commandspy \ No newline at end of file