aboutsummaryrefslogtreecommitdiff
path: root/features/dataLoader
diff options
context:
space:
mode:
Diffstat (limited to 'features/dataLoader')
-rw-r--r--features/dataLoader/index.js128
-rw-r--r--features/dataLoader/metadata.json8
2 files changed, 136 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
diff --git a/features/dataLoader/metadata.json b/features/dataLoader/metadata.json
new file mode 100644
index 0000000..4953f99
--- /dev/null
+++ b/features/dataLoader/metadata.json
@@ -0,0 +1,8 @@
+{
+ "name": "Data loader",
+ "description": "Loads data",
+ "isHidden": true,
+ "isTogglable": false,
+ "defaultEnabled": true,
+ "sortA": 0
+} \ No newline at end of file