Skip to content

Commit

Permalink
Switch sudo to command dispatch, this will allow vanilla commands to …
Browse files Browse the repository at this point in the history
…be executed.
  • Loading branch information
khobbits committed Jul 12, 2014
1 parent 727c3b8 commit d67cca7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
28 changes: 14 additions & 14 deletions Essentials/src/com/earth2me/essentials/commands/Commandsudo.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
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
Expand Down Expand Up @@ -36,37 +34,39 @@ public void run(final Server server, final CommandSource sender, final String co
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())
{
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));
}
}
}
3 changes: 1 addition & 2 deletions Essentials/src/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions Essentials/src/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit d67cca7

Please sign in to comment.