Added CommandSpy

This commit is contained in:
Brianna O'Keefe 2019-02-28 18:00:22 -05:00
parent 89212cdaba
commit 322d9b371f
5 changed files with 85 additions and 4 deletions

View File

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

View File

@ -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<UUID> 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<String> 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.";
}
}

View File

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

View File

@ -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..."
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..."

View File

@ -51,4 +51,8 @@ commands:
Spy:
description: Spy
default: false
usage: /spy
usage: /spy
CommandSpy:
description: CommandSpy
default: false
usage: /commandspy