From 41878b72f99f28bed7d425db727a1303dd547201 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Tue, 22 Nov 2022 14:30:08 +0100 Subject: [PATCH] Improved ItemStackBuilder --- .../lib/paper/util/ItemStackBuilder.java | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 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 8b7d748..6dcbc22 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 @@ -1,8 +1,10 @@ package fr.pandacube.lib.paper.util; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; import fr.pandacube.lib.chat.ChatStatic; @@ -22,6 +24,8 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.format.TextDecoration.State; +import static fr.pandacube.lib.chat.ChatStatic.chatComponent; + public class ItemStackBuilder { /** @@ -98,10 +102,7 @@ public class ItemStackBuilder { public ItemStackBuilder displayName(ComponentLike displayName) { if (displayName != null) { - Component cmp = displayName.asComponent(); - if (cmp.style().decoration(TextDecoration.ITALIC) == State.NOT_SET) - cmp.style().decoration(TextDecoration.ITALIC, State.FALSE); - return rawDisplayName(cmp); + return rawDisplayName(Chat.italicFalseIfNotSet(chatComponent(displayName)).asComponent()); } else return rawDisplayName(null); @@ -116,7 +117,7 @@ public class ItemStackBuilder { public ItemStackBuilder lore(List lore) { if (lore != null) { return rawLore(lore.stream() - .map(line -> Chat.italicFalseIfNotSet(ChatStatic.chatComponent(line)).getAdv()) + .map(line -> Chat.italicFalseIfNotSet(chatComponent(line)).getAdv()) .toList()); } else @@ -131,7 +132,7 @@ public class ItemStackBuilder { Streams.concat( baseLore.stream(), lores.stream() - .map(line -> Chat.italicFalseIfNotSet(ChatStatic.chatComponent(line)).getAdv()) + .map(line -> Chat.italicFalseIfNotSet(chatComponent(line)).getAdv()) ) .toList()); } @@ -164,11 +165,29 @@ public class ItemStackBuilder { public ItemStackBuilder hideAttributes() { return flags(ItemFlag.HIDE_ATTRIBUTES); } - + public ItemStackBuilder fakeEnchant() { enchant(Enchantment.DURABILITY, 1); return hideEnchants(); } + + public ItemStackBuilder unbreakable() { + getOrInitMeta().setUnbreakable(true); + updateMeta(); + return this; + } + + public ItemStackBuilder canDestroy(Set destroyable) { + getOrInitMeta().setCanDestroy(destroyable); + updateMeta(); + return this; + } + + public ItemStackBuilder canPlaceOn(Set placeOn) { + getOrInitMeta().setCanPlaceOn(placeOn); + updateMeta(); + return this; + } public ItemStackBuilder damage(int d) { ItemMeta m = getOrInitMeta();