From 5ab7b0e252448e02645f02cbd56433d44620e67f Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Wed, 24 Aug 2022 23:13:27 +0200 Subject: [PATCH] Made ItemStackBuilder and GUIInventory more tolerant with some method parameters --- .../pandacube/lib/paper/gui/GUIInventory.java | 25 ++++++++++--------- .../lib/paper/util/ItemStackBuilder.java | 22 ++++++++-------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/gui/GUIInventory.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/gui/GUIInventory.java index f3b507d..27d89cd 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/gui/GUIInventory.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/gui/GUIInventory.java @@ -8,6 +8,7 @@ import java.util.function.Consumer; import com.google.common.collect.ImmutableMap; import fr.pandacube.lib.paper.PandaLibPaper; +import net.kyori.adventure.text.ComponentLike; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; @@ -29,7 +30,7 @@ import fr.pandacube.lib.paper.util.ItemStackBuilder; public class GUIInventory implements Listener { /** - * Used as parameter of {@link #buildButton(ItemStack, Integer, Chat, List, Map)} to indicate that a button should + * Used as parameter of {@link #buildButton(ItemStack, Integer, ComponentLike, List, Map)} to indicate that a button should * shine like an enchanted object, without showing enchant informations in the hover text. */ public static final Map FAKE_ENCHANT = ImmutableMap.of(Enchantment.DURABILITY, 1); @@ -211,8 +212,8 @@ public class GUIInventory implements Listener { - public static ItemStack buildButton(ItemStack base, Integer amount, Chat displayName, - List lores, Map enchantments) { + public static ItemStack buildButton(ItemStack base, Integer amount, ComponentLike displayName, + List lores, Map enchantments) { ItemStackBuilder iStackBuilder = ItemStackBuilder.of(base); @@ -234,33 +235,33 @@ public class GUIInventory implements Listener { return iStackBuilder.build(); } - public static ItemStack buildButton(ItemStack base, Chat displayName, List lores, Map enchantments) { + public static ItemStack buildButton(ItemStack base, ComponentLike displayName, List lores, Map enchantments) { return buildButton(base, null, displayName, lores, enchantments); } - public static ItemStack buildButton(ItemStack base, Chat displayName, Map enchantments) { + public static ItemStack buildButton(ItemStack base, ComponentLike displayName, Map enchantments) { return buildButton(base, null, displayName, null, enchantments); } - public static ItemStack buildButton(ItemStack base, Integer amount, Chat displayName, List lores) { + public static ItemStack buildButton(ItemStack base, Integer amount, ComponentLike displayName, List lores) { return buildButton(base, amount, displayName, lores, null); } - public static ItemStack buildButton(ItemStack base, Chat displayName, List lores) { + public static ItemStack buildButton(ItemStack base, ComponentLike displayName, List lores) { return buildButton(base, null, displayName, lores, null); } - public static ItemStack buildButton(ItemStack base, Chat displayName) { + public static ItemStack buildButton(ItemStack base, ComponentLike displayName) { return buildButton(base, null, displayName, null, null); } - public static ItemStack buildButton(Material m, Chat displayName, List lores, Map enchantments) { + public static ItemStack buildButton(Material m, ComponentLike displayName, List lores, Map enchantments) { return buildButton(new ItemStack(m), null, displayName, lores, enchantments); } - public static ItemStack buildButton(Material m, Chat displayName, Map enchantments) { + public static ItemStack buildButton(Material m, ComponentLike displayName, Map enchantments) { return buildButton(new ItemStack(m), null, displayName, null, enchantments); } - public static ItemStack buildButton(Material m, Chat displayName, List lores) { + public static ItemStack buildButton(Material m, ComponentLike displayName, List lores) { return buildButton(new ItemStack(m), null, displayName, lores, null); } - public static ItemStack buildButton(Material m, Chat displayName) { + public static ItemStack buildButton(Material m, ComponentLike displayName) { return buildButton(new ItemStack(m), null, displayName, null, null); } 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 be01e36..b863273 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 @@ -5,6 +5,8 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import fr.pandacube.lib.chat.ChatStatic; +import net.kyori.adventure.text.ComponentLike; import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.inventory.ItemFlag; @@ -94,11 +96,11 @@ public class ItemStackBuilder { return this; } - public ItemStackBuilder displayName(Chat displayName) { + public ItemStackBuilder displayName(ComponentLike displayName) { if (displayName != null) { - if (displayName.getAdv().style().decoration(TextDecoration.ITALIC) == State.NOT_SET) + if (displayName.asComponent().style().decoration(TextDecoration.ITALIC) == State.NOT_SET) ((FormatableChat)displayName).italic(false); - return rawDisplayName(displayName.getAdv()); + return rawDisplayName(displayName.asComponent()); } else return rawDisplayName(null); @@ -110,17 +112,17 @@ public class ItemStackBuilder { return this; } - public ItemStackBuilder lore(List lore) { + public ItemStackBuilder lore(List lore) { if (lore != null) { return rawLore(lore.stream() - .map(line -> Chat.italicFalseIfNotSet(line).getAdv()) - .collect(Collectors.toList())); + .map(line -> Chat.italicFalseIfNotSet(ChatStatic.chatComponent(line)).getAdv()) + .toList()); } else return rawLore(Collections.emptyList()); } - public ItemStackBuilder addLoreAfter(List lores) { + public ItemStackBuilder addLoreAfter(List lores) { if (lores != null) { List baseLore = getOrInitMeta().lore(); if (baseLore == null) baseLore = Collections.emptyList(); @@ -128,15 +130,15 @@ public class ItemStackBuilder { Streams.concat( baseLore.stream(), lores.stream() - .map(line -> Chat.italicFalseIfNotSet(line).getAdv()) + .map(line -> Chat.italicFalseIfNotSet(ChatStatic.chatComponent(line)).getAdv()) ) - .collect(Collectors.toList())); + .toList()); } else return this; } - public ItemStackBuilder addLoreAfter(Chat... lores) { + public ItemStackBuilder addLoreAfter(ComponentLike... lores) { if (lores == null || lores.length == 0) return this; return addLoreAfter(Arrays.asList(lores));