TFM-4.3-Reloaded/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java

59 lines
1.7 KiB
Java

package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker;
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
@CommandParameters(description = "Send a command as someone else.", usage = "/<command> <fromname> <outcommand>")
public class Command_gcmd extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length < 2)
{
return false;
}
Player player;
try
{
player = getPlayer(args[0]);
}
catch (PlayerNotFoundException ex)
{
sender.sendMessage(ex.getMessage());
return true;
}
final String outCommand = StringUtils.join(args, " ", 1, args.length);
if (TFM_CommandBlocker.getInstance().isCommandBlocked(outCommand, sender))
{
return true;
}
try
{
playerMsg("Sending command as " + player.getName() + ": " + outCommand);
if (server.dispatchCommand(player, outCommand))
{
playerMsg("Command sent.");
}
else
{
playerMsg("Unknown error sending command.");
}
}
catch (Throwable ex)
{
playerMsg("Error sending command: " + ex.getMessage());
}
return true;
}
}