本文整理匯總了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;
}
示例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;
}
示例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);
}
}
示例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()]);
}
示例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);
}
示例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;
}
示例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);
}
}
示例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);
}
示例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);
}
示例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()));
}
}
}
}
示例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);
}
示例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()));
}
}
}
示例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;
}
}
}
}
示例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);
}
}
示例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);
}
}