From 7f65e46a048f1bc2b57775d84b32400dce707321 Mon Sep 17 00:00:00 2001 From: Vitaly Turovsky Date: Sat, 13 Jul 2024 05:48:53 +0300 Subject: [PATCH] properly cleanup all entities --- lib/plugins/entities.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/plugins/entities.js b/lib/plugins/entities.js index 05f3b9ac1..389c83db0 100644 --- a/lib/plugins/entities.js +++ b/lib/plugins/entities.js @@ -95,6 +95,7 @@ function inject (bot) { bot._client.on('login', (packet) => { bot.players = {} bot.uuidToUsername = {} + removeAllEntities() bot.entities = {} // login bot.entity = fetchEntity(packet.entityId) @@ -115,6 +116,18 @@ function inject (bot) { bot.emit('entityEquip', entity) }) + const removeAllEntities = () => { + for (const entity of Object.values(bot.entities ?? {})) { + // refactor to function + bot.emit('entityGone', entity) + entity.isValid = false + if (entity.username && bot.players[entity.username]) { + bot.players[entity.username].entity = null + } + delete bot.entities[entity.id] + } + } + bot._client.on('bed', (packet) => { // use bed const entity = fetchEntity(packet.entityId)