[1.20.2] Fix custom payload packet logic
Signed-off-by: Irmo van den Berge <irmo.vandenberge@ziggo.nl>
This commit is contained in:
1 parent
c4b72dc4f4
commit
1f10dbf6ae
2 files changed
+31
-9
No files matched your search
@@ -716,7 +716,7 @@ public class CommonBootstrap {
|
||||
}
|
||||
}
|
||||
if (anonTypeName != null) {
|
||||
remappings.put("net.minecraft.network.protocol.common.BukkitCustomPayload", anonTypeName);
|
||||
remappings.put("net.minecraft.network.protocol.common.custom.BukkitCustomPayload", anonTypeName);
|
||||
} else {
|
||||
Logging.LOGGER_REFLECTION.log(Level.WARNING, "Unable to identify the Bukkit custom payload type");
|
||||
}
|
||||
|
||||
+30
-8
@@ -4,11 +4,13 @@ import net.minecraft.network.protocol.Packet;
|
||||
import net.minecraft.network.chat.IChatBaseComponent;
|
||||
import net.minecraft.network.PacketDataSerializer;
|
||||
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||
import net.minecraft.network.protocol.common.custom.BukkitCustomPayload;
|
||||
|
||||
import com.bergerkiller.bukkit.common.wrappers.ChatText;
|
||||
|
||||
import com.bergerkiller.generated.net.minecraft.network.protocol.common.ClientboundKeepAlivePacketHandle;
|
||||
import com.bergerkiller.generated.net.minecraft.network.protocol.common.ClientboundCustomPayloadPacketHandle;
|
||||
import com.bergerkiller.generated.net.minecraft.resources.MinecraftKeyHandle;
|
||||
|
||||
class ServerboundKeepAlivePacket extends Packet {
|
||||
#if version >= 1.12.2
|
||||
@@ -127,8 +129,8 @@ class ClientboundCustomPayloadPacket extends Packet {
|
||||
// Get channel name (Bukkit custom payload packet only)
|
||||
public String getChannel() {
|
||||
#if version >= 1.20.2
|
||||
//TODO: Implement this
|
||||
#error NOT IMPLEMENTED
|
||||
net.minecraft.resources.MinecraftKey channel = instance.payload().id();
|
||||
return (channel == null) ? null : channel.toString();
|
||||
#elseif version >= 1.13
|
||||
#select version >=
|
||||
#case 1.17: #require ClientboundCustomPayloadPacket private final net.minecraft.resources.MinecraftKey channel:identifier;
|
||||
@@ -145,12 +147,20 @@ class ClientboundCustomPayloadPacket extends Packet {
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
// Read raw payload
|
||||
public byte[] getMessage() {
|
||||
#if version >= 1.20.2
|
||||
//TODO: Implement this
|
||||
#error NOT IMPLEMENTED
|
||||
CustomPacketPayload payload = instance.payload();
|
||||
if (payload instanceof BukkitCustomPayload) {
|
||||
#require BukkitCustomPayload private final byte[] message:val$message;
|
||||
return payload#message;
|
||||
} else {
|
||||
// Use serializer with a byte buffer
|
||||
io.netty.buffer.ByteBuf buf = io.netty.buffer.Unpooled.buffer();
|
||||
PacketDataSerializer serializer = new PacketDataSerializer(io.netty.buffer.Unpooled.buffer());
|
||||
payload.write(serializer);
|
||||
return java.util.Arrays.copyOf(buf.array(), buf.writerIndex());
|
||||
}
|
||||
#else
|
||||
#select version >=
|
||||
#case 1.17: #require ClientboundCustomPayloadPacket private final PacketDataSerializer payload_data:data;
|
||||
@@ -168,10 +178,22 @@ class ClientboundCustomPayloadPacket extends Packet {
|
||||
// Constructor
|
||||
public static (ClientboundCustomPayloadPacketHandle) ClientboundCustomPayloadPacket createNew(String channel, byte[] message) {
|
||||
#if version >= 1.20.2
|
||||
net.minecraft.resources.MinecraftKey key;
|
||||
key = (net.minecraft.resources.MinecraftKey) MinecraftKeyHandle.createNew(channel).getRaw();
|
||||
|
||||
// Warning: this type is fake and is remapped in CommonBootstrap to an anonymous class in CraftPlayer!
|
||||
// TODO: Implement this stuff!
|
||||
#error NOT IMPLEMENTED
|
||||
CustomPacketPayload payload = new net.minecraft.network.protocol.common.BukkitCustomPayload(???);
|
||||
// If the server was built with a newer JDK the CraftPlayer argument may have been dropped as well - future-proof it!
|
||||
#if exists net.minecraft.network.protocol.common.custom.BukkitCustomPayload BukkitCustomPayload(org.bukkit.craftbukkit.entity.CraftPlayer p, byte[] message, net.minecraft.resources.MinecraftKey channel);
|
||||
#require BukkitCustomPayload BukkitCustomPayload createCustom:<init>(org.bukkit.craftbukkit.entity.CraftPlayer p, byte[] message, net.minecraft.resources.MinecraftKey channel);
|
||||
CustomPacketPayload payload = BukkitCustomPayload#createCustom(null, message, key);
|
||||
#elseif exists net.minecraft.network.protocol.common.custom.BukkitCustomPayload BukkitCustomPayload(byte[] message, net.minecraft.resources.MinecraftKey channel);
|
||||
#require BukkitCustomPayload BukkitCustomPayload createCustom:<init>(byte[] message, net.minecraft.resources.MinecraftKey channel);
|
||||
CustomPacketPayload payload = BukkitCustomPayload#createCustom(message, key);
|
||||
#else
|
||||
#error Missing BukkitCustomPayload constructor we can use!
|
||||
#endif
|
||||
|
||||
return new ClientboundCustomPayloadPacket(payload);
|
||||
#else
|
||||
PacketDataSerializer serializer = new PacketDataSerializer(io.netty.buffer.Unpooled.wrappedBuffer(message));
|
||||
|
||||
|
||||
Reference in new issue
Block a user