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


Java PlayerInventory.getSize方法代碼示例

本文整理匯總了Java中org.bukkit.inventory.PlayerInventory.getSize方法的典型用法代碼示例。如果您正苦於以下問題:Java PlayerInventory.getSize方法的具體用法?Java PlayerInventory.getSize怎麽用?Java PlayerInventory.getSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.bukkit.inventory.PlayerInventory的用法示例。


在下文中一共展示了PlayerInventory.getSize方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getConsumeSlots

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public static List<Integer> getConsumeSlots(Player player, ItemStack consumeItem) {
	if(consumeItem == null) return null;

	List<Integer> list = new ArrayList<Integer>();
	PlayerInventory inventory = player.getInventory();
	int inventorySize = inventory.getSize();
	int requiredAmount = consumeItem.getAmount();

	try {
		for(int i = 0; i < inventorySize && requiredAmount > 0; i++) {
			ItemStack item = inventory.getItem(i);

			if(item == null || !consumeItem.isSimilar(item)) {
				continue;
			}

			list.add(i);

			requiredAmount -= item.getAmount();
		}
       } catch (Exception ex) {
       }

	return requiredAmount > 0 ? null :list;
}
 
開發者ID:Aleksey-Terzi,項目名稱:CastleGates,代碼行數:26,代碼來源:Helper.java

示例2: save

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
/**
 * Saves the inventory of given player into a map
 *
 * @param player The player
 */
public static void save(Player player){
    PlayerInventory inventory = player.getInventory();

    List<SimplePair<ItemStack, Integer>> contents = new ArrayList<>();
    for(int i = 0; i < inventory.getSize(); i++){
        ItemStack item = inventory.getItem(i);

        if(item == null || item.getType() == Material.AIR){
            continue;
        }

        contents.add(new SimplePair<>(item, i));
    }

    contentMap.put(player, contents);
}
 
開發者ID:Superioz,項目名稱:CastleRush,代碼行數:22,代碼來源:InventoryBackup.java

示例3: Kit

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public Kit(String name, PlayerInventory playerInventory) {
    this.name = name;
    this.displayed = ItemBuilder.builder().type(Material.DIAMOND_SWORD).name("&7&l" + name).lore(Arrays.asList("&aClick to send", "&aa duel request", "&awith this kit!")).build();
    
    Map<Integer, ItemStack> inventory = new HashMap<>();

    for (int i = 0; i < playerInventory.getSize(); i++) {
        ItemStack item = playerInventory.getContents()[i];

        if (item == null) {
            continue;
        }

        inventory.put(i, item.clone());
    }

    Map<Integer, ItemStack> armor = new HashMap<>();

    if (playerInventory.getHelmet() != null) {
        armor.put(1, playerInventory.getHelmet().clone());
    }

    if (playerInventory.getChestplate() != null) {
        armor.put(2, playerInventory.getChestplate().clone());
    }

    if (playerInventory.getLeggings() != null) {
        armor.put(3, playerInventory.getLeggings().clone());
    }

    if (playerInventory.getBoots() != null) {
        armor.put(4, playerInventory.getBoots().clone());
    }

    items.put(KitManager.Type.INVENTORY, inventory);
    items.put(KitManager.Type.ARMOR, armor);
}
 
開發者ID:RealizedMC,項目名稱:Duels,代碼行數:38,代碼來源:Kit.java

示例4: giveItem

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public static void giveItem(Player player, ItemStack item) {
	PlayerInventory inv = player.getInventory();
	for (int i = 0; i < inv.getSize(); i++) {
		if (inv.getItem(i) == null) {
			inv.setItem(i, item);
			return;
		}
	}
	player.getWorld().dropItem(player.getLocation(), item);
}
 
開發者ID:bobmandude9889,項目名稱:iZenith-PVP,代碼行數:11,代碼來源:Util.java

示例5: loadInventory

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
private void loadInventory(PlayerInventory inv) {
    inv.clear();
    inv.setArmorContents(new ItemStack[] {null, null, null, null});
    if(!this.database.contains(this.key + ".inventory")) {
        return;
    }

    Map<String, Object> inventory = null;
    try {
        BukkitObjectInputStream in = new BukkitObjectInputStream(new ByteArrayInputStream(this.database.getBytes(this.key + ".inventory")));
        inventory = (Map<String, Object>) in.readObject();
    } catch(Exception e) {
        this.module.getLogger().log(Level.SEVERE, "Failed to load inventory.", e);
        return;
    }

    for(int slot = 0; slot < inv.getSize(); slot++) {
        if(inventory.containsKey(String.valueOf(slot))) {
            inv.setItem(slot, ItemStack.deserialize((Map<String, Object>) inventory.get(String.valueOf(slot))));
        } else {
            inv.setItem(slot, null);
        }
    }

    if(inventory.containsKey("helmet")) {
        inv.setHelmet(ItemStack.deserialize((Map<String, Object>) inventory.get(String.valueOf("helmet"))));
    }

    if(inventory.containsKey("chestplate")) {
        inv.setChestplate(ItemStack.deserialize((Map<String, Object>) inventory.get(String.valueOf("chestplate"))));
    }

    if(inventory.containsKey("leggings")) {
        inv.setLeggings(ItemStack.deserialize((Map<String, Object>) inventory.get(String.valueOf("leggings"))));
    }

    if(inventory.containsKey("boots")) {
        inv.setBoots(ItemStack.deserialize((Map<String, Object>) inventory.get(String.valueOf("boots"))));
    }
}
 
開發者ID:Steveice10,項目名稱:Peacecraft,代碼行數:41,代碼來源:WorldPlayerData.java

示例6: remove

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
public static void remove(String playerName, int amount, ItemStack compareItem){
	Player player = Bukkit.getPlayer(playerName);
	if (player != null) {
		PlayerInventory inventory = player.getInventory();
    	
    	// Remove held item first:
		if (isSameItem(compareItem, player.getItemInHand())) { 
	    	int heldAmount = player.getItemInHand().getAmount();
	    	if (heldAmount <= amount) {
	    		amount -= heldAmount;
	    		inventory.clear(inventory.getHeldItemSlot());
	    	} else {
	    		player.getItemInHand().setAmount(heldAmount - amount);
	    		amount = 0;
	    	}
		}
    	
    	int counter = amount;
    	int leftover = 0;

    	// Remove from other stacks:
    	for (int invIndex = 0; invIndex < inventory.getSize(); invIndex++) {
    		ItemStack current = inventory.getItem(invIndex);

    		if (current == null || current.getAmount() <= 0) 
    			continue;
    		
    		if (!isSameItem(compareItem, current)) 
    			continue;

    		if (current.getAmount() > counter) {
    			leftover = current.getAmount() - counter;
    		}

    		if (leftover != 0) {
    			current.setAmount(leftover);
    			counter = 0;
    			break;
    		} else {
    			counter -= current.getAmount();
    			inventory.clear(invIndex);
    		}
    	}
	}
}
 
開發者ID:virustotalop,項目名稱:ObsidianAuctions,代碼行數:46,代碼來源:Items.java

示例7: saveInventory

import org.bukkit.inventory.PlayerInventory; //導入方法依賴的package包/類
private void saveInventory(PlayerInventory inv) {
    Map<String, Object> inventory = new HashMap<String, Object>();
    for(int slot = 0; slot < inv.getSize(); slot++) {
        ItemStack item = inv.getItem(slot);
        if(item != null) {
            inventory.put(String.valueOf(slot), inv.getItem(slot).serialize());
        }
    }

    ItemStack helmet = inv.getHelmet();
    ItemStack chestplate = inv.getChestplate();
    ItemStack leggings = inv.getLeggings();
    ItemStack boots = inv.getBoots();

    if(helmet != null) {
        inventory.put("helmet", helmet.serialize());
    }

    if(chestplate != null) {
        inventory.put("chestplate", chestplate.serialize());
    }

    if(leggings != null) {
        inventory.put("leggings", leggings.serialize());
    }

    if(boots != null) {
        inventory.put("boots", boots.serialize());
    }

    try {
        ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
        BukkitObjectOutputStream out = new BukkitObjectOutputStream(byteOut);
        out.writeObject(inventory);
        out.close();

        this.database.setValue(this.key + ".inventory", byteOut.toByteArray());
    } catch(IOException e) {
        this.module.getLogger().log(Level.SEVERE, "Failed to save inventory.", e);
    }
}
 
開發者ID:Steveice10,項目名稱:Peacecraft,代碼行數:42,代碼來源:WorldPlayerData.java


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