Skip to content

Commit

Permalink
✨ feat: Support 1.16.5
Browse files Browse the repository at this point in the history
  • Loading branch information
blank038 committed Dec 8, 2024
1 parent 8326d2b commit 9562d42
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ dependencies {
runtimeOnly(project(":common"))
runtimeOnly(project(":bukkit"))
runtimeOnly(project(":nms:v1_12_R1"))
runtimeOnly(project(":nms:v1_16_R3"))
}

tasks.register<ShadowJar>("shadowJarAll") {
Expand Down
5 changes: 5 additions & 0 deletions nms/v1_16_R3/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dependencies {
compileOnly(project(":bukkit"))
compileOnly("org.spigotmc:spigot:1.16.5-R0.1-SNAPSHOT")
compileOnly("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.aiyostudio.esync.internal.v1_16_R3

import com.aiyostudio.esync.internal.serializer.IDataSerializer
import io.netty.buffer.Unpooled
import net.minecraft.server.v1_16_R3.PacketDataSerializer
import net.minecraft.server.v1_16_R3.ServerStatisticManager
import net.minecraft.server.v1_16_R3.StatisticManager
import org.bukkit.Bukkit
import org.bukkit.craftbukkit.v1_16_R3.CraftServer
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack
import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack

class DataSerializer : IDataSerializer {

override fun serializerItem(itemStack: ItemStack): ByteArray {
val buf = Unpooled.buffer()
val packet = PacketDataSerializer(buf)
packet.a(CraftItemStack.asNMSCopy(itemStack))
return packet.array()
}

override fun deserializerItem(byteArray: ByteArray): ItemStack {
val buf = Unpooled.wrappedBuffer(byteArray)
val packet = PacketDataSerializer(buf)
return CraftItemStack.asBukkitCopy(packet.n())
}

override fun serializerStatistics(player: Player): String? {
val statisticManager = (player as CraftPlayer).handle.statisticManager
StatisticManager::class.java.declaredFields.find { it.name == "a" }?.let {
it.isAccessible = true
// reflect call
ServerStatisticManager::class.java.declaredMethods.find { method -> method.name == "b" }?.let { method ->
method.isAccessible = true
val result = method.invoke(statisticManager) as String
return result
}
}
return null
}

override fun deserializerStatistics(player: Player, str: String?): Boolean {
val statisticManager = (player as CraftPlayer).handle.statisticManager
statisticManager.a((Bukkit.getServer() as CraftServer).server.dataFixer, str)
return true
}
}
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ plugins {
}
rootProject.name = "eSync"

include("common", "bukkit", ":nms:v1_12_R1")
include("common", "bukkit", ":nms:v1_12_R1", ":nms:v1_16_R3")
include(":module:pixelmon-1.12.2")

0 comments on commit 9562d42

Please sign in to comment.