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

73 lines
2.2 KiB
Java
Raw Normal View History

package me.totalfreedom.totalfreedommod.commands;
2013-07-04 21:32:11 +00:00
import me.totalfreedom.totalfreedommod.rank.PlayerRank;
2013-07-04 21:32:11 +00:00
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
import org.apache.commons.lang3.StringUtils;
2013-07-04 21:32:11 +00:00
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "See who has a block and optionally smite.", usage = "/<command> <item> [smite]", aliases = "wh")
public class Command_whohas extends FreedomCommand
2013-07-04 21:32:11 +00:00
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length < 1)
2013-07-04 21:32:11 +00:00
{
return false;
2013-07-04 21:32:11 +00:00
}
final boolean doSmite = args.length >= 2 && "smite".equalsIgnoreCase(args[1]);
final String materialName = args[0];
Material material = Material.matchMaterial(materialName);
2013-07-04 21:32:11 +00:00
if (material == null)
{
try
{
material = DepreciationAggregator.getMaterial(Integer.parseInt(materialName));
2013-07-04 21:32:11 +00:00
}
catch (NumberFormatException ex)
2013-07-04 21:32:11 +00:00
{
}
}
2013-07-04 21:32:11 +00:00
if (material == null)
{
playerMsg("Invalid block: " + materialName, ChatColor.RED);
return true;
2013-07-04 21:32:11 +00:00
}
final List<String> players = new ArrayList<String>();
2013-07-04 21:32:11 +00:00
for (final Player player : server.getOnlinePlayers())
2013-07-04 21:32:11 +00:00
{
2013-08-14 14:01:42 +00:00
if (player.getInventory().contains(material))
2013-07-04 21:32:11 +00:00
{
2013-08-14 14:01:42 +00:00
players.add(player.getName());
if (doSmite && !plugin.al.isAdmin(player))
2013-07-04 21:32:11 +00:00
{
2013-08-14 14:01:42 +00:00
Command_smite.smite(player);
2013-07-04 21:32:11 +00:00
}
}
}
if (players.isEmpty())
{
playerMsg("There are no players with that item");
2013-07-04 21:32:11 +00:00
}
else
{
playerMsg("Players with item " + material.name() + ": " + StringUtils.join(players, ", "));
2013-07-04 21:32:11 +00:00
}
return true;
}
}