@@ -3,6 +3,7 @@ package com.github.syari.spigot.api.component
3
3
import com.github.syari.spigot.api.UnsupportedMinecraftVersion
4
4
import com.github.syari.spigot.api.item.nbtTag
5
5
import com.github.syari.spigot.api.string.toColor
6
+ import net.md_5.bungee.api.chat.BaseComponent
6
7
import net.md_5.bungee.api.chat.ClickEvent
7
8
import net.md_5.bungee.api.chat.HoverEvent
8
9
import net.md_5.bungee.api.chat.ItemTag
@@ -20,6 +21,19 @@ import org.bukkit.inventory.ItemStack
20
21
*/
21
22
inline fun buildTextComponent (action : TextComponentBuilder .() -> Unit ) = TextComponentBuilder ().apply (action).build()
22
23
24
+ /* *
25
+ * @param hover [HoverEvent] default: null
26
+ * @param click [ClickEvent] default: null
27
+ * @since 2.2.3
28
+ */
29
+ fun <T : BaseComponent > T.with (
30
+ hover : HoverEvent ? = null,
31
+ click : ClickEvent ? = null,
32
+ ) = apply {
33
+ hoverEvent = hover
34
+ clickEvent = click
35
+ }
36
+
23
37
/* *
24
38
* @param text 文字列
25
39
* @param hover [HoverEvent] default: null
@@ -30,10 +44,7 @@ fun textComponent(
30
44
text : String ,
31
45
hover : HoverEvent ? = null,
32
46
click : ClickEvent ? = null,
33
- ) = TextComponent (text.toColor()).apply {
34
- hoverEvent = hover
35
- clickEvent = click
36
- }
47
+ ) = TextComponent (text.toColor()).with (hover, click)
37
48
38
49
/* *
39
50
* [TranslatableComponent] を生成する
@@ -46,10 +57,7 @@ fun translateComponent(
46
57
translate : String ,
47
58
hover : HoverEvent ? = null,
48
59
click : ClickEvent ? = null,
49
- ) = TranslatableComponent (translate).apply {
50
- hoverEvent = hover
51
- clickEvent = click
52
- }
60
+ ) = TranslatableComponent (translate).with (hover, click)
53
61
54
62
/* *
55
63
* [Material] から [TranslatableComponent] を生成する
@@ -77,10 +85,7 @@ fun keybindComponent(
77
85
identifier : String ,
78
86
hover : HoverEvent ? = null,
79
87
click : ClickEvent ? = null,
80
- ) = KeybindComponent (identifier).apply {
81
- hoverEvent = hover
82
- clickEvent = click
83
- }
88
+ ) = KeybindComponent (identifier).with (hover, click)
84
89
85
90
/* *
86
91
* [ClickEvent.Action.RUN_COMMAND] の [ClickEvent]
0 commit comments