2015-10-19 17:43:46 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.commands;
|
2013-07-04 21:32:11 +00:00
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.permission.PlayerRank;
|
2013-07-04 21:32:11 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.admin.AdminList;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
|
2014-11-29 19:16:00 +00:00
|
|
|
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;
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
@CommandPermissions(level = PlayerRank.SUPER_ADMIN, source = SourceType.BOTH)
|
2014-07-20 01:02:00 +00:00
|
|
|
@CommandParameters(description = "See who has a block and optionally smite.", usage = "/<command> <item> [smite]", aliases = "wh")
|
2015-10-19 17:43:46 +00:00
|
|
|
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)
|
|
|
|
{
|
2014-07-26 15:48:17 +00:00
|
|
|
if (args.length < 1)
|
2013-07-04 21:32:11 +00:00
|
|
|
{
|
2014-07-26 15:48:17 +00:00
|
|
|
return false;
|
2013-07-04 21:32:11 +00:00
|
|
|
}
|
|
|
|
|
2014-07-26 15:48:17 +00:00
|
|
|
final boolean doSmite = args.length >= 2 && "smite".equalsIgnoreCase(args[1]);
|
2013-07-11 01:46:29 +00:00
|
|
|
|
2014-07-26 15:48:17 +00:00
|
|
|
final String materialName = args[0];
|
2014-07-20 01:02:00 +00:00
|
|
|
Material material = Material.matchMaterial(materialName);
|
2013-07-04 21:32:11 +00:00
|
|
|
if (material == null)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
material = DepreciationAggregator.getMaterial(Integer.parseInt(materialName));
|
2013-07-04 21:32:11 +00:00
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (NumberFormatException ex)
|
2013-07-04 21:32:11 +00:00
|
|
|
{
|
|
|
|
}
|
2014-07-20 01:02:00 +00:00
|
|
|
}
|
2013-07-04 21:32:11 +00:00
|
|
|
|
2014-07-20 01:02:00 +00:00
|
|
|
if (material == null)
|
|
|
|
{
|
|
|
|
playerMsg("Invalid block: " + materialName, ChatColor.RED);
|
|
|
|
return true;
|
2013-07-04 21:32:11 +00:00
|
|
|
}
|
|
|
|
|
2014-07-20 01:02:00 +00:00
|
|
|
final List<String> players = new ArrayList<String>();
|
2013-07-04 21:32:11 +00:00
|
|
|
|
2014-07-20 01:02:00 +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());
|
2015-10-19 17:43:46 +00:00
|
|
|
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())
|
|
|
|
{
|
2013-07-11 01:46:29 +00:00
|
|
|
playerMsg("There are no players with that item");
|
2013-07-04 21:32:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-11 01:46:29 +00:00
|
|
|
playerMsg("Players with item " + material.name() + ": " + StringUtils.join(players, ", "));
|
2013-07-04 21:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|