Skip to content

Commit 1911272

Browse files
authored
Bump version to 3.20.0 and refactor binary tag handling (#369)
2 parents 7db0de7 + 289a2b2 commit 1911272

7 files changed

Lines changed: 69 additions & 8 deletions

File tree

buildSrc/src/main/kotlin/core-convention.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ tasks {
7171
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
7272

7373
val relocationPrefix: String by project
74-
relocate("net.kyori.adventure.nbt", "$relocationPrefix.kyori.nbt")
74+
relocate("net.kyori.adventure.nbt", "$relocationPrefix.kyori.nbt") {
75+
exclude("net.kyori.adventure.nbt.api.**")
76+
}
7577
relocate("org.spongepowered.configurate", "$relocationPrefix.configurate")
7678
}
7779

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=26.1.2
99
group=dev.slne.surf.api
10-
version=3.19.0
10+
version=3.20.0
1111
relocationPrefix=dev.slne.surf.api.libs
1212
snapshot=false

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8902,6 +8902,9 @@ public final class dev/slne/surf/api/core/nbt/InternalNbtBridge$Companion : dev/
89028902
}
89038903

89048904
public final class dev/slne/surf/api/core/nbt/Nbt_extensionKt {
8905+
public static final fun asTagHolder (Lnet/kyori/adventure/nbt/BinaryTag;)Lnet/kyori/adventure/nbt/api/BinaryTagHolder;
8906+
public static final fun decodeCompoundTag (Lnet/kyori/adventure/nbt/api/BinaryTagHolder;)Lnet/kyori/adventure/nbt/CompoundBinaryTag;
8907+
public static final fun decodeTag (Lnet/kyori/adventure/nbt/api/BinaryTagHolder;)Lnet/kyori/adventure/nbt/BinaryTag;
89058908
public static final fun isCollectionTag (Lnet/kyori/adventure/nbt/BinaryTag;)Z
89068909
public static final fun tagIterator (Lnet/kyori/adventure/nbt/ByteArrayBinaryTag;)Ljava/util/Iterator;
89078910
public static final fun tagIterator (Lnet/kyori/adventure/nbt/IntArrayBinaryTag;)Ljava/util/Iterator;

surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/nbt/nbt-extension.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,43 @@
11
package dev.slne.surf.api.core.nbt
22

33
import net.kyori.adventure.nbt.*
4+
import net.kyori.adventure.nbt.api.BinaryTagHolder
5+
import net.kyori.adventure.util.Codec
6+
import java.io.IOException
47
import java.util.*
58
import java.util.stream.Stream
69
import java.util.stream.StreamSupport
710

11+
private val binaryTagHolderCodec = object : Codec<BinaryTag, String, IOException, IOException> {
12+
private val tagStringIO = TagStringIO.builder()
13+
.acceptLegacy(false)
14+
.build()
15+
16+
override fun decode(encoded: String): BinaryTag {
17+
return tagStringIO.asTag(encoded)
18+
}
19+
20+
override fun encode(decoded: BinaryTag): String {
21+
return tagStringIO.asString(decoded)
22+
}
23+
}
24+
25+
fun BinaryTag.asTagHolder(): BinaryTagHolder {
26+
return BinaryTagHolder.encode(this, binaryTagHolderCodec)
27+
}
28+
29+
fun BinaryTagHolder.decodeTag(): BinaryTag {
30+
return get(binaryTagHolderCodec)
31+
}
32+
33+
fun BinaryTagHolder.decodeCompoundTag(): CompoundBinaryTag {
34+
val decoded = get(binaryTagHolderCodec)
35+
if (decoded !is CompoundBinaryTag) {
36+
error("Expected a CompoundBinaryTag, but got ${decoded::class.simpleName}")
37+
}
38+
return decoded
39+
}
40+
841
fun BinaryTag.isCollectionTag() =
942
this is ListBinaryTag || this is ByteArrayBinaryTag || this is LongArrayBinaryTag || this is IntArrayBinaryTag
1043

surf-api-gradle-plugin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ plugins {
2020

2121
group = groupId
2222
version = buildString {
23-
append("2.0.7")
23+
append("2.0.8")
2424
if (snapshot) append("-SNAPSHOT")
2525
}
2626

surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/api/gradle/platform/common/CommonSurfPlugin.kt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ abstract class CommonSurfPlugin<E : CommonSurfExtension>(
3535
"com.google.devtools.ksp"
3636
)
3737

38-
private val relocations = mutableMapOf<String, String>()
38+
private val relocations = mutableListOf<Relocation>()
3939
private val dependencyDependentRelocations = mutableMapOf<String, MutableMap<String, String>>()
4040

4141
init {
@@ -70,7 +70,15 @@ abstract class CommonSurfPlugin<E : CommonSurfExtension>(
7070
}
7171

7272
protected infix fun String.relocatesTo(to: String) {
73-
relocations[this] = to
73+
relocations += Relocation(this, to)
74+
}
75+
76+
protected fun relocatePackage(
77+
from: String,
78+
to: String,
79+
excludes: List<String> = emptyList(),
80+
) {
81+
relocations += Relocation(from, to, excludes)
7482
}
7583

7684
fun addRelocationsForDependency(
@@ -116,8 +124,13 @@ abstract class CommonSurfPlugin<E : CommonSurfExtension>(
116124

117125
private fun Project.configure() {
118126
tasks.withType<ShadowJar> {
119-
relocations.forEach { (from, to) ->
120-
relocate(from, "${Constants.RELOCATION_PREFIX}.$to")
127+
relocations.forEach { relocation ->
128+
relocate(
129+
relocation.from,
130+
"${Constants.RELOCATION_PREFIX}.${relocation.to}"
131+
) {
132+
relocation.excludes.forEach { exclude(it) }
133+
}
121134
}
122135
}
123136

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

286299
protected open fun Project.afterEvaluated0(extension: E) {
287300
}
301+
302+
private data class Relocation(
303+
val from: String,
304+
val to: String,
305+
val excludes: List<String> = emptyList(),
306+
)
288307
}

surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/api/gradle/platform/core/CoreSurfPlugin.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ internal abstract class AbstractCoreSurfPlugin<E : CoreSurfExtension>(
1010
init {
1111
"com.mojang.serialization" relocatesTo "mojang.serialization"
1212
"com.mojang.datafixers" relocatesTo "mojang.datafixers"
13-
"net.kyori.adventure.nbt" relocatesTo "kyori.nbt"
13+
relocatePackage(
14+
from = "net.kyori.adventure.nbt",
15+
to = "kyori.nbt",
16+
excludes = listOf("net.kyori.adventure.nbt.api.**")
17+
)
1418
}
1519

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

0 commit comments

Comments
 (0)