TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/commands/Command_qop.java

62 lines
1.9 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.commands;
2011-10-19 00:37:00 +00:00
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.totalfreedommod.util.FUtil;
import org.apache.commons.lang3.StringUtils;
2011-10-19 00:37:00 +00:00
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = PlayerRank.OP, source = SourceType.BOTH)
@CommandParameters(description = "Quick Op - op someone based on a partial name.", usage = "/<command> <partialname>")
public class Command_qop 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 < 1)
2011-10-19 00:37:00 +00:00
{
return false;
}
boolean silent = false;
if (args.length == 2)
{
silent = args[1].equalsIgnoreCase("-s");
}
final String targetName = args[0].toLowerCase();
final List<String> matchedPlayerNames = new ArrayList<String>();
for (final Player player : server.getOnlinePlayers())
2012-09-16 12:29:40 +00:00
{
if (player.getName().toLowerCase().contains(targetName) || player.getDisplayName().toLowerCase().contains(targetName))
{
if (!player.isOp())
{
matchedPlayerNames.add(player.getName());
player.setOp(true);
player.sendMessage(FreedomCommand.YOU_ARE_OP);
}
}
2011-10-19 00:37:00 +00:00
}
if (!matchedPlayerNames.isEmpty())
{
if (!silent)
{
FUtil.adminAction(sender.getName(), "Opping " + StringUtils.join(matchedPlayerNames, ", "), false);
}
}
else
2011-10-19 00:37:00 +00:00
{
playerMsg("No targets matched.");
2011-10-19 00:37:00 +00:00
}
return true;
}
}