diff options
author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-06-25 17:12:12 +0800 |
---|---|---|
committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-06-25 17:12:12 +0800 |
commit | b1bc366e52cf719f0e3f01719fd787e7873baf84 (patch) | |
tree | 4c744c4829db830855e54269b1b14004d61e644e | |
parent | ce4f287e9bce572bcb6512fd42d4b299ea846687 (diff) | |
download | SoopyV2-b1bc366e52cf719f0e3f01719fd787e7873baf84.tar.gz SoopyV2-b1bc366e52cf719f0e3f01719fd787e7873baf84.tar.bz2 SoopyV2-b1bc366e52cf719f0e3f01719fd787e7873baf84.zip |
+ changes
-rw-r--r-- | featureClass/featureManager.js | 151 | ||||
-rw-r--r-- | features/suggestionsGui/index.js | 150 | ||||
-rw-r--r-- | utils/networkUtils.js | 20 |
3 files changed, 198 insertions, 123 deletions
diff --git a/featureClass/featureManager.js b/featureClass/featureManager.js index ba6bcfb..5200b57 100644 --- a/featureClass/featureManager.js +++ b/featureClass/featureManager.js @@ -18,9 +18,10 @@ let StrongCachingModuleScriptProvider = new StrongCachingModuleScriptProviderCla let CTRequire = new JSLoader.CTRequire(StrongCachingModuleScriptProvider) let loadedModules = new Set() +let shouldRequireNoCache = true function RequireNoCache(place) { - if (!logger.isDev) return require(place) + if (!logger.isDev && shouldRequireNoCache) return require(place) if (!loadedModules.has(place)) { loadedModules.add(place) return require(place) //performance optimisation @@ -68,7 +69,8 @@ class FeatureManager { this.longEventTime = 20 - this.perfTrackingFeatures = new Set() + this.perfTrackingFeatures = false + this.stack = [] this.featureMetas = {} @@ -182,16 +184,40 @@ class FeatureManager { loadPerformanceData() { new Thread(() => { - ChatLib.chat(this.messagePrefix + "Recording performance impact, this will take around 35 seconds to complete!") - this.loadEventLag() - this.loadForgeRenderLag() - this.loadSoopyLag() + ChatLib.chat(this.messagePrefix + "Recording performance impact, this will take around 50 seconds to complete!") + shouldRequireNoCache = false + let eventLagData = this.loadEventLag() + ChatLib.chat(this.messagePrefix + "ETA: 40s") + this.unloadSoopy() + this.loadSoopy() + let eventLagDataFull = this.loadEventLag() + this.unloadSoopy() + this.loadSoopy() + ChatLib.chat(this.messagePrefix + "ETA: 25s") + let forgeLagData = this.loadForgeRenderLag() + ChatLib.chat(this.messagePrefix + "ETA: 15s") + let soopyLagData = this.loadSoopyLag() + + let lagData = { + eventLagDataFull, + eventLagData, + forgeLagData, + soopyLagData + } + + shouldRequireNoCache = true + let url = this.reportLagData(lagData) ChatLib.chat(this.messagePrefix + "Done!") + new TextComponent(this.messagePrefix + "See the report at " + url).setClick("open_url", url).setHover("show_text", "Click to open the report.").chat() }).start() } + reportLagData(data) { + return fetch("http://soopymc.my.to/soopy/submitlag", { postData: data }).text() + } + loadSoopyLag() { - ChatLib.chat(this.messagePrefix + "Recording All Soopy Lag...") + // ChatLib.chat(this.messagePrefix + "Recording All Soopy Lag...") let framesWith = 0 let framesWithOut = 0 let event = this.registerEvent("renderWorld", () => { @@ -210,15 +236,20 @@ class FeatureManager { Thread.sleep(5000) this.unregisterEvent(event) - ChatLib.chat(this.messagePrefix + "Soopy Lag:") - ChatLib.chat("&eFps without Soopy: &7" + (framesWithOut / 5)) - ChatLib.chat("&eFps with Soopy: &7" + (framesWith / 5)) + // ChatLib.chat(this.messagePrefix + "Soopy Lag:") + // ChatLib.chat("&eFps without Soopy: &7" + (framesWithOut / 5)) + // ChatLib.chat("&eFps with Soopy: &7" + (framesWith / 5)) this.loadSoopy() + + return { + fpsWith: (framesWith / 5), + fpsWithout: (framesWithOut / 5) + } } loadForgeRenderLag() { - ChatLib.chat(this.messagePrefix + "Recording Forge-Rendering Lag...") + // ChatLib.chat(this.messagePrefix + "Recording Forge-Rendering Lag...") let framesWith = 0 let framesWithOut = 0 let renderingForge = true @@ -237,50 +268,55 @@ class FeatureManager { } this.unregisterEvent(event) - ChatLib.chat(this.messagePrefix + "Forge Lag:") - ChatLib.chat("&eFps without forge: &7" + (framesWithOut / 5)) - ChatLib.chat("&eFps with forge: &7" + (framesWith / 5)) + // ChatLib.chat(this.messagePrefix + "Forge Lag:") + // ChatLib.chat("&eFps without forge: &7" + (framesWithOut / 5)) + // ChatLib.chat("&eFps with forge: &7" + (framesWith / 5)) + return { + fpsWith: (framesWith / 5), + fpsWithout: (framesWithOut / 5) + } } loadEventLag() { this.recordingPerformanceUsage = true this.performanceUsage = {} - ChatLib.chat(this.messagePrefix + "Recording Event Lag...") + // ChatLib.chat(this.messagePrefix + "Recording Event Lag...") Thread.sleep(10000) - let totalMsGlobal = 0 + // let totalMsGlobal = 0 this.recordingPerformanceUsage = false - ChatLib.chat(this.messagePrefix + "Event Lag:") - Object.keys(this.performanceUsage).sort((a, b) => { - let totalMsA = 0 - Object.keys(this.performanceUsage[a]).forEach((event) => { - totalMsA += this.performanceUsage[a][event].time - }) - let totalMsB = 0 - Object.keys(this.performanceUsage[b]).forEach((event) => { - totalMsB += this.performanceUsage[b][event].time - }) - - return totalMsA - totalMsB - }).forEach((moduleName) => { - let totalMs = 0 - let totalCalls = 0 - Object.keys(this.performanceUsage[moduleName]).forEach((event) => { - totalMs += this.performanceUsage[moduleName][event].time - totalCalls += this.performanceUsage[moduleName][event].count - }) - - totalMsGlobal += totalMs - - ChatLib.chat("&eModule: &7" + moduleName) - ChatLib.chat("&eTotal: &7" + totalMs.toFixed(2) + "ms (" + totalCalls + " calls)") - Object.keys(this.performanceUsage[moduleName]).sort((a, b) => { return this.performanceUsage[moduleName][a].time - this.performanceUsage[moduleName][b].time }).forEach((event) => { - ChatLib.chat(" &eEvent:&7 " + event + " - " + this.performanceUsage[moduleName][event].time.toFixed(2) + "ms (" + this.performanceUsage[moduleName][event].count + " calls) [" + ((this.performanceUsage[moduleName][event].time / this.performanceUsage[moduleName][event].count).toFixed(2)) + "ms avg]") - }) - }) + // ChatLib.chat(this.messagePrefix + "Event Lag:") + // Object.keys(this.performanceUsage).sort((a, b) => { + // let totalMsA = 0 + // Object.keys(this.performanceUsage[a]).forEach((event) => { + // totalMsA += this.performanceUsage[a][event].time + // }) + // let totalMsB = 0 + // Object.keys(this.performanceUsage[b]).forEach((event) => { + // totalMsB += this.performanceUsage[b][event].time + // }) - ChatLib.chat("&eTotal: &7" + totalMsGlobal.toFixed(2) + "ms") + // return totalMsA - totalMsB + // }).forEach((moduleName) => { + // let totalMs = 0 + // let totalCalls = 0 + // Object.keys(this.performanceUsage[moduleName]).forEach((event) => { + // totalMs += this.performanceUsage[moduleName][event].time + // totalCalls += this.performanceUsage[moduleName][event].count + // }) + + // totalMsGlobal += totalMs + + // ChatLib.chat("&eModule: &7" + moduleName) + // ChatLib.chat("&eTotal: &7" + totalMs.toFixed(2) + "ms (" + totalCalls + " calls)") + // Object.keys(this.performanceUsage[moduleName]).sort((a, b) => { return this.performanceUsage[moduleName][a].time - this.performanceUsage[moduleName][b].time }).forEach((event) => { + // ChatLib.chat(" &eEvent:&7 " + event + " - " + this.performanceUsage[moduleName][event].time.toFixed(2) + "ms (" + this.performanceUsage[moduleName][event].count + " calls) [" + ((this.performanceUsage[moduleName][event].time / this.performanceUsage[moduleName][event].count).toFixed(2)) + "ms avg]") + // }) + // }) + + // ChatLib.chat("&eTotal: &7" + totalMsGlobal.toFixed(2) + "ms") + return this.performanceUsage } loadFeatureSettings() { @@ -610,16 +646,35 @@ class FeatureManager { addPerformanceTracking(feature) { let featureId = feature.getId() - if (!this.perfTrackingFeatures.has(featureId)) return + if (!this.perfTrackingFeatures) return Object.getOwnPropertyNames(Object.getPrototypeOf(feature)).forEach(key => { ChatLib.chat(key + " " + typeof (feature[key])) if (typeof (feature[key]) === "function") { let fun = feature[key].bind(feature) feature[key] = () => { - ChatLib.chat("entering " + key) + if (!this.recordingPerformanceUsage) { + fun() + return + } + + let pushedId = false + + if (this.stack.length === 0) { + this.stack.push(featureId) + pushedId = true + } + + this.stack.push(featureId + "." + key) + + let start = this.getExactTime() fun() - ChatLib.chat("exiting " + key) + let time = this.getExactTime() - start + + this.performanceUsage + + this.stack.pop() + if (pushedId) this.stack.pop() } } }) diff --git a/features/suggestionsGui/index.js b/features/suggestionsGui/index.js index 5da46d1..57d76cb 100644 --- a/features/suggestionsGui/index.js +++ b/features/suggestionsGui/index.js @@ -18,60 +18,62 @@ import Dropdown from "../../../guimanager/GuiElement/Dropdown"; import SoopyContentChangeEvent from "../../../guimanager/EventListener/SoopyContentChangeEvent"; import { fetch } from "../../utils/networkUtils"; +let allowed = new Set(["dc8c39647b294e03ae9ed13ebd65dd29", "83c5626ede2d4754b86064d558809615"]) + class SuggestionGui extends Feature { constructor() { super() } - onEnable(){ + onEnable() { this.initVariables() this.GuiPage = new SuggestionPage() } - initVariables(){ + initVariables() { this.GuiPage = undefined } - onDisable(){ + onDisable() { this.initVariables() } } class SuggestionPage extends GuiPage { - constructor(){ + constructor() { super(7) - + this.name = "Suggestions" this.pages = [this.newPage()] this.password = "" - if(Player.getUUID().toString().replace(/-/g,"") === "dc8c39647b294e03ae9ed13ebd65dd29"){ + if (allowed.has(Player.getUUID().toString().replace(/-/g, ""))) { let elm = new PasswordInput().setPlaceholder("Suggestions").setLocation(0.125, 0.05, 0.3, 0.1) this.pages[0].addChild(elm) - elm.addEvent(new SoopyKeyPressEvent().setHandler((key, keyId)=>{ - if(elm.text.selected && keyId === 28){ + elm.addEvent(new SoopyKeyPressEvent().setHandler((key, keyId) => { + if (elm.text.selected && keyId === 28) { this.password = elm.text.text elm.setText("") elm.text.selected = false } })) - }else{ + } else { this.pages[0].addChild(new SoopyTextElement().setText("§0Suggestions").setMaxTextScale(3).setLocation(0.125, 0.05, 0.3, 0.1)) } let button = new ButtonWithArrow().setText("§0Suggest feature (Opens in browser)").setLocation(0.45, 0.05, 0.5, 0.1) this.pages[0].addChild(button) - button.addEvent(new SoopyMouseClickEvent().setHandler(()=>{ + button.addEvent(new SoopyMouseClickEvent().setHandler(() => { java.awt.Desktop.getDesktop().browse( - new java.net.URI("https://soopymc.my.to/soopyv2suggestion?uuid=" + Player.getUUID().toString().replace(/-/g,"") ) - ); + new java.net.URI("https://soopymc.my.to/soopyv2suggestion?uuid=" + Player.getUUID().toString().replace(/-/g, "")) + ); })) this.suggestionElements = {} @@ -80,134 +82,134 @@ class SuggestionPage extends GuiPage { this.pages[0].addChild(this.suggestionsArea) - fetch("http://soopymc.my.to/api/soopyv2/suggestionTags.json").json(data=>{ + fetch("http://soopymc.my.to/api/soopyv2/suggestionTags.json").json(data => { this.tags = data }) this.finaliseLoading() } - loadSuggestionPage(){ + loadSuggestionPage() { - fetch("http://soopymc.my.to/api/soopyv2/suggestion/new").json(data=>{ + fetch("http://soopymc.my.to/api/soopyv2/suggestion/new").json(data => { this.suggestionElements = {} this.suggestionsArea.clearChildren() - + let i = 0 - + data.suggestions.forEach((suggestion) => { - - if(suggestion.status === "pending_review" || suggestion.status === "closed"){ - if(suggestion.uuid !== Player.getUUID().toString().replace(/-/g, "") && Player.getUUID().toString().replace(/-/g, "") !== "dc8c39647b294e03ae9ed13ebd65dd29")return + + if (suggestion.status === "pending_review" || suggestion.status === "closed") { + if (suggestion.uuid !== Player.getUUID().toString().replace(/-/g, "") && !allowed.has(Player.getUUID().toString().replace(/-/g, ""))) return } - + let box = new SoopyBoxElement().setLocation(0, 0.225 * i, 1, 0.2).setLore(["Click for more information + vote buttons"]) this.suggestionsArea.addChild(box) - - let title = new SoopyTextElement().setText("§0" + suggestion.title + " §7(" + this.tags.suggestionTags[suggestion.tag] + ")").setMaxTextScale(2).setLocation(0, 0, 0.8,1) + + let title = new SoopyTextElement().setText("§0" + suggestion.title + " §7(" + this.tags.suggestionTags[suggestion.tag] + ")").setMaxTextScale(2).setLocation(0, 0, 0.8, 1) box.addChild(title) - - let popularity = new SoopyTextElement().setText("§0Opinion: " + numberWithCommas(suggestion.likes-suggestion.dislikes)).setMaxTextScale(2).setLocation(0.85,0,0.1,1) + + let popularity = new SoopyTextElement().setText("§0Opinion: " + numberWithCommas(suggestion.likes - suggestion.dislikes)).setMaxTextScale(2).setLocation(0.85, 0, 0.1, 1) box.addChild(popularity) - + this.suggestionElements[suggestion._id] = { title: title, popularity: popularity } - - box.addEvent(new SoopyMouseClickEvent().setHandler(()=>{ + + box.addEvent(new SoopyMouseClickEvent().setHandler(() => { this.loadSuggestion(suggestion._id) })) - + i++ }); }) } - loadSuggestion(id){ - fetch("http://soopymc.my.to/api/soopyv2/suggestion/" + id + "/user/" + Player.getUUID().toString().replace(/-/g,"")).json(data=>{ - let sideBarElm = new SoopyGuiElement().setLocation(0,0,1,1).setScrollable(true) - if(!data.success){ - sideBarElm.addChild(new SoopyTextElement().setText("§cError loading suggestion").setMaxTextScale(3).setLocation(0.5,0.5,0.5,0.5)) + loadSuggestion(id) { + fetch("http://soopymc.my.to/api/soopyv2/suggestion/" + id + "/user/" + Player.getUUID().toString().replace(/-/g, "")).json(data => { + let sideBarElm = new SoopyGuiElement().setLocation(0, 0, 1, 1).setScrollable(true) + if (!data.success) { + sideBarElm.addChild(new SoopyTextElement().setText("§cError loading suggestion").setMaxTextScale(3).setLocation(0.5, 0.5, 0.5, 0.5)) this.openSidebarPage(sideBarElm) return } - + this.suggestionElements[id].title.setText("§0" + data.suggestion.title + " §7(" + this.tags.suggestionTags[data.suggestion.tag] + ")") - this.suggestionElements[id].popularity.setText("§0Opinion: " + numberWithCommas(data.suggestion.likes-data.suggestion.dislikes)) - - - let title = new SoopyTextElement().setText("§0" + data.suggestion.title + " §7(" + this.tags.suggestionTags[data.suggestion.tag] + ")").setMaxTextScale(2).setLocation(0.05, 0.05, 0.9,0.1) + this.suggestionElements[id].popularity.setText("§0Opinion: " + numberWithCommas(data.suggestion.likes - data.suggestion.dislikes)) + + + let title = new SoopyTextElement().setText("§0" + data.suggestion.title + " §7(" + this.tags.suggestionTags[data.suggestion.tag] + ")").setMaxTextScale(2).setLocation(0.05, 0.05, 0.9, 0.1) sideBarElm.addChild(title) - - if(Player.getUUID().toString().replace(/-/g, "") !== "dc8c39647b294e03ae9ed13ebd65dd29"){ - let suggestor = new SoopyTextElement().setText("§7Suggested by " + data.suggestion.username + " | Status: " + this.tags.statusTags[data.suggestion.status]).setMaxTextScale(1).setLocation(0.05, 0.15, 0.9,0.05) + + if (!allowed.has(Player.getUUID().toString().replace(/-/g, ""))) { + let suggestor = new SoopyTextElement().setText("§7Suggested by " + data.suggestion.username + " | Status: " + this.tags.statusTags[data.suggestion.status]).setMaxTextScale(1).setLocation(0.05, 0.15, 0.9, 0.05) sideBarElm.addChild(suggestor) - }else{ - let suggestor = new SoopyTextElement().setText("§7Suggested by " + data.suggestion.username + " | Status: ").setMaxTextScale(1).setLocation(0.05, 0.15, 0.6,0.05) + } else { + let suggestor = new SoopyTextElement().setText("§7Suggested by " + data.suggestion.username + " | Status: ").setMaxTextScale(1).setLocation(0.05, 0.15, 0.6, 0.05) sideBarElm.addChild(suggestor) - - let drop = new Dropdown().setLocation(0.65, 0.13, 0.3, 0.09).setOptions({...this.tags.statusTags,"delete": "Delete"}).setSelectedOption(data.suggestion.status) + + let drop = new Dropdown().setLocation(0.65, 0.13, 0.3, 0.09).setOptions({ ...this.tags.statusTags, "delete": "Delete" }).setSelectedOption(data.suggestion.status) sideBarElm.addChild(drop) - - drop.addEvent(new SoopyContentChangeEvent().setHandler((newVal)=>{ - if(newVal === "delete"){ + + drop.addEvent(new SoopyContentChangeEvent().setHandler((newVal) => { + if (newVal === "delete") { fetch("http://soopymc.my.to/api/soopyv2/suggestion/" + id + "/delete/" + this.password).async() - + this.loadSuggestionPage() this.closeSidebarPage() return } - fetch("http://soopymc.my.to/api/soopyv2/suggestion/" + id + "/status/" + newVal+ "/" + this.password).async() - + fetch("http://soopymc.my.to/api/soopyv2/suggestion/" + id + "/status/" + newVal + "/" + this.password).async() + this.loadSuggestion(id) })) } - - let likesText = new SoopyTextElement().setText("§0Dislikes: " + numberWithCommas(data.suggestion.dislikes) + " Likes: " + numberWithCommas(data.suggestion.likes)).setMaxTextScale(1).setLocation(0.35, 0.225, 0.3,0.1) + + let likesText = new SoopyTextElement().setText("§0Dislikes: " + numberWithCommas(data.suggestion.dislikes) + " Likes: " + numberWithCommas(data.suggestion.likes)).setMaxTextScale(1).setLocation(0.35, 0.225, 0.3, 0.1) sideBarElm.addChild(likesText) - if(!data.suggestion.hasDisliked){ - let dislikeButton = new ButtonWithArrow().setDirectionRight(false).setText("§cDislike").setLocation(0.05, 0.225, 0.275,0.1) + if (!data.suggestion.hasDisliked) { + let dislikeButton = new ButtonWithArrow().setDirectionRight(false).setText("§cDislike").setLocation(0.05, 0.225, 0.275, 0.1) sideBarElm.addChild(dislikeButton) - dislikeButton.addEvent(new SoopyMouseClickEvent().setHandler(()=>{ + dislikeButton.addEvent(new SoopyMouseClickEvent().setHandler(() => { this.voteSuggestion(id, "dislike") })) - }else{ - let dislikeButton = new ButtonWithArrow().setDirectionRight(false).setText("§cUndislike").setLocation(0.05, 0.225, 0.275,0.1) + } else { + let dislikeButton = new ButtonWithArrow().setDirectionRight(false).setText("§cUndislike").setLocation(0.05, 0.225, 0.275, 0.1) sideBarElm.addChild(dislikeButton) - dislikeButton.addEvent(new SoopyMouseClickEvent().setHandler(()=>{ + dislikeButton.addEvent(new SoopyMouseClickEvent().setHandler(() => { this.voteSuggestion(id, "clear") })) } - if(!data.suggestion.hasLiked){ - let likeButton = new ButtonWithArrow().setText("§aLike").setLocation(0.675, 0.225, 0.275,0.1) + if (!data.suggestion.hasLiked) { + let likeButton = new ButtonWithArrow().setText("§aLike").setLocation(0.675, 0.225, 0.275, 0.1) sideBarElm.addChild(likeButton) - likeButton.addEvent(new SoopyMouseClickEvent().setHandler(()=>{ + likeButton.addEvent(new SoopyMouseClickEvent().setHandler(() => { this.voteSuggestion(id, "like") })) - }else{ - let likeButton = new ButtonWithArrow().setText("§aUnlike").setLocation(0.675, 0.225, 0.275,0.1) + } else { + let likeButton = new ButtonWithArrow().setText("§aUnlike").setLocation(0.675, 0.225, 0.275, 0.1) sideBarElm.addChild(likeButton) - likeButton.addEvent(new SoopyMouseClickEvent().setHandler(()=>{ + likeButton.addEvent(new SoopyMouseClickEvent().setHandler(() => { this.voteSuggestion(id, "clear") })) } - - - let description = new SoopyMarkdownElement().setText(data.suggestion.description).setLocation(0.05, 0.325, 0.9,0.6) + + + let description = new SoopyMarkdownElement().setText(data.suggestion.description).setLocation(0.05, 0.325, 0.9, 0.6) sideBarElm.addChild(description) - + this.openSidebarPage(sideBarElm) }) } - voteSuggestion(id, type){ - fetch("http://soopymc.my.to/api/soopyv2/suggestion/" + id + "/vote/" + (type) + "/" + Player.getUUID().toString().replace(/-/g,"")).async() + voteSuggestion(id, type) { + fetch("http://soopymc.my.to/api/soopyv2/suggestion/" + id + "/vote/" + (type) + "/" + Player.getUUID().toString().replace(/-/g, "")).async() this.loadSuggestion(id) - } + } - onOpen(){ + onOpen() { this.loadSuggestionPage() } } diff --git a/utils/networkUtils.js b/utils/networkUtils.js index 0233ac0..31269fb 100644 --- a/utils/networkUtils.js +++ b/utils/networkUtils.js @@ -5,8 +5,9 @@ if (!global.networkUtilsThingSoopy) { let jCollectors = Java.type("java.util.stream.Collectors") let jBufferedReader = Java.type("java.io.BufferedReader") let jInputStreamReader = Java.type("java.io.InputStreamReader") + let jString = Java.type("java.lang.String") - function getUrlContent(theUrl, { userAgent = "Mozilla/5.0", includeConnection = false } = {}) { + function getUrlContent(theUrl, { userAgent = "Mozilla/5.0", includeConnection = false, postData = undefined } = {}) { if (global.soopyv2loggerthing) { global.soopyv2loggerthing.logMessage("Loading API: " + theUrl, 4) @@ -20,6 +21,23 @@ if (!global.networkUtilsThingSoopy) { let conn = new jURL(theUrl).openConnection() conn.setRequestProperty("User-Agent", userAgent) + if (postData) { + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/json"); + conn.setDoOutput(true); + + let jsonInputString = new jString(JSON.stringify(postData)) + + let os + try { + os = conn.getOutputStream() + input = jsonInputString.getBytes("utf-8"); + os.write(input, 0, input.length); + } finally { + os.close() + } + } + let stringData if (conn.getResponseCode() < 400) { |