2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2015-10-19 17:43:46 +00:00
|
|
|
|
2020-04-14 06:40:22 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2020-04-14 06:40:22 +00:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2015-10-19 17:43:46 +00:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2019-12-12 23:33:23 +00:00
|
|
|
@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>")
|
2015-10-19 17:43:46 +00:00
|
|
|
public class Command_op extends FreedomCommand
|
|
|
|
{
|
2020-07-22 21:40:58 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
@Override
|
2015-11-22 18:26:47 +00:00
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
2020-04-14 06:40:22 +00:00
|
|
|
if (args.length < 1)
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-14 06:40:22 +00:00
|
|
|
boolean silent = false;
|
|
|
|
if (args.length == 2)
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
2020-04-14 06:40:22 +00:00
|
|
|
silent = args[1].equalsIgnoreCase("-s");
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
|
|
|
|
2020-04-14 06:40:22 +00:00
|
|
|
final String targetName = args[0].toLowerCase();
|
|
|
|
|
2020-04-26 02:13:54 +00:00
|
|
|
List<String> matchedPlayerNames = new ArrayList<>();
|
2020-04-14 06:40:22 +00:00
|
|
|
for (final Player player : server.getOnlinePlayers())
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
2020-04-26 02:13:54 +00:00
|
|
|
if (player.getName().toLowerCase().contains(targetName) || player.getDisplayName().toLowerCase().contains(targetName)
|
|
|
|
|| player.getName().contains(targetName) || player.getDisplayName().contains(targetName))
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
2020-08-15 22:58:48 +00:00
|
|
|
if (!player.isOp() && !plugin.sl.isVanished(player.getName()))
|
2020-04-14 06:40:22 +00:00
|
|
|
{
|
|
|
|
matchedPlayerNames.add(player.getName());
|
|
|
|
player.setOp(true);
|
|
|
|
player.sendMessage(FreedomCommand.YOU_ARE_OP);
|
|
|
|
}
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 06:40:22 +00:00
|
|
|
if (!matchedPlayerNames.isEmpty())
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
2020-04-14 06:40:22 +00:00
|
|
|
if (!silent)
|
2015-10-19 17:43:46 +00:00
|
|
|
{
|
2020-08-15 22:42:46 +00:00
|
|
|
FUtil.staffAction(sender.getName(), "Opping " + StringUtils.join(matchedPlayerNames, ", "), false);
|
2015-10-19 17:43:46 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-14 06:40:22 +00:00
|
|
|
else
|
2019-01-12 03:05:12 +00:00
|
|
|
{
|
2020-04-26 02:13:54 +00:00
|
|
|
msg("Either the player is already opped, or the player could not be found.");
|
2019-01-12 03:05:12 +00:00
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-07-22 21:40:58 +00:00
|
|
|
}
|