2012-02-20 15:09:44 -05:00
|
|
|
/*
|
2012-03-03 13:58:24 -05:00
|
|
|
* Copyright (C) 2011-2012 lishid. All rights reserved.
|
2012-02-20 15:09:44 -05:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, version 3.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2011-06-03 10:32:54 -04:00
|
|
|
package lishid.openinv.commands;
|
|
|
|
|
2012-08-10 13:36:36 -04:00
|
|
|
import lishid.openinv.Permissions;
|
2011-06-03 10:32:54 -04:00
|
|
|
|
2012-11-15 22:45:53 -05:00
|
|
|
import org.bukkit.Bukkit;
|
2011-06-03 10:32:54 -04:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2012-06-28 10:53:11 -04:00
|
|
|
public class SearchInvPluginCommand implements CommandExecutor
|
|
|
|
{
|
2012-11-15 22:45:53 -05:00
|
|
|
public SearchInvPluginCommand()
|
2012-06-28 10:53:11 -04:00
|
|
|
{
|
2012-11-15 22:45:53 -05:00
|
|
|
|
2011-06-03 10:32:54 -04:00
|
|
|
}
|
|
|
|
|
2012-06-28 10:53:11 -04:00
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args)
|
|
|
|
{
|
|
|
|
if (sender instanceof Player)
|
|
|
|
{
|
2012-08-10 13:36:36 -04:00
|
|
|
if (!sender.hasPermission(Permissions.PERM_SEARCH))
|
2012-06-28 10:53:11 -04:00
|
|
|
{
|
2012-02-18 01:46:39 -05:00
|
|
|
sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories");
|
|
|
|
return true;
|
|
|
|
}
|
2012-06-28 10:53:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
String PlayerList = "";
|
|
|
|
|
2011-06-03 10:32:54 -04:00
|
|
|
Material material = null;
|
|
|
|
int count = 1;
|
2012-06-28 10:53:11 -04:00
|
|
|
|
|
|
|
if (args.length >= 1)
|
|
|
|
{
|
2011-06-03 10:32:54 -04:00
|
|
|
String[] gData = null;
|
|
|
|
gData = args[0].split(":");
|
|
|
|
material = Material.matchMaterial(gData[0]);
|
|
|
|
}
|
2012-06-28 10:53:11 -04:00
|
|
|
if (args.length >= 2)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2011-06-03 10:32:54 -04:00
|
|
|
count = Integer.parseInt(args[1]);
|
2012-06-28 10:53:11 -04:00
|
|
|
}
|
|
|
|
catch (NumberFormatException ex)
|
|
|
|
{
|
2011-06-03 10:32:54 -04:00
|
|
|
sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a number!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-06-28 10:53:11 -04:00
|
|
|
|
|
|
|
if (material == null)
|
|
|
|
{
|
2011-06-03 10:32:54 -04:00
|
|
|
sender.sendMessage(ChatColor.RED + "Unknown item");
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-28 10:53:11 -04:00
|
|
|
|
2012-11-15 22:45:53 -05:00
|
|
|
for (Player templayer : Bukkit.getServer().getOnlinePlayers())
|
2012-06-28 10:53:11 -04:00
|
|
|
{
|
|
|
|
if (templayer.getInventory().contains(material, count))
|
|
|
|
{
|
|
|
|
PlayerList += templayer.getName() + " ";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-03 10:32:54 -04:00
|
|
|
sender.sendMessage("Players with the item " + material.toString() + ": " + PlayerList);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|