2011-11-16 03:00:31 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2013-10-16 19:59:39 +00:00
|
|
|
import com.earth2me.essentials.CommandSource;
|
2014-03-20 15:54:07 +00:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
2011-11-16 03:00:31 +00:00
|
|
|
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;
|
2011-11-16 03:00:31 +00:00
|
|
|
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");
|
2011-11-16 03:00:31 +00:00
|
|
|
|
|
|
|
@Override
|
2013-10-16 19:59:39 +00:00
|
|
|
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception
|
2011-11-16 03:00:31 +00:00
|
|
|
{
|
|
|
|
if (args.length < 2)
|
|
|
|
{
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
|
|
|
|
2013-06-02 15:09:56 +00:00
|
|
|
final User user = getPlayer(server, sender, args, 0);
|
2014-05-18 20:32:07 +00:00
|
|
|
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
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
throw new Exception(tl("sudoExempt"));
|
2012-10-01 16:31:15 +00:00
|
|
|
}
|
2014-04-13 00:01:49 +00:00
|
|
|
user.getBase().chat(getFinalArg(args, 1).substring(2));
|
2012-10-01 16:31:15 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-11-16 03:00:31 +00:00
|
|
|
final String command = args[1];
|
2011-11-16 03:26:24 +00:00
|
|
|
final String[] arguments = new String[args.length - 2];
|
2011-11-21 01:55:26 +00:00
|
|
|
if (arguments.length > 0)
|
|
|
|
{
|
2011-11-16 03:26:24 +00:00
|
|
|
System.arraycopy(args, 2, arguments, 0, args.length - 2);
|
|
|
|
}
|
2011-11-16 03:00:31 +00:00
|
|
|
|
2013-10-17 23:04:17 +00:00
|
|
|
if (user.isAuthorized("essentials.sudo.exempt") && sender.isPlayer())
|
2012-02-09 22:11:46 +00:00
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
throw new Exception(tl("sudoExempt"));
|
2012-02-09 22:11:46 +00:00
|
|
|
}
|
|
|
|
|
2014-03-20 15:54:07 +00:00
|
|
|
sender.sendMessage(tl("sudoRun", user.getDisplayName(), command, getFinalArg(arguments, 0)));
|
2011-11-16 03:00:31 +00:00
|
|
|
|
2011-11-18 19:30:05 +00:00
|
|
|
final PluginCommand execCommand = ess.getServer().getPluginCommand(command);
|
|
|
|
if (execCommand != null)
|
2011-11-16 03:00:31 +00:00
|
|
|
{
|
2014-05-18 20:32:07 +00:00
|
|
|
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
|
|
|
}
|
2014-05-18 20:32:07 +00:00
|
|
|
else
|
|
|
|
{
|
2014-03-20 15:54:07 +00:00
|
|
|
sender.sendMessage(tl("errorCallingCommand", command));
|
2011-11-16 03:00:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|