2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2013-07-04 21:32:11 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2019-07-28 06:04:16 +00:00
|
|
|
import org.apache.commons.lang.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;
|
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
|
2016-10-02 21:05:03 +00:00
|
|
|
@CommandParameters(description = "See who has a block and optionally clears the item.", usage = "/<command> <item> clear", 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
|
|
|
}
|
|
|
|
|
2016-10-02 21:05:03 +00:00
|
|
|
final boolean doClear = args.length >= 2 && "clear".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
|
|
|
|
2014-07-20 01:02:00 +00:00
|
|
|
if (material == null)
|
|
|
|
{
|
2018-07-25 02:08:29 +00:00
|
|
|
msg("Invalid item: " + 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());
|
2016-10-02 21:05:03 +00:00
|
|
|
if (doClear && !plugin.al.isAdmin(player))
|
2013-07-04 21:32:11 +00:00
|
|
|
{
|
2016-10-02 21:05:03 +00:00
|
|
|
player.getInventory().remove(material);
|
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;
|
|
|
|
}
|
|
|
|
}
|