本文整理汇总了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;
}
示例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);
}
示例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);
}
示例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);
}
示例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"))));
}
}
示例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);
}
}
}
}
示例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);
}
}