From 89c3a6001a59c8f6ee43545ca5a070ba485766fe Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Mon, 2 Jan 2023 13:30:07 -0500 Subject: [PATCH] add model data option to most items Took 6 minutes --- .../helpers/ConfigurationItemHelper.java | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/java/ca/tweetzy/auctionhouse/helpers/ConfigurationItemHelper.java b/src/main/java/ca/tweetzy/auctionhouse/helpers/ConfigurationItemHelper.java index 8d3f042..8e5a4c5 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/helpers/ConfigurationItemHelper.java +++ b/src/main/java/ca/tweetzy/auctionhouse/helpers/ConfigurationItemHelper.java @@ -18,9 +18,11 @@ package ca.tweetzy.auctionhouse.helpers; -import ca.tweetzy.flight.comp.enums.CompMaterial; +import ca.tweetzy.core.utils.NumberUtils; import ca.tweetzy.core.utils.TextUtils; import ca.tweetzy.core.utils.nms.NBTEditor; +import ca.tweetzy.flight.comp.enums.CompMaterial; +import ca.tweetzy.flight.comp.enums.ServerVersion; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; @@ -38,11 +40,14 @@ import java.util.stream.Collectors; */ public class ConfigurationItemHelper { - public static ItemStack createConfigurationItem(ItemStack stack, String title, List lore, HashMap replacements, String... nbtData) { + public static ItemStack createConfigurationItem(ItemStack stack, int model, String title, List lore, HashMap replacements, String... nbtData) { final ItemMeta meta = stack.getItemMeta(); assert meta != null; meta.setDisplayName(TextUtils.formatText(title)); + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14)) + meta.setCustomModelData(model); + if (replacements != null) { for (String key : replacements.keySet()) { if (title.contains(key)) title = title.replace(key, String.valueOf(replacements.get(key))); @@ -70,6 +75,17 @@ public class ConfigurationItemHelper { } public static ItemStack createConfigurationItem(String item, String title, List lore, HashMap replacements) { - return createConfigurationItem(Objects.requireNonNull(CompMaterial.matchCompMaterial(item).get().parseItem()), title, lore, replacements); + String[] split = item.split(":"); + + if (split.length == 2 && NumberUtils.isInt(split[1])) { + return createConfigurationItem(Objects.requireNonNull(CompMaterial.matchCompMaterial(split[0]).get().parseItem()), Integer.parseInt(split[1]), title, lore, replacements); + } else { + return createConfigurationItem(Objects.requireNonNull(CompMaterial.matchCompMaterial(item).get().parseItem()), -1, title, lore, replacements); + + } + } + + public static ItemStack createConfigurationItem(ItemStack item, String title, List lore, HashMap replacements) { + return createConfigurationItem(item, 0, title, lore, replacements); } }