TotalFreedomMod/src/me/StevenLawson/TotalFreedomMod/Commands/Command_gcmd.java

60 lines
1.7 KiB
Java
Raw Normal View History

2011-10-19 00:37:00 +00:00
package me.StevenLawson.TotalFreedomMod.Commands;
import me.StevenLawson.TotalFreedomMod.TFM_CommandBlocker;
import net.minecraft.util.org.apache.commons.lang3.StringUtils;
2011-10-19 00:37:00 +00:00
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>")
2011-10-19 00:37:00 +00:00
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)
2011-10-19 00:37:00 +00:00
{
return false;
}
2011-10-19 00:37:00 +00:00
2013-08-14 14:01:42 +00:00
Player player;
try
{
2013-08-14 14:01:42 +00:00
player = getPlayer(args[0]);
}
catch (PlayerNotFoundException ex)
{
sender.sendMessage(ex.getMessage());
return true;
}
2011-10-19 00:37:00 +00:00
final String outCommand = StringUtils.join(args, " ", 1, args.length);
if (TFM_CommandBlocker.getInstance().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;
}
}