Skip to content

Commit 321841d

Browse files
authored
refactor: update reflection proxies and improve JSON serialization for player stats (#291)
2 parents 46dfb04 + 77ad847 commit 321841d

6 files changed

Lines changed: 15 additions & 19 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=26.1.1
99
group=dev.slne.surf
10-
version=26.1.1-3.0.2
10+
version=26.1.1-3.0.3
1111
relocationPrefix=dev.slne.surf.api.libs
1212
snapshot=false

surf-api-paper/surf-api-paper-server/src/main/kotlin/dev/slne/surf/api/paper/server/impl/nms/bridges/SurfPaperNmsItemBridgeImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import dev.slne.surf.api.core.util.checkInstantiationByServiceLoader
55
import dev.slne.surf.api.paper.nms.NmsUseWithCaution
66
import dev.slne.surf.api.paper.nms.bridges.SurfPaperNmsItemBridge
77
import dev.slne.surf.api.paper.server.nms.nms
8-
import dev.slne.surf.api.paper.server.reflection.Reflection
98
import net.minecraft.core.component.DataComponentMap
109
import net.minecraft.core.component.DataComponents
1110
import org.bukkit.inventory.ItemType
@@ -25,6 +24,7 @@ class SurfPaperNmsItemBridgeImpl : SurfPaperNmsItemBridge {
2524
.addAll(nmsItem.components())
2625
.set(DataComponents.MAX_STACK_SIZE, maxStackSize)
2726
.build()
28-
Reflection.ITEM_PROXY.setComponents(nmsItem, updatedComponents)
27+
28+
nmsItem.builtInRegistryHolder().bindComponents(updatedComponents)
2929
}
3030
}

surf-api-paper/surf-api-paper-server/src/main/kotlin/dev/slne/surf/api/paper/server/impl/nms/bridges/SurfPaperNmsStatsBridgeImpl.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class SurfPaperNmsStatsBridgeImpl : SurfPaperNmsStatsBridge {
1616
}
1717

1818
override fun getPlayerStatsAsJson(player: Player): String {
19-
return Reflection.SERVER_STATS_COUNTER_PROXY.toJson(player.toNms().stats)
19+
val gson = Reflection.SERVER_STATS_COUNTER_PROXY.getGson()
20+
val jsonElement = Reflection.SERVER_STATS_COUNTER_PROXY.toJson(player.toNms().stats)
21+
return gson.toJson(jsonElement)
2022
}
2123

2224
override fun savePlayerStatsToFile(player: Player) {

surf-api-paper/surf-api-paper-server/src/main/kotlin/dev/slne/surf/api/paper/server/reflection/ItemProxy.kt

Lines changed: 0 additions & 12 deletions
This file was deleted.

surf-api-paper/surf-api-paper-server/src/main/kotlin/dev/slne/surf/api/paper/server/reflection/Reflection.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import xyz.jpenilla.reflectionremapper.proxy.ReflectionProxyFactory
88

99
object Reflection {
1010
val SERVER_STATS_COUNTER_PROXY: ServerStatsCounterProxy
11-
val ITEM_PROXY: ItemProxy
1211
val ENTITY_PROXY: EntityProxy
1312
val SERVER_CONNECTION_LISTENER_PROXY: ServerConnectionListenerProxy
1413
val JAVA_PLUGIN_PROXY: JavaPluginProxy
@@ -21,7 +20,6 @@ object Reflection {
2120
ReflectionProxyFactory.create(remapper, Reflection::class.java.classLoader)
2221

2322
SERVER_STATS_COUNTER_PROXY = proxyFactory.reflectionProxy<ServerStatsCounterProxy>()
24-
ITEM_PROXY = SurfReflection.createProxy<ItemProxy>()
2523
ENTITY_PROXY = proxyFactory.reflectionProxy<EntityProxy>()
2624
SERVER_CONNECTION_LISTENER_PROXY =
2725
proxyFactory.reflectionProxy<ServerConnectionListenerProxy>()
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
package dev.slne.surf.api.paper.server.reflection
22

3+
import com.google.gson.Gson
4+
import com.google.gson.JsonElement
35
import net.minecraft.stats.ServerStatsCounter
6+
import xyz.jpenilla.reflectionremapper.proxy.annotation.FieldGetter
47
import xyz.jpenilla.reflectionremapper.proxy.annotation.MethodName
58
import xyz.jpenilla.reflectionremapper.proxy.annotation.Proxies
9+
import xyz.jpenilla.reflectionremapper.proxy.annotation.Static
610

711
@Proxies(ServerStatsCounter::class)
812
interface ServerStatsCounterProxy {
913

1014
@MethodName("toJson")
11-
fun toJson(statsCounter: ServerStatsCounter): String
15+
fun toJson(statsCounter: ServerStatsCounter): JsonElement
16+
17+
@FieldGetter("GSON")
18+
@Static
19+
fun getGson(): Gson
1220
}

0 commit comments

Comments
 (0)