Improved ItemStackBuilder

This commit is contained in:
Marc Baloup 2022-11-22 14:30:08 +01:00
parent 8755725d51
commit 41878b72f9
Signed by: marcbal
GPG Key ID: BBC0FE3ABC30B893

View File

@ -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<? extends ComponentLike> 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());
}
@ -170,6 +171,24 @@ public class ItemStackBuilder {
return hideEnchants();
}
public ItemStackBuilder unbreakable() {
getOrInitMeta().setUnbreakable(true);
updateMeta();
return this;
}
public ItemStackBuilder canDestroy(Set<Material> destroyable) {
getOrInitMeta().setCanDestroy(destroyable);
updateMeta();
return this;
}
public ItemStackBuilder canPlaceOn(Set<Material> placeOn) {
getOrInitMeta().setCanPlaceOn(placeOn);
updateMeta();
return this;
}
public ItemStackBuilder damage(int d) {
ItemMeta m = getOrInitMeta();
if (m instanceof Damageable)