azalea-rs / azalea

A collection of Rust crates for making Minecraft bots, clients, and tools.
https://azalea.matdoes.dev
MIT License
399 stars 50 forks source link

added disconnect reason #114

Closed 1zun4 closed 11 months ago

1zun4 commented 11 months ago

Hello there,

with this PR I have added the possibility to catch disconnect events and their reason easily.

But here is an issue that I am facing and cannot figure out how to fix: When the server disconnects us from the game, we normally get ClientboundGamePacket::Disconnect but the connection is closed before we can read the packet and fire the event with an reason. This causes us to not get the actual disconnect message and I really need HELP with this issue.

1zun4 commented 11 months ago

How it should look like (disconnect by Velocity). image

How it fails (disconnect by plugin): image

Seems Velocity, when disconnected by plugin, sends it as ClientboundCustomPayloadPacket, that explains why I could not capture it as ClientboundGamePacket::Disconnect.

Edit: Might handle custom payloads (as disconnect), for my use-case this https://github.com/CCBlueX/azalea/commit/86db6816775fcb9119640c93ed4dd860d7911c80 is enough. Also might not parse it already, as it does not always use the standarised ResourceLocation format.