Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Fixed a bug where system messages would kick the user
Browse files Browse the repository at this point in the history
  • Loading branch information
V1nc3ntWasTaken committed Aug 5, 2022
1 parent c8d53fa commit 7a41328
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/main/java/me/doclic/noencryption/PlayerListener.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package me.doclic.noencryption;

import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.ChannelPromise;
import me.doclic.noencryption.compatibility.*;
import io.netty.channel.*;
import me.doclic.noencryption.compatibility.CompatiblePacketListener;
import me.doclic.noencryption.compatibility.CompatiblePlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -20,7 +17,7 @@ public void onPlayerJoin (PlayerJoinEvent e) {

final Player player = e.getPlayer();
final ChannelPipeline pipeline = new CompatiblePlayer().getChannel(player).pipeline();
pipeline.addBefore("packet_handler", player.getUniqueId().toString(), new ChannelDuplexHandler() {
pipeline.addBefore("packet_handler", "no_encryption", new ChannelDuplexHandler() {

@Override
public void channelRead(ChannelHandlerContext channelHandlerContext, Object packet) throws Exception {
Expand All @@ -47,7 +44,7 @@ public void onPlayerQuit (PlayerQuitEvent e) {

final Player player = e.getPlayer();
final Channel channel = new CompatiblePlayer().getChannel(player);
channel.eventLoop().submit(() -> channel.pipeline().remove(player.getUniqueId().toString()));
channel.eventLoop().submit(() -> channel.pipeline().remove("no_encryption"));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import net.md_5.bungee.chat.ComponentSerializer;
import net.minecraft.network.chat.*;
import net.minecraft.network.protocol.game.ClientboundPlayerChatHeaderPacket;
import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket;
import net.minecraft.network.protocol.game.ClientboundSystemChatPacket;

import java.util.Optional;
import java.util.UUID;
Expand Down Expand Up @@ -40,6 +43,22 @@ public Object writePacket(ChannelHandlerContext channelHandlerContext, Object pa
chatType);
}

if (packet instanceof final ClientboundSystemChatPacket clientboundSystemChatPacket) {
return new ClientboundSystemChatPacket(
ComponentSerializer.parse(clientboundSystemChatPacket.content()),
clientboundSystemChatPacket.overlay());
}

if (packet instanceof final ClientboundPlayerChatHeaderPacket clientboundPlayerChatHeaderPacket) {
return new ClientboundPlayerChatHeaderPacket(
new SignedMessageHeader(
new MessageSignature(new byte[0]),
new UUID(0,0)),
new MessageSignature(new byte[0]),
clientboundPlayerChatHeaderPacket.bodyDigest()
);
}

return packet;

}
Expand Down

0 comments on commit 7a41328

Please sign in to comment.