Skip to content

Commit

Permalink
1.0.8: added model id support
Browse files Browse the repository at this point in the history
  • Loading branch information
benfiratkaya committed Apr 30, 2024
1 parent ce7bc8b commit 523466a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
21 changes: 21 additions & 0 deletions bukkit/src/main/java/net/leaderos/plugin/helpers/ItemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ public class Category {
*/
private XMaterial material;

/**
* Category model id
*/
private int modelId;

/**
* Sub-categories of category
*/
Expand Down Expand Up @@ -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())
Expand All @@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public class Product {
*/
private XMaterial material;

/**
* Product model id
*/
private int modelId;

/**
* Product price
*/
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 523466a

Please sign in to comment.