diff --git a/library/paper/utils/src/main/java/me/denarydev/crystal/utils/ItemUtils.java b/library/paper/utils/src/main/java/me/denarydev/crystal/utils/ItemUtils.java index e73aa8d..9a60b4a 100644 --- a/library/paper/utils/src/main/java/me/denarydev/crystal/utils/ItemUtils.java +++ b/library/paper/utils/src/main/java/me/denarydev/crystal/utils/ItemUtils.java @@ -86,13 +86,12 @@ public static ItemStack getCustomHead(final String signature, final String textu * Builder for {@link ItemStack} */ public static class Builder { - private ItemStack item; - private Material type; private String texture; + private ItemStack itemStack; private int amount; private Component displayname; - private List lore; + private List lore; private final Map enchantments = new HashMap<>(); private ItemFlag[] itemFlags; private boolean unbreakable; @@ -115,13 +114,13 @@ public Builder texture(String texture) { return this; } - public Builder itemStack(ItemStack item) { - this.item = item; + public Builder itemStack(ItemStack itemStack) { + this.itemStack = itemStack; return this; } public Builder amount(int amount) { - this.amount = amount; + this.amount = Math.max(Math.min(amount, 64), 1); return this; } @@ -151,7 +150,7 @@ public Builder loreRich(List lore, TagResolver... tags) { } public Builder lorePlain(List lore) { - this.lore = new ArrayList<>(lore.stream().map(s -> PlainTextComponentSerializer.plainText().deserialize(s)).toList()); + this.lore = lore.stream().map(s -> PlainTextComponentSerializer.plainText().deserialize(s)).toList(); return this; } @@ -203,12 +202,20 @@ public Builder persistentData(NamespacedKey key, Object value) { } public ItemStack build() { - if (item == null) { - amount = Math.max(Math.min(amount, 64), 1); + final ItemStack item; + if (itemStack != null) { + item = itemStack; + if (type != null) { + item.setType(type); + } + } else { if (texture != null) { item = getCustomHead(texture, amount); + } else if (type != null) { + item = new ItemStack(type, amount); + } else { + throw new IllegalArgumentException("The ItemStack type or texture must be present!"); } - item = new ItemStack(type, amount); } if (metaEditor != null)