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

62 lines
2.0 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.command;
2020-04-14 06:40:22 +00:00
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.FUtil;
2020-04-14 06:40:22 +00:00
import org.apache.commons.lang.StringUtils;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = Rank.OP, source = SourceType.BOTH, cooldown = 5)
2020-04-14 06:40:22 +00:00
@CommandParameters(description = "OP a player", usage = "/<command> <partialname>")
public class Command_op extends FreedomCommand
{
2020-07-22 21:40:58 +00:00
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
2020-04-14 06:40:22 +00:00
if (args.length < 1)
{
return false;
}
2020-04-14 06:40:22 +00:00
boolean silent = false;
if (args.length == 2)
{
2020-04-14 06:40:22 +00:00
silent = args[1].equalsIgnoreCase("-s");
}
2020-04-14 06:40:22 +00:00
final String targetName = args[0].toLowerCase();
List<String> matchedPlayerNames = new ArrayList<>();
2020-04-14 06:40:22 +00:00
for (final Player player : server.getOnlinePlayers())
{
if (player.getName().toLowerCase().contains(targetName) || player.getDisplayName().toLowerCase().contains(targetName)
|| player.getName().contains(targetName) || player.getDisplayName().contains(targetName))
{
if (!player.isOp() && !plugin.al.isVanished(player))
2020-04-14 06:40:22 +00:00
{
matchedPlayerNames.add(player.getName());
player.setOp(true);
player.sendMessage(FreedomCommand.YOU_ARE_OP);
}
}
}
2020-04-14 06:40:22 +00:00
if (!matchedPlayerNames.isEmpty())
{
2020-04-14 06:40:22 +00:00
if (!silent)
{
FUtil.adminAction(sender.getName(), "Opping " + StringUtils.join(matchedPlayerNames, ", "), false);
}
}
2020-04-14 06:40:22 +00:00
else
2019-01-12 03:05:12 +00:00
{
msg("Either the player is already opped, or the player could not be found.");
2019-01-12 03:05:12 +00:00
}
return true;
}
2020-07-22 21:40:58 +00:00
}