From 40a45f3b5f6b7ba93c7177d8213c531bd5a83b25 Mon Sep 17 00:00:00 2001 From: Boy Date: Sat, 16 Dec 2023 14:14:40 +0100 Subject: [PATCH] fix: properly uninject channels --- .../emojy/nms/v1_19_R1/EmojyNMSHandler.kt | 15 ++++++--------- .../emojy/nms/v1_19_R2/EmojyNMSHandler.kt | 15 ++++++--------- .../emojy/nms/v1_19_R3/EmojyNMSHandler.kt | 11 ++++++----- .../emojy/nms/v1_20_R1/EmojyNMSHandler.kt | 7 ++----- .../emojy/nms/v1_20_R2/EmojyNMSHandler.kt | 2 +- .../emojy/nms/v1_20_R3/EmojyNMSHandler.kt | 2 +- 6 files changed, 22 insertions(+), 30 deletions(-) diff --git a/v1_19_R1/src/main/kotlin/com/mineinabyss/emojy/nms/v1_19_R1/EmojyNMSHandler.kt b/v1_19_R1/src/main/kotlin/com/mineinabyss/emojy/nms/v1_19_R1/EmojyNMSHandler.kt index 9d8f3c0..135b58e 100644 --- a/v1_19_R1/src/main/kotlin/com/mineinabyss/emojy/nms/v1_19_R1/EmojyNMSHandler.kt +++ b/v1_19_R1/src/main/kotlin/com/mineinabyss/emojy/nms/v1_19_R1/EmojyNMSHandler.kt @@ -19,10 +19,7 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.ListTag import net.minecraft.nbt.StringTag -import net.minecraft.network.Connection -import net.minecraft.network.FriendlyByteBuf -import net.minecraft.network.PacketEncoder -import net.minecraft.network.SkipPacketException +import net.minecraft.network.* import net.minecraft.network.protocol.Packet import net.minecraft.network.protocol.PacketFlow import net.minecraft.server.MinecraftServer @@ -126,15 +123,15 @@ class EmojyNMSHandler : IEmojyNMSHandler { private fun Channel.uninject() { if (this in encoder.keys) { - val prevHandler = encoder[this] + val prevHandler = encoder.remove(this) val handler = if (prevHandler is PacketEncoder) PacketEncoder(PacketFlow.CLIENTBOUND) else prevHandler - handler?.let { this.pipeline().replace(prevHandler, "encoder", handler) } + handler?.let { this.pipeline().replace("encoder", "encoder", handler) } } if (this in decoder.keys) { - val prevHandler = decoder[this] - val handler = if (prevHandler is PacketEncoder) PacketEncoder(PacketFlow.SERVERBOUND) else prevHandler - handler?.let { this.pipeline().replace(prevHandler, "decoder", handler) } + val prevHandler = decoder.remove(this) + val handler = if (prevHandler is PacketDecoder) PacketDecoder(PacketFlow.SERVERBOUND) else prevHandler + handler?.let { this.pipeline().replace("decoder", "decoder", handler) } } } diff --git a/v1_19_R2/src/main/kotlin/com/mineinabyss/emojy/nms/v1_19_R2/EmojyNMSHandler.kt b/v1_19_R2/src/main/kotlin/com/mineinabyss/emojy/nms/v1_19_R2/EmojyNMSHandler.kt index 2d5767f..d0a04bd 100644 --- a/v1_19_R2/src/main/kotlin/com/mineinabyss/emojy/nms/v1_19_R2/EmojyNMSHandler.kt +++ b/v1_19_R2/src/main/kotlin/com/mineinabyss/emojy/nms/v1_19_R2/EmojyNMSHandler.kt @@ -19,10 +19,7 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.ListTag import net.minecraft.nbt.StringTag -import net.minecraft.network.Connection -import net.minecraft.network.FriendlyByteBuf -import net.minecraft.network.PacketEncoder -import net.minecraft.network.SkipPacketException +import net.minecraft.network.* import net.minecraft.network.protocol.Packet import net.minecraft.network.protocol.PacketFlow import net.minecraft.server.MinecraftServer @@ -129,15 +126,15 @@ class EmojyNMSHandler : IEmojyNMSHandler { private fun Channel.uninject() { if (this in encoder.keys) { - val prevHandler = encoder[this] + val prevHandler = encoder.remove(this) val handler = if (prevHandler is PacketEncoder) PacketEncoder(PacketFlow.CLIENTBOUND) else prevHandler - handler?.let { this.pipeline().replace(prevHandler, "encoder", handler) } + handler?.let { this.pipeline().replace("encoder", "encoder", handler) } } if (this in decoder.keys) { - val prevHandler = decoder[this] - val handler = if (prevHandler is PacketEncoder) PacketEncoder(PacketFlow.SERVERBOUND) else prevHandler - handler?.let { this.pipeline().replace(prevHandler, "decoder", handler) } + val prevHandler = decoder.remove(this) + val handler = if (prevHandler is PacketDecoder) PacketDecoder(PacketFlow.SERVERBOUND) else prevHandler + handler?.let { this.pipeline().replace("decoder", "decoder", handler) } } } diff --git a/v1_19_R3/src/main/kotlin/com/mineinabyss/emojy/nms/v1_19_R3/EmojyNMSHandler.kt b/v1_19_R3/src/main/kotlin/com/mineinabyss/emojy/nms/v1_19_R3/EmojyNMSHandler.kt index 834123b..ab673de 100644 --- a/v1_19_R3/src/main/kotlin/com/mineinabyss/emojy/nms/v1_19_R3/EmojyNMSHandler.kt +++ b/v1_19_R3/src/main/kotlin/com/mineinabyss/emojy/nms/v1_19_R3/EmojyNMSHandler.kt @@ -21,6 +21,7 @@ import net.minecraft.nbt.ListTag import net.minecraft.nbt.StringTag import net.minecraft.network.Connection import net.minecraft.network.FriendlyByteBuf +import net.minecraft.network.PacketDecoder import net.minecraft.network.PacketEncoder import net.minecraft.network.SkipPacketException import net.minecraft.network.protocol.Packet @@ -134,15 +135,15 @@ class EmojyNMSHandler : IEmojyNMSHandler { private fun Channel.uninject() { if (this in encoder.keys) { - val prevHandler = encoder[this] + val prevHandler = encoder.remove(this) val handler = if (prevHandler is PacketEncoder) PacketEncoder(PacketFlow.CLIENTBOUND) else prevHandler - handler?.let { this.pipeline().replace(prevHandler, "encoder", handler) } + handler?.let { this.pipeline().replace("encoder", "encoder", handler) } } if (this in decoder.keys) { - val prevHandler = decoder[this] - val handler = if (prevHandler is PacketEncoder) PacketEncoder(PacketFlow.SERVERBOUND) else prevHandler - handler?.let { this.pipeline().replace(prevHandler, "decoder", handler) } + val prevHandler = decoder.remove(this) + val handler = if (prevHandler is PacketDecoder) PacketDecoder(PacketFlow.SERVERBOUND) else prevHandler + handler?.let { this.pipeline().replace("decoder", "decoder", handler) } } } diff --git a/v1_20_R1/src/main/kotlin/com/mineinabyss/emojy/nms/v1_20_R1/EmojyNMSHandler.kt b/v1_20_R1/src/main/kotlin/com/mineinabyss/emojy/nms/v1_20_R1/EmojyNMSHandler.kt index a322e02..46f207c 100644 --- a/v1_20_R1/src/main/kotlin/com/mineinabyss/emojy/nms/v1_20_R1/EmojyNMSHandler.kt +++ b/v1_20_R1/src/main/kotlin/com/mineinabyss/emojy/nms/v1_20_R1/EmojyNMSHandler.kt @@ -18,10 +18,7 @@ import io.netty.handler.codec.MessageToByteEncoder import net.minecraft.nbt.CompoundTag import net.minecraft.nbt.ListTag import net.minecraft.nbt.StringTag -import net.minecraft.network.Connection -import net.minecraft.network.FriendlyByteBuf -import net.minecraft.network.PacketEncoder -import net.minecraft.network.SkipPacketException +import net.minecraft.network.* import net.minecraft.network.protocol.Packet import net.minecraft.network.protocol.PacketFlow import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket @@ -128,7 +125,7 @@ class EmojyNMSHandler : IEmojyNMSHandler { if (this in decoder.keys) { val prevHandler = decoder.remove(this) - val handler = if (prevHandler is PacketEncoder) PacketEncoder(PacketFlow.SERVERBOUND) else prevHandler + val handler = if (prevHandler is PacketDecoder) PacketDecoder(PacketFlow.SERVERBOUND) else prevHandler handler?.let { this.pipeline().replace("decoder", "decoder", handler) } } } diff --git a/v1_20_R2/src/main/kotlin/com/mineinabyss/emojy/nms/v1_20_R2/EmojyNMSHandler.kt b/v1_20_R2/src/main/kotlin/com/mineinabyss/emojy/nms/v1_20_R2/EmojyNMSHandler.kt index d87da35..99a85be 100644 --- a/v1_20_R2/src/main/kotlin/com/mineinabyss/emojy/nms/v1_20_R2/EmojyNMSHandler.kt +++ b/v1_20_R2/src/main/kotlin/com/mineinabyss/emojy/nms/v1_20_R2/EmojyNMSHandler.kt @@ -126,7 +126,7 @@ class EmojyNMSHandler : IEmojyNMSHandler { if (this in decoder.keys) { val prevHandler = decoder.remove(this) - val handler = if (prevHandler is PacketEncoder) PacketEncoder(Connection.ATTRIBUTE_SERVERBOUND_PROTOCOL) else prevHandler + val handler = if (prevHandler is PacketDecoder) PacketDecoder(Connection.ATTRIBUTE_SERVERBOUND_PROTOCOL) else prevHandler handler?.let { this.pipeline().replace("decoder", "decoder", handler) } } } diff --git a/v1_20_R3/src/main/kotlin/com/mineinabyss/emojy/nms/v1_20_R3/EmojyNMSHandler.kt b/v1_20_R3/src/main/kotlin/com/mineinabyss/emojy/nms/v1_20_R3/EmojyNMSHandler.kt index 80be579..3055f03 100644 --- a/v1_20_R3/src/main/kotlin/com/mineinabyss/emojy/nms/v1_20_R3/EmojyNMSHandler.kt +++ b/v1_20_R3/src/main/kotlin/com/mineinabyss/emojy/nms/v1_20_R3/EmojyNMSHandler.kt @@ -126,7 +126,7 @@ class EmojyNMSHandler : IEmojyNMSHandler { if (this in decoder.keys) { val prevHandler = decoder.remove(this) - val handler = if (prevHandler is PacketEncoder) PacketEncoder(Connection.ATTRIBUTE_SERVERBOUND_PROTOCOL) else prevHandler + val handler = if (prevHandler is PacketDecoder) PacketDecoder(Connection.ATTRIBUTE_SERVERBOUND_PROTOCOL) else prevHandler handler?.let { this.pipeline().replace("decoder", "decoder", handler) } } }