Add delayable command "ncp delay", for arbitrary commands.

This commit is contained in:
asofold 2012-09-03 05:45:53 +02:00
parent a4780bf079
commit 77802bd3e5
4 changed files with 41 additions and 7 deletions

View File

@ -14,12 +14,13 @@ commands:
description: NoCheatPlus command(s).
# permission: nocheatplus.admin.reload
usage: |
/<command> info <player>: Display the violations of a player
/<command> info (player): Display the violations of a player
/<command> reload: reload NoCheatPlus configuration
Auxiliary:
/<command> ban [delay=<ticks>] <player> [<reason>...]: ban player
/<command> kick [delay=<ticks>] <player> [<reason>...]: kick player
/<command> tell [delay=<ticks>] <player> <message>: tell a message
/<command> ban [delay=(ticks)] (player) [(reason)...]: ban player
/<command> kick [delay=(ticks)] (player) [(reason)...]: kick player
/<command> tell [delay=(ticks)] (player) (message)...: tell a message
/<command> delay [delay=(ticks)] (command)...: delay a command
permissions:
nocheatplus:

View File

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

View File

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

View File

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