diff options
author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-03-27 15:41:20 +0800 |
---|---|---|
committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-03-27 15:41:20 +0800 |
commit | 0cf3a67c2bbd4cdaa5d364436c9153e6456624f1 (patch) | |
tree | 03d6b37ee2f4109875050d61d63f363659031e6b /features/dataLoader | |
parent | b94794a3de8827f4bddb5251b010dc32943d79a1 (diff) | |
download | SoopyV2-0cf3a67c2bbd4cdaa5d364436c9153e6456624f1.tar.gz SoopyV2-0cf3a67c2bbd4cdaa5d364436c9153e6456624f1.tar.bz2 SoopyV2-0cf3a67c2bbd4cdaa5d364436c9153e6456624f1.zip |
make network requests all go on one permenantly open thread
Diffstat (limited to 'features/dataLoader')
-rw-r--r-- | features/dataLoader/index.js | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/features/dataLoader/index.js b/features/dataLoader/index.js index 7bf2bf9..f320ea6 100644 --- a/features/dataLoader/index.js +++ b/features/dataLoader/index.js @@ -1,6 +1,7 @@ /// <reference types="../../../CTAutocomplete" /> /// <reference lib="es2015" /> import Feature from "../../featureClass/class"; +import { fetch } from "../../utils/networkUtils"; class DataLoader extends Feature { constructor() { @@ -39,19 +40,18 @@ class DataLoader extends Feature { } loadApi(){ - try{ - let data = JSON.parse(FileLib.getUrlContent("http://soopymc.my.to/api/v2/player_skyblock/" + Player.getUUID().replace(/-/g, ""))) + fetch("http://soopymc.my.to/api/v2/player_skyblock/" + Player.getUUID().replace(/-/g, "")).json(data=>{ if(!data.success) return this.api_loaded_event.trigger(data, "skyblock", true, true) this.lastApiData.skyblock = data - }catch(e){} + }) } loadApiData(type, soopyServer){ - while(this.FeatureManager.features["globalSettings"] === undefined || this.FeatureManager.features["globalSettings"].class.apiKeySetting === undefined){ - Thread.sleep(100) + if(this.FeatureManager.features["globalSettings"] === undefined || this.FeatureManager.features["globalSettings"].class.apiKeySetting === undefined){ + return } let key = this.FeatureManager.features["globalSettings"].class.apiKeySetting.getValue() if(!key) return @@ -66,18 +66,12 @@ class DataLoader extends Feature { }else{ if(type === "skyblock"){ - try{ - // console.log("loading") - let data = JSON.parse(FileLib.getUrlContent("https://api.hypixel.net/skyblock/profiles?key=" + key + "&uuid=" + Player.getUUID().replace(/-/g, ""))) - + fetch("https://api.hypixel.net/skyblock/profiles?key=" + key + "&uuid=" + Player.getUUID().replace(/-/g, "")).json(data=>{ if(!data.success) return this.api_loaded_event.trigger(data, "skyblock", false, true) this.lastApiData.skyblock_raw = data - }catch(e){ - console.log("Hypixel api request failed:") - console.log(JSON.stringify(e, undefined, 2)) - } + }) } } } |