PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.96k stars 904 forks source link

How to catch a window closing? #1288

Closed ghost closed 4 years ago

ghost commented 4 years ago

Versions

Clear question

I tried to catch the window closing, but I couldn't do it. Can you show me an example?

What did you try yet?

I tried to use

bot.on('windowClose', (window) But I got nothing

Your current code


bot.on('windowClose', (window) => {
console.log("Window closed")
})

Additional context

rom1504 commented 4 years ago

https://github.com/PrismarineJS/mineflayer/blob/9b14ae7509c8eb1c48448c5b60bba1e99b5ef3e3/lib/plugins/inventory.js#L334

What kind of window is closing?

ghost commented 4 years ago

https://github.com/PrismarineJS/mineflayer/blob/9b14ae7509c8eb1c48448c5b60bba1e99b5ef3e3/lib/plugins/inventory.js#L334

What kind of window is closing?

server menu window

Karang commented 4 years ago

You can listen directly to the "close_window" packet as in https://github.com/PrismarineJS/mineflayer/blob/9b14ae7509c8eb1c48448c5b60bba1e99b5ef3e3/lib/plugins/inventory.js#L641

If you don't receive it, that means the server doesn't send a packet on window close (and the closing must happen client-side)