diff options
author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-03-08 21:20:21 +0800 |
---|---|---|
committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-03-08 21:20:21 +0800 |
commit | 133f781e0838445bca104490c8ffe0b6398a876e (patch) | |
tree | 4fd5d2fc125ec3b812aec1e780720704746796bb | |
parent | 7ba09eb9ee619197849f3ed8de971e6bfab7d721 (diff) | |
download | SoopyV2-133f781e0838445bca104490c8ffe0b6398a876e.tar.gz SoopyV2-133f781e0838445bca104490c8ffe0b6398a876e.tar.bz2 SoopyV2-133f781e0838445bca104490c8ffe0b6398a876e.zip |
update meta + make dungeon map sync player locations thru socket
-rw-r--r-- | featureClass/featureManager.js | 29 | ||||
-rw-r--r-- | features/cosmetics/index.js | 10 | ||||
-rw-r--r-- | features/dungeonMap/index.js | 103 | ||||
-rw-r--r-- | metadata.json | 4 | ||||
-rw-r--r-- | socketConnection.js | 11 |
5 files changed, 129 insertions, 28 deletions
diff --git a/featureClass/featureManager.js b/featureClass/featureManager.js index 4d3c616..113e1cb 100644 --- a/featureClass/featureManager.js +++ b/featureClass/featureManager.js @@ -63,6 +63,8 @@ class FeatureManager { this.recordingPerformanceUsage = false this.performanceUsage = {} //{<moduleName>: {<event>: {time: 0, count: 0}}} + this.longEventTime = 20 + this.featureMetas = {} @@ -157,6 +159,9 @@ class FeatureManager { this.loadFeature(args) }).start() }, this) + this.registerCommand("soopysetlongeventtime", (args)=>{ + this.longEventTime = parseInt(args) + }, this) this.registerCommand("soopylaginformation", (args)=>{ //TODO: make this a dedicated GUI new Thread(()=>{ this.recordingPerformanceUsage = true @@ -192,7 +197,7 @@ class FeatureManager { 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)") + 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]") }) }) @@ -284,7 +289,12 @@ class FeatureManager { for(Event of Object.values(this.events[event])){ if(Event.context.enabled){ this.startRecordingPerformance(Event.context.constructor.name, event) + let start = Date.now() Event.func.call(Event.context, ...args) + let time = Date.now()-start + if(time > this.longEventTime){ + logger.logMessage("Long event triggered [" + time + "ms] (" + Event.context.constructor.name + "/" + event + ")", 3) + } this.stopRecordingPerformance(Event.context.constructor.name, event) } } @@ -300,7 +310,12 @@ class FeatureManager { for(Event of Object.values(this.soopyEventHandlers[event])){ if(Event.context.enabled){ this.startRecordingPerformance(Event.context.constructor.name, event) + let start = Date.now() Event.func.call(Event.context, ...args) + let time = Date.now()-start + if(time > this.longEventTime){ + logger.logMessage("Long event triggered [" + time + "ms] (" + context.constructor.name + "/" + event + ")", 3) + } this.stopRecordingPerformance(Event.context.constructor.name, event) } } @@ -393,7 +408,12 @@ class FeatureManager { try{ if(context.enabled){ this.startRecordingPerformance(context.constructor.name, type) + let start = Date.now() func.call(context, ...(args || [])) + let time = Date.now()-start + if(time > this.longEventTime){ + logger.logMessage("Long event triggered [" + time + "ms] (" + context.constructor.name + "/" + type + ")", 3) + } this.stopRecordingPerformance(context.constructor.name, type) } }catch(e){ @@ -418,7 +438,12 @@ class FeatureManager { try{ if(context.enabled){ this.startRecordingPerformance(context.constructor.name, event.class.name) + let start = Date.now() func.call(context, ...(args || [])) + let time = Date.now()-start + if(time > this.longEventTime){ + console.log(this.messagePrefix + "Long (forge) event triggered (" + context.constructor.name + "/" + event.class.toString() + ")") + } this.stopRecordingPerformance(context.constructor.name, event.class.name) } }catch(e){ @@ -521,7 +546,7 @@ class FeatureManager { return this } - unloadFeature(feature){ //run in seperate thread so ondisable can do network requests + unloadFeature(feature){ if(!this.features[feature]) return this.features[feature].class._onDisable() diff --git a/features/cosmetics/index.js b/features/cosmetics/index.js index d4b9fcb..e1879d0 100644 --- a/features/cosmetics/index.js +++ b/features/cosmetics/index.js @@ -50,7 +50,7 @@ class Cosmetics extends Feature { this.registerEvent("playerLeft", this.playerLeft) this.registerEvent("worldLoad", this.worldLoad) this.registerStep(false, 2, this.step) - this.registerEvent('worldUnload', ()=>{ + this.registerEvent('gameUnload', ()=>{ if(this.postRenderEntityTrigger){ this.postRenderEntityTrigger.unregister() this.postRenderEntityTrigger = undefined @@ -60,7 +60,6 @@ class Cosmetics extends Feature { // new Thread(()=>{this.loadCosmeticsData.call(this)}).start() // }) // this.registerEvent("renderEntity", this.renderEntity) - this.loadedRenderEntity = false if(global.soopyV2Server.userCosmeticPermissions){ this.updateUserCosmeticPermissionSettings() @@ -78,8 +77,8 @@ class Cosmetics extends Feature { } renderWorld(ticks){ - for(let cosmetic of this.loadedCosmetics){ - cosmetic.onRenderEntity(ticks, false) + for(let i = 0;i<this.loadedCosmetics.length;i++){ + this.loadedCosmetics[i].onRenderEntity(ticks, false) } } @@ -88,7 +87,7 @@ class Cosmetics extends Feature { this.cosmeticsData = data this.playerHasACosmeticA = !!data[Player.getUUID().toString().replace(/-/g,"")] - if(this.playerHasACosmeticA && !this.loadedRenderEntity){ + if(this.playerHasACosmeticA && !this.postRenderEntityTrigger){ // this.registerEvent("postRenderEntity", this.renderEntity) this.postRenderEntityTrigger = register("postRenderEntity", (entity, pos, ticks, event)=>{ if(ticks !== 1) return @@ -99,7 +98,6 @@ class Cosmetics extends Feature { } } }) - this.loadedRenderEntity = true } this.scanForNewCosmetics() diff --git a/features/dungeonMap/index.js b/features/dungeonMap/index.js index 05bd25a..7261c60 100644 --- a/features/dungeonMap/index.js +++ b/features/dungeonMap/index.js @@ -13,6 +13,7 @@ import SoopyGuiElement from "../../../guimanager/GuiElement/SoopyGuiElement"; import SoopyMouseClickEvent from "../../../guimanager/EventListener/SoopyMouseClickEvent"; import ButtonWithArrow from "../../../guimanager/GuiElement/ButtonWithArrow"; import ImageLocationSetting from "../settings/settingThings/imageLocation"; +import socketConnection from "../../socketConnection"; const BufferedImage = Java.type("java.awt.image.BufferedImage") const AlphaComposite = Java.type("java.awt.AlphaComposite") @@ -86,6 +87,7 @@ class DungeonMap extends Feature { // this.registerEvent("tick", this.tick) this.registerStep(true, 3, this.step) + this.registerStep(false, 5, this.step5s) this.registerEvent("renderOverlay", this.renderOverlay) this.registerEvent("renderWorld", this.renderWorld) this.registerEvent("worldLoad", this.worldLoad) @@ -94,6 +96,17 @@ class DungeonMap extends Feature { if(this.spiritLeapOverlay.getValue()) this.spiritLeapOverlayGui.guiOpened.call(this.spiritLeapOverlayGui, event) }) + this.boringMap = false + this.registerChat("&r&r&r ${*}&r&cThe Catacombs &r&8- &r&eFloor ${*}&r", ()=>{ + this.boringMap = true + }) + this.registerChat("&r&r&r ${*}&r&cMaster Mode Catacombs &r&8- &r&eFloor ${*}&r", ()=>{ + this.boringMap = true + }) + this.registerChat("&r&aDungeon starts in 1 second.&r", ()=>{ + this.boringMap = false + }) + this.running = true this.registerEvent("gameUnload", ()=>{ this.running = false @@ -148,11 +161,53 @@ class DungeonMap extends Feature { drawMap(x, y, size, scale){ if(this.mapImage){ - this.mapImage.draw(x, y, size, size) + if(this.boringMap){ + this.mapImage.draw(x, y, size, size) + return + } + renderLibs.scizzor(x, y, size, size) + + World.getAllPlayers().forEach(player=>{ + if(player.getPing()===-1)return + if(!this.people.includes(player.getName())) return + this.mapDataPlayers[player.getUUID().toString()] = { + x: player.getX(), + y: player.getZ(), + rot: player.getYaw()+180, + username: player.getName(), + uuid: player.getUUID().toString() + } + }) + + let uuid = Player.getUUID().toString() + let renderX + let renderY + let xOff = 0 + let yOff = 0 + if(this.mapDataPlayers[uuid]){ + + if(this.currDungeonBossImage){ + renderX = (this.mapDataPlayers[uuid].x-this.currDungeonBossImage.topLeftLocation[0])/this.currDungeonBossImage.widthInWorld*size + renderY = (this.mapDataPlayers[uuid].y-this.currDungeonBossImage.topLeftLocation[1])/this.currDungeonBossImage.heightInWorld*size + }else{ + renderX = this.mapDataPlayers[uuid].x/this.mapScale/128*size+this.offset[0]/128*size//*16/this.roomWidth + renderY = this.mapDataPlayers[uuid].y/this.mapScale/128*size+this.offset[1]/128*size//*16/this.roomWidth + } + + if(renderX < 0 || renderX>size + || renderY < 0 || renderY > size){ + xOff = size/2-renderX + yOff = size/2-renderY + } + } + + this.mapImage.draw(x+xOff, y+yOff, size, size) - this.drawOtherMisc(x, y, size, scale) + this.drawOtherMisc(x+xOff, y+yOff, size, scale) - this.drawPlayersLocations(x, y, size, scale) + this.drawPlayersLocations(x+xOff, y+yOff, size, scale) + + renderLibs.stopScizzor() } } @@ -181,13 +236,6 @@ class DungeonMap extends Feature { if(player.getPing()===-1)return if(!this.people.includes(player.getName())) return uuidToPlayer[player.getUUID().toString()] = player - this.mapDataPlayers[player.getUUID().toString()] = { - x: player.getX(), - y: player.getZ(), - rot: player.getYaw()+180, - username: player.getName(), - uuid: player.getUUID().toString() - } }) Object.keys(this.mapDataPlayers).forEach((uuid)=>{ @@ -198,10 +246,6 @@ class DungeonMap extends Feature { if(this.currDungeonBossImage){ renderX = (this.mapDataPlayers[uuid].x-this.currDungeonBossImage.topLeftLocation[0])/this.currDungeonBossImage.widthInWorld*size renderY = (this.mapDataPlayers[uuid].y-this.currDungeonBossImage.topLeftLocation[1])/this.currDungeonBossImage.heightInWorld*size - console.log( - (this.mapDataPlayers[uuid].x-this.currDungeonBossImage.topLeftLocation[0])/this.currDungeonBossImage.widthInWorld, - (this.mapDataPlayers[uuid].y-this.currDungeonBossImage.topLeftLocation[1])/this.currDungeonBossImage.heightInWorld - ) }else{ renderX = this.mapDataPlayers[uuid].x/this.mapScale/128*size+this.offset[0]/128*size//*16/this.roomWidth renderY = this.mapDataPlayers[uuid].y/this.mapScale/128*size+this.offset[1]/128*size//*16/this.roomWidth @@ -222,10 +266,6 @@ class DungeonMap extends Feature { if(this.currDungeonBossImage){ renderX = (this.mapDataPlayers[uuid].x-this.currDungeonBossImage.topLeftLocation[0])/this.currDungeonBossImage.widthInWorld*size renderY = (this.mapDataPlayers[uuid].y-this.currDungeonBossImage.topLeftLocation[1])/this.currDungeonBossImage.heightInWorld*size - console.log( - (this.mapDataPlayers[uuid].x-this.currDungeonBossImage.topLeftLocation[0])/this.currDungeonBossImage.widthInWorld, - (this.mapDataPlayers[uuid].y-this.currDungeonBossImage.topLeftLocation[1])/this.currDungeonBossImage.heightInWorld - ) }else{ renderX = this.mapDataPlayers[uuid].x/this.mapScale/128*size+this.offset[0]/128*size//*16/this.roomWidth renderY = this.mapDataPlayers[uuid].y/this.mapScale/128*size+this.offset[1]/128*size//*16/this.roomWidth @@ -562,6 +602,33 @@ class DungeonMap extends Feature { // this.mapImage.setImage(this.renderImage) } + + step5s(){ + if(!this.FeatureManager.features["dataLoader"].class.isInDungeon) return + if(this.people.length < 1) return + + let data = [] + + World.getAllPlayers().forEach(player=>{ + if(player.getPing()===-1)return + if(!this.people.includes(player.getName())) return + data.push({ + x: player.getX(), + y: player.getZ(), + rot: player.getYaw()+180, + username: player.getName(), + uuid: player.getUUID().toString() + }) + }) + // console.log("Sending: " + JSON.stringify(this.people, undefined, 2)+JSON.stringify(data, undefined, 2)) + socketConnection.sendDungeonData(this.people, data) + } + updateDungeonMapData(data){ + // console.log("Recieved: " + JSON.stringify(data, undefined, 2)) + data.forEach(p=>{ + this.mapDataPlayers[p.uuid] = p + }) + } getImageForPlayer(uuid){ if(!this.playerImages) return this.defaultPlayerImage diff --git a/metadata.json b/metadata.json index 219d83e..91f211c 100644 --- a/metadata.json +++ b/metadata.json @@ -5,8 +5,8 @@ "entry": "index.js", "description": "Soopy addons v2", "name": "SoopyV2", - "version": "2.1.35", - "versionId": 162, + "version": "2.1.36", + "versionId": 163, "requires": [ "soopyApis", "soopyAddonsData", diff --git a/socketConnection.js b/socketConnection.js index c74d98a..4e3fbda 100644 --- a/socketConnection.js +++ b/socketConnection.js @@ -39,6 +39,9 @@ class SoopyV2Server extends WebsiteCommunicator { this.lbdatathing = data.data this.lbdatathingupdated = data.lastUpdated } + if(data.type === "dungeonMapData"){ + if(global.soopyv2featuremanagerthing.features.dungeonMap)global.soopyv2featuremanagerthing.features.dungeonMap.class.updateDungeonMapData(data.data) + } } onConnect(){ @@ -113,6 +116,14 @@ class SoopyV2Server extends WebsiteCommunicator { username: username }) } + + sendDungeonData(names, data){ + this.sendData({ + type: "dungeonMapData", + names: names, + data: data + }) + } } if(!global.soopyV2Server){ |