本文整理匯總了Java中org.bukkit.inventory.Inventory.getContents方法的典型用法代碼示例。如果您正苦於以下問題:Java Inventory.getContents方法的具體用法?Java Inventory.getContents怎麽用?Java Inventory.getContents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bukkit.inventory.Inventory
的用法示例。
在下文中一共展示了Inventory.getContents方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: openFakeInv
import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
/**
* Copy an inventory and open it for player
*
* @param i Inventory to open
* @param p Player that needs the inventory
*/
public static void openFakeInv(Inventory i, OMGPlayer p) {
Inventory fake = Bukkit.createInventory(p.bukkit, i.getSize(), i.getTitle());
for (int slot = 0; slot < i.getContents().length; slot++) {
ItemStack e = i.getContents()[slot];
if (e != null) {
e = e.clone();
ItemMeta im = e.getItemMeta();
im.addItemFlags(ItemFlag.HIDE_ATTRIBUTES);
im.addItemFlags(ItemFlag.HIDE_ENCHANTS);
if ((NBTParser.getTagCompound(e).hasKey("kitid") && NBTParser.getTagCompound(e).getString("kitid").equals(p.kit.name)) || (NBTParser.getTagCompound(e).hasKey("teamid") && NBTParser.getTagCompound(e).getString("teamid").equals(p.requestedTeam.id)))
im.addEnchant(Enchantment.DURABILITY, 1, true);
if (NBTParser.getTagCompound(e).hasKey("kitid")) {
ItemStack finalE = e;
OMGKit.kits.stream().filter(k -> k.getName().equals(NBTParser.getTagCompound(finalE).getString("kitid"))).forEach(k -> {
List<String> ss = im.hasLore() ? im.getLore() : new ArrayList<>();
ss.add(ChatColor.GREEN + "Can use: " + (OMGPI.g.player_hasKit(p, k) ? (ChatColor.GREEN + "YES") : (ChatColor.RED + "NO")));
im.setLore(ss);
});
}
e.setItemMeta(im);
fake.setItem(slot, e);
}
}
p.bukkit.openInventory(fake);
}
示例2: serializeInventory
import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
private String serializeInventory(Inventory inv) {
StringBuilder sb = new StringBuilder();
ItemStack[] arr = inv.getContents();
for (int k = 0; k < arr.length; k++) {
if (arr[k] != null) {
sb.append(k);
sb.append("::");
sb.append(RSerializer.serializeItemStack(arr[k]));
sb.append("@");
}
}
String s = sb.toString().trim();
if (s.endsWith("@"))
s = s.substring(0, s.length() - 1);
return s;
}
示例3: serializeBank
import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
private String serializeBank(Inventory inv) {
StringBuilder sb = new StringBuilder();
ItemStack[] arr = inv.getContents();
for (int k = 0; k < arr.length; k++) {
if (arr[k] != null) {
sb.append(k);
sb.append("::");
sb.append(RSerializer.serializeItemStack(arr[k]));
sb.append("@");
}
}
String s = sb.toString().trim();
if (s.endsWith("@"))
s = s.substring(0, s.length() - 1);
return s;
}
示例4: saveBackpack
import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
public static void saveBackpack(Inventory inv, ItemStack item)
{
int id = -1;
String uuid = "";
for(Iterator iterator = item.getItemMeta().getLore().iterator(); iterator.hasNext();)
{
String line = (String)iterator.next();
if(line.startsWith(ChatColor.translateAlternateColorCodes('&', "&7ID: ")) && line.contains("#"))
try
{
id = Integer.parseInt(line.split("#")[1]);
uuid = line.split("#")[0].replace(ChatColor.translateAlternateColorCodes('&', "&7ID: "), "");
}
catch(NumberFormatException numberformatexception) { }
}
if(id >= 0)
{
Config cfg = new Config(new File((new StringBuilder("data-storage/Slimefun/Players/")).append(uuid).append(".yml").toString()));
for(int i = 0; i < inv.getContents().length; i++)
cfg.setValue((new StringBuilder("backpacks.")).append(id).append(".contents.").append(i).toString(), inv.getContents()[i]);
cfg.save();
}
}
示例5: ItemInventory
import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
public ItemInventory(Inventory inventory) {
this.inventory = inventory;
ArrayList<InventoryItem> iitems = new ArrayList<>();
int slot = 0;
for (ItemStack stack : inventory.getContents()) {
if (stack != null && inventory.getItem(slot) != null) {
iitems.add(new InventoryItem(stack, inventory.first(stack)));
inventory.removeItem(inventory.getItem(slot));
}
slot++;
}
this.items = iitems.toArray(new InventoryItem[iitems.size()]);
}
示例6: onBlockDispense
import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockDispense(BlockDispenseEvent e) {
if (!cm.isAntiNegativeItemDupe) {
return;
}
Inventory content = null;
if (e.getBlock().getState() instanceof InventoryHolder) {
content = ((InventoryHolder) e.getBlock().getState()).getInventory();
}
if (content == null || content.getSize() == 0) {
return;
}
for (ItemStack item : content.getContents()) {
if (item != null && item.getType() != Material.AIR) {
if (item.getAmount() <= 0) {
item.setType(Material.AIR);
}
}
}
}
示例7: playerCanTakeBackpack
import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
public static boolean playerCanTakeBackpack(Player player) {
if (BACKPACK_LIMIT == 0) {
return true;
}
// Check vanilla inventory
Inventory inventory = player.getInventory();
int count = 0;
for (ItemStack item : inventory.getContents()) {
if (isBackpack(item)) {
count++;
}
}
// Check RPGInventory slots
inventory = InventoryManager.get(player).getInventory();
Slot backpackSlot = SlotManager.instance().getBackpackSlot();
if (BackpackManager.isBackpack(inventory.getItem(backpackSlot.getSlotId())) && !backpackSlot.isQuick()) {
count++;
}
return count < BACKPACK_LIMIT;
}
示例8: fillSupplyDropContent
import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
public Inventory fillSupplyDropContent(Inventory inventory) {
Random r = new Random();
for (SupplyDropContent content : supplyContent) {
if (r.nextInt(100) < content.getItemChance()) {
int slot = r.nextInt(inventory.getSize());
// Add the items to the inventory on random slots.
while (inventory.getContents()[slot] != null)
slot = r.nextInt(inventory.getSize());
inventory.setItem(slot, new ItemStack(content.getItemMaterial(), content.getItemAmount()));
}
}
// A 5 % chance to add a Generator item
if (r.nextInt(100) < 5)
inventory.addItem(RecipeManager.getGenerator());
return inventory;
}
示例9: countCurrency
import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
public static int countCurrency(Inventory i) {
int count = 0;
for (ItemStack item : i.getContents()) {
if (isShard(item))
count += item.getAmount();
else if (isCube(item))
count += item.getAmount() * 64;
else if (isPurifiedCube(item))
count += item.getAmount() * 64 * 64;
}
return count;
}
示例10: countModularized
import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
private static int countModularized(Player p, Function<ItemStack, Boolean> f) {
Inventory i = p.getInventory();
int count = 0;
for (ItemStack item : i.getContents()) {
if (f.apply(item))
count += item.getAmount();
}
return count;
}
示例11: fillEmptySlots
import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
/**
* Fills empty slots in the inventory with the default item
*
* @param inventory inventory
*/
private void fillEmptySlots(Inventory inventory) {
for (int i = 0; i < inventory.getContents().length; i++) {
if (inventory.getItem(i) == null || inventory.getItem(i).getType() == Material.AIR) {
final Optional<GUIItemContainer> optEmptySlot = Config.getInstance().getGuiItemsController().getGUIItemFromName("empty-slot");
if (!optEmptySlot.isPresent()) {
throw new RuntimeException("PetBlocks gui item 'empty-slot' is not correctly loaded.");
} else {
inventory.setItem(i, (ItemStack) optEmptySlot.get().generate(inventory.getHolder()));
}
}
}
}
示例12: hasSpace
import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
public static boolean hasSpace(Inventory inventory) {
for (ItemStack stack : inventory.getContents()) {
if (stack == null || stack.getType() == Material.AIR) {
return true;
}
}
return false;
}
示例13: getInventory
import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
private static Inventory getInventory(TOAUser p) {
Inventory i = Bukkit.createInventory(null, getInvSize(p), ChatColor.RED + "Mochila");
ItemStack[] item = i.getContents();
if (FileUtils.getInv().contains(p.getName())) {
for (int x = 0; x < getInvSize(p); x++)
item[x] = FileUtils.getInv().getItemStack(p.getName() + ".inv_" + x);
i.setContents(item);
return i;
}
return i;
}
示例14: getFreeSlots
import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
private static int getFreeSlots(TOAUser p, Inventory i) {
if (invNoNull(i, p)) {
ItemStack[] item = i.getContents();
int sl = 0;
for (int x = 0; x < getInvSize(p); x++) if (item[x] == null) sl++;
return sl;
}
return 0;
}
示例15: inventoryToString
import org.bukkit.inventory.Inventory; //導入方法依賴的package包/類
public static String inventoryToString(Inventory inv) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < inv.getContents().length; ++i) {
builder.append(i).append("#").append(itemStackToString(inv.getContents()[i]));
if (i != inv.getContents().length - 1) {
builder.append(";");
}
}
return builder.toString();
}