当前位置: 首页>>代码示例>>Java>>正文


Java Inventory.getItem方法代码示例

本文整理汇总了Java中org.bukkit.inventory.Inventory.getItem方法的典型用法代码示例。如果您正苦于以下问题:Java Inventory.getItem方法的具体用法?Java Inventory.getItem怎么用?Java Inventory.getItem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bukkit.inventory.Inventory的用法示例。


在下文中一共展示了Inventory.getItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: tryToSaveSlot

import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
public boolean tryToSaveSlot(int slot) {
    Inventory inv = player.getInventory();
    ItemStack item = inv.getItem(slot);
    if (item == null)
        return true;
    ListIterator<ItemStack> i = inv.iterator();
    while (i.hasNext()) {
        int ind = i.nextIndex();
        ItemStack itm = i.next();
        if (ind == slot || (ind < 9 && hotbarsBySlot[ind] != null))
            continue;
        if(itm == null) {
            i.set(item);
            return true;
        } else if (itm.isSimilar(item)) {
            int free = itm.getAmount() - itm.getMaxStackSize();
            if(item.getAmount() > free) {
                itm.setAmount(itm.getMaxStackSize());
            } else {
                itm.setAmount(itm.getAmount() + free);
                return true;
            }
        }
    }
    return false;
}
 
开发者ID:upperlevel,项目名称:uppercore,代码行数:27,代码来源:HotbarView.java

示例2: hasEnoughSpace

import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
public static boolean hasEnoughSpace(Inventory inventory, ItemStack item, int amount) {
    for (int i = 0; i < inventory.getSize(); i++) {
        if (i >= 36 && i <= 39 && inventory instanceof PlayerInventory) {
            continue;
        }
        if (inventory.getItem(i) != null && item.isSimilar(inventory.getItem(i)) &&
                inventory.getItem(i).getAmount() < item.getMaxStackSize()) {
            amount -= item.getMaxStackSize() - inventory.getItem(i).getAmount();
        } else if (inventory.getItem(i) == null || inventory.getItem(i).getType() == Material.AIR) {
            amount = 0;
        }
        if (amount < 1) {
            return true;
        }
    }
    return false;
}
 
开发者ID:NyaaCat,项目名称:NyaaCore,代码行数:18,代码来源:InventoryUtils.java

示例3: onMyPetCreate

import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void onMyPetCreate(MyPetCreateEvent event) {
    Player player = event.getOwner().getPlayer();
    if (!InventoryManager.playerIsLoaded(player)) {
        return;
    }

    ItemStack petItem = new ItemStack(Material.MONSTER_EGG);
    ItemMeta meta = petItem.getItemMeta();
    meta.setDisplayName(RPGInventory.getLanguage().getMessage("mypet.egg", event.getMyPet().getPetName()));
    petItem.setItemMeta(meta);
    petItem = ItemUtils.setTag(petItem, MYPET_TAG, event.getMyPet().getUUID().toString());

    Inventory inventory = InventoryManager.get(player).getInventory();
    Slot petSlot = getMyPetSlot();

    ItemStack currentPet = inventory.getItem(petSlot.getSlotId());
    boolean hasPet = !petSlot.isCup(currentPet);
    inventory.setItem(petSlot.getSlotId(), petItem);

    if (hasPet) {
        player.getInventory().addItem(currentPet);
    }
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:25,代码来源:MyPetManager.java

示例4: 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

示例5: notify

import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
@Override
public void notify(Player player, Object extra) {
    Location eye = player.getEyeLocation();
    Vector direction = eye.getDirection().multiply(2);
    Block source = (Block) extra;
    Projectile projectile = player.getWorld().spawn(source.getRelative(BlockFace.UP).getLocation().setDirection(direction), LargeFireball.class);
    projectile.setShooter(player);
    projectile.setVelocity(direction);
    
    Inventory inv = player.getInventory();
    if (inv.contains(Material.TNT)) {
        int slot = inv.first(Material.TNT);
        ItemStack ammo = inv.getItem(slot);
        int amount = ammo.getAmount();
        if (amount > 1) {
            ammo.setAmount(amount - 1);
            inv.setItem(slot, ammo);
        } else {
            inv.setItem(slot, null);
        }
        
        projectile.setCustomName("recreator.structure.turret.tnt");
    }
    
    AzureAPI.playSound(player, Sound.ITEM_FIRECHARGE_USE, true);
}
 
开发者ID:Recraft,项目名称:Recreator,代码行数:27,代码来源:StructureTurret.java

示例6: getActiveItems

import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
/**
 * Get all active item from RPGInventory of specific player
 *
 * @param player - the player
 * @return List of not null active item
 */
@NotNull
public static List<ItemStack> getActiveItems(Player player) {
    List<ItemStack> activeItems = new ArrayList<>();

    if (!InventoryManager.playerIsLoaded(player)) {
        return activeItems;
    }

    Inventory inventory = InventoryManager.get(player).getInventory();
    for (Slot slot : SlotManager.instance().getActiveSlots()) {
        ItemStack item = inventory.getItem(slot.getSlotId());

        if (!ItemUtils.isEmpty(item) && !InventoryManager.isQuickEmptySlot(item)) {
            activeItems.add(item);
        }
    }

    return activeItems;
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:26,代码来源:InventoryAPI.java

示例7: syncPlayer

import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
private static void syncPlayer(MyPetPlayer mpPlayer) {
    Slot petSlot = getMyPetSlot();
    if (mpPlayer.isOnline() && mpPlayer.hasMyPet()) {
        Player player = mpPlayer.getPlayer();

        if (!InventoryManager.playerIsLoaded(player)) {
            return;
        }

        Inventory inventory = InventoryManager.get(player).getInventory();
        ItemStack currentPet = inventory.getItem(petSlot.getSlotId());
        if (isMyPetItem(currentPet)) {
            MyPet pet = mpPlayer.getMyPet();
            UUID petUUID = UUID.fromString(ItemUtils.getTag(currentPet, MYPET_TAG));
            if (petUUID.equals(pet.getUUID())) {
                return;
            }
        } else {
            inventory.setItem(petSlot.getSlotId(), petSlot.getCup());
        }

        MyPetApi.getMyPetManager().deactivateMyPet(mpPlayer, false);
    }
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:25,代码来源:MyPetManager.java

示例8: checkItem

import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
private static void checkItem(TOAUser p, ItemStack item) {
    Inventory i = getInventory(p);
    for (int x = 0; x < getInvSize(p); x++) {
        if (i.getItem(x) != null) {
            if ((i.getItem(x).getType() == item.getType()) && (i.getItem(x).getDurability() == item.getDurability()) &&
                    (i.getItem(x).getAmount() + item.getAmount() <= item.getMaxStackSize())) {
                i.setItem(x, new ItemStack(item.getType(), item.getAmount() + i.getItem(x).getAmount(), item.getDurability()));
                saveInv(p, i);
                break;
            }
        } else if (i.getItem(x) == null) {
            i.setItem(x, item);
            saveInv(p, i);
            break;
        }
    }
    advisePlayer(p);
}
 
开发者ID:cadox8,项目名称:PA,代码行数:19,代码来源:BagEvents.java

示例9: despawnPet

import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
public static void despawnPet(OfflinePlayer player) {
    if (!InventoryManager.playerIsLoaded(player) || !PetManager.isEnabled()) {
        return;
    }

    PlayerWrapper playerWrapper = InventoryManager.get(player);
    Inventory inventory = playerWrapper.getInventory();

    LivingEntity pet = playerWrapper.getPet();
    ItemStack petItem = inventory.getItem(SLOT_PET);

    if (pet == null) {
        return;
    }

    if (petItem != null) {
        PetManager.saveHealth(petItem, pet.getHealth());
        inventory.setItem(SLOT_PET, petItem);
    }

    EffectUtils.playDespawnEffect(pet);
    pet.remove();
    playerWrapper.setPet(null);
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:25,代码来源:PetManager.java

示例10: 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

示例11: setItem

import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
private void setItem(Inventory inv, int slot, ItemStack i){
    if (inv.getItem(slot) != null){
        setItem(inv, getSlot(r, inv), i);
        return;
    }
    inv.setItem(slot, i);
}
 
开发者ID:cadox8,项目名称:WC,代码行数:8,代码来源:ChestManager.java

示例12: refresh

import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
public void refresh(VPPlayer viewer, Inventory inv){
	MenuLink ml = (MenuLink) ((inv.getHolder() instanceof MenuLink) ? inv.getHolder() : null); 
	for (int i = 1; i < icons.length; i++) {
		if (icons[i] != null && !icons[i].isStatic()){
			Icon icon = icons[i].getIcon(viewer);
			if(icon == null) {
				if(type == InventoryType.PLAYER) {
					ItemStack[] memory = viewer.getInventory(false);
					if(memory[i-1] != null) {
						inv.setItem(i-1, memory[i-1]);
						memory[i-1] = null;
						viewer.setInventory(memory, false);
					}
				}else
					inv.setItem(i-1, new ItemStack(Material.AIR));
				continue;
			}
			if(icon.skullSelf()){
				ItemStack item = inv.getItem(i-1);
				if(item != null && item.getType() == Material.SKULL_ITEM){
					ItemMeta itemMeta = item.getItemMeta();
					itemMeta.setLore(icon.getLores(ml == null ? viewer : ml.getView(), viewer.getLanguage()));
					itemMeta.setDisplayName(icon.getName(ml == null ? viewer : ml.getView(), viewer.getLanguage()));
					((SkullMeta)itemMeta).setOwner(ml == null ? viewer.getName() : ml.getView().getName());
					item.setItemMeta(itemMeta);
					continue;
				}
			}
			if(icon != null)
				inv.setItem(i-1, icon.getItemstack(ml == null ? viewer : ml.getView(), viewer.getLanguage()));
		}
	}
}
 
开发者ID:dracnis,项目名称:VanillaPlus,代码行数:34,代码来源:Menu.java

示例13: processClickEvent

import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
private void processClickEvent(InventoryClickEvent event) {
    if (event.getAction() == InventoryAction.COLLECT_TO_CURSOR) {
        ItemStack cursorItem = event.getCursor();
        Inventory topInv = event.getView().getTopInventory();
        for (int i = 0; i < topInv.getSize(); i++) {
            ItemStack item = topInv.getItem(i);
            if (item != null && item.isSimilar(cursorItem)) {
                event.setCancelled(true);
                break;
            }
        }
    }
}
 
开发者ID:EntryPointKR,项目名称:MCLibrary,代码行数:14,代码来源:ClickHandler.java

示例14: onPetDeath

import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
@EventHandler
public void onPetDeath(EntityDeathEvent event) {
    if (!(event.getEntity() instanceof Tameable)) {
        return;
    }

    Tameable petEntity = (Tameable) event.getEntity();
    final OfflinePlayer player;
    if (!petEntity.isTamed() || (player = (OfflinePlayer) petEntity.getOwner()) == null || !player.isOnline()) {
        return;
    }

    if (!InventoryManager.playerIsLoaded(player)) {
        return;
    }

    PlayerWrapper playerWrapper = InventoryManager.get(player);
    if (petEntity == playerWrapper.getPet()) {
        Inventory inventory = playerWrapper.getInventory();
        final ItemStack petItem = inventory.getItem(PetManager.getPetSlotId());
        PetType petType = PetManager.getPetFromItem(petItem);

        if (petType != null && petType.isRevival()) {
            PetManager.saveDeathTime(petItem);
            PetManager.saveHealth(petItem, 0);
            inventory.setItem(PetManager.getPetSlotId(), petItem);
            PetManager.startCooldownTimer(player.getPlayer(), petItem);
        } else {
            inventory.setItem(PetManager.getPetSlotId(), null);
        }

        event.getDrops().clear();
        playerWrapper.setPet(null);
    }
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:36,代码来源:PetListener.java

示例15: savePlayer

import org.bukkit.inventory.Inventory; //导入方法依赖的package包/类
static void savePlayer(PlayerWrapper playerWrapper, Path file) throws IOException {
    List<NbtCompound> slotList = new ArrayList<>();
    try (DataOutputStream dataOutput = new DataOutputStream(new GZIPOutputStream(Files.newOutputStream(file)))) {
        for (Slot slot : SlotManager.instance().getSlots()) {
            if (slot.getSlotType() == Slot.SlotType.ARMOR) {
                continue;
            }

            List<NbtCompound> itemList = new ArrayList<>();
            List<Integer> slotIds = slot.getSlotIds();
            Inventory inventory = playerWrapper.getInventory();
            for (int i = 0; i < slotIds.size(); i++) {
                int slotId = slotIds.get(i);
                ItemStack itemStack = inventory.getItem(slotId);
                if (!ItemUtils.isEmpty(itemStack) && !slot.isCup(itemStack)) {
                    itemList.add(ItemUtils.itemStackToNBT(itemStack, i + ""));
                }
            }

            if (itemList.size() > 0 || playerWrapper.isBuyedSlot(slot.getName())) {
                NbtCompound slotNbt = NbtFactory.ofCompound(slot.getName());
                slotNbt.put("type", slot.getSlotType().name());
                if (playerWrapper.isBuyedSlot(slot.getName())) {
                    slotNbt.put("buyed", "true");
                }
                slotNbt.put(NbtFactory.ofCompound("items", itemList));
                slotList.add(slotNbt);
            }
        }

        NbtCompound playerNbt = NbtFactory.ofCompound("Inventory");
        playerNbt.put(NbtFactory.ofCompound("slots", slotList));
        playerNbt.put("buyed-slots", playerWrapper.getBuyedGenericSlots());

        NbtBinarySerializer.DEFAULT.serialize(playerNbt, dataOutput);
    }
}
 
开发者ID:EndlessCodeGroup,项目名称:RPGInventory,代码行数:38,代码来源:InventorySerializer.java


注:本文中的org.bukkit.inventory.Inventory.getItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。