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

62 lines
1.9 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
{
@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();
final List<String> matchedPlayerNames = new ArrayList<>();
for (final Player player : server.getOnlinePlayers())
{
2020-04-14 06:40:22 +00:00
if (player.getName().toLowerCase().contains(targetName) || player.getDisplayName().toLowerCase().contains(targetName))
{
2020-04-14 06:40:22 +00:00
if (!player.isOp() && !plugin.al.vanished.contains(player))
{
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)
{
2020-04-14 06:40:22 +00:00
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
{
2020-04-14 06:40:22 +00:00
msg("No targets matched.");
2019-01-12 03:05:12 +00:00
}
return true;
}
}