TF-EssentialsX/Essentials/src/com/earth2me/essentials/commands/Commandsudo.java

73 lines
2 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import static com.earth2me.essentials.I18n.tl;
import com.earth2me.essentials.User;
2013-03-10 02:04:11 +00:00
import java.util.Locale;
2012-09-08 20:10:26 +00:00
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Server;
import org.bukkit.command.PluginCommand;
public class Commandsudo extends EssentialsCommand
{
public Commandsudo()
{
super("sudo");
}
2013-12-07 20:03:05 +00:00
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:"))
2012-10-01 16:31:15 +00:00
{
2013-10-17 23:04:17 +00:00
if (user.isAuthorized("essentials.sudo.exempt") && sender.isPlayer())
2012-10-01 16:31:15 +00:00
{
throw new Exception(tl("sudoExempt"));
2012-10-01 16:31:15 +00:00
}
user.getBase().chat(getFinalArg(args, 1).substring(2));
2012-10-01 16:31:15 +00:00
return;
}
final String command = args[1];
final String[] arguments = new String[args.length - 2];
if (arguments.length > 0)
{
System.arraycopy(args, 2, arguments, 0, args.length - 2);
}
2013-10-17 23:04:17 +00:00
if (user.isAuthorized("essentials.sudo.exempt") && sender.isPlayer())
{
throw new Exception(tl("sudoExempt"));
}
sender.sendMessage(tl("sudoRun", user.getDisplayName(), command, getFinalArg(arguments, 0)));
2011-11-18 19:30:05 +00:00
final PluginCommand execCommand = ess.getServer().getPluginCommand(command);
if (execCommand != null)
{
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);
}
}
ess.scheduleSyncDelayedTask(new SudoCommandTask());
2012-09-08 20:10:26 +00:00
}
else
{
sender.sendMessage(tl("errorCallingCommand", command));
}
}
}