Skip to content

Commit 10d42b9

Browse files
Add a way to set the TextHolder title
1 parent b79d7d5 commit 10d42b9

File tree

1 file changed

+67
-4
lines changed

1 file changed

+67
-4
lines changed

core/src/main/java/me/flame/menus/builders/items/BaseItemBuilder.java

Lines changed: 67 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
package me.flame.menus.builders.items;
22

3+
import me.flame.menus.adventure.Lore;
4+
import me.flame.menus.adventure.TextHolder;
35
import me.flame.menus.items.MenuItem;
46
import me.flame.menus.util.ItemResponse;
57
import me.flame.menus.util.VersionHelper;
68

79
import org.bukkit.Material;
10+
import org.bukkit.attribute.Attribute;
11+
import org.bukkit.attribute.AttributeModifier;
812
import org.bukkit.enchantments.Enchantment;
913
import org.bukkit.entity.Damageable;
1014
import org.bukkit.inventory.ItemFlag;
@@ -13,7 +17,6 @@
1317

1418
import org.jetbrains.annotations.NotNull;
1519

16-
import java.util.Arrays;
1720
import java.util.List;
1821

1922
import static org.bukkit.ChatColor.translateAlternateColorCodes;
@@ -24,6 +27,8 @@ public abstract class BaseItemBuilder<B extends BaseItemBuilder<B>> {
2427

2528
ItemMeta meta;
2629

30+
private static final ItemFlag[] flags = ItemFlag.values();
31+
2732
private final boolean hasNoItemMeta;
2833

2934
BaseItemBuilder(Material material, int amount) {
@@ -83,9 +88,7 @@ public B setName(String name) {
8388
* @return the builder for chaining
8489
*/
8590
public B setLore(String... lore) {
86-
if (this.hasNoItemMeta) return (B) this;
87-
this.meta.setLore(Arrays.asList(lore));
88-
return (B) this;
91+
return this.setLore(List.of(lore));
8992
}
9093

9194
/**
@@ -99,6 +102,32 @@ public B setLore(List<String> lore) {
99102
return (B) this;
100103
}
101104

105+
/**
106+
* Sets the lore of the itemStack to whatever the provided lore is.
107+
* @param lore the new lore
108+
* @return the builder for chaining
109+
*/
110+
public B setLore(TextHolder... lore) {
111+
if (this.hasNoItemMeta) return (B) this;
112+
Lore itemLore = new Lore(meta);
113+
itemLore.copyFrom(lore);
114+
itemLore.toItemLore(item, false);
115+
return (B) this;
116+
}
117+
118+
/**
119+
* Sets the lore of the itemStack to whatever the provided lore is.
120+
* @param lore the new lore
121+
* @return the builder for chaining
122+
*/
123+
public B setTextLore(List<TextHolder> lore) {
124+
if (this.hasNoItemMeta) return (B) this;
125+
Lore itemLore = new Lore(meta);
126+
itemLore.copyFrom(lore.toArray(new TextHolder[0]));
127+
itemLore.toItemLore(item, false);
128+
return (B) this;
129+
}
130+
102131
/**
103132
* Enchant the itemStack with the provided enchantment
104133
* @param enchant the enchantment to enchant the itemStack with
@@ -195,6 +224,40 @@ public B setUnbreakable(boolean breakable) {
195224
return (B) this;
196225
}
197226

227+
/**
228+
* Add all the item flags to the item meta
229+
* @return the builder for chaining
230+
*/
231+
public B addAllItemFlags() {
232+
if (this.hasNoItemMeta) return (B) this;
233+
this.meta.addItemFlags(flags);
234+
return (B) this;
235+
}
236+
237+
/**
238+
* Adds an item flag to the item meta.
239+
* @param flag the flag to add
240+
* @return the updated item meta
241+
*/
242+
public B addItemFlags(ItemFlag flag) {
243+
if (this.hasNoItemMeta) return (B) this;
244+
this.meta.addItemFlags(flag);
245+
return (B) this;
246+
}
247+
248+
/**
249+
* Adds an attribute modifier to the item meta.
250+
*
251+
* @param attribute the attribute to modify
252+
* @param modifier the modifier to apply
253+
* @return the updated item meta
254+
*/
255+
public B addAttributeModifier(Attribute attribute, AttributeModifier modifier) {
256+
if (this.hasNoItemMeta) return (B) this;
257+
this.meta.addAttributeModifier(attribute, modifier);
258+
return (B) this;
259+
}
260+
198261
/**
199262
* Set the damage to the itemStack
200263
* @param d the damage

0 commit comments

Comments
 (0)