Made ItemStackBuilder and GUIInventory more tolerant with some method parameters
This commit is contained in:
parent
6afa1086c2
commit
5ab7b0e252
@ -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<Enchantment, Integer> 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<Chat> lores, Map<Enchantment, Integer> enchantments) {
|
||||
public static ItemStack buildButton(ItemStack base, Integer amount, ComponentLike displayName,
|
||||
List<? extends ComponentLike> lores, Map<Enchantment, Integer> 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<Chat> lores, Map<Enchantment, Integer> enchantments) {
|
||||
public static ItemStack buildButton(ItemStack base, ComponentLike displayName, List<? extends ComponentLike> lores, Map<Enchantment, Integer> enchantments) {
|
||||
return buildButton(base, null, displayName, lores, enchantments);
|
||||
}
|
||||
public static ItemStack buildButton(ItemStack base, Chat displayName, Map<Enchantment, Integer> enchantments) {
|
||||
public static ItemStack buildButton(ItemStack base, ComponentLike displayName, Map<Enchantment, Integer> enchantments) {
|
||||
return buildButton(base, null, displayName, null, enchantments);
|
||||
}
|
||||
public static ItemStack buildButton(ItemStack base, Integer amount, Chat displayName, List<Chat> lores) {
|
||||
public static ItemStack buildButton(ItemStack base, Integer amount, ComponentLike displayName, List<? extends ComponentLike> lores) {
|
||||
return buildButton(base, amount, displayName, lores, null);
|
||||
}
|
||||
public static ItemStack buildButton(ItemStack base, Chat displayName, List<Chat> lores) {
|
||||
public static ItemStack buildButton(ItemStack base, ComponentLike displayName, List<? extends ComponentLike> 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<Chat> lores, Map<Enchantment, Integer> enchantments) {
|
||||
public static ItemStack buildButton(Material m, ComponentLike displayName, List<? extends ComponentLike> lores, Map<Enchantment, Integer> enchantments) {
|
||||
return buildButton(new ItemStack(m), null, displayName, lores, enchantments);
|
||||
}
|
||||
public static ItemStack buildButton(Material m, Chat displayName, Map<Enchantment, Integer> enchantments) {
|
||||
public static ItemStack buildButton(Material m, ComponentLike displayName, Map<Enchantment, Integer> enchantments) {
|
||||
return buildButton(new ItemStack(m), null, displayName, null, enchantments);
|
||||
}
|
||||
public static ItemStack buildButton(Material m, Chat displayName, List<Chat> lores) {
|
||||
public static ItemStack buildButton(Material m, ComponentLike displayName, List<? extends ComponentLike> 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);
|
||||
}
|
||||
|
||||
|
@ -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<Chat> lore) {
|
||||
public ItemStackBuilder lore(List<? extends ComponentLike> 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<Chat> lores) {
|
||||
public ItemStackBuilder addLoreAfter(List<? extends ComponentLike> lores) {
|
||||
if (lores != null) {
|
||||
List<Component> 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));
|
||||
|
Loading…
Reference in New Issue
Block a user