-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
49 changes: 49 additions & 0 deletions
49
nms/v1_16_R3/src/main/java/com/aiyostudio/esync/internal/v1_16_R3/DataSerializer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters