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

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

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

Inventory.getStorageContents介绍

暂无

代码示例

代码示例来源:origin: ChestShop-authors/ChestShop-3

private static ItemStack[] getStorageContents(Inventory inventory) {
  if (legacyContents == null) {
    try {
      inventory.getStorageContents();
      legacyContents = false;
    } catch (NoSuchMethodError e) {
      legacyContents = true;
    }
  }
  return legacyContents ? inventory.getContents() : inventory.getStorageContents();
}

代码示例来源:origin: CitizensDev/CitizensAPI

@EventHandler(ignoreCancelled = true)
public void inventoryCloseEvent(InventoryCloseEvent event) {
  if (!views.contains(event.getView()))
    return;
  ItemStack[] contents = event.getInventory().getContents();
  for (int i = 0; i < contents.length; i++) {
    this.contents[i] = contents[i]; 
    if (i == 0) {
      npc.getTrait(Equipment.class).setItemInHand(contents[i]);
    }
  }
  if (npc.getEntity() instanceof InventoryHolder) {
    try {
      int maxSize = ((InventoryHolder) npc.getEntity()).getInventory().getStorageContents().length;
      ((InventoryHolder) npc.getEntity()).getInventory().setStorageContents(Arrays.copyOf(contents, maxSize));
    } catch (NoSuchMethodError e) {
      int maxSize = ((InventoryHolder) npc.getEntity()).getInventory().getContents().length;
      ((InventoryHolder) npc.getEntity()).getInventory().setContents(Arrays.copyOf(contents, maxSize));
    }
  }
  views.remove(event.getView());
}

相关文章