Make sudo a loop command. Adds #23.

This commit is contained in:
drtshock 2015-05-03 15:08:32 -05:00
parent 4169996e7a
commit 20f79f117f
2 changed files with 24 additions and 17 deletions

View File

@ -1,49 +1,56 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import net.ess3.api.MaxMoneyException;
import org.bukkit.Server;
import java.util.Locale;
import java.util.logging.Logger;
import static com.earth2me.essentials.I18n.tl;
public class Commandsudo extends EssentialsCommand {
public class Commandsudo extends EssentialsLoopCommand {
public Commandsudo() {
super("sudo");
}
private static final Logger LOGGER = Logger.getLogger("Essentials");
@Override
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
if (args.length < 2) {
throw new NotEnoughArgumentsException();
}
final User user = getPlayer(server, sender, args, 0);
if (args[1].toLowerCase(Locale.ENGLISH).startsWith("c:")) {
if (user.isAuthorized("essentials.sudo.exempt") && sender.isPlayer()) {
throw new Exception(tl("sudoExempt"));
}
user.getBase().chat(getFinalArg(args, 1).substring(2));
return;
}
final String[] arguments = new String[args.length - 1];
if (arguments.length > 0) {
System.arraycopy(args, 1, arguments, 0, args.length - 1);
}
if (user.isAuthorized("essentials.sudo.exempt") && sender.isPlayer()) {
throw new Exception(tl("sudoExempt"));
final String command = getFinalArg(arguments, 0);
boolean multiple = sender.getSender().hasPermission("essentials.sudo.multiple");
sender.sendMessage(tl("sudoRun", args[0], command, ""));
loopOnlinePlayers(server, sender, multiple, multiple, args[0], new String[]{command});
}
@Override
protected void updatePlayer(final Server server, final CommandSource sender, final User user, String[] args) throws NotEnoughArgumentsException, PlayerExemptException, ChargeException, MaxMoneyException {
if (user.getName().equals(sender.getSender().getName())) {
return; // Silently don't do anything.
}
final String command = getFinalArg(arguments, 0);
if (user.isAuthorized("essentials.sudo.exempt") && sender.isPlayer()) {
sender.sendMessage(tl("sudoExempt", user.getName()));
return;
}
sender.sendMessage(tl("sudoRun", user.getDisplayName(), command, ""));
if (args[0].toLowerCase(Locale.ENGLISH).startsWith("c:")) {
user.getBase().chat(getFinalArg(args, 0).substring(2));
return;
}
final String command = getFinalArg(args, 0);
if (command != null && command.length() > 0) {
class SudoCommandTask implements Runnable {
@Override

View File

@ -403,7 +403,7 @@ socialSpy=\u00a76SocialSpy for \u00a7c{0}\u00a76\: \u00a7c{1}
soloMob=\u00a74That mob likes to be alone.
spawnSet=\u00a76Spawn location set for group\u00a7c {0}\u00a76.
spawned=spawned
sudoExempt=\u00a74You cannot sudo this user.
sudoExempt=\u00a74You cannot sudo \u00a7c{0}.
sudoRun=\u00a76Forcing\u00a7c {0} \u00a76to run\:\u00a7r /{1}
suicideMessage=\u00a76Goodbye cruel world...
suicideSuccess=\u00a76Player \u00a7c{0} \u00a76took their own life.