From c24996efa2d677df15f33a67b18fe4e459663812 Mon Sep 17 00:00:00 2001 From: Killian Duboucher Date: Thu, 27 Feb 2025 04:41:19 +0100 Subject: [PATCH 1/2] Fix: handle null lore properly If an item is created without modifying its lore, its lore is automatically set to null rather than retaining that of the base item. --- .../io/github/bakedlibs/dough/items/CustomItemStack.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dough-items/src/main/java/io/github/bakedlibs/dough/items/CustomItemStack.java b/dough-items/src/main/java/io/github/bakedlibs/dough/items/CustomItemStack.java index 157cda58..eeb98f64 100644 --- a/dough-items/src/main/java/io/github/bakedlibs/dough/items/CustomItemStack.java +++ b/dough-items/src/main/java/io/github/bakedlibs/dough/items/CustomItemStack.java @@ -25,10 +25,11 @@ public static ItemStack create(Material material, Consumer metaConsume } public static ItemStack create(ItemStack item, @Nullable String name, String... lore) { - return new ItemStackEditor(item) - .setDisplayName(name) - .setLore(lore) - .create(); + ItemStackEditor editor = new ItemStackEditor(item).setDisplayName(name); + if (lore != null) { + editor.setLore(lore); + } + return editor.create(); } public static ItemStack create(Material material, @Nullable String name, String... lore) { From dfe7eae473f7f1ed1cd2984f857a654abd1e4f43 Mon Sep 17 00:00:00 2001 From: Tiakin Date: Tue, 4 Mar 2025 14:09:45 +0100 Subject: [PATCH 2/2] Fix: update create methods in CustomItemStack to handle nullable lore parameters --- .../bakedlibs/dough/items/CustomItemStack.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/dough-items/src/main/java/io/github/bakedlibs/dough/items/CustomItemStack.java b/dough-items/src/main/java/io/github/bakedlibs/dough/items/CustomItemStack.java index eeb98f64..5307ac29 100644 --- a/dough-items/src/main/java/io/github/bakedlibs/dough/items/CustomItemStack.java +++ b/dough-items/src/main/java/io/github/bakedlibs/dough/items/CustomItemStack.java @@ -4,6 +4,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; import java.util.List; @@ -24,20 +25,17 @@ public static ItemStack create(Material material, Consumer metaConsume return new ItemStackEditor(material).andMetaConsumer(metaConsumer).create(); } - public static ItemStack create(ItemStack item, @Nullable String name, String... lore) { + public static ItemStack create(ItemStack item, @Nullable String name, @Nullable String... lore) { ItemStackEditor editor = new ItemStackEditor(item).setDisplayName(name); - if (lore != null) { - editor.setLore(lore); - } - return editor.create(); + return (lore != null) ? editor.setLore(lore).create() : editor.create(); } - public static ItemStack create(Material material, @Nullable String name, String... lore) { + public static ItemStack create(Material material, @Nullable String name, @Nullable String... lore) { return create(new ItemStack(material), name, lore); } - public static ItemStack create(Material type, @Nullable String name, List lore) { - return create(new ItemStack(type), name, lore.toArray(String[]::new)); + public static ItemStack create(Material type, @Nullable String name, @Nullable List lore) { + return create(new ItemStack(type), name, (lore != null) ? lore.toArray(String[]::new): null); }