當前位置: 首頁>>代碼示例>>Java>>正文


Java Inventory.getContents方法代碼示例

本文整理匯總了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);
}
 
開發者ID:BurnyDaKath,項目名稱:OMGPI,代碼行數:32,代碼來源:Inventories.java

示例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;
}
 
開發者ID:edasaki,項目名稱:ZentrelaRPG,代碼行數:17,代碼來源:RerollCommand.java

示例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;
}
 
開發者ID:edasaki,項目名稱:ZentrelaRPG,代碼行數:17,代碼來源:RerollCommand.java

示例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();
    }
}
 
開發者ID:StarWishsama,項目名稱:Slimefun4-Chinese-Version,代碼行數:26,代碼來源:Backpacks.java

示例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()]);
}
 
開發者ID:AlphaHelixDev,項目名稱:AlphaLibary,代碼行數:18,代碼來源:ItemInventory.java

示例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);
			}
		}
	}
}
 
開發者ID:jiongjionger,項目名稱:NeverLag,代碼行數:21,代碼來源:AntiNegativeItemDupe.java

示例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;
}
 
開發者ID:EndlessCodeGroup,項目名稱:RPGInventory,代碼行數:25,代碼來源:BackpackManager.java

示例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;
}
 
開發者ID:kadeska,項目名稱:MT_Core,代碼行數:21,代碼來源:SupplyDropManager.java

示例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;
}
 
開發者ID:edasaki,項目名稱:ZentrelaRPG,代碼行數:13,代碼來源:ShardManager.java

示例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;
}
 
開發者ID:edasaki,項目名稱:ZentrelaRPG,代碼行數:10,代碼來源:ShardManager.java

示例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()));
            }
        }
    }
}
 
開發者ID:Shynixn,項目名稱:PetBlocks,代碼行數:18,代碼來源:GUI.java

示例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;
}
 
開發者ID:DRE2N,項目名稱:FactionsXL,代碼行數:9,代碼來源:PageGUI.java

示例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;
}
 
開發者ID:cadox8,項目名稱:PA,代碼行數:12,代碼來源:BagEvents.java

示例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;
}
 
開發者ID:cadox8,項目名稱:PA,代碼行數:10,代碼來源:BagEvents.java

示例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();
}
 
開發者ID:ijoeleoli,項目名稱:ZorahPractice,代碼行數:13,代碼來源:InventoryUtils.java


注:本文中的org.bukkit.inventory.Inventory.getContents方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。