Added /whohas

This commit is contained in:
Jerom van der Sar 2013-07-04 23:32:11 +02:00
parent ee87d1147d
commit 93914370a1
3 changed files with 85 additions and 5 deletions

View File

@ -1,5 +1,5 @@
#Thu, 04 Jul 2013 22:45:10 +0200 #Thu, 04 Jul 2013 23:31:51 +0200
program.VERSION=2.21 program.VERSION=2.21
program.BUILDNUM=262 program.BUILDNUM=266
program.BUILDDATE=07/04/2013 10\:45 PM program.BUILDDATE=07/04/2013 11\:31 PM

View File

@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit! #Build Number for ANT. Do not edit!
#Thu Jul 04 12:21:05 EDT 2013 #Thu Jul 04 23:31:51 CEST 2013
build.number=263 build.number=267

View File

@ -0,0 +1,80 @@
package me.StevenLawson.TotalFreedomMod.Commands;
import java.util.ArrayList;
import java.util.List;
import me.StevenLawson.TotalFreedomMod.TFM_SuperadminList;
import org.apache.commons.lang.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 = AdminLevel.SUPER, source = SourceType.BOTH)
@CommandParameters(description = "Spy on commands", usage = "/<command> <item> [smite]", aliases="wh")
public class Command_whohas extends TFM_Command
{
@Override
public boolean run(CommandSender sender, Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{
boolean smite = false;
if (args.length != 1)
{
if (args.length == 2 && args[1].equals("smite"))
{
smite = true;
}
else
{
return false;
}
}
Material material = Material.matchMaterial(args[0]);
if (material == null)
{
try
{
material = Material.getMaterial(Integer.parseInt(args[0]));
}
catch (NumberFormatException ex)
{
}
if (material == null)
{
playerMsg("Invalid block: " + args[0], ChatColor.RED);
return true;
}
}
List<String> players = new ArrayList<String>();
for (Player p : server.getOnlinePlayers())
{
if (p.getInventory().contains(material))
{
players.add(p.getName());
if (smite & !TFM_SuperadminList.isUserSuperadmin(p))
{
Command_smite.smite(p);
}
}
}
if (players.isEmpty())
{
playerMsg("There are no players with that item");
}
else
{
playerMsg("Players with item " + material.name() + ": "+ StringUtils.join(players, ", "));
}
return true;
}
}