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
4 changes: 3 additions & 1 deletion buildSrc/src/main/kotlin/core-convention.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ tasks {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE

val relocationPrefix: String by project
relocate("net.kyori.adventure.nbt", "$relocationPrefix.kyori.nbt")
relocate("net.kyori.adventure.nbt", "$relocationPrefix.kyori.nbt") {
exclude("net.kyori.adventure.nbt.api.**")
}
relocate("org.spongepowered.configurate", "$relocationPrefix.configurate")
}

Expand Down
2 changes: 1 addition & 1 deletion 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.1.2
group=dev.slne.surf.api
version=3.19.0
version=3.20.0
relocationPrefix=dev.slne.surf.api.libs
snapshot=false
3 changes: 3 additions & 0 deletions surf-api-core/surf-api-core/api/surf-api-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -8902,6 +8902,9 @@ public final class dev/slne/surf/api/core/nbt/InternalNbtBridge$Companion : dev/
}

public final class dev/slne/surf/api/core/nbt/Nbt_extensionKt {
public static final fun asTagHolder (Lnet/kyori/adventure/nbt/BinaryTag;)Lnet/kyori/adventure/nbt/api/BinaryTagHolder;
public static final fun decodeCompoundTag (Lnet/kyori/adventure/nbt/api/BinaryTagHolder;)Lnet/kyori/adventure/nbt/CompoundBinaryTag;
public static final fun decodeTag (Lnet/kyori/adventure/nbt/api/BinaryTagHolder;)Lnet/kyori/adventure/nbt/BinaryTag;
public static final fun isCollectionTag (Lnet/kyori/adventure/nbt/BinaryTag;)Z
public static final fun tagIterator (Lnet/kyori/adventure/nbt/ByteArrayBinaryTag;)Ljava/util/Iterator;
public static final fun tagIterator (Lnet/kyori/adventure/nbt/IntArrayBinaryTag;)Ljava/util/Iterator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,43 @@
package dev.slne.surf.api.core.nbt

import net.kyori.adventure.nbt.*
import net.kyori.adventure.nbt.api.BinaryTagHolder
import net.kyori.adventure.util.Codec
import java.io.IOException
import java.util.*
import java.util.stream.Stream
import java.util.stream.StreamSupport

private val binaryTagHolderCodec = object : Codec<BinaryTag, String, IOException, IOException> {
private val tagStringIO = TagStringIO.builder()
.acceptLegacy(false)
.build()

override fun decode(encoded: String): BinaryTag {
return tagStringIO.asTag(encoded)
}

override fun encode(decoded: BinaryTag): String {
return tagStringIO.asString(decoded)
}
}

fun BinaryTag.asTagHolder(): BinaryTagHolder {
return BinaryTagHolder.encode(this, binaryTagHolderCodec)
}
Comment thread
twisti-dev marked this conversation as resolved.

fun BinaryTagHolder.decodeTag(): BinaryTag {
return get(binaryTagHolderCodec)
}
Comment thread
twisti-dev marked this conversation as resolved.

fun BinaryTagHolder.decodeCompoundTag(): CompoundBinaryTag {
val decoded = get(binaryTagHolderCodec)
if (decoded !is CompoundBinaryTag) {
error("Expected a CompoundBinaryTag, but got ${decoded::class.simpleName}")
}
return decoded
}
Comment thread
twisti-dev marked this conversation as resolved.

fun BinaryTag.isCollectionTag() =
this is ListBinaryTag || this is ByteArrayBinaryTag || this is LongArrayBinaryTag || this is IntArrayBinaryTag

Expand Down
2 changes: 1 addition & 1 deletion surf-api-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ plugins {

group = groupId
version = buildString {
append("2.0.7")
append("2.0.8")
if (snapshot) append("-SNAPSHOT")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract class CommonSurfPlugin<E : CommonSurfExtension>(
"com.google.devtools.ksp"
)

private val relocations = mutableMapOf<String, String>()
private val relocations = mutableListOf<Relocation>()
private val dependencyDependentRelocations = mutableMapOf<String, MutableMap<String, String>>()

init {
Expand Down Expand Up @@ -70,7 +70,15 @@ abstract class CommonSurfPlugin<E : CommonSurfExtension>(
}

protected infix fun String.relocatesTo(to: String) {
relocations[this] = to
relocations += Relocation(this, to)
}

protected fun relocatePackage(
from: String,
to: String,
excludes: List<String> = emptyList(),
) {
relocations += Relocation(from, to, excludes)
}

fun addRelocationsForDependency(
Expand Down Expand Up @@ -116,8 +124,13 @@ abstract class CommonSurfPlugin<E : CommonSurfExtension>(

private fun Project.configure() {
tasks.withType<ShadowJar> {
relocations.forEach { (from, to) ->
relocate(from, "${Constants.RELOCATION_PREFIX}.$to")
relocations.forEach { relocation ->
relocate(
relocation.from,
"${Constants.RELOCATION_PREFIX}.${relocation.to}"
) {
relocation.excludes.forEach { exclude(it) }
}
}
}

Expand Down Expand Up @@ -285,4 +298,10 @@ abstract class CommonSurfPlugin<E : CommonSurfExtension>(

protected open fun Project.afterEvaluated0(extension: E) {
}

private data class Relocation(
val from: String,
val to: String,
val excludes: List<String> = emptyList(),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ internal abstract class AbstractCoreSurfPlugin<E : CoreSurfExtension>(
init {
"com.mojang.serialization" relocatesTo "mojang.serialization"
"com.mojang.datafixers" relocatesTo "mojang.datafixers"
"net.kyori.adventure.nbt" relocatesTo "kyori.nbt"
relocatePackage(
from = "net.kyori.adventure.nbt",
to = "kyori.nbt",
excludes = listOf("net.kyori.adventure.nbt.api.**")
)
}

final override fun Project.afterEvaluated0(extension: E) {
Expand Down