2020-10-30 02:24:06 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
|
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2020-12-27 23:18:05 +00:00
|
|
|
import org.bukkit.ChatColor;
|
2021-01-07 19:29:47 +00:00
|
|
|
import org.bukkit.command.Command;
|
2020-10-30 02:24:06 +00:00
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
@CommandPermissions(level = Rank.ADMIN, source = SourceType.BOTH, blockHostConsole = true)
|
|
|
|
@CommandParameters(description = "Send a command as someone else.", usage = "/<command> <fromname> <outcommand>")
|
|
|
|
public class Command_gcmd extends FreedomCommand
|
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
|
|
|
{
|
|
|
|
if (args.length < 2)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
final Player player = getPlayer(args[0]);
|
|
|
|
|
|
|
|
if (player == null)
|
|
|
|
{
|
2021-04-05 23:13:26 +00:00
|
|
|
msg(PLAYER_NOT_FOUND);
|
2020-10-30 02:24:06 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
final String outCommand = StringUtils.join(args, " ", 1, args.length);
|
|
|
|
|
|
|
|
if (plugin.cb.isCommandBlocked(outCommand, sender))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2021-01-07 19:29:47 +00:00
|
|
|
|
|
|
|
if (plugin.al.isAdmin(player))
|
2020-12-27 23:04:57 +00:00
|
|
|
{
|
|
|
|
msg(ChatColor.RED + "You can not use gcmd on admins");
|
|
|
|
return true;
|
|
|
|
}
|
2020-10-30 02:24:06 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
msg("Sending command as " + player.getName() + ": " + outCommand);
|
|
|
|
if (server.dispatchCommand(player, outCommand))
|
|
|
|
{
|
|
|
|
msg("Command sent.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
msg("Unknown error sending command.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Throwable ex)
|
|
|
|
{
|
|
|
|
msg("Error sending command: " + ex.getMessage());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-12-27 23:04:57 +00:00
|
|
|
}
|