|
4 | 4 | import static com.earth2me.essentials.I18n.tl; |
5 | 5 | import com.earth2me.essentials.User; |
6 | 6 | import java.util.Locale; |
7 | | -import java.util.logging.Level; |
8 | 7 | import java.util.logging.Logger; |
9 | 8 | import org.bukkit.Server; |
10 | | -import org.bukkit.command.PluginCommand; |
11 | 9 |
|
12 | 10 |
|
13 | 11 | public class Commandsudo extends EssentialsCommand |
@@ -36,37 +34,39 @@ public void run(final Server server, final CommandSource sender, final String co |
36 | 34 | user.getBase().chat(getFinalArg(args, 1).substring(2)); |
37 | 35 | return; |
38 | 36 | } |
39 | | - final String command = args[1]; |
40 | | - final String[] arguments = new String[args.length - 2]; |
| 37 | + final String[] arguments = new String[args.length - 1]; |
41 | 38 | if (arguments.length > 0) |
42 | 39 | { |
43 | | - System.arraycopy(args, 2, arguments, 0, args.length - 2); |
| 40 | + System.arraycopy(args, 1, arguments, 0, args.length - 1); |
44 | 41 | } |
45 | 42 |
|
46 | 43 | if (user.isAuthorized("essentials.sudo.exempt") && sender.isPlayer()) |
47 | 44 | { |
48 | 45 | throw new Exception(tl("sudoExempt")); |
49 | 46 | } |
50 | 47 |
|
51 | | - sender.sendMessage(tl("sudoRun", user.getDisplayName(), command, getFinalArg(arguments, 0))); |
| 48 | + final String command = getFinalArg(arguments, 0); |
52 | 49 |
|
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) |
55 | 53 | { |
56 | 54 | class SudoCommandTask implements Runnable |
57 | 55 | { |
58 | 56 | @Override |
59 | 57 | public void run() |
60 | 58 | { |
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 | + } |
63 | 67 | } |
64 | 68 | } |
65 | 69 | ess.scheduleSyncDelayedTask(new SudoCommandTask()); |
66 | 70 | } |
67 | | - else |
68 | | - { |
69 | | - sender.sendMessage(tl("errorCallingCommand", command)); |
70 | | - } |
71 | 71 | } |
72 | 72 | } |
0 commit comments