Skip to content

Commit

Permalink
fix: properly uninject channels
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy0000 committed Dec 16, 2023
1 parent d494342 commit 40a45f3
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}
Expand Down

0 comments on commit 40a45f3

Please sign in to comment.