@@ -12,23 +12,46 @@ import org.bukkit.inventory.ItemStack
12
12
import org.bukkit.inventory.meta.ItemMeta
13
13
14
14
/* *
15
- * @author zp4rker
15
+ * Creates a customised [ItemStack]
16
+ *
17
+ * @param type material of the itemstack
18
+ * @param data customisations of itemstack
16
19
*/
17
20
fun item (type : Material , data : ItemStack .() -> Unit ) = ItemStack (type).apply (data)
18
21
22
+ /* *
23
+ * Customises an [ItemStack]
24
+ *
25
+ * @param base the itemstack to start off with
26
+ * @see item
27
+ */
19
28
fun item (base : ItemStack , data : ItemStack .() -> Unit ) = ItemStack (base).apply (data)
20
29
30
+ /* *
31
+ * Apply changes to [ItemMeta]
32
+ *
33
+ * @param data the meta to apply
34
+ */
21
35
fun <T : ItemMeta > ItemStack.meta (data : T .() -> Unit ) {
22
36
val meta = itemMeta(type, data)
23
37
itemMeta = meta
24
38
}
25
39
40
+ /* *
41
+ * Customised [ItemMeta] for type
42
+ *
43
+ * @param type material to generate meta for
44
+ * @param data the meta to apply
45
+ */
26
46
@Suppress(" UNCHECKED_CAST" )
27
47
fun <T : ItemMeta > itemMeta (type : Material , data : T .() -> Unit ) = Bukkit .getItemFactory().getItemMeta(type)
28
48
.let { it as ? T }
29
49
?.apply (data)
30
50
? : throw IllegalArgumentException (" Invalid ItemMeta for specified material." )
31
51
52
+ /* *
53
+ * [ItemMeta] lore lines as combined string in [net.kyori.adventure.text.minimessage.MiniMessage] format
54
+ */
32
55
var ItemMeta .loreString: String?
33
56
get() = lore()?.joinToString(" \n " ) { it.minimessage() }
34
57
set(value) {
@@ -37,9 +60,15 @@ var ItemMeta.loreString: String?
37
60
}
38
61
}
39
62
63
+ /* *
64
+ * [ItemMeta] lore lines in plain text
65
+ */
40
66
val ItemMeta .plainLore: List <String >?
41
67
get() = lore()?.map { it.plain() }
42
68
69
+ /* *
70
+ * [ItemMeta] lore lines in plain text as combined string
71
+ */
43
72
val ItemMeta .plainLoreString: String?
44
73
get() = plainLore?.joinToString(" \n " )
45
74
@@ -61,6 +90,11 @@ var ItemMeta.unbreakable: Boolean
61
90
62
91
fun ItemMeta.flag (vararg flags : ItemFlag ) = addItemFlags(* flags)
63
92
93
+ /* *
94
+ * Add [ItemAttributes] to [ItemMeta]
95
+ *
96
+ * @param data the attributes to apply
97
+ */
64
98
fun ItemMeta.attributes (data : ItemAttributes .() -> Unit ) {
65
99
val attributes = ItemAttributes ().apply (data)
66
100
val mods = attributes.modifiers
@@ -71,6 +105,12 @@ fun ItemMeta.attributes(data: ItemAttributes.() -> Unit) {
71
105
}
72
106
}
73
107
108
+ /* *
109
+ * Add enchants to [ItemMeta]
110
+ *
111
+ * @param unsafe bypass level restriction
112
+ * @param data the enchants to apply
113
+ */
74
114
fun ItemMeta.enchant (unsafe : Boolean = false, data : EnchantNode .() -> Unit ) {
75
115
EnchantNode ().apply (data).set.forEach {
76
116
addEnchant(it.enchantment, it.level, unsafe)
0 commit comments