Example #1
0
 private void loadSuperRegions() {
   unfedRegions = new HashSet<SuperRegion>();
   outer:
   for (SuperRegion sr : rm.getSortedSuperRegions()) {
     SuperRegionType srt = rm.getSuperRegionType(sr.getType());
     if (!srt.hasEffect(EFFECT_NAME)) {
       continue;
     }
     boolean fed = false;
     for (Region r : rm.getContainedRegions(sr)) {
       if (regionHasEffect(r, EFFECT_NAME) != 0) {
         fed = true;
         break;
       }
     }
     if (!fed) {
       unfedRegions.add(sr);
     }
   }
 }
  public static void openListInventory(
      ArrayList<RegionType> regions,
      ArrayList<SuperRegionType> superRegions,
      Player player,
      String category) {
    int size = 9;
    int actualSize = regions.size() + superRegions.size() + 1;
    if (actualSize > size) {
      size = actualSize + 9 - (actualSize % 9);
      if (actualSize % 9 == 0) {
        size -= 9;
      }
    }
    category = category.toLowerCase();
    // Inventory inv = Bukkit.createInventory(null, size, ChatColor.RED + category + " Regions");
    // Inventory inv = Bukkit.createInventory(new MenuHolder(Bukkit.createInventory(null, size)),
    // size, ChatColor.RED + WordUtils.capitalize(category) +  " Regions");
    Inventory inv =
        Bukkit.createInventory(
            null, size, ChatColor.RED + WordUtils.capitalize(category) + " Regions");

    NumberFormat formatter = NumberFormat.getCurrencyInstance();
    int i = 0;
    for (RegionType r : regions) {
      ItemStack is = new ItemStack(r.getIcon());
      ItemMeta isMeta = is.getItemMeta();
      String displayName = ChatColor.RESET + r.getName();
      ArrayList<String> lore = new ArrayList<String>();
      lore.add(ChatColor.RESET + "" + ChatColor.GRAY + "Region");
      if (r.getDescription() != null && !r.getDescription().equals("")) {
        lore.addAll(Util.textWrap(ChatColor.RESET + "" + ChatColor.GOLD, r.getDescription()));
      }
      if (r.getMoneyRequirement() > 0) {
        lore.add(
            ChatColor.RESET
                + ""
                + ChatColor.BLUE
                + "Cost: "
                + formatter.format(r.getMoneyRequirement()));
      }
      /*if (r.getRequirements().size() > 0) {
          lore.add("Requirements");
          for (ArrayList<TOItem> items : r.getRequirements()) {
              String reagents = "";
              for (TOItem item : items) {
                  if (!reagents.equals("")) {
                      reagents += " or ";
                  }
                  String itemName = "";
                  if (item.isWildDamage()) {
                      itemName = item.getMat().name().replace("_", " ").toLowerCase();
                  } else {
                      ItemStack ist = new ItemStack(item.getMat(), 1, (short) item.getDamage());
                      itemName = Items.itemByStack(ist).getName();
                  }
                  reagents += item.getQty() + " " + itemName;
              }
              lore.addAll(Util.textWrap("", reagents));
          }
      }*/
      isMeta.setDisplayName(displayName);

      // Trim lore
      trimLore:
      {
        boolean addEllipses = lore.size() > 20;
        if (addEllipses) {
          for (int k = lore.size(); k > 19; k--) {
            lore.remove(k - 1);
          }
          lore.add("To be continued...");
        }
      }

      isMeta.setLore(lore);
      is.setItemMeta(isMeta);
      inv.setItem(i, is);
      i++;
    }
    for (SuperRegionType sr : superRegions) {
      ItemStack is = new ItemStack(sr.getIcon());
      ItemMeta isMeta = is.getItemMeta();
      String displayName = ChatColor.RESET + sr.getName();
      ArrayList<String> lore = new ArrayList<String>();
      lore.add(ChatColor.RESET + "" + ChatColor.GRAY + "Super Region");
      if (sr.getDescription() != null && !sr.getDescription().equals("")) {
        lore.addAll(Util.textWrap(ChatColor.GOLD + "", sr.getDescription()));
      }
      if (sr.getChildren().size() > 0) {
        lore.add(ChatColor.GREEN + "Upgrade from:");
        int lineCount = 0;
        String childString = "";
        for (String srt : sr.getChildren()) {
          if (!childString.equals("")) {
            childString += ", ";
          } else {
            childString += ChatColor.GREEN + "";
          }
          lineCount += srt.length();
          if (lineCount > 50) {
            lore.add(childString);
            childString = new String();
            lineCount = srt.length();
          }
          childString += srt;
        }
        lore.add(childString);
      }
      if (sr.getMoneyRequirement() > 0) {
        lore.add("Cost: " + formatter.format(sr.getMoneyRequirement()));
      }
      if (sr.getRequirements().size() > 0) {
        lore.add(ChatColor.BLUE + "Requirements:");
        for (String s : sr.getRequirements().keySet()) {
          lore.add(ChatColor.BLUE + " " + sr.getRequirement(s) + " " + s);
        }
      }
      isMeta.setDisplayName(displayName);

      // Trim lore
      trimLore:
      {
        boolean addEllipses = lore.size() > 20;
        if (addEllipses) {
          for (int k = lore.size(); k > 19; k--) {
            lore.remove(k - 1);
          }
          lore.add("To be continued...");
        }
      }

      isMeta.setLore(lore);
      is.setItemMeta(isMeta);
      inv.setItem(i, is);
      i++;
    }
    ItemStack is = new ItemStack(Material.REDSTONE_BLOCK);
    ItemMeta isMeta = is.getItemMeta();
    isMeta.setDisplayName(ChatColor.RESET + "Back to Categories");
    ArrayList<String> lore = new ArrayList<String>();
    lore.add("list " + category);
    isMeta.setLore(lore);
    is.setItemMeta(isMeta);
    inv.setItem(size - 1, is);
    player.openInventory(inv);
  }