From 5db44566ab59077701ad6ba40116335294865618 Mon Sep 17 00:00:00 2001 From: Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> Date: Thu, 9 Dec 2021 19:58:26 +0800 Subject: Reset globals correctly after gameunload --- featureClass/featureManager.js | 10 ++++++++-- features/hud/index.js | 2 +- features/settings/settingsCommunicator.js | 8 +++++++- logger.js | 3 +++ metadata.js | 4 ++++ socketConnection.js | 4 ++++ 6 files changed, 27 insertions(+), 4 deletions(-) diff --git a/featureClass/featureManager.js b/featureClass/featureManager.js index ee99199..95fba3c 100644 --- a/featureClass/featureManager.js +++ b/featureClass/featureManager.js @@ -463,7 +463,7 @@ class FeatureManager { } loadFeatureMetas(){ - featuresDir = new File("./config/ChatTriggers/modules/" + metadata.name + "/features") + let featuresDir = new File("./config/ChatTriggers/modules/" + metadata.name + "/features") featuresDir.list().forEach((pathName)=>{ if(pathName.includes(".")) return; @@ -475,7 +475,10 @@ class FeatureManager { } data.id = pathName this.featureMetas[pathName] = data - }catch(_){} + }catch(e){ + console.log("Error loading feature metadata for " + pathName) + console.log(JSON.stringify(e, undefined, 2)) + } }) } @@ -571,6 +574,9 @@ class FeatureManager { if(!global.soopyv2featuremanagerthing){ global.soopyv2featuremanagerthing = new FeatureManager() + register("gameUnload", ()=>{ + global.soopyv2featuremanagerthing = undefined + }) } export default global.soopyv2featuremanagerthing diff --git a/features/hud/index.js b/features/hud/index.js index 8e2b826..e703db5 100644 --- a/features/hud/index.js +++ b/features/hud/index.js @@ -269,7 +269,7 @@ class Hud extends Feature { this.cpsElement.setText("&6Cps&7> &f" + cpsText) //Scan opened inventory for all pet levels - if(Player && Player.getOpenedInventory().getName().includes(") Pets")){ + if(Player && Player.getOpenedInventory() && Player.getOpenedInventory().getName().includes(") Pets")){ let inv = Player.getOpenedInventory().getItems() for(let i = 0; i < inv.length; i++){ if(inv[i]!=null && inv[i].getName().includes("[Lvl ")){ diff --git a/features/settings/settingsCommunicator.js b/features/settings/settingsCommunicator.js index d0a55fc..053a7c1 100644 --- a/features/settings/settingsCommunicator.js +++ b/features/settings/settingsCommunicator.js @@ -24,6 +24,12 @@ class SettingsCommunicator { } } -if(!global.soopyv2SettingsCommunicator) global.soopyv2SettingsCommunicator = new SettingsCommunicator() +if(!global.soopyv2SettingsCommunicator){ + global.soopyv2SettingsCommunicator = new SettingsCommunicator() + + register("gameUnload", ()=>{ + global.soopyv2SettingsCommunicator = undefined + }) +} export default global.soopyv2SettingsCommunicator \ No newline at end of file diff --git a/logger.js b/logger.js index cd6d4e2..9c27a93 100644 --- a/logger.js +++ b/logger.js @@ -39,5 +39,8 @@ if(!global.soopyv2loggerthing){ devs.push(Player.getUUID().toString().replace(/-/g, "")) }).setName("pleasegivemeaccesstosoopyv2devconsolelogs") //yep + register("gameUnload", ()=>{ + global.soopyv2loggerthing = undefined + }) } export default global.soopyv2loggerthing \ No newline at end of file diff --git a/metadata.js b/metadata.js index aa492b2..7aa6ac9 100644 --- a/metadata.js +++ b/metadata.js @@ -1,5 +1,9 @@ if(!global.soopyaddonsv2metathing){ global.soopyaddonsv2metathing = JSON.parse(FileLib.read("SoopyV2", "metadata.json")) + + register("gameUnload", ()=>{ + global.soopyaddonsv2metathing = undefined + }) } export default global.soopyaddonsv2metathing \ No newline at end of file diff --git a/socketConnection.js b/socketConnection.js index 23c72b0..96f9ceb 100644 --- a/socketConnection.js +++ b/socketConnection.js @@ -89,6 +89,10 @@ class SoopyV2Server extends WebsiteCommunicator { if(!global.soopyV2Server){ global.soopyV2Server = new SoopyV2Server() + + register("gameUnload", ()=>{ + global.soopyV2Server = undefined + }) } export default global.soopyV2Server \ No newline at end of file -- cgit