Skip to content
This repository was archived by the owner on Feb 16, 2022. It is now read-only.

Commit c540376

Browse files
committed
api(component): BaseComponent.with を追加
1 parent 591db64 commit c540376

File tree

1 file changed

+17
-12
lines changed
  • api/src/main/kotlin/com/github/syari/spigot/api/component

1 file changed

+17
-12
lines changed

api/src/main/kotlin/com/github/syari/spigot/api/component/extension.kt

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.github.syari.spigot.api.component
33
import com.github.syari.spigot.api.UnsupportedMinecraftVersion
44
import com.github.syari.spigot.api.item.nbtTag
55
import com.github.syari.spigot.api.string.toColor
6+
import net.md_5.bungee.api.chat.BaseComponent
67
import net.md_5.bungee.api.chat.ClickEvent
78
import net.md_5.bungee.api.chat.HoverEvent
89
import net.md_5.bungee.api.chat.ItemTag
@@ -20,6 +21,19 @@ import org.bukkit.inventory.ItemStack
2021
*/
2122
inline fun buildTextComponent(action: TextComponentBuilder.() -> Unit) = TextComponentBuilder().apply(action).build()
2223

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+
2337
/**
2438
* @param text 文字列
2539
* @param hover [HoverEvent] default: null
@@ -30,10 +44,7 @@ fun textComponent(
3044
text: String,
3145
hover: HoverEvent? = null,
3246
click: ClickEvent? = null,
33-
) = TextComponent(text.toColor()).apply {
34-
hoverEvent = hover
35-
clickEvent = click
36-
}
47+
) = TextComponent(text.toColor()).with(hover, click)
3748

3849
/**
3950
* [TranslatableComponent] を生成する
@@ -46,10 +57,7 @@ fun translateComponent(
4657
translate: String,
4758
hover: HoverEvent? = null,
4859
click: ClickEvent? = null,
49-
) = TranslatableComponent(translate).apply {
50-
hoverEvent = hover
51-
clickEvent = click
52-
}
60+
) = TranslatableComponent(translate).with(hover, click)
5361

5462
/**
5563
* [Material] から [TranslatableComponent] を生成する
@@ -77,10 +85,7 @@ fun keybindComponent(
7785
identifier: String,
7886
hover: HoverEvent? = null,
7987
click: ClickEvent? = null,
80-
) = KeybindComponent(identifier).apply {
81-
hoverEvent = hover
82-
clickEvent = click
83-
}
88+
) = KeybindComponent(identifier).with(hover, click)
8489

8590
/**
8691
* [ClickEvent.Action.RUN_COMMAND] の [ClickEvent]

0 commit comments

Comments
 (0)