diff options
author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-08-04 20:38:05 +0800 |
---|---|---|
committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-08-04 20:38:05 +0800 |
commit | a5dbdbac4598852fce436a20155616634fc4718f (patch) | |
tree | 9da797a77c4b4336465776319c012000c5d5d4ec | |
parent | c9d34afde5042076b41673f4a3de7aa9e23e7e3b (diff) | |
download | SoopyV2-a5dbdbac4598852fce436a20155616634fc4718f.tar.gz SoopyV2-a5dbdbac4598852fce436a20155616634fc4718f.tar.bz2 SoopyV2-a5dbdbac4598852fce436a20155616634fc4718f.zip |
item worth
-rw-r--r-- | features/globalSettings/index.js | 37 | ||||
-rw-r--r-- | socketConnection.js | 23 | ||||
-rw-r--r-- | utils/utils.js | 3 |
3 files changed, 61 insertions, 2 deletions
diff --git a/features/globalSettings/index.js b/features/globalSettings/index.js index c215ae8..e53c3f9 100644 --- a/features/globalSettings/index.js +++ b/features/globalSettings/index.js @@ -8,13 +8,13 @@ import firstLoadPages from "./firstLoadPages"; import GuiPage from "../soopyGui/GuiPage" import Notification from "../../../guimanager/Notification"; import logger from "../../logger"; -import soopyV2Server from "../../socketConnection"; import { numberWithCommas } from "../../utils/numberUtils"; import { firstLetterCapital } from "../../utils/stringUtils"; import { fetch } from "../../utils/networkUtils"; import socketConnection from "../../socketConnection"; import renderLibs from "../../../guimanager/renderLibs"; import { f } from "../../../mappings/mappings"; +import { addLore, getSBUUID } from "../../utils/utils"; const Files = Java.type("java.nio.file.Files") const Paths = Java.type("java.nio.file.Paths") const JavaString = Java.type("java.lang.String") @@ -48,6 +48,7 @@ class GlobalSettings extends Feature { this.hideFallingBlocks = new ToggleSetting("Hide falling blocks", "NOTE: this may cause more lag because of render entity event", false, "hide_falling_sand", this) this.twitchCommands = new ToggleSetting("Ingame twitch bot commands", "Allows u to use twitch bot commands ingame (eg -sa)", true, "twitch_commands_ingame", this) + this.itemWorth = new ToggleSetting("(Approximate) Item worth in lore", "Accounts for stuff like enchants/recombs ect", false, "item_worth", this) this.privacySettings = [] @@ -85,6 +86,12 @@ class GlobalSettings extends Feature { this.registerEvent("tick", this.fixNEU) } + this.requestingPrices = new Set() + this.registerStep(false, 1, this.updateItemPrices) + this.registerEvent("worldLoad", () => { + this.requestingPrices.clear() + }) + try { //This enables links from soopy.dev to be shown in patcher image preview let hasHost = false @@ -160,6 +167,34 @@ class GlobalSettings extends Feature { }) } + updateItemPrices() { + if (!this.itemWorth.getValue()) return; + + [...Player.getInventory().getItems(), ...Player.getContainer().getItems()].forEach(i => { + let uuid = getSBUUID(i) + if (!uuid) return + + let a = socketConnection.itemPricesCache.get(uuid) + + if (!a && socketConnection.itemPricesCache2.get(uuid)) { + a = socketConnection.itemPricesCache2.get(uuid) + socketConnection.itemPricesCache.set(uuid, a) + } + + if (a) { + addLore(i, "§eWorth: ", "§6$" + numberWithCommas(Math.round(a))) + return + } + + if (this.requestingPrices.has(uuid)) return + + this.requestingPrices.add(uuid) + + let json = i.getNBT().toObject() + socketConnection.requestItemPrice(json, uuid) + }) + } + // renderWebpage() { // let url = this.getField(Client.currentGui.get(), f.linkText) diff --git a/socketConnection.js b/socketConnection.js index 1c1a792..fbf6910 100644 --- a/socketConnection.js +++ b/socketConnection.js @@ -23,6 +23,9 @@ class SoopyV2Server extends WebsiteCommunicator { this.eventData = undefined + this.itemPricesCache = new Map() + this.itemPricesCache2 = new Map() + this.cookieCount = 0 this.cookieData = undefined this.cookieDataUpdated = 0 @@ -35,6 +38,22 @@ class SoopyV2Server extends WebsiteCommunicator { this.cookieDataUpdated = 0 } }).setDelay(60) + + register("worldLoad", () => { + this.itemPricesCache2.clear() + for (let val of this.itemPricesCache.values()) { + this.itemPricesCache2.set(val[0], val[1]) + } + this.itemPricesCache.clear() + }) + } + + requestItemPrice(json, uuid) { + this.sendData({ + type: "loadItemWorth", + id: uuid, + itemData: json + }) } joinApiQ() { @@ -109,9 +128,11 @@ class SoopyV2Server extends WebsiteCommunicator { this.chEvent = data.event } if (data.type === "api") { - if (this.apithingo) this.apithingo(data.uuid, data.packetId) } + if (data.type === "itemWorth") { + this.itemPricesCache.set(data.id, data.price) + } } onConnect() { diff --git a/utils/utils.js b/utils/utils.js index 504b3bf..15b5489 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -32,6 +32,9 @@ let utils = { getSBID: function (item) { return item?.getNBT()?.getCompoundTag("tag")?.getCompoundTag("ExtraAttributes")?.getString("id") || null }, + getSBUUID: function (item) { + return item?.getNBT()?.getCompoundTag("tag")?.getCompoundTag("ExtraAttributes")?.getString("uuid") || null + }, getSBEnchant: function (item, enchant) { return item?.getNBT()?.getCompoundTag("tag")?.getCompoundTag("ExtraAttributes")?.getCompoundTag("enchantments")?.getInteger(enchant) || null }, |