diff --git a/bukkit/src/main/java/net/leaderos/plugin/helpers/ItemUtil.java b/bukkit/src/main/java/net/leaderos/plugin/helpers/ItemUtil.java index e12bf331a..f37e49f38 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/helpers/ItemUtil.java +++ b/bukkit/src/main/java/net/leaderos/plugin/helpers/ItemUtil.java @@ -132,6 +132,27 @@ public static int getDurability(ItemStack item, int maxDurability) { return result; } + /** + * Check for material and + * get item with a material and model id. + * @param material of item + * @param name of item + * @param lore of item + * @return ItemStack of destination item + */ + public static @NotNull ItemStack getItem(XMaterial material, String name, List lore, int modelId) { + ItemStack result; + // material based item + result = material.parseItem(); + ItemMeta meta = result.getItemMeta(); + meta.setLore(lore); + meta.setDisplayName(name); + if (XMaterial.supports(14) && modelId > 0) + meta.setCustomModelData(modelId); + result.setItemMeta(meta); + return result; + } + /** * Check for material and * get item with a material. diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Category.java b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Category.java index 108372c19..b1d94ee74 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Category.java +++ b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Category.java @@ -58,6 +58,11 @@ public class Category { */ private XMaterial material; + /** + * Category model id + */ + private int modelId; + /** * Sub-categories of category */ @@ -109,6 +114,10 @@ public Category(@NotNull JSONObject category) { if (material == null || !material.isSupported()) this.material = XMaterial.matchXMaterial(Bukkit.getInstance().getModulesFile().getWebStore().getGui().getCategoryDefaultMaterial()).orElse(XMaterial.CHEST); + String modelId = category.getString("minecraftItemModelID"); + if (modelId != null && !modelId.isEmpty()) + this.modelId = Integer.parseInt(modelId); + // products JSONArray products = category.getJSONArray("products"); if (!products.isEmpty()) @@ -133,7 +142,7 @@ public Category(@NotNull JSONObject category) { * @return category item */ public ItemStack getCategoryIcon() { - return ItemUtil.getItem(getMaterial(), ChatUtil.color(getCategoryName()), ChatUtil.color(getCategoryLore())); + return ItemUtil.getItem(getMaterial(), ChatUtil.color(getCategoryName()), ChatUtil.color(getCategoryLore()), getModelId()); } } diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Product.java b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Product.java index 9196ab0d8..a56654757 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Product.java +++ b/bukkit/src/main/java/net/leaderos/plugin/modules/webstore/model/Product.java @@ -53,6 +53,11 @@ public class Product { */ private XMaterial material; + /** + * Product model id + */ + private int modelId; + /** * Product price */ @@ -136,6 +141,10 @@ public Product(@NotNull JSONObject product) { if (material == null || !material.isSupported()) this.material = XMaterial.matchXMaterial(Bukkit.getInstance().getModulesFile().getWebStore().getGui().getProductDefaultMaterial()).orElse(XMaterial.DIAMOND); + + String modelId = product.getString("minecraftItemModelID"); + if (modelId != null && !modelId.isEmpty()) + this.modelId = Integer.parseInt(modelId); } /** @@ -195,6 +204,6 @@ public ItemStack getProductIcon() { lore = ChatUtil.color(lore); displayName = ChatUtil.color(displayName); - return ItemUtil.getItem(getMaterial(), displayName, lore); + return ItemUtil.getItem(getMaterial(), displayName, lore, getModelId()); } }