Skip to content

Commit a131527

Browse files
committed
Switch sudo to command dispatch, this will allow vanilla commands to be executed.
1 parent 0b925e6 commit a131527

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

Essentials/src/com/earth2me/essentials/commands/Commandsudo.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
import static com.earth2me.essentials.I18n.tl;
55
import com.earth2me.essentials.User;
66
import java.util.Locale;
7-
import java.util.logging.Level;
87
import java.util.logging.Logger;
98
import org.bukkit.Server;
10-
import org.bukkit.command.PluginCommand;
119

1210

1311
public class Commandsudo extends EssentialsCommand
@@ -36,37 +34,39 @@ public void run(final Server server, final CommandSource sender, final String co
3634
user.getBase().chat(getFinalArg(args, 1).substring(2));
3735
return;
3836
}
39-
final String command = args[1];
40-
final String[] arguments = new String[args.length - 2];
37+
final String[] arguments = new String[args.length - 1];
4138
if (arguments.length > 0)
4239
{
43-
System.arraycopy(args, 2, arguments, 0, args.length - 2);
40+
System.arraycopy(args, 1, arguments, 0, args.length - 1);
4441
}
4542

4643
if (user.isAuthorized("essentials.sudo.exempt") && sender.isPlayer())
4744
{
4845
throw new Exception(tl("sudoExempt"));
4946
}
5047

51-
sender.sendMessage(tl("sudoRun", user.getDisplayName(), command, getFinalArg(arguments, 0)));
48+
final String command = getFinalArg(arguments, 0);
5249

53-
final PluginCommand execCommand = ess.getServer().getPluginCommand(command);
54-
if (execCommand != null)
50+
sender.sendMessage(tl("sudoRun", user.getDisplayName(), command, ""));
51+
52+
if (command != null && command.length() > 0)
5553
{
5654
class SudoCommandTask implements Runnable
5755
{
5856
@Override
5957
public void run()
6058
{
61-
LOGGER.log(Level.INFO, String.format("[Sudo] %s issued server command: /%s %s", user.getName(), command, getFinalArg(arguments, 0)));
62-
execCommand.execute(user.getBase(), command, arguments);
59+
try
60+
{
61+
ess.getServer().dispatchCommand(user.getBase(), command);
62+
}
63+
catch (Exception e)
64+
{
65+
sender.sendMessage(tl("errorCallingCommand", command));
66+
}
6367
}
6468
}
6569
ess.scheduleSyncDelayedTask(new SudoCommandTask());
6670
}
67-
else
68-
{
69-
sender.sendMessage(tl("errorCallingCommand", command));
70-
}
7171
}
7272
}

Essentials/src/messages.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ soloMob=\u00a74That mob likes to be alone.
404404
spawnSet=\u00a76Spawn location set for group\u00a7c {0}\u00a76.
405405
spawned=spawned
406406
sudoExempt=\u00a74You cannot sudo this user.
407-
sudoRun=\u00a76Forcing\u00a7c {0} \u00a76to run\:\u00a7r /{1} {2}
407+
sudoRun=\u00a76Forcing\u00a7c {0} \u00a76to run\:\u00a7r /{1}
408408
suicideMessage=\u00a76Goodbye cruel world...
409409
suicideSuccess=\u00a76Player \u00a7c{0} \u00a76took their own life.
410410
survival=survival
@@ -548,7 +548,6 @@ mailTooLong=\u00a74Mail message too long. Try to keep it below 1000 characters.
548548
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
549549
seenAccounts=\u00a76Player has also been known as\:\u00a7c {0}
550550
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.
551-
552551
itemsConverted=\u00a76Converted all items into blocks.
553552
itemsNotConverted=\u00a74You have no items that can be converted into blocks.
554553
mailSentTo=\u00a7c{0}\u00a76 has been sent the following mail:

Essentials/src/messages_en.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ soloMob=\u00a74That mob likes to be alone.
404404
spawnSet=\u00a76Spawn location set for group\u00a7c {0}\u00a76.
405405
spawned=spawned
406406
sudoExempt=\u00a74You cannot sudo this user.
407-
sudoRun=\u00a76Forcing\u00a7c {0} \u00a76to run\:\u00a7r /{1} {2}
407+
sudoRun=\u00a76Forcing\u00a7c {0} \u00a76to run\:\u00a7r /{1}
408408
suicideMessage=\u00a76Goodbye cruel world...
409409
suicideSuccess=\u00a76Player \u00a7c{0} \u00a76took their own life.
410410
survival=survival
@@ -548,7 +548,6 @@ mailTooLong=\u00a74Mail message too long. Try to keep it below 1000 characters.
548548
mailDelay=Too many mails have been sent within the last minute. Maximum\: {0}
549549
seenAccounts=\u00a76Player has also been known as\:\u00a7c {0}
550550
unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item.
551-
552551
itemsConverted=\u00a76Converted all items into blocks.
553552
itemsNotConverted=\u00a74You have no items that can be converted into blocks.
554553
mailSentTo=\u00a7c{0}\u00a76 has been sent the following mail:

0 commit comments

Comments
 (0)