TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whohas.java
marcocorriero 2443d3eaca Adds Something that is missing
Adds Futil.strictcolorize (that filters Banned colors on smite and gtfo)

Adds Actual Server-TFM features
Adds Wipewarps
adds wipecoreprotectdata
adds spectator
adds rainbownick
adds rainbowtag
2017-11-16 23:32:09 +01:00

78 lines
2.4 KiB
Java

package me.totalfreedom.totalfreedommod.command;
import java.util.ArrayList;
import java.util.List;
import me.totalfreedom.totalfreedommod.command.CommandParameters;
import me.totalfreedom.totalfreedommod.command.CommandPermissions;
import me.totalfreedom.totalfreedommod.command.FreedomCommand;
import me.totalfreedom.totalfreedommod.command.SourceType;
import me.totalfreedom.totalfreedommod.rank.Rank;
import me.totalfreedom.totalfreedommod.util.DepreciationAggregator;
import org.apache.commons.lang3.StringUtils;
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 = Rank.SUPER_ADMIN, source = SourceType.BOTH)
@CommandParameters(description = "See who has a block and optionally clears the item.", usage = "/<command> <item> clear", aliases = "wh")
public class Command_whohas extends FreedomCommand
{
@Override
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
if (args.length < 1)
{
return false;
}
final boolean doClear = args.length >= 2 && "clear".equalsIgnoreCase(args[1]);
final String materialName = args[0];
Material material = Material.matchMaterial(materialName);
if (material == null)
{
try
{
material = DepreciationAggregator.getMaterial(Integer.parseInt(materialName));
}
catch (NumberFormatException ex)
{
}
}
if (material == null)
{
msg("Invalid block: " + materialName, ChatColor.RED);
return true;
}
final List<String> players = new ArrayList<>();
for (final Player player : server.getOnlinePlayers())
{
if (player.getInventory().contains(material))
{
players.add(player.getName());
if (doClear && !plugin.al.isAdmin(player))
{
player.getInventory().remove(material);
}
}
}
if (players.isEmpty())
{
msg("There are no players with that item");
}
else
{
msg("Players with item " + material.name() + ": " + StringUtils.join(players, ", "));
}
return true;
}
}