OpenInv/src/main/java/com/lishid/openinv/commands/SearchInvPluginCommand.java

78 lines
2.5 KiB
Java
Raw Normal View History

2012-02-20 15:09:44 -05:00
/*
2013-12-07 04:49:15 -05:00
* Copyright (C) 2011-2014 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/>.
*/
package com.lishid.openinv.commands;
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;
2013-12-06 02:31:14 -05:00
import com.lishid.openinv.OpenInv;
import com.lishid.openinv.Permissions;
2013-12-07 04:47:02 -05:00
public class SearchInvPluginCommand implements CommandExecutor {
public SearchInvPluginCommand() {
2011-06-03 10:32:54 -04:00
}
2013-12-07 04:47:02 -05:00
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
if (!OpenInv.hasPermission(sender, Permissions.PERM_SEARCH)) {
sender.sendMessage(ChatColor.RED + "You do not have permission to access player inventories");
return true;
}
}
2013-12-07 04:47:02 -05:00
String PlayerList = "";
2013-12-07 04:47:02 -05:00
2011-06-03 10:32:54 -04:00
Material material = null;
int count = 1;
2013-12-07 04:47:02 -05: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]);
}
2013-12-07 04:47:02 -05:00
if (args.length >= 2) {
try {
2011-06-03 10:32:54 -04:00
count = Integer.parseInt(args[1]);
}
2013-12-07 04:47:02 -05:00
catch (NumberFormatException ex) {
2011-06-03 10:32:54 -04:00
sender.sendMessage(ChatColor.RED + "'" + args[1] + "' is not a number!");
return false;
}
}
2013-12-07 04:47:02 -05:00
if (material == null) {
2011-06-03 10:32:54 -04:00
sender.sendMessage(ChatColor.RED + "Unknown item");
return false;
}
2013-12-07 04:47:02 -05:00
for (Player templayer : Bukkit.getServer().getOnlinePlayers()) {
if (templayer.getInventory().contains(material, count)) {
PlayerList += templayer.getName() + " ";
}
}
2013-12-07 04:47:02 -05:00
2011-06-03 10:32:54 -04:00
sender.sendMessage("Players with the item " + material.toString() + ": " + PlayerList);
return true;
}
}