From d67cca7f515e4de6f01941bb0b9b3b4281af9713 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 12 Jul 2014 15:24:38 +0100 Subject: Switch sudo to command dispatch, this will allow vanilla commands to be executed. --- .../earth2me/essentials/commands/Commandsudo.java | 28 +++++++++++----------- Essentials/src/messages.properties | 3 +-- Essentials/src/messages_en.properties | 3 +-- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java b/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java index 823ee17f4..9c9bb2df9 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java @@ -4,10 +4,8 @@ import com.earth2me.essentials.CommandSource; import static com.earth2me.essentials.I18n.tl; import com.earth2me.essentials.User; import java.util.Locale; -import java.util.logging.Level; import java.util.logging.Logger; import org.bukkit.Server; -import org.bukkit.command.PluginCommand; public class Commandsudo extends EssentialsCommand @@ -36,11 +34,10 @@ public class Commandsudo extends EssentialsCommand user.getBase().chat(getFinalArg(args, 1).substring(2)); return; } - final String command = args[1]; - final String[] arguments = new String[args.length - 2]; + final String[] arguments = new String[args.length - 1]; if (arguments.length > 0) { - System.arraycopy(args, 2, arguments, 0, args.length - 2); + System.arraycopy(args, 1, arguments, 0, args.length - 1); } if (user.isAuthorized("essentials.sudo.exempt") && sender.isPlayer()) @@ -48,25 +45,28 @@ public class Commandsudo extends EssentialsCommand throw new Exception(tl("sudoExempt")); } - sender.sendMessage(tl("sudoRun", user.getDisplayName(), command, getFinalArg(arguments, 0))); + final String command = getFinalArg(arguments, 0); - final PluginCommand execCommand = ess.getServer().getPluginCommand(command); - if (execCommand != null) + sender.sendMessage(tl("sudoRun", user.getDisplayName(), command, "")); + + if (command != null && command.length() > 0) { class SudoCommandTask implements Runnable { @Override public void run() { - LOGGER.log(Level.INFO, String.format("[Sudo] %s issued server command: /%s %s", user.getName(), command, getFinalArg(arguments, 0))); - execCommand.execute(user.getBase(), command, arguments); + try + { + ess.getServer().dispatchCommand(user.getBase(), command); + } + catch (Exception e) + { + sender.sendMessage(tl("errorCallingCommand", command)); + } } } ess.scheduleSyncDelayedTask(new SudoCommandTask()); } - else - { - sender.sendMessage(tl("errorCallingCommand", command)); - } } } diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index c2a8abb9a..14aaea799 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -404,7 +404,7 @@ soloMob=\u00a74That mob likes to be alone. spawnSet=\u00a76Spawn location set for group\u00a7c {0}\u00a76. spawned=spawned sudoExempt=\u00a74You cannot sudo this user. -sudoRun=\u00a76Forcing\u00a7c {0} \u00a76to run\:\u00a7r /{1} {2} +sudoRun=\u00a76Forcing\u00a7c {0} \u00a76to run\:\u00a7r /{1} suicideMessage=\u00a76Goodbye cruel world... suicideSuccess=\u00a76Player \u00a7c{0} \u00a76took their own life. survival=survival @@ -548,7 +548,6 @@ mailTooLong=\u00a74Mail message too long. Try to keep it below 1000 characters. mailDelay=Too many mails have been sent within the last minute. Maximum\: {0} seenAccounts=\u00a76Player has also been known as\:\u00a7c {0} unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item. - itemsConverted=\u00a76Converted all items into blocks. itemsNotConverted=\u00a74You have no items that can be converted into blocks. mailSentTo=\u00a7c{0}\u00a76 has been sent the following mail: diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index c2a8abb9a..14aaea799 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -404,7 +404,7 @@ soloMob=\u00a74That mob likes to be alone. spawnSet=\u00a76Spawn location set for group\u00a7c {0}\u00a76. spawned=spawned sudoExempt=\u00a74You cannot sudo this user. -sudoRun=\u00a76Forcing\u00a7c {0} \u00a76to run\:\u00a7r /{1} {2} +sudoRun=\u00a76Forcing\u00a7c {0} \u00a76to run\:\u00a7r /{1} suicideMessage=\u00a76Goodbye cruel world... suicideSuccess=\u00a76Player \u00a7c{0} \u00a76took their own life. survival=survival @@ -548,7 +548,6 @@ mailTooLong=\u00a74Mail message too long. Try to keep it below 1000 characters. mailDelay=Too many mails have been sent within the last minute. Maximum\: {0} seenAccounts=\u00a76Player has also been known as\:\u00a7c {0} unableToSpawnItem=\u00a74Cannot spawn \u00a7c{0}\u00a74, this is not a spawnable item. - itemsConverted=\u00a76Converted all items into blocks. itemsNotConverted=\u00a74You have no items that can be converted into blocks. mailSentTo=\u00a7c{0}\u00a76 has been sent the following mail: -- cgit v1.2.3