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

65 lines
1.8 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.command;
2011-10-19 00:37:00 +00:00
import me.totalfreedom.totalfreedommod.rank.Rank;
2019-07-31 04:35:41 +00:00
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang.StringUtils;
2011-10-19 00:37:00 +00:00
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
2019-07-31 04:35:41 +00:00
import org.bukkit.ChatColor;
2011-10-19 00:37:00 +00:00
@CommandPermissions(level = Rank.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
2019-07-31 04:35:41 +00:00
if (!FUtil.isExecutive(sender.getName()) && plugin.al.isAdmin(player))
{
msg("Only Executives may use this command on admins", ChatColor.RED);
return true;
}
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
{
msg("Sending command as " + player.getName() + ": " + outCommand);
if (server.dispatchCommand(player, outCommand))
2011-10-19 00:37:00 +00:00
{
msg("Command sent.");
2011-10-19 00:37:00 +00:00
}
else
2011-10-19 00:37:00 +00:00
{
msg("Unknown error sending command.");
2011-10-19 00:37:00 +00:00
}
}
catch (Throwable ex)
2011-10-19 00:37:00 +00:00
{
msg("Error sending command: " + ex.getMessage());
2011-10-19 00:37:00 +00:00
}
return true;
}
}