Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit aab4a17

Browse files
committed
feat(player-extension): add some Player#sendActionBar methods
1 parent 51b83af commit aab4a17

File tree

4 files changed

+40
-14
lines changed

4 files changed

+40
-14
lines changed

common/src/main/java/com/undefined/api/extension/BlockExtsonsion.kt renamed to common/src/main/java/com/undefined/api/extension/BlockExtension.kt

File renamed without changes.

common/src/main/java/com/undefined/api/extension/NumberExtensions.kt renamed to common/src/main/java/com/undefined/api/extension/NumberExtension.kt

File renamed without changes.

common/src/main/java/com/undefined/api/extension/PlayerExtension.kt

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,35 @@ import org.bukkit.entity.Player
1515
/**
1616
* Sends an action bar message to the player.
1717
*
18-
* @param string The action bar message to be sent.
18+
* @param message The action bar message to be sent.
1919
* @param time The duration for which the action bar message should be displayed.
2020
* @param timeUnit The time unit in which the duration is measured. (Default: [TimeUnit.TICKS])
2121
*
2222
* @throws IllegalArgumentException if the provided `time` parameter is negative.
2323
*/
24-
fun Player.sendActionBar(string: String, time: Int, timeUnit: TimeUnit = TimeUnit.TICKS) {
24+
fun Player.sendActionBar(message: String, time: Int, timeUnit: TimeUnit = TimeUnit.TICKS) {
2525
repeatingTask(
2626
1,
2727
timeUnit.toTicks(time.toLong()).toInt()
28-
) { this@sendActionBar.sendActionBar(string) }
28+
) { this@sendActionBar.sendActionBar(message) }
2929
}
3030

3131
/**
3232
* Sends an action bar message to the player.
3333
*
34-
* @param string The message to be displayed in the action bar.
34+
* @param message The message to be displayed in the action bar.
3535
*/
36-
fun Player.sendActionBar(string: String) {
37-
this.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent(string))
36+
fun Player.sendActionBar(message: String) {
37+
this.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent(message))
3838
}
39+
3940
/**
4041
* Sends an action bar message to the player.
4142
*
42-
* @param string The message to be displayed in the action bar.
43+
* @param message The message to be displayed in the action bar.
4344
* @param time The duration in ticks for which the message should be displayed.
4445
*/
45-
fun Player.sendActionBar(string: String, time: Int) = sendActionBar(string, time, TimeUnit.TICKS)
46+
fun Player.sendActionBar(message: String, time: Int) = sendActionBar(message, time, TimeUnit.TICKS)
4647

4748
/**
4849
* Sets the food level of the player to the maximum value (20).
@@ -114,17 +115,40 @@ fun Player.removeActivePotionEffects() {
114115
/**
115116
* Sends a message to the player.
116117
*
117-
* @param component the message component to send
118+
* @param component The message component to send
118119
*/
119120
fun Player.sendMessage(component: Component) = UndefinedAPI.adventure().player(this).sendMessage(component)
120121

121122
/**
122123
* Sends an action bar message to the player.
123124
*
124-
* @param component The message to be displayed as the action bar, represented as a [Component].
125+
* @param message The action bar message to be sent.
126+
* @param time The duration for which the action bar message should be displayed.
127+
* @param timeUnit The time unit in which the duration is measured. (Default: [TimeUnit.TICKS])
128+
*
129+
* @throws IllegalArgumentException if the provided `time` parameter is negative.
125130
*/
126-
fun Player.sendActionBar(component: Component) = UndefinedAPI.adventure().player(this).sendActionBar(component)
131+
fun Player.sendActionBar(message: Component, time: Int, timeUnit: TimeUnit = TimeUnit.TICKS) {
132+
repeatingTask(
133+
1,
134+
timeUnit.toTicks(time.toLong()).toInt()
135+
) { this@sendActionBar.sendActionBar(message) }
136+
}
127137

138+
/**
139+
* Sends an action bar message to the player.
140+
*
141+
* @param message The message to be displayed as the action bar, represented as a [Component].
142+
*/
143+
fun Player.sendActionBar(message: Component) = UndefinedAPI.adventure().player(this).sendActionBar(message)
144+
145+
/**
146+
* Sends an action bar message to the player.
147+
*
148+
* @param message The message to be displayed in the action bar.
149+
* @param time The duration in ticks for which the message should be displayed.
150+
*/
151+
fun Player.sendActionBar(message: Component, time: Int) = sendActionBar(message, time, TimeUnit.TICKS)
128152

129153
fun Player.sendBlockUpdateArray(hashMap: HashMap<Location, BlockData>) {
130154
sendBlockUpdateArray(hashMap.keys.toList(), hashMap.values.toList())
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.undefined.api
22

33
import com.undefined.api.command.UndefinedCommand
4+
import com.undefined.api.extension.sendActionBar
45
import com.undefined.api.nms.triggerTotem
6+
import com.undefined.api.scheduler.TimeUnit
7+
import net.kyori.adventure.text.Component
58
import org.bukkit.plugin.java.JavaPlugin
69

7-
class Main: JavaPlugin() {
10+
class Main : JavaPlugin() {
811

912
lateinit var api: UndefinedAPI
1013

@@ -13,9 +16,8 @@ class Main: JavaPlugin() {
1316

1417
UndefinedCommand("test")
1518
.addExecutePlayer {
16-
this.triggerTotem()
19+
sendActionBar(Component.text("hi!"), 1, TimeUnit.SECONDS)
1720
return@addExecutePlayer false
1821
}
19-
2022
}
2123
}

0 commit comments

Comments
 (0)