Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ dependencies {
implementation(libs.ksp.gradle.plugin)
implementation(libs.kotlin.serialization)
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
implementation(libs.asm)
}
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
javaVersion=25
mcVersion=26.2
group=dev.slne.surf.api
version=3.25.0
version=3.26.0
relocationPrefix=dev.slne.surf.api.libs
snapshot=false
snapshot=true
6 changes: 5 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ luckpermsplugin-bukkit = "v5.5.17-bukkit" # "luckpermsplugin" is written without
scoreboard-library = "2.7.4"

# Adventure
adventure-api = "4.26.1"
adventure-api = "5.1.1"

# Velocity
velocity-api = "3.5.0-SNAPSHOT"
Expand All @@ -35,6 +35,8 @@ placeholder-api = "2.12.2"
mccoroutine = "2.22.2"

# Miscellaneous Libraries
asm = "9.8"
slf4j = "2.0.1"
guava = "33.6.0-jre"
caffeine = "3.2.4"
caffeine-courotines = "3.0.4"
Expand Down Expand Up @@ -128,6 +130,8 @@ mccoroutine-velocity-api = { module = "dev.slne.forks.mccoroutine:mccoroutine-ve
mccoroutine-velocity-core = { module = "dev.slne.forks.mccoroutine:mccoroutine-velocity-core", version.ref = "mccoroutine" }

# Miscellaneous Libraries
asm = { module = "org.ow2.asm:asm", version.ref = "asm" }
slf4j = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
guava = { module = "com.google.guava:guava", version.ref = "guava" }
caffeine = { module = "com.github.ben-manes.caffeine:caffeine", version.ref = "caffeine" }
caffeine-courotines = { module = "com.sksamuel.aedile:aedile-core", version.ref = "caffeine-courotines" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import dev.slne.surf.api.core.util.freeze
import dev.slne.surf.api.core.util.mutableObject2ObjectMapOf
import dev.slne.surf.api.core.util.synchronize
import net.kyori.adventure.nbt.*
import net.kyori.examination.ExaminableProperty
import net.kyori.examination.string.StringExaminer
import java.util.function.Consumer
import java.util.stream.Stream

Expand All @@ -22,7 +20,6 @@ class FastCompoundBinaryTagImpl(synchronize: Boolean) : FastCompoundBinaryTag {

override fun contains(key: String, type: BinaryTagType<*>): Boolean {
val tag = tags[key] ?: return false

return type.test(tag.type())
}

Expand Down Expand Up @@ -91,7 +88,6 @@ class FastCompoundBinaryTagImpl(synchronize: Boolean) : FastCompoundBinaryTag {

override fun getByteArray(key: String, defaultValue: ByteArray?): ByteArray? {
val tag = tags[key] as? ByteArrayBinaryTag ?: return defaultValue

return tag.value()
}

Expand Down Expand Up @@ -137,21 +133,15 @@ class FastCompoundBinaryTagImpl(synchronize: Boolean) : FastCompoundBinaryTag {

override fun stream(): Stream<Map.Entry<String, BinaryTag>> = tags.entries.stream()

override fun examinableProperties(): Stream<ExaminableProperty> = Stream.of(
ExaminableProperty.of("tags", tags)
)

override fun iterator() = tags.object2ObjectEntrySet().iterator()

override fun forEach(action: Consumer<in MutableMap.MutableEntry<String, out BinaryTag>>) {
tags.object2ObjectEntrySet().forEach(action)
}

override fun examinableName(): String {
return type().toString()
override fun asBinaryTag(): CompoundBinaryTag {
return CompoundBinaryTag.from(tags)
}

override fun toString(): String {
return examine(StringExaminer.simpleEscaping())
}
}
override fun toString(): String = "FastCompoundBinaryTag{tags=$tags}"
}
140 changes: 85 additions & 55 deletions surf-api-core/surf-api-core/api/surf-api-core.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import dev.slne.surf.api.core.messages.adventure.appendNewline
import dev.slne.surf.api.core.messages.adventure.appendText
import dev.slne.surf.api.core.messages.adventure.clickOpensUrl
import dev.slne.surf.api.core.messages.adventure.text
import dev.slne.surf.api.core.messages.builder.SurfComponentBuilder
import dev.slne.surf.api.core.util.mutableObjectListOf
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.JoinConfiguration
Expand Down Expand Up @@ -205,6 +206,32 @@ object CommonComponents {
return builder.build()
}

inline fun renderKickDisconnectMessage(
builder: SurfComponentBuilder,
messageRenderer: SurfComponentBuilder.() -> Unit,
footerRenderer: SurfComponentBuilder.() -> Unit = { },
): TextComponent {
with(builder) {
append(DISCONNECT_HEADER)
appendText("DU WURDEST VOM SERVER GEWORFEN", ERROR)
appendNewline(3)
messageRenderer()
appendNewline(3)
footerRenderer()
}

return builder.build()
}

inline fun renderKickDisconnectMessage(
builder: SurfComponentBuilder,
messageRenderer: SurfComponentBuilder.() -> Unit,
issue: Boolean,
) = renderKickDisconnectMessage(builder, messageRenderer) {
if (issue) append(ISSUE_FOOTER)
else append(RETRY_LATER_FOOTER)
}

/**
* Renders a structured kick message with an automatic issue or retry footer.
*
Expand Down Expand Up @@ -397,6 +424,24 @@ object CommonComponents {
return builder.build()
}

inline fun renderDisconnectMessage(
builder: SurfComponentBuilder,
disconnectReason: @NoLowercase String,
suggestHelp: SurfComponentBuilder.() -> Unit,
footerRenderer: SurfComponentBuilder.() -> Unit = { },
): TextComponent {
with(builder) {
append(DISCONNECT_HEADER)
appendText(disconnectReason.uppercase(), ERROR)
appendNewline(3)
suggestHelp()
appendNewline(3)
footerRenderer()
}

return builder.build()
}

/**
* Renders a structured disconnection message with an automatic issue or retry footer.
*
Expand Down Expand Up @@ -469,6 +514,16 @@ object CommonComponents {
else append(RETRY_LATER_FOOTER)
}

inline fun renderDisconnectMessage(
builder: SurfComponentBuilder,
disconnectReason: @NoLowercase String,
suggestHelp: SurfComponentBuilder.() -> Unit,
issue: Boolean,
) = renderDisconnectMessage(builder, disconnectReason, suggestHelp) {
if (issue) append(ISSUE_FOOTER)
else append(RETRY_LATER_FOOTER)
}

/**
* Formats a collection into a comma-separated list component.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
@file:Suppress("DEPRECATION")

package dev.slne.surf.api.core.messages.adventure

import net.kyori.adventure.audience.Audience
import net.kyori.adventure.text.BuildableComponent
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.ComponentBuilder
import net.kyori.adventure.text.event.ClickCallback
import net.kyori.adventure.text.event.ClickEvent
Expand All @@ -12,24 +10,20 @@ import kotlin.experimental.ExperimentalTypeInference
import kotlin.time.Duration
import kotlin.time.toJavaDuration

@Suppress("DEPRECATION")
fun <C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.clickCallback(
fun <C : Component, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.clickCallback(
callback: ClickCallback<Audience>,
) = clickEvent(ClickEvent.callback(callback))

@Suppress("DEPRECATION")
fun <C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.clickCallbackWithOptions(
fun <C : Component, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.clickCallbackWithOptions(
builder: ClickCallbackWithOptionsBuilder<Audience>.() -> Unit,
) = clickEvent(ClickCallbackWithOptionsBuilder(Audience::class.java).apply(builder).build())

@Suppress("DEPRECATION")
inline fun <reified T : Audience, C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.clickCallbackTyped(
inline fun <reified T : Audience, C : Component, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.clickCallbackTyped(
callback: ClickCallback<T>,
) = clickEvent(ClickEvent.callback(ClickCallback.widen(callback, T::class.java)))

@OptIn(ExperimentalTypeInference::class)
@Suppress("DEPRECATION")
inline fun <reified T : Audience, C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.clickCallbackTypedWithOptions(
inline fun <reified T : Audience, C : Component, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.clickCallbackTypedWithOptions(
@BuilderInference builder: ClickCallbackWithOptionsBuilder<T>.() -> Unit
) = clickEvent(ClickCallbackWithOptionsBuilder(T::class.java).apply(builder).build())

Expand Down Expand Up @@ -66,12 +60,12 @@ class ClickCallbackWithOptionsBuilder<T : Audience> @PublishedApi internal const
}

@PublishedApi
internal fun build(): ClickEvent {
internal fun build(): ClickEvent<*> {
val callback = callback ?: return ClickEvent.callback { }
val callbackWithPermission = permission
?.let { permission -> callback.requiringPermission(permission, permissionOtherwise) }
?: callback

return ClickEvent.callback(ClickCallback.widen(callbackWithPermission, type), options)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
@file:Suppress("DEPRECATION")

package dev.slne.surf.api.core.messages.adventure

import dev.slne.surf.api.core.messages.builder.SurfComponentBuilder
import net.kyori.adventure.text.BuildableComponent
import net.kyori.adventure.text.Component
import net.kyori.adventure.text.ComponentBuilder
import net.kyori.adventure.text.TextComponent
Expand All @@ -28,8 +25,7 @@ inline fun buildText(block: SurfComponentBuilder.() -> Unit): TextComponent {
* @param color The optional text color.
* @return The modified builder instance.
*/
@Suppress("DEPRECATION")
fun <C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.appendText(
fun <C : Component, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.appendText(
text: String,
color: TextColor? = null,
) = append(Component.text(text, color))
Expand All @@ -43,8 +39,7 @@ fun <C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<
* @param block The configuration block for the text component.
* @return The modified builder instance.
*/
@Suppress("DEPRECATION")
fun <C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.appendText(
fun <C : Component, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.appendText(
text: String,
color: TextColor? = null,
block: TextComponent.Builder.() -> Unit,
Expand All @@ -56,8 +51,7 @@ fun <C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<
* @param url The URL to open on click.
* @return The modified builder instance.
*/
@Suppress("DEPRECATION")
fun <C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.clickOpensUrl(
fun <C : Component, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.clickOpensUrl(
url: String,
) = clickEvent(ClickEvent.openUrl(url))

Expand All @@ -67,8 +61,7 @@ fun <C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<
* @param command The command to run on click.
* @return The modified builder instance.
*/
@Suppress("DEPRECATION")
fun <C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.clickRunsCommand(
fun <C : Component, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.clickRunsCommand(
command: String,
) = clickEvent(ClickEvent.runCommand(command))

Expand All @@ -78,8 +71,7 @@ fun <C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<
* @param command The command to suggest on click.
* @return The modified builder instance.
*/
@Suppress("DEPRECATION")
fun <C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.clickSuggestsCommand(
fun <C : Component, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.clickSuggestsCommand(
command: String,
) = clickEvent(ClickEvent.suggestCommand(command))

Expand All @@ -89,8 +81,7 @@ fun <C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<
* @param value The value to copy to the clipboard on click.
* @return The modified builder instance.
*/
@Suppress("DEPRECATION")
fun <C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.clickCopiesToClipboard(
fun <C : Component, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.clickCopiesToClipboard(
value: String,
) = clickEvent(ClickEvent.copyToClipboard(value))

Expand All @@ -100,8 +91,7 @@ fun <C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<
* @param amount The number of newline characters to append.
* @return The modified builder instance.
*/
@Suppress("DEPRECATION")
fun <C : BuildableComponent<C, B>, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.appendNewline(
fun <C : Component, B : ComponentBuilder<C, B>> ComponentBuilder<C, B>.appendNewline(
amount: Int,
) = repeat(amount) { appendNewline() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import java.util.*
* val myPointer = pointer<String>(myKey)
* ```
*/
inline fun <reified V> pointer(key: Key) = Pointer.pointer(V::class.java, key)
inline fun <reified V : Any> pointer(key: Key) = Pointer.pointer(V::class.java, key)

/**
* Creates an [Identity] instance using the provided [UUID].
Expand Down
Loading