TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/commands/Command_gcmd.java

57 lines
1.6 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.commands;
2011-10-19 00:37:00 +00:00
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
import org.apache.commons.lang3.StringUtils;
2011-10-19 00:37:00 +00:00
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH, blockHostConsole = true)
@CommandParameters(description = "Send a command as someone else.", usage = "/<command> <fromname> <outcommand>")
public class Command_gcmd extends FreedomCommand
2011-10-19 00:37:00 +00:00
{
2011-10-19 00:37:00 +00:00
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
2011-10-19 00:37:00 +00:00
{
if (args.length < 2)
2011-10-19 00:37:00 +00:00
{
return false;
}
2011-10-19 00:37:00 +00:00
final Player player = getPlayer(args[0]);
if (player == null)
{
sender.sendMessage(FreedomCommand.PLAYER_NOT_FOUND);
return true;
}
2011-10-19 00:37:00 +00:00
final String outCommand = StringUtils.join(args, " ", 1, args.length);
if (plugin.cb.isCommandBlocked(outCommand, sender))
{
return true;
}
2011-10-19 00:37:00 +00:00
try
{
playerMsg("Sending command as " + player.getName() + ": " + outCommand);
if (server.dispatchCommand(player, outCommand))
2011-10-19 00:37:00 +00:00
{
playerMsg("Command sent.");
2011-10-19 00:37:00 +00:00
}
else
2011-10-19 00:37:00 +00:00
{
playerMsg("Unknown error sending command.");
2011-10-19 00:37:00 +00:00
}
}
catch (Throwable ex)
2011-10-19 00:37:00 +00:00
{
playerMsg("Error sending command: " + ex.getMessage());
2011-10-19 00:37:00 +00:00
}
return true;
}
}