1
1
package me .flame .menus .builders .items ;
2
2
3
+ import me .flame .menus .adventure .Lore ;
4
+ import me .flame .menus .adventure .TextHolder ;
3
5
import me .flame .menus .items .MenuItem ;
4
6
import me .flame .menus .util .ItemResponse ;
5
7
import me .flame .menus .util .VersionHelper ;
6
8
7
9
import org .bukkit .Material ;
10
+ import org .bukkit .attribute .Attribute ;
11
+ import org .bukkit .attribute .AttributeModifier ;
8
12
import org .bukkit .enchantments .Enchantment ;
9
13
import org .bukkit .entity .Damageable ;
10
14
import org .bukkit .inventory .ItemFlag ;
13
17
14
18
import org .jetbrains .annotations .NotNull ;
15
19
16
- import java .util .Arrays ;
17
20
import java .util .List ;
18
21
19
22
import static org .bukkit .ChatColor .translateAlternateColorCodes ;
@@ -24,6 +27,8 @@ public abstract class BaseItemBuilder<B extends BaseItemBuilder<B>> {
24
27
25
28
ItemMeta meta ;
26
29
30
+ private static final ItemFlag [] flags = ItemFlag .values ();
31
+
27
32
private final boolean hasNoItemMeta ;
28
33
29
34
BaseItemBuilder (Material material , int amount ) {
@@ -83,9 +88,7 @@ public B setName(String name) {
83
88
* @return the builder for chaining
84
89
*/
85
90
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 ));
89
92
}
90
93
91
94
/**
@@ -99,6 +102,32 @@ public B setLore(List<String> lore) {
99
102
return (B ) this ;
100
103
}
101
104
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
+
102
131
/**
103
132
* Enchant the itemStack with the provided enchantment
104
133
* @param enchant the enchantment to enchant the itemStack with
@@ -195,6 +224,40 @@ public B setUnbreakable(boolean breakable) {
195
224
return (B ) this ;
196
225
}
197
226
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
+
198
261
/**
199
262
* Set the damage to the itemStack
200
263
* @param d the damage
0 commit comments