Пример #1
0
  public void createNewGui() {
    try {
      clearCache();
      String gui = Json.getJSON(Api.getUrl() + "/gui");
      Log.response("GUI", gui);
      if (Json.isJson(gui)) {
        JSONObject json = new JSONObject(gui);
        JSONArray itemArray = json.optJSONArray("result");
        JSONArray categoryArray = json.optJSONArray("categories");
        int max = itemArray.length();
        for (int i = 0; i < categoryArray.length(); i++) {
          if (i == 0) {

            // Creating categories hub
            guiHub = createInventory("Categories", getInventorySize(categoryArray.length()));
            for (int cate = 0; cate < categoryArray.length(); cate++) {
              String name = getJsonString(categoryArray, cate, "name");
              String icon = "130";
              try {
                icon = getJsonString(categoryArray, cate, "iconid");
              } catch (Exception e) {
                icon = "130";
              }
              if (icon.equalsIgnoreCase("null") || icon.equals("")) {
                icon = "130";
              }
              guiHub.setItem(cate, Createcategory(name, icon));
            }
          }

          // Creating single category packages
          int id = getJsonInt(categoryArray, i, "id");
          String name = "Category: " + getJsonString(categoryArray, i, "name");
          int InvSize = itemCount(id, itemArray);
          Inventory inv = createInventory(name, getInventorySize(InvSize + 1));

          // Adding packages to caregory
          int placement = 0;
          for (int t = 0; t < max; t++) {
            int iid = getJsonInt(itemArray, t, "categoryid");
            if (iid == id) {
              inv.setItem(placement, createItem(t, itemArray));
              placement++;
            }
          }
          inv.setItem(inv.getSize() - 1, createCategoryPage());

          // Setting up new category
          ShopCategory category = new ShopCategory(name, id, i, inv);
          // Create || adding to GUI
          category.create();
        }
      }
    } catch (Exception e) {
      Log.log(e);
    }
  }
Пример #2
0
  private ItemStack createItem(int i, JSONArray jsonresult) {
    if (jsonresult != null) {
      try {
        String name = getJsonString(jsonresult, i, "name");
        String cate = getJsonString(jsonresult, i, "category");
        String url = getJsonString(jsonresult, i, "url");
        String price = getJsonString(jsonresult, i, "price");
        int id = getJsonInt(jsonresult, i, "id");
        String icon;
        try {
          icon = getJsonString(jsonresult, i, "iconid");
        } catch (Exception e) {
          icon = "54";
        }
        String currency = getJsonString(jsonresult, i, "currency");
        String description = jsonresult.getJSONObject(i).getString("description");

        // Create GUI package
        ShopPackage guiPackage =
            new ShopPackage(id, name, currency, price, cate, description, url, icon);
        guiPackage.create();
        return guiPackage.getItem();
      } catch (Exception e) {
        Log.log(e);
      }
    }
    return null;
  }