From 721175f965bed40a3e48fbeab849533e52a7328f Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sat, 7 Jan 2023 17:22:09 +0100 Subject: [PATCH] Refactor ItemStackBuilder#meta to use ItemStack#editMeta method --- .../lib/paper/util/ItemStackBuilder.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/ItemStackBuilder.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/ItemStackBuilder.java index 5cbb3dc..e0cf8aa 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/ItemStackBuilder.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/util/ItemStackBuilder.java @@ -92,19 +92,14 @@ public class ItemStackBuilder { } public ItemStackBuilder meta(Consumer metaUpdater) { - metaUpdater.accept(getOrInitMeta()); - updateMeta(); - return this; + return meta(metaUpdater, ItemMeta.class); } public ItemStackBuilder meta(Consumer metaUpdater, Class metaType) { - ItemMeta m = getOrInitMeta(); - if (!metaType.isInstance(m)) { - Log.warning("Item meta of " + stack.getType() + " is not of type " + metaType.getSimpleName(), new Throwable()); - return this; - } - metaUpdater.accept(metaType.cast(m)); - updateMeta(); + stack.editMeta(metaType, m -> { + metaUpdater.accept(m); + cachedMeta = m; + }); return this; }