From 77802bd3e57a87732beb91c73bef7a223bfeced2 Mon Sep 17 00:00:00 2001 From: asofold Date: Mon, 3 Sep 2012 05:45:53 +0200 Subject: [PATCH] Add delayable command "ncp delay", for arbitrary commands. --- plugin.yml | 9 +++--- .../nocheatplus/command/CommandHandler.java | 3 +- .../nocheatplus/command/DelayCommand.java | 32 +++++++++++++++++++ .../nocheatplus/players/Permissions.java | 4 +-- 4 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 src/fr/neatmonster/nocheatplus/command/DelayCommand.java diff --git a/plugin.yml b/plugin.yml index 4505e777..c4335c99 100644 --- a/plugin.yml +++ b/plugin.yml @@ -14,12 +14,13 @@ commands: description: NoCheatPlus command(s). # permission: nocheatplus.admin.reload usage: | - / info : Display the violations of a player + / info (player): Display the violations of a player / reload: reload NoCheatPlus configuration Auxiliary: - / ban [delay=] [...]: ban player - / kick [delay=] [...]: kick player - / tell [delay=] : tell a message + / ban [delay=(ticks)] (player) [(reason)...]: ban player + / kick [delay=(ticks)] (player) [(reason)...]: kick player + / tell [delay=(ticks)] (player) (message)...: tell a message + / delay [delay=(ticks)] (command)...: delay a command permissions: nocheatplus: diff --git a/src/fr/neatmonster/nocheatplus/command/CommandHandler.java b/src/fr/neatmonster/nocheatplus/command/CommandHandler.java index c5714935..b6e869f8 100644 --- a/src/fr/neatmonster/nocheatplus/command/CommandHandler.java +++ b/src/fr/neatmonster/nocheatplus/command/CommandHandler.java @@ -81,7 +81,8 @@ public class CommandHandler implements CommandExecutor { new InfoCommand(plugin), new KickCommand(plugin), new ReloadCommand(plugin), - new TellCommand(plugin) + new TellCommand(plugin), + new DelayCommand(plugin), }){ commands.put(cmd.label, cmd); } diff --git a/src/fr/neatmonster/nocheatplus/command/DelayCommand.java b/src/fr/neatmonster/nocheatplus/command/DelayCommand.java new file mode 100644 index 00000000..dc0a0a6d --- /dev/null +++ b/src/fr/neatmonster/nocheatplus/command/DelayCommand.java @@ -0,0 +1,32 @@ +package fr.neatmonster.nocheatplus.command; + +import org.bukkit.Bukkit; +import org.bukkit.Server; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import fr.neatmonster.nocheatplus.NoCheatPlus; +import fr.neatmonster.nocheatplus.players.Permissions; + +public class DelayCommand extends DelayableCommand { + + public DelayCommand(NoCheatPlus plugin){ + super(plugin, "delay", Permissions.ADMINISTRATION_DELAY); + } + + @Override + public boolean execute(CommandSender sender, Command command, String label, + String[] alteredArgs, long delay) { + if (alteredArgs.length < 2) return false; + final String cmd = join(alteredArgs, 1); + schedule(new Runnable() { + @Override + public void run() { + Server server = Bukkit.getServer(); + server.dispatchCommand(server.getConsoleSender(), cmd); + } + }, delay); + return true; + } + +} diff --git a/src/fr/neatmonster/nocheatplus/players/Permissions.java b/src/fr/neatmonster/nocheatplus/players/Permissions.java index a1ed978d..1f698398 100644 --- a/src/fr/neatmonster/nocheatplus/players/Permissions.java +++ b/src/fr/neatmonster/nocheatplus/players/Permissions.java @@ -24,7 +24,8 @@ public class Permissions { */ private static final String ADMINISTRATION = NOCHEATPLUS + ".admin"; - public static final String ADMINISTRATION_BAN = ADMINISTRATION + ".ban"; + public static final String ADMINISTRATION_BAN = ADMINISTRATION + ".ban"; + public static final String ADMINISTRATION_DELAY = ADMINISTRATION + ".delay"; public static final String ADMINISTRATION_INFO = ADMINISTRATION + ".info"; public static final String ADMINISTRATION_KICK = ADMINISTRATION + ".kick"; public static final String ADMINISTRATION_NOTIFY = ADMINISTRATION + ".notify"; @@ -176,5 +177,4 @@ public class Permissions { public static final String ZOMBE_FLY = ZOMBE + ".fly"; public static final String ZOMBE_NOCLIP = ZOMBE + ".noclip"; public static final String ZOMBE_CHEAT = ZOMBE + ".cheat"; - }