org.bukkit.inventory.Inventory.iterator()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(2.9k)|赞(0)|评价(0)|浏览(120)

本文整理了Java中org.bukkit.inventory.Inventory.iterator()方法的一些代码示例,展示了Inventory.iterator()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Inventory.iterator()方法的具体详情如下:
包路径:org.bukkit.inventory.Inventory
类名称:Inventory
方法名:iterator

Inventory.iterator介绍

[英]Returns an iterator starting at the given index. If the index is positive, then the first call to next() will return the item at that index; if it is negative, the first call to previous will return the item at index (getSize() + index).
[中]返回从给定索引开始的迭代器。如果索引为正,则对next()的第一次调用将返回该索引处的项;如果为负,则对previous的第一次调用将返回索引处的项(getSize()+index)。

代码示例

代码示例来源:origin: bergerkiller/BKCommonLib

@Override
public ListIterator<ItemStack> iterator() {
  return base.iterator();
}

代码示例来源:origin: bergerkiller/BKCommonLib

@Override
public ListIterator<ItemStack> iterator(int index) {
  return base.iterator(index);
}

代码示例来源:origin: bergerkiller/BKCommonLib

@Override
public ListIterator<ItemStack> iterator() {
  return base.iterator();
}

代码示例来源:origin: bergerkiller/BKCommonLib

@Override
public ListIterator<ItemStack> iterator(int index) {
  return base.iterator(index);
}

代码示例来源:origin: catageek/ByteCart

/**
 * Get a slot containing a ticket
 *
 *
 * @param inv The inventory to search in
 * @return a slot number, or -1
 */
static int getTicketslot(Inventory inv) {
  if (inv.contains(Material.WRITTEN_BOOK)) {
    // priority given to book in hand
    if (inv instanceof PlayerInventory) {
      if (isTicket(((PlayerInventory) inv).getItemInMainHand())) {
        return ((PlayerInventory) inv).getHeldItemSlot();
      }
    }
    ListIterator<ItemStack> it = inv.iterator();
    while (it.hasNext()) {
      if (isTicket(it.next()))
        return it.previousIndex();
    }
  }
  return -1;
}

代码示例来源:origin: NyaaCat/RPGItems-reloaded

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onInventoryOpen(final InventoryOpenEvent e) {
  if (e.getInventory().getHolder() == null || e.getInventory().getLocation() == null)
    return;
  if (e.getInventory().getType() != InventoryType.CHEST) {
    Inventory in = e.getInventory();
    Iterator<ItemStack> it = in.iterator();
    try {
      while (it.hasNext()) {
        ItemStack item = it.next();
        ItemManager.toRPGItem(item).ifPresent(rpgItem -> rpgItem.updateItem(item));
      }
    } catch (ArrayIndexOutOfBoundsException ex) {
      logger.log(Level.WARNING, "Exception when InventoryOpenEvent. May be harmless.", ex);
      // Fix for the bug with anvils in craftbukkit
    }
  }
}

代码示例来源:origin: catageek/ByteCart

ListIterator<? extends ItemStack> it = inv.iterator();

代码示例来源:origin: catageek/ByteCart

@Override
  public void trigger() {
    org.bukkit.entity.Vehicle vehicle = this.getVehicle();

    // we eject the passenger
    vehicle.eject();

    // we drop items
    if (ByteCart.myPlugin.keepItems()) {
      org.bukkit.inventory.Inventory inventory;
      if (vehicle instanceof InventoryHolder) {
        inventory = ((InventoryHolder) vehicle).getInventory();
        World world = this.getBlock().getWorld();
        org.bukkit.Location loc = this.getBlock().getRelative(BlockFace.UP, 2).getLocation();
        ListIterator<ItemStack> it = inventory.iterator();
        while (it.hasNext()) {
          ItemStack stack = it.next();
          if (stack != null)
            world.dropItem(loc, stack);
        }
      }
    }

    vehicle.remove();
  }
}

相关文章