Skip to content

Commit 35973f8

Browse files
authored
Feat/some new nice to have things (#251)
2 parents cbfd821 + ed01f8a commit 35973f8

9 files changed

Lines changed: 95 additions & 10 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
77
javaVersion=25
88
mcVersion=1.21.11
99
group=dev.slne.surf
10-
version=1.21.11-2.67.0
10+
version=1.21.11-2.68.0
1111
relocationPrefix=dev.slne.surf.surfapi.libs
1212
snapshot=false

surf-api-bukkit/surf-api-bukkit-api/api/surf-api-bukkit-api.api

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,7 @@ public final class dev/slne/surf/surfapi/bukkit/api/inventory/dsl/StaticPaneScop
776776
}
777777

778778
public final class dev/slne/surf/surfapi/bukkit/api/inventory/framework/InventoryFrameworkExtensions {
779+
public static final fun getOutlineItem (Lme/devnatan/inventoryframework/View;)Lorg/bukkit/inventory/ItemStack;
779780
public static final fun modifyConfig (Lme/devnatan/inventoryframework/context/OpenContext;Lkotlin/jvm/functions/Function1;)Lme/devnatan/inventoryframework/ViewConfigBuilder;
780781
public static final fun open (Lme/devnatan/inventoryframework/View;Ljava/util/Collection;)V
781782
public static final fun open (Lme/devnatan/inventoryframework/View;Ljava/util/Collection;Ljava/lang/Object;)V
@@ -2431,6 +2432,7 @@ public final class dev/slne/surf/surfapi/bukkit/api/util/UtilBukkit {
24312432
public static final fun isChunkVisible (Lorg/bukkit/entity/Player;Lorg/bukkit/Location;)Z
24322433
public static final fun isChunkVisible (Lorg/bukkit/entity/Player;Lorg/bukkit/World;II)Z
24332434
public static final fun key (Ljava/lang/String;)Lorg/bukkit/NamespacedKey;
2435+
public static final fun readableString (Lorg/bukkit/Location;Z)Ljava/lang/String;
24342436
public static final fun toOfflinePlayers (Ljava/lang/Iterable;)Ljava/util/List;
24352437
public static final fun toOfflinePlayers (Lkotlin/sequences/Sequence;)Lkotlin/sequences/Sequence;
24362438
public static final fun toPlayers (Ljava/lang/Iterable;)Ljava/util/List;

surf-api-bukkit/surf-api-bukkit-api/src/main/kotlin/dev/slne/surf/surfapi/bukkit/api/inventory/framework/extensions.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22

33
package dev.slne.surf.surfapi.bukkit.api.inventory.framework
44

5+
import dev.slne.surf.surfapi.bukkit.api.builder.buildItem
6+
import dev.slne.surf.surfapi.bukkit.api.builder.displayName
57
import dev.slne.surf.surfapi.bukkit.api.inventory.framework.view.InventoryFrameworkDSL
68
import dev.slne.surf.surfapi.core.api.messages.builder.SurfComponentBuilder
79
import me.devnatan.inventoryframework.View
810
import me.devnatan.inventoryframework.ViewConfigBuilder
911
import me.devnatan.inventoryframework.context.OpenContext
12+
import net.kyori.adventure.text.Component
13+
import org.bukkit.Material
1014
import org.bukkit.entity.Player
1115

1216
/**
@@ -142,4 +146,15 @@ inline fun ViewConfigBuilder.titleBuilder(title: @InventoryFrameworkDSL SurfComp
142146
* @param modifier DSL block applied to the [ViewConfigBuilder]
143147
*/
144148
inline fun OpenContext.modifyConfig(modifier: @InventoryFrameworkDSL ViewConfigBuilder.() -> Unit) =
145-
this.modifyConfig().apply(modifier)
149+
this.modifyConfig().apply(modifier)
150+
151+
/**
152+
* Builds a neutral outline item for this [View], typically used as a UI border or filler slot.
153+
*
154+
* The returned item is a gray stained glass pane with an empty display name so it does not
155+
* distract from interactive elements in the inventory.
156+
*/
157+
val View.outlineItem
158+
get() = buildItem(Material.GRAY_STAINED_GLASS_PANE) {
159+
displayName(Component.empty())
160+
}

surf-api-bukkit/surf-api-bukkit-api/src/main/kotlin/dev/slne/surf/surfapi/bukkit/api/util/bukkit-util.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,30 @@ suspend fun World.getBlockAtAsync(pos: BlockPosition): Block {
281281
)
282282
}
283283
}
284+
285+
/**
286+
* Constructs a human-readable string representing the location, including coordinates and optionally
287+
* rotation data.
288+
*
289+
* @param showRotation Determines whether to include rotation values (yaw and pitch) in the output string.
290+
*/
291+
fun Location.readableString(showRotation: Boolean) = buildString {
292+
append(world?.name ?: "null")
293+
append(":(")
294+
append("%.2f".format(x))
295+
append(", ")
296+
append("%.2f".format(y))
297+
append(", ")
298+
append("%.2f".format(z))
299+
if (showRotation) {
300+
append(") [")
301+
append("%.2f".format(yaw))
302+
append(", ")
303+
append("%.2f".format(pitch))
304+
append("]")
305+
} else {
306+
append(")")
307+
}
308+
}
309+
310+
typealias BukkitSound = Sound

surf-api-core/surf-api-core-api/api/surf-api-core-api.api

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ public final class dev/slne/surf/surfapi/core/api/config/serializer/SpongeConfig
285285

286286
public final class dev/slne/surf/surfapi/core/api/extensions/Packet_eventsKt {
287287
public static final fun getPacketEvents ()Lcom/github/retrooper/packetevents/PacketEventsAPI;
288+
public static final fun sendPacket (Lcom/github/retrooper/packetevents/wrapper/PacketWrapper;Ljava/lang/Object;)V
289+
public static final fun sendPacket (Lcom/github/retrooper/packetevents/wrapper/PacketWrapper;Ljava/util/UUID;)V
288290
}
289291

290292
public final class dev/slne/surf/surfapi/core/api/font/Small_capsKt {
@@ -6677,6 +6679,7 @@ public final class dev/slne/surf/surfapi/core/api/messages/adventure/Audience_ex
66776679
public static final fun openBook (Lnet/kyori/adventure/audience/Audience;Lkotlin/jvm/functions/Function1;)V
66786680
public static final fun playSound (Lnet/kyori/adventure/audience/Audience;Lkotlin/jvm/functions/Function1;)V
66796681
public static final fun playSound (Lnet/kyori/adventure/audience/Audience;ZLkotlin/jvm/functions/Function1;)V
6682+
public static final fun sendActionBar (Lnet/kyori/adventure/audience/Audience;Lkotlin/jvm/functions/Function1;)V
66806683
public static final fun sendText (Lnet/kyori/adventure/audience/Audience;Lkotlin/jvm/functions/Function1;)V
66816684
public static final fun showBossBar (Lnet/kyori/adventure/audience/Audience;Lkotlin/jvm/functions/Function1;)V
66826685
public static final fun showTitle (Lnet/kyori/adventure/audience/Audience;Lkotlin/jvm/functions/Function1;)V
@@ -7073,6 +7076,8 @@ public abstract interface class dev/slne/surf/surfapi/core/api/messages/builder/
70737076
public static synthetic fun text$default (Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;Ljava/lang/Number;Lnet/kyori/adventure/text/format/TextColor;[Lnet/kyori/adventure/text/format/TextDecoration;ILjava/lang/Object;)Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;
70747077
public static synthetic fun text$default (Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;Ljava/lang/String;Lnet/kyori/adventure/text/format/TextColor;[Lnet/kyori/adventure/text/format/TextDecoration;ILjava/lang/Object;)Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;
70757078
public static synthetic fun text$default (Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;ZLnet/kyori/adventure/text/format/TextColor;[Lnet/kyori/adventure/text/format/TextDecoration;ILjava/lang/Object;)Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;
7079+
public fun translatable (Ljava/lang/String;Lnet/kyori/adventure/text/format/TextColor;[Lnet/kyori/adventure/text/format/TextDecoration;)Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;
7080+
public static synthetic fun translatable$default (Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;Ljava/lang/String;Lnet/kyori/adventure/text/format/TextColor;[Lnet/kyori/adventure/text/format/TextDecoration;ILjava/lang/Object;)Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;
70767081
}
70777082

70787083
public final class dev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder$Companion {
@@ -7215,6 +7220,8 @@ public final class dev/slne/surf/surfapi/core/api/messages/builder/SurfComponent
72157220
public static synthetic fun text$default (Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;Ljava/lang/Number;Lnet/kyori/adventure/text/format/TextColor;[Lnet/kyori/adventure/text/format/TextDecoration;ILjava/lang/Object;)Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;
72167221
public static synthetic fun text$default (Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;Ljava/lang/String;Lnet/kyori/adventure/text/format/TextColor;[Lnet/kyori/adventure/text/format/TextDecoration;ILjava/lang/Object;)Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;
72177222
public static synthetic fun text$default (Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;ZLnet/kyori/adventure/text/format/TextColor;[Lnet/kyori/adventure/text/format/TextDecoration;ILjava/lang/Object;)Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;
7223+
public static fun translatable (Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;Ljava/lang/String;Lnet/kyori/adventure/text/format/TextColor;[Lnet/kyori/adventure/text/format/TextDecoration;)Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;
7224+
public static synthetic fun translatable$default (Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;Ljava/lang/String;Lnet/kyori/adventure/text/format/TextColor;[Lnet/kyori/adventure/text/format/TextDecoration;ILjava/lang/Object;)Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;
72187225
public static fun variableKey (Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;C[Lnet/kyori/adventure/text/format/TextDecoration;)Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;
72197226
public static fun variableKey (Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;Ljava/lang/Number;[Lnet/kyori/adventure/text/format/TextDecoration;)Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;
72207227
public static fun variableKey (Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;Ljava/lang/String;[Lnet/kyori/adventure/text/format/TextDecoration;)Ldev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder;
Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
package dev.slne.surf.surfapi.core.api.extensions
22

33
import com.github.retrooper.packetevents.PacketEvents
4+
import com.github.retrooper.packetevents.wrapper.PacketWrapper
5+
import dev.slne.surf.surfapi.core.api.surfCoreApi
6+
import java.util.*
47

5-
val packetEvents get() = PacketEvents.getAPI() ?: error("PacketEvents API is not yet initialized")
8+
val packetEvents get() = PacketEvents.getAPI() ?: error("PacketEvents API is not yet initialized")
9+
10+
/**
11+
* Sends the current packet to the player associated with the provided UUID.
12+
* If no player is found for the specified UUID, the method returns without performing any action.
13+
*
14+
* @param uuid the UUID of the player to whom the packet will be sent
15+
*/
16+
fun PacketWrapper<*>.sendPacket(uuid: UUID) {
17+
val player = surfCoreApi.getPlayer(uuid) ?: return
18+
sendPacket(player)
19+
}
20+
21+
/**
22+
* Sends the current packet to the specified player.
23+
*
24+
* @param player the platform-specific player object to whom the packet will be sent
25+
*/
26+
fun PacketWrapper<*>.sendPacket(player: Any) {
27+
packetEvents.playerManager.sendPacket(player, this)
28+
}

surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/messages/adventure/audience-extension.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ inline fun Audience.sendText(block: SurfComponentBuilder.() -> Unit) {
1515
sendMessage(SurfComponentBuilder(block))
1616
}
1717

18+
inline fun Audience.sendActionBar(block: SurfComponentBuilder.() -> Unit) {
19+
sendActionBar(SurfComponentBuilder(block))
20+
}
21+
1822
inline fun Audience.openBook(block: @BookDsl Book.Builder.() -> Unit) {
1923
openBook(Book(block))
2024
}
@@ -45,8 +49,11 @@ inline fun Audience.uuid() = uuidOrNull() ?: error("Audience does not have a UUI
4549
inline fun Audience.nameOrNull() = getPointer(Identity.NAME)
4650
inline fun Audience.name() = nameOrNull() ?: error("Audience does not have a name pointer")
4751
inline fun Audience.displayNameOrNull() = getPointer(Identity.DISPLAY_NAME)
48-
inline fun Audience.displayName() = displayNameOrNull() ?: error("Audience does not have a display name pointer")
52+
inline fun Audience.displayName() =
53+
displayNameOrNull() ?: error("Audience does not have a display name pointer")
54+
4955
inline fun Audience.testPermission(permission: String) =
5056
getPointer(PermissionChecker.POINTER)?.value(permission) ?: TriState.NOT_SET
5157

52-
inline fun Audience.hasPermission(permission: String) = getPointer(PermissionChecker.POINTER)?.test(permission) ?: false
58+
inline fun Audience.hasPermission(permission: String) =
59+
getPointer(PermissionChecker.POINTER)?.test(permission) ?: false

surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/messages/adventure/sound-extensions.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ inline fun sound(block: @SoundDsl Sound.Builder.() -> Unit): Sound {
3535
* @param block The configuration block for building the sound.
3636
* @return A configured [Sound] instance.
3737
*/
38-
inline fun Sound(block: @SoundDsl Sound.Builder.() -> Unit) = sound(block)
38+
inline fun Sound(block: @SoundDsl Sound.Builder.() -> Unit) = sound(block)
39+
40+
typealias AdventureSound = Sound

surf-api-core/surf-api-core-api/src/main/kotlin/dev/slne/surf/surfapi/core/api/messages/builder/SurfComponentBuilder.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package dev.slne.surf.surfapi.core.api.messages.builder
22

3+
import dev.slne.surf.surfapi.core.api.messages.*
34
import dev.slne.surf.surfapi.core.api.messages.Colors.Companion.NOTE
45
import dev.slne.surf.surfapi.core.api.messages.Colors.Companion.PREFIX
56
import dev.slne.surf.surfapi.core.api.messages.Colors.Companion.SPACER
67
import dev.slne.surf.surfapi.core.api.messages.Colors.Companion.VARIABLE_VALUE
7-
import dev.slne.surf.surfapi.core.api.messages.CommonComponents
88
import dev.slne.surf.surfapi.core.api.messages.CommonComponents.DISCONNECT_HEADER
99
import dev.slne.surf.surfapi.core.api.messages.CommonComponents.DISCORD_LINK
1010
import dev.slne.surf.surfapi.core.api.messages.CommonComponents.TIME_SEPARATOR
11-
import dev.slne.surf.surfapi.core.api.messages.NoLowercase
12-
import dev.slne.surf.surfapi.core.api.messages.joinToComponent
13-
import dev.slne.surf.surfapi.core.api.messages.joinToComponentNewLine
1411
import net.kyori.adventure.key.Key
1512
import net.kyori.adventure.text.*
1613
import net.kyori.adventure.text.event.ClickEvent
@@ -83,6 +80,11 @@ interface SurfComponentBuilder : TextComponent.Builder, ComponentBuilderColors {
8380
fun note(any: Any, vararg decoration: TextDecoration) = text(any.toString(), NOTE, *decoration)
8481

8582
fun ellipsis(color: TextColor? = SPACER) = append(CommonComponents.ELLIPSIS.color(color))
83+
fun translatable(
84+
key: String,
85+
color: TextColor? = Colors.WHITE,
86+
vararg decoration: TextDecoration
87+
) = append(Component.translatable(key, color, *decoration))
8688

8789
fun appendDiscordLink() = append(DISCORD_LINK)
8890
fun appendDisconnectHeader() = append(DISCONNECT_HEADER)

0 commit comments

Comments
 (0)