diff options
-rw-r--r-- | featureClass/featureManager.js | 89 | ||||
-rw-r--r-- | features/dataLoader/index.js | 2 | ||||
-rw-r--r-- | features/events/index.js | 27 | ||||
-rw-r--r-- | features/hud/index.js | 3 | ||||
-rw-r--r-- | features/soopyGui/GuiPage.js | 18 | ||||
-rw-r--r-- | features/stat_next_to_name/index.js | 11 | ||||
-rw-r--r-- | logger.js | 17 | ||||
-rw-r--r-- | socketConnection.js | 6 | ||||
-rw-r--r-- | utils/renderLib2d.js | 22 |
9 files changed, 167 insertions, 28 deletions
diff --git a/featureClass/featureManager.js b/featureClass/featureManager.js index 651ae52..b0da324 100644 --- a/featureClass/featureManager.js +++ b/featureClass/featureManager.js @@ -7,9 +7,31 @@ import metadata from "../metadata.js" import soopyV2Server from "../socketConnection"; import { registerForge as registerForgeBase, unregisterForge as unregisterForgeBase} from "./forgeEvents.js" +const JSLoader = Java.type("com.chattriggers.ctjs.engine.langs.js.JSLoader") +const UrlModuleSourceProvider = Java.type("org.mozilla.javascript.commonjs.module.provider.UrlModuleSourceProvider") +const UrlModuleSourceProviderInstance = new UrlModuleSourceProvider(null, null) +const StrongCachingModuleScriptProviderClass = Java.type("org.mozilla.javascript.commonjs.module.provider.StrongCachingModuleScriptProvider") +let StrongCachingModuleScriptProvider = new StrongCachingModuleScriptProviderClass(UrlModuleSourceProviderInstance) +let CTRequire = new JSLoader.CTRequire(StrongCachingModuleScriptProvider) + +let loadedModules = [] + +function RequireNoCache(place){ + if(loadedModules.includes(place)){ + loadedModules.push(place) + return require(place) //performance optimisation + } + if(!logger.isDev) return require(place) + StrongCachingModuleScriptProvider = new StrongCachingModuleScriptProviderClass(UrlModuleSourceProviderInstance) + CTRequire = new JSLoader.CTRequire(StrongCachingModuleScriptProvider) + return CTRequire(place) +} + class FeatureManager { constructor(){ + this.isDev = logger.isDev + this.messagePrefix = "&6[SOOPY V2]&7 " this.enabled = true //make triggers work with this context @@ -68,8 +90,47 @@ class FeatureManager { }, this) this.registerEvent("worldUnload", this.saveFeatureSettings, this) - this.registerEvent("gameUnload", this.saveFeatureSettings, this) - this.registerEvent("gameUnload", this.unloadAllFeatures, this) + + this.registerEvent("gameUnload", ()=>{ + this.saveFeatureSettings() + this.unloadAllFeatures() + + this.enabled = false + }, this) + this.registerStep(true, 2, ()=>{ + if(this.reloadModuleTime!==0 && Date.now()-this.reloadModuleTime > 0){ + new Thread(()=>{ + this.reloadModuleTime = 0 + this.reloadingModules.forEach(m=>{ + this.unloadFeature(m) + }) + this.reloadingModules.forEach(m=>{ + this.loadFeature(m) + }) + this.reloadingModules = [] + }).start() + } + }, this) + + this.watches = {} + this.addedWatches = [] + this.watchService = Java.type("java.nio.file.FileSystems").getDefault().newWatchService(); + this.reloadingModules = [] + this.reloadModuleTime = 0 + new Thread(()=>{ + while(this.enabled){ + key = this.watchService.take(); + let moduleToReload = this.watches[key] + if(this.features[moduleToReload] && !this.reloadingModules.includes(moduleToReload)){ //if enabled && not alr in queue + this.reloadingModules.push(moduleToReload) + this.reloadModuleTime = Date.now()+1000 + } + key.pollEvents()/*.forEach(event=>{ + console.log(event.context().toString()) + })*/ + key.reset(); + } + }).start() this.registerCommand("soopyunloadfeature", (args)=>{ new Thread(()=>{ @@ -421,8 +482,10 @@ class FeatureManager { if(this.features[feature]) return try{ - let LoadedFeature = require("../features/" + feature + "/index.js") - + + let LoadedFeature = RequireNoCache("../features/" + feature + "/index.js") + // let LoadedFeature = RequireNoCache(new File("config/ChatTriggers/modules/" + metadata.name + "/features/" + feature + "/index.js")) + this.features[feature] = LoadedFeature LoadedFeature.class.setId(feature) @@ -430,6 +493,12 @@ class FeatureManager { LoadedFeature.class._onEnable(this) logger.logMessage("Loaded feature " + feature, 3) + + if(this.isDev && !this.addedWatches.includes(feature)){ + this.addedWatches.push(feature) + let path = Java.type("java.nio.file.Paths").get("./config/ChatTriggers/modules/SoopyV2/features/" + feature + "/"); + this.watches[path.register(this.watchService, Java.type("java.nio.file.StandardWatchEventKinds").ENTRY_MODIFY)] = feature + } }catch(e){ logger.logMessage("Error loading feature " + feature, 1) console.log(JSON.stringify(e, undefined, 2)) @@ -502,4 +571,14 @@ class FeatureManager { if(!global.soopyv2featuremanagerthing){ global.soopyv2featuremanagerthing = new FeatureManager() } -export default global.soopyv2featuremanagerthing
\ No newline at end of file +export default global.soopyv2featuremanagerthing + + +function getField(e, field){ + + let field2 = e.class.getDeclaredField(field); + + field2.setAccessible(true) + + return field2.get(e) +}
\ No newline at end of file diff --git a/features/dataLoader/index.js b/features/dataLoader/index.js index 41f0c61..43b0f7a 100644 --- a/features/dataLoader/index.js +++ b/features/dataLoader/index.js @@ -46,7 +46,7 @@ class DataLoader extends Feature { } loadApiData(type, soopyServer){ - while(this.FeatureManager.features["globalSettings"] === undefined){ + while(this.FeatureManager.features["globalSettings"] === undefined || this.FeatureManager.features["globalSettings"].class.apiKeySetting === undefined){ Thread.sleep(100) } let key = this.FeatureManager.features["globalSettings"].class.apiKeySetting.getValue() diff --git a/features/events/index.js b/features/events/index.js index 80ba200..5586503 100644 --- a/features/events/index.js +++ b/features/events/index.js @@ -41,7 +41,8 @@ class Events extends Feature { .requires(this.burrialWaypointsEnabled) .editTempText("&6Update&7> &f100s")) this.hudElements.push(this.updateTimer) - + + this.registerEvent("worldLoad", this.worldLoad) this.registerEvent("spawnParticle", this.spawnParticle) this.registerEvent("renderWorld", this.renderWorld) @@ -75,14 +76,7 @@ class Events extends Feature { }) } if(this.showingWaypoints){ - let sorted = [...this.burrialData.locations] - sorted.sort((a,b)=>{ - let aDist = calculateDistanceQuick([Player.getX(),Player.getY(),Player.getZ()],[a.x+0.5,a.y+2.5,a.z+0.5]) - let bDist = calculateDistanceQuick([Player.getX(),Player.getY(),Player.getZ()],[b.x+0.5,b.y+2.5,b.z+0.5]) - - return bDist-aDist - }) - sorted.forEach((loc,i)=>{ + this.burrialData.locations.forEach((loc,i)=>{ let typeReplace = [ "Start", @@ -119,6 +113,17 @@ class Events extends Feature { } } + sortBurrialLocations(){ + let sorted = [...this.burrialData.locations] + sorted.sort((a,b)=>{ + let aDist = calculateDistanceQuick([Player.getX(),Player.getY(),Player.getZ()],[a.x+0.5,a.y+2.5,a.z+0.5]) + let bDist = calculateDistanceQuick([Player.getX(),Player.getY(),Player.getZ()],[b.x+0.5,b.y+2.5,b.z+0.5]) + + return bDist-aDist + }) + this.burrialData.locations = sorted + } + step(){ hasDianaShovle = false @@ -160,6 +165,7 @@ class Events extends Feature { }).start() } } + this.sortBurrialLocations() } worldLoad(){ @@ -234,6 +240,7 @@ class Events extends Feature { }) this.burrialData.locations = newLocs + this.sortBurrialLocations() this.updateBurrialPath() } @@ -376,7 +383,7 @@ class Events extends Feature { return false }) if(this.burrialData.historicalLocations.length > 10) this.burrialData.historicalLocations.pop() - this.lastPathCords.shift() + if(this.lastPathCords) this.lastPathCords.shift() new Thread(()=>{ this.updateBurrialPath() }).start() diff --git a/features/hud/index.js b/features/hud/index.js index e8dc604..704c954 100644 --- a/features/hud/index.js +++ b/features/hud/index.js @@ -9,8 +9,6 @@ import HudTextElement from "./HudTextElement"; class Hud extends Feature { constructor() { super() - - this.initVariables() } initVariables(){ @@ -58,6 +56,7 @@ class Hud extends Feature { } onEnable(){ + this.initVariables() this.numberUtils = require("../../utils/numberUtils.js") diff --git a/features/soopyGui/GuiPage.js b/features/soopyGui/GuiPage.js index 13778fe..fb93bbe 100644 --- a/features/soopyGui/GuiPage.js +++ b/features/soopyGui/GuiPage.js @@ -5,15 +5,31 @@ class GuiPage{ this.currentPageId = 0; this.priority = priority - this.soopyGui = require('./index.js').class; + this.soopyGui = undefined; + new Thread(()=>{ + while(global.soopyv2featuremanagerthing.features["soopyGui"] === undefined){ + Thread.sleep(100) + } + + this.soopyGui = global.soopyv2featuremanagerthing.features["soopyGui"].class; + + if(this.finalisedLoading){ + this.finaliseLoading() + } + }).start() this.name = "" this.pages = {} this.showBackButton = true + this.finalisedLoading = false } finaliseLoading(){ + if(!this.soopyGui){ + this.finalisedLoading = true + return + } this.soopyGui.addCategory(this); } diff --git a/features/stat_next_to_name/index.js b/features/stat_next_to_name/index.js index 59a84f7..586c4ba 100644 --- a/features/stat_next_to_name/index.js +++ b/features/stat_next_to_name/index.js @@ -23,6 +23,7 @@ class StatNextToName extends Feature { soopyV2Server.onPlayerStatsLoaded = (stats)=>{this.playerStatsLoaded.call(this, stats)} this.registerStep(false, 5, this.loadPlayerStatsTick) + this.registerEvent("worldLoad", this.worldLoad) } loadPlayerStatsTick(){ @@ -35,6 +36,7 @@ class StatNextToName extends Feature { return } if(this.loadingStats.includes(player.getUUID().toString().replace(/-/g, ""))) return + if(Player.getUUID().replace(/-/g, "").toString().substr(12, 1) !== "4") return let dist = Math.pow(player.getX() - Player.getX(), 2) + Math.pow(player.getY() - Player.getY(), 2) + Math.pow(player.getZ() - Player.getZ(), 2) if(dist < nearestDistance){ @@ -48,6 +50,15 @@ class StatNextToName extends Feature { } } + worldLoad(){ + let playerStats = this.userStats[Player.getUUID().toString().replace(/-/g, "")] + this.userStats = {} + this.loadingStats = [] + if(playerStats){ + this.userStats[Player.getUUID().toString().replace(/-/g, "")] = playerStats + } + } + updatePlayerNametag(player){ let stats = this.userStats[player.getUUID().toString().replace(/-/g, "")] @@ -3,7 +3,8 @@ class Logger{ constructor(){ - this.loglevel = isDev()?4:2 //0=none, 1=error, 2=warn, 3=info, 4=debug + this.isDev = isDev() + this.loglevel = this.isDev?4:2 //0=none, 1=error, 2=warn, 3=info, 4=debug this.logToMcChat = false this.logPrefixes = [ "[SOOPYADDONS] ", @@ -24,15 +25,19 @@ class Logger{ } } } - let devs = ["dc8c39647b294e03ae9ed13ebd65dd29"] function isDev(){ return devs.includes(Player.getUUID().toString().replace(/-/g, "")) } -register("command", ()=>{ - devs.push(Player.getUUID().toString().replace(/-/g, "")) -}).setName("pleasegivemeaccesstosoopyv2devconsolelogs") //yep -export default new Logger()
\ No newline at end of file +if(!global.soopyv2loggerthing){ + global.soopyv2loggerthing = new Logger() + + register("command", ()=>{ + devs.push(Player.getUUID().toString().replace(/-/g, "")) + }).setName("pleasegivemeaccesstosoopyv2devconsolelogs") //yep + +} +export default global.soopyv2loggerthing
\ No newline at end of file diff --git a/socketConnection.js b/socketConnection.js index f8c61b4..11339f1 100644 --- a/socketConnection.js +++ b/socketConnection.js @@ -86,6 +86,8 @@ class SoopyV2Server extends WebsiteCommunicator { } } -let soopyV2Server = new SoopyV2Server() +if(!global.soopyV2Server){ + global.soopyV2Server = new SoopyV2Server() +} -export default soopyV2Server
\ No newline at end of file +export default global.soopyV2Server
\ No newline at end of file diff --git a/utils/renderLib2d.js b/utils/renderLib2d.js index e9769b7..22dbca7 100644 --- a/utils/renderLib2d.js +++ b/utils/renderLib2d.js @@ -3,9 +3,10 @@ // CODE BY DJtheRedstoner // IM COPYING THIS BECAUSE THE UPLOADED VERSION IS FOR // CT 2.0.0 ONLY +// +// Edit: iv added some features to this so might keep as is //-------------------------------------------------------------------------- -//TODO: just require the module when ct 2.0 comes out const GL11 = Java.type("org.lwjgl.opengl.GL11"); @@ -20,6 +21,8 @@ const viewportDims = BufferUtils.createIntBuffer(16); const ScaledResolution = net.minecraft.client.gui.ScaledResolution; +const AxisAlignedBB = Java.type("net.minecraft.util.AxisAlignedBB") + register('renderWorld', () => { GlStateManager.func_179094_E(); @@ -66,6 +69,19 @@ export default class RenderLib2D { return { x, y, z }; } + static drawLine(x1, y1, z1, x2, y2, z2, color, thickness=1) { + let pos1 = RenderLib2D.projectPoint(x1, y1, z1); + let pos2 = RenderLib2D.projectPoint(x2, y2, z2); + + if(!pos1 || !pos2) return; + + let {x, y} = pos1 + let {x:ox, y:oy} = pos2 + + console.log(x, y, ox, oy, thickness) + Renderer.drawLine(color, x, y, ox, oy, thickness); + } + // Original made by DJtheRedstoner static calculateBoundingBox = (box) => { let vertices = RenderLib2D.getVertices(box); @@ -146,4 +162,8 @@ export default class RenderLib2D { if (projected[4] && projected[7]) Renderer.drawLine(color, projected[4].x, projected[4].y, projected[7].x, projected[7].y, thickness); if (projected[5] && projected[6]) Renderer.drawLine(color, projected[5].x, projected[5].y, projected[6].x, projected[6].y, thickness); } + + static getBlockAABB = (x, y, z) => { + return new AxisAlignedBB(x, y, z, x + 1, y + 1, z + 1); + } } |