feat: bukkit chat support 1.17
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
dbe9657b26
commit
a4368cc9ba
@ -15,6 +15,7 @@ let downgrade = false
|
|||||||
* 获取NMS版本
|
* 获取NMS版本
|
||||||
*/
|
*/
|
||||||
let nmsVersion = undefined
|
let nmsVersion = undefined
|
||||||
|
let nmsSubVersion = undefined
|
||||||
/**
|
/**
|
||||||
* 获取NMS类
|
* 获取NMS类
|
||||||
*/
|
*/
|
||||||
@ -49,15 +50,23 @@ function remapFieldName(clazz: any, origin: string, test: string) {
|
|||||||
function init() {
|
function init() {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
nmsVersion = org.bukkit.Bukkit.server.class.name.split('.')[3]
|
nmsVersion = org.bukkit.Bukkit.server.class.name.split('.')[3]
|
||||||
|
nmsSubVersion = nmsVersion.split("_")[1]
|
||||||
try {
|
try {
|
||||||
RemapUtils = Java.type('catserver.server.remapper.RemapUtils')
|
RemapUtils = Java.type('catserver.server.remapper.RemapUtils')
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
}
|
}
|
||||||
let nmsChatSerializerClass = nmsCls(nmsVersion.split("_")[1] > 7 ? "IChatBaseComponent$ChatSerializer" : "ChatSerializer")
|
let nmsChatSerializerClass = undefined
|
||||||
|
if (nmsSubVersion < 8) {
|
||||||
|
nmsChatSerializerClass = nmsCls("ChatSerializer")
|
||||||
|
} else if (nmsSubVersion < 17) {
|
||||||
|
nmsChatSerializerClass = nmsCls("IChatBaseComponent$ChatSerializer")
|
||||||
|
} else {
|
||||||
|
nmsChatSerializerClass = base.getClass('net.minecraft.network.chat.IChatBaseComponent$ChatSerializer')
|
||||||
|
}
|
||||||
let nmsChatSerializerMethod = remapMethod(nmsChatSerializerClass, 'a', 'func_150699_a', base.getClass('java.lang.String'))
|
let nmsChatSerializerMethod = remapMethod(nmsChatSerializerClass, 'a', 'func_150699_a', base.getClass('java.lang.String'))
|
||||||
nmsChatSerializerMethodName = nmsChatSerializerMethod.getName()
|
nmsChatSerializerMethodName = nmsChatSerializerMethod.getName()
|
||||||
ChatSerializer = Java.type(nmsChatSerializerClass.getName())
|
ChatSerializer = Java.type(nmsChatSerializerClass.getName())
|
||||||
let packetTypeClass = nmsCls("PacketPlayOutChat")
|
let packetTypeClass = nmsSubVersion < 17 ? nmsCls("PacketPlayOutChat") : base.getClass('net.minecraft.network.protocol.game.PacketPlayOutChat')
|
||||||
PacketPlayOutChat = Java.type(packetTypeClass.getName())
|
PacketPlayOutChat = Java.type(packetTypeClass.getName())
|
||||||
let packetTypeConstructor: { parameterTypes: any[] }
|
let packetTypeConstructor: { parameterTypes: any[] }
|
||||||
let constructors = packetTypeClass.constructors
|
let constructors = packetTypeClass.constructors
|
||||||
@ -75,9 +84,14 @@ function init() {
|
|||||||
if (nmsChatMessageTypeClass.isEnum()) {
|
if (nmsChatMessageTypeClass.isEnum()) {
|
||||||
chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants()
|
chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants()
|
||||||
}
|
}
|
||||||
let playerConnectionField = remapFieldName(nmsCls('EntityPlayer'), 'playerConnection', 'field_71135_a')
|
let playerConnectionField = undefined
|
||||||
|
if (nmsSubVersion < 17) {
|
||||||
|
playerConnectionField = remapFieldName(nmsCls('EntityPlayer'), 'playerConnection', 'field_71135_a')
|
||||||
|
} else {
|
||||||
|
playerConnectionField = base.getClass('net.minecraft.server.level.EntityPlayer').getField('b')
|
||||||
|
}
|
||||||
playerConnectionFieldName = playerConnectionField.getName()
|
playerConnectionFieldName = playerConnectionField.getName()
|
||||||
sendPacketMethodName = remapMethod(playerConnectionField.getType(), 'sendPacket', 'func_179290_a', nmsCls('Packet')).getName()
|
sendPacketMethodName = remapMethod(playerConnectionField.getType(), 'sendPacket', 'func_179290_a', nmsSubVersion < 17 ? nmsCls('Packet') : base.getClass('net.minecraft.network.protocol.Packet')).getName()
|
||||||
}
|
}
|
||||||
|
|
||||||
function json(sender: { name: string }, json: string) {
|
function json(sender: { name: string }, json: string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user