Skip to content

Commit c2a6828

Browse files
committed
migrated api, fixed toolchain (maybe)
1 parent c7e3249 commit c2a6828

11 files changed

+226
-210
lines changed

.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"presets": [],
33
"plugins": [
4-
"./babel-substitute-mappings/babel-substitute-mappings.mjs"
4+
"./babel-substitute-mappings/babel-substitute-mappings.js"
55
]
66
}

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
Data/roomdata.json
22
out
3-
node_modules
3+
node_modules
4+
.gradle
5+
.idea
6+
build
7+
.vscode

Components/DungeonMap.js

+24-44
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,8 @@ class DungeonMap {
140140

141141
mess.addTextComponent(new TextComponent("&6" + p.minRooms + "-" + p.maxRooms).setHover("show_text", roomLore.trim()))
142142

143-
if (settings.settings.apiKey) {
144-
mess.addTextComponent(new TextComponent("&7 rooms | &6" + p.secretsCollected + "&7 secrets"))
145-
}
146-
else {
147-
mess.addTextComponent(new TextComponent("&7 rooms and got &c[NO API KEY]&7 secrets"))
148-
}
143+
mess.addTextComponent(new TextComponent("&7 rooms | &6" + p.secretsCollected + "&7 secrets"))
144+
149145
mess.addTextComponent(new TextComponent("&7 | &6" + p.deaths + "&7 deaths"))
150146

151147
mess.chat()
@@ -183,16 +179,15 @@ class DungeonMap {
183179
}))
184180

185181
this.triggers.push(register("chat", (info) => {
186-
let player = ChatLib.removeFormatting(info).split(" ")[0]
187-
182+
let player = ChatLib.removeFormatting(info).split(" ")[0];
188183
for (let p of this.players) {
189-
if (p.username === player) {
190-
p.deaths++
191-
}
184+
if (p.username === player || p.username == Player.getName() && player.toLowerCase() === 'you') {
185+
p.deaths++;
186+
}
192187
}
193-
194-
this.scanFirstDeathForSpiritPet(player)
195-
}).setChatCriteria("&r&c ☠ ${info} and became a ghost&r&7.&r"))
188+
189+
this.scanFirstDeathForSpiritPet(player);
190+
}).setChatCriteria("&r&c ☠ ${info} became a ghost&r&7.&r"));
196191

197192
this.triggers.push(register("chat", (info) => {
198193
this.roomsArr.forEach(r => {
@@ -984,37 +979,22 @@ class DungeonMap {
984979
}
985980

986981
scanFirstDeathForSpiritPet(username) {
987-
if (this.firstDeath) return
988-
this.firstDeath = true
989-
990-
if (!this.nameToUuid[username.toLowerCase()]) return
991-
let uuid = this.nameToUuid[username.toLowerCase()]?.replace(/-/g, "")
992-
993-
let apiKey = settings.settings.apiKey
994-
982+
if (this.firstDeath) return;
983+
this.firstDeath = true;
984+
985+
if (!this.nameToUuid[username.toLowerCase()]) return;
986+
let uuid = this.nameToUuid[username.toLowerCase()]?.replace(/-/g, "");
987+
995988
const printSpiritMessage = () => {
996-
if (this.firstDeathHadSpirit) return ChatLib.chat(`${MESSAGE_PREFIX}${username} ${username == "You" ? "do" : "does"} have a spirit pet.`)
997-
ChatLib.chat(`${MESSAGE_PREFIX}${username} ${username == "You" ? "do" : "does"} not have a spirit pet.`)
998-
}
999-
1000-
if (apiKey) {
1001-
fetch(`https://api.hypixel.net/skyblock/profiles?key=${apiKey}&uuid=${uuid}`).json(data => {
1002-
if (!data.success) return
1003-
let latestProfile = data.profiles.find(a => a.selected)
1004-
if (!latestProfile) return // This shouldn't happen
1005-
this.firstDeathHadSpirit = latestProfile.members[uuid].pets.some(pet => pet.type === "SPIRIT" && pet.tier === "LEGENDARY")
1006-
printSpiritMessage()
1007-
})
1008-
}
1009-
else {
1010-
// Works without api key, api key still recommended though for secrets tracking
1011-
fetch(`https://soopy.dev/api/v2/player_skyblock/${uuid}`).json(data => {
1012-
if (!data.success) return
1013-
this.firstDeathHadSpirit = data.data.profiles[data.data.stats.currentProfileId].members[uuid].pets.some(pet => pet.type === "SPIRIT" && pet.tier === "LEGENDARY")
1014-
printSpiritMessage()
1015-
})
1016-
}
1017-
}
989+
if (this.firstDeathHadSpirit) return ChatLib.chat(`${MESSAGE_PREFIX}${username} ${username == "You" ? "do" : "does"} have a spirit pet.`);
990+
ChatLib.chat(`${MESSAGE_PREFIX}${username} ${username == "You" ? "do" : "does"} not have a spirit pet.`);
991+
};
992+
993+
fetch(`https://api.tenios.dev/spiritPet/${uuid}`).json((spirit) => {
994+
this.firstDeathHadSpirit = spirit
995+
printSpiritMessage();
996+
});
997+
}
1018998

1019999
secretCountActionBar(min, max) {
10201000
if (!this.canUpdateRoom()) return

Components/MapPlayer.js

+7-11
Original file line numberDiff line numberDiff line change
@@ -314,20 +314,16 @@ register("step", () => {
314314
function getPlayerSecrets(uuid, cacheMs, callback) {
315315

316316
if (secretsData.get(uuid)?.[0]?.timestamp > Date.now() - cacheMs) {
317-
callback(secretsData.get(uuid)[1])
318-
return
317+
callback(secretsData.get(uuid)[1]);
318+
return;
319319
}
320320

321-
let apiKey = settings.settings.apiKey
321+
fetch(`https://api.tenios.dev/secrets/${uuid}`).text((secretsNum) => {
322+
let secrets = parseInt(secretsNum);
323+
secretsData.set(uuid, [Date.now(), secrets]);
322324

323-
if (!apiKey) return
324-
fetch(`https://api.hypixel.net/player?key=${apiKey}&uuid=${uuid}`).json(data => {
325-
let secrets = data?.player?.achievements?.skyblock_treasure_hunter || 0
326-
327-
secretsData.set(uuid, [Date.now(), secrets])
328-
329-
callback(secretsData.get(uuid)[1])
330-
})
325+
callback(secretsData.get(uuid)[1]);
326+
});
331327
}
332328

333329
const markerSelf = new Image("markerSelf.png", "https://i.imgur.com/mwpjgRz.png");

Extra/Settings/Changelog.md

+6
Original file line numberDiff line numberDiff line change
@@ -135,4 +135,10 @@ First released version!
135135
@ver v1.0.15
136136
```diff
137137
! Fixed score calc breaking from changed tab list
138+
```
139+
140+
@ver v1.0.16
141+
```diff
142+
! Migrated secret count api
143+
! Fixed death counts for own player not working
138144
```

Extra/Settings/SettingGui.js

-141
Original file line numberDiff line numberDiff line change
@@ -343,15 +343,6 @@ class SettingGui {
343343

344344
this.addToggle("Spirit leap overlay", "spiritLeapOverlay", this.currentSettings.spiritLeapOverlay)[1].setLore(["You can click on player heads in overlay!", "Most people probs wont like the design though."])
345345

346-
this.addSidebarElement(new ButtonWithArrow().setText("&0Load api key from other mods").addEvent(new SoopyMouseClickEvent().setHandler(() => {
347-
findKey(key => {
348-
this.setApiKey(key)
349-
})
350-
})), 0.3, 0.4, 0.075)
351-
this.addSidebarElement() // Adds a gap because the button diddnt auto add one
352-
353-
this.apiKeySetting = this.addHiddenString("Api key", "apiKey", this.currentSettings.apiKey)[0]
354-
355346
this.addToggle("Show dev info", "devInfo", this.currentSettings.devInfo)
356347

357348
// END OF SETTINGS
@@ -402,21 +393,9 @@ class SettingGui {
402393
Renderer.drawRect(Renderer.color(0, 0, 0, this.backgroundOpacity.get()), 0, 0, Renderer.screen.getWidth(), Renderer.screen.getHeight())
403394
}
404395

405-
register("chat", (key, event) => { // Api key detection
406-
ChatLib.chat(MESSAGE_PREFIX + "Copied api key!")
407-
408-
this.setApiKey(key)
409-
}).setChatCriteria("&aYour new API key is &r&b${key}&r")
410-
411396
this.generateChangelog()
412397
}
413398

414-
setApiKey(key) {
415-
this.apiKeySetting.setText(key)
416-
417-
this.changed("apiKey", key)
418-
}
419-
420399
/**
421400
* Will add a gear to the right of the last added setting
422401
* @param {function():Boolean} shouldShowFun
@@ -738,126 +717,6 @@ class SettingGui {
738717

739718
export default SettingGui
740719

741-
742-
function verifyApiKeySync(key) {
743-
if (key) {
744-
try {
745-
var url = "https://api.hypixel.net/key?key=" + key
746-
let data = fetch(url).json()
747-
748-
return !!data.success
749-
} catch (e) {
750-
return false
751-
}
752-
} else {
753-
return false
754-
}
755-
}
756-
757-
const JavaString = Java.type("java.lang.String")
758-
const JavaLong = Java.type("java.lang.Long")
759-
const Files = Java.type("java.nio.file.Files")
760-
const Paths = Java.type("java.nio.file.Paths")
761-
/**
762-
* NOTE: this will display a notification with key finding information
763-
*/
764-
function findKey(callback = () => { }) {
765-
new Thread(() => {
766-
767-
// NEU
768-
try {
769-
let testKey = JSON.parse(new JavaString(Files.readAllBytes(Paths.get("./config/notenoughupdates/configNew.json")))).apiKey.apiKey
770-
if (testKey) {
771-
if (verifyApiKeySync(testKey)) {
772-
new Notification("§aSuccess!", ["Found api key in NotEnoughUpdates!"])
773-
callback(testKey)
774-
return;
775-
} else {
776-
console.log("[BETERMAP] Found invalid key in NotEnoughUpdates")
777-
}
778-
}
779-
} catch (_) { }
780-
781-
// SBE
782-
try {
783-
let testKey = JSON.parse(new JavaString(Files.readAllBytes(Paths.get("./config/SkyblockExtras.cfg")))).values.apiKey
784-
if (testKey) {
785-
if (verifyApiKeySync(testKey)) {
786-
new Notification("§aSuccess!", ["Found api key in SkyblockExtras!"])
787-
callback(testKey)
788-
return;
789-
} else {
790-
console.log("[BETERMAP] Found invalid key in SkyblockExtras")
791-
}
792-
}
793-
} catch (_) { }
794-
// SKYTILS
795-
try {
796-
let testKey2 = new JavaString(Files.readAllBytes(Paths.get("./config/skytils/config.toml")))
797-
let testKey = undefined
798-
testKey2.split("\n").forEach(line => {
799-
if (line.startsWith(" hypixel_api_key = \"")) {
800-
testKey = line.split("\"")[1]
801-
}
802-
})
803-
if (testKey) {
804-
if (verifyApiKeySync(testKey)) {
805-
new Notification("§aSuccess!", ["Found api key in Skytils!"])
806-
callback(testKey)
807-
return;
808-
} else {
809-
console.log("[BETERMAP] Found invalid key in Skytils")
810-
}
811-
}
812-
} catch (_) { }
813-
814-
// SOOPYADDONS DATA
815-
try {
816-
let testKey = FileLib.read("soopyAddonsData", "apikey.txt")
817-
if (testKey) {
818-
if (verifyApiKeySync(testKey)) {
819-
new Notification("§aSuccess!", ["Found api key in old soopyaddons version!"])
820-
callback(testKey)
821-
return;
822-
} else {
823-
console.log("[BETERMAP] Found invalid key in soopyaddonsData")
824-
}
825-
}
826-
} catch (_) { }
827-
828-
// SOOPYV2
829-
try {
830-
let testKey = JSON.parse(FileLib.read("soopyAddonsData", "soopyaddonsbetafeaturesdata.json")).globalSettings.subSettings.api_key.value
831-
if (testKey) {
832-
if (verifyApiKeySync(testKey)) {
833-
new Notification("§aSuccess!", ["Found api key in old soopyaddons version!"])
834-
callback(testKey)
835-
return;
836-
} else {
837-
console.log("[BETERMAP] Found invalid key in soopyaddonsData")
838-
}
839-
}
840-
} catch (_) { }
841-
842-
// HypixelApiKeyManager
843-
try {
844-
let testKey = JSON.parse(FileLib.read("HypixelApiKeyManager", "localdata.json")).key
845-
if (testKey) {
846-
if (verifyApiKeySync(testKey)) {
847-
new Notification("§aSuccess!", ["Found api key in HypixelApiKeyManager!"])
848-
callback(testKey)
849-
return;
850-
} else {
851-
console.log("[BETERMAP] Found invalid key in HypixelApiKeyManager")
852-
}
853-
}
854-
} catch (_) { }
855-
856-
857-
new Notification("§cUnable to find api key", [])
858-
}).start()
859-
}
860-
861720
function isNumber(val) {
862721
if (val.includes(".")) return false
863722
val = "" + val; // Coerce num to be a string

Render/RenderContext.js

-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
* @property {Boolean} spiritLeapOverlay - Show an overlay on the spirit leap gui
3636
* @property {Boolean} forcePaul - Wether to force enable the +10 score for paul (eg if jerry mayor)
3737
* @property {Boolean} clearedRoomInfo - Show a summory of what rooms people cleared after run finishes
38-
* @property {String} apiKey - The user's api key, or "" if unknown
3938
* @property {Boolean} devInfo - Wether to show def info in various places in the map
4039
* @property {[r:Number, g:Number, b:Number, a:number]} mapBorderColor - The RGBO value of the map border color
4140
* @property {[r:Number, g:Number, b:Number, a:number]} mapBackgroundColor - The RGBO value of the map backround color
@@ -204,10 +203,6 @@ class RenderContext {
204203
return this.settings.boxDoors
205204
}
206205

207-
get apiKey() {
208-
return this.settings.apiKey
209-
}
210-
211206
get devInfo() {
212207
return this.settings.devInfo
213208
}
@@ -449,7 +444,6 @@ class RenderContext {
449444
spiritLeapOverlay = false,
450445
forcePaul = false,
451446
clearedRoomInfo = true,
452-
apiKey = "",
453447
devInfo = false,
454448
boxDoors = true,
455449
mapBorderColor = [0, 0, 0, 255],
@@ -511,7 +505,6 @@ class RenderContext {
511505
spiritLeapOverlay,
512506
forcePaul,
513507
clearedRoomInfo,
514-
apiKey,
515508
devInfo,
516509
boxDoors,
517510
mapBorderColor,

0 commit comments

Comments
 (0)