private boolean compare(Inventory inv, Inventory inv2) {
   if (inv == null || inv2 == null) {
     return false;
   }
   if (!inv.getTitle().equals(inv2.getTitle())) {
     return false;
   }
   if (inv.getMaxStackSize() != inv2.getMaxStackSize()) {
     return false;
   }
   if (!inv.getViewers().equals(inv2.getViewers())) {
     return false;
   }
   return true;
 }
  /**
   * Parses through all of the previously created CustomItems, and places them into this newly
   * formed Inventory. The items will be displayed for the user.
   */
  public void createInventory() {
    if (page < 0) page = 0;
    if (displays.containsKey(player)) {
      Inventory inv = displays.get(player).inventory;
      if (inv.getViewers().size() > 0) return;
      else displays.remove(player);
    }

    Inventory inv = Bukkit.createInventory(null, INV_SIZE, "Bending Items");
    ArrayList<ItemStack> cistacks = new ArrayList<ItemStack>();
    for (CustomItem citem : CustomItem.itemList) {
      ItemStack istack = citem.generateItem();
      ItemMeta meta = istack.getItemMeta();
      if (showStats) {
        ArrayList<String> lore = new ArrayList<String>();
        for (Attribute att : citem.getAttributes()) {
          if (att.getValues().toString().length() < 40)
            lore.add(new String(att.getName() + ":" + att.getValues()));
          else lore.add(new String(att.getName()));
        }
        meta.setLore(lore);
      } else {
        List<String> lore = meta.getLore();
        if (lore == null) lore = new ArrayList<String>();

        String s = "";
        if (citem.getRecipe().size() == 0) s = ChatColor.RED + "Uncraftable";
        else if (citem.isUnshapedRecipe()) s = ChatColor.GREEN + "Craftable (unshaped)";
        else s = ChatColor.GREEN + "Craftable (shaped)";
        lore.add(s);
        meta.setLore(lore);
      }
      istack.setItemMeta(meta);
      cistacks.add(istack);
    }

    for (int i = (INV_SIZE - 9) * page; i < (INV_SIZE - 9) * (page + 1); i++) {
      if (i >= 0 && i < cistacks.size()) inv.addItem(cistacks.get(i));
      else break;
    }
    if (cistacks.size() > INV_ITEM_QTY) inv.setItem(INV_SIZE - 1, NEXT_BUTTON);
    if (page > 0) inv.setItem(INV_SIZE - 9, PREV_BUTTON);

    this.inventory = inv;
    displays.put(player, this);
    player.openInventory(inv);
  }
Esempio n. 3
0
 @Override
 public void onClose(Player player, Inventory inventory) {
   getSession().end();
   PlayerShopsManager.FutureShop futureShop =
       getSession().getHandler().getShopsManager().release(getSession().getLocation());
   if (futureShop != null) {
     try {
       PlayerShop shop = futureShop.getShop();
       shop.getLock().lock();
       try {
         if (inventory.getViewers().size() < 2) inventory.clear();
       } finally {
         shop.getLock().unlock();
       }
     } catch (ShopDataException e) {
       e.printStackTrace();
     }
   } else {
     inventory.clear();
   }
 }
Esempio n. 4
0
  @Override
  public void onDisable() {
    for (Player player : Bukkit.getOnlinePlayers()) {
      if (this.inVault.containsKey(player.getName())) {
        Inventory inventory = player.getOpenInventory().getTopInventory();
        if (inventory.getViewers().size() == 1) {
          VaultViewInfo info = this.inVault.get(player.getName());
          UUIDVaultManager.getInstance()
              .saveVault(inventory, player.getUniqueId(), info.getNumber(), false);
          this.openInventories.remove(info.toString());
        }

        this.inVault.remove(player.getName());
      }

      player.closeInventory();
    }

    if (getConfig().getBoolean("cleanup.enable", false)) {
      saveSignsFile();
    }
  }