aboutsummaryrefslogtreecommitdiff
path: root/features/dataLoader/index.js
diff options
context:
space:
mode:
authorSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2021-10-31 09:49:42 +0800
committerSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2021-10-31 09:49:42 +0800
commit48653ec89538f1650106a5e77463412cad4684c2 (patch)
tree09687cd579462e04d539fd4615369fa6dae13902 /features/dataLoader/index.js
downloadSoopyV2-48653ec89538f1650106a5e77463412cad4684c2.tar.gz
SoopyV2-48653ec89538f1650106a5e77463412cad4684c2.tar.bz2
SoopyV2-48653ec89538f1650106a5e77463412cad4684c2.zip
first commit
Diffstat (limited to 'features/dataLoader/index.js')
-rw-r--r--features/dataLoader/index.js128
1 files changed, 128 insertions, 0 deletions
diff --git a/features/dataLoader/index.js b/features/dataLoader/index.js
new file mode 100644
index 0000000..41f0c61
--- /dev/null
+++ b/features/dataLoader/index.js
@@ -0,0 +1,128 @@
+/// <reference types="../../../CTAutocomplete" />
+/// <reference lib="es2015" />
+import Feature from "../../featureClass/class";
+
+class DataLoader extends Feature {
+ constructor() {
+ super()
+ }
+
+ onEnable(){
+ this.initVariables()
+
+ this.stats = {}
+
+ this.area = undefined
+
+ this.isInSkyblock = false
+
+ this.registerStep(true, 2, this.step)
+
+ this.registerEvent("worldLoad", this.worldLoad)
+
+ this.api_loaded_event = this.createCustomEvent("apiLoad")
+
+ this.lastApiData = {
+ "skyblock": undefined,
+ "player": undefined,
+ "skyblock_raw": undefined, //the _raw is loaded from hypixel api instead of soopy api
+ "player_raw": undefined
+ }
+
+ this.loadApi()
+ }
+
+ worldLoad(){
+ this.area = undefined
+ }
+
+ loadApi(){
+ let data = JSON.parse(FileLib.getUrlContent("http://soopymc.my.to/api/v2/player_skyblock/" + Player.getUUID().replace(/-/g, "")))
+
+ if(!data.success) return
+
+ this.api_loaded_event.trigger(data, "skyblock", true, true)
+ this.lastApiData.skyblock = data
+ }
+
+ loadApiData(type, soopyServer){
+ while(this.FeatureManager.features["globalSettings"] === undefined){
+ Thread.sleep(100)
+ }
+ let key = this.FeatureManager.features["globalSettings"].class.apiKeySetting.getValue()
+ if(!key) return
+
+ if(soopyServer){
+
+ }else{
+ if(type === "skyblock"){
+ let data = JSON.parse(FileLib.getUrlContent("https://api.hypixel.net/skyblock/profiles?key=" + key + "&uuid=" + Player.getUUID().replace(/-/g, "")))
+
+ if(!data.success) return
+
+ this.api_loaded_event.trigger(data, "skyblock", false, true)
+ this.lastApiData.skyblock_raw = data
+ }
+ }
+ }
+
+ step(){ //2fps
+ this.stats["Area"] = undefined
+ this.stats["Dungeon"] = undefined
+ TabList.getNames().forEach(n=>{
+ n = ChatLib.removeFormatting(n)
+ if(n.includes(": ")){
+ this.stats[n.split(": ")[0].trim()] = n.split(": ")[1].trim()
+ }
+ })
+ if(this.stats["Dungeon"]){
+ this.stats["Area"] = this.stats["Dungeon"]
+ this.isInDungeon = true
+ }else{
+ this.isInDungeon = false
+ }
+
+ this.dungeonFloor = undefined
+ Scoreboard.getLines().forEach(line=>{
+ let name = ChatLib.removeFormatting(line.getName()).replace(/[^A-z0-9 \:\(\)\.]/g, "")
+ if(this.isInDungeon){
+ if(name.includes("The Catacombs (")){
+ this.dungeonFloor = name.split("(")[1].split(")")[0].toUpperCase()
+ }
+ }
+ if(ChatLib.removeFormatting(line).startsWith(" ⏣ ")){
+ this.areaFine = ChatLib.removeFormatting(line).split(" ⏣ ")[1].replace(/[^A-z0-9 \:\(\)\.\-]/g, "")
+ }
+ if(name.startsWith("Purse: ")){
+ this.purse = parseInt(name.split("Purse: ")[1].split(" ")[0])
+ }
+ if(name.startsWith("Bits: ")){
+ this.bits = parseInt(name.split("Bits: ")[1].split(" ")[0])
+ }
+ })
+
+ this.isInSkyblock = Scoreboard.getTitle()?.removeFormatting().endsWith("SKYBLOCK")
+ this.area = this.stats["Area"]
+ }
+
+ initVariables(){
+ this.stats = undefined
+ this.isInDungeon = false
+
+ this.dungeonFloor = undefined
+ this.area = undefined
+ this.areaFine = undefined
+ this.bits = undefined
+ this.purse = undefined
+ this.lastApiData = undefined
+ this.isInSkyblock = undefined
+ }
+
+ onDisable(){
+ this.initVariables()
+ }
+}
+
+module.exports = {
+ class: new DataLoader()
+} \ No newline at end of file