2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2013-07-04 21:32:11 +00:00
|
|
|
|
2015-11-15 23:32:04 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.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.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
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2013-07-04 21:32:11 +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)
|
2013-07-04 21:32:11 +00:00
|
|
|
{
|
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)
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("Invalid block: " + materialName, ChatColor.RED);
|
2014-07-20 01:02:00 +00:00
|
|
|
return true;
|
2013-07-04 21:32:11 +00:00
|
|
|
}
|
|
|
|
|
2016-03-02 19:28:01 +00:00
|
|
|
final List<String> players = new ArrayList<>();
|
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())
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("There are no players with that item");
|
2013-07-04 21:32:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("Players with item " + material.name() + ": " + StringUtils.join(players, ", "));
|
2013-07-04 21:32:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|