diff options
-rw-r--r-- | features/improvements/index.js | 1 | ||||
-rw-r--r-- | features/soopyGui/index.js | 12 | ||||
-rw-r--r-- | features/stat_next_to_name/index.js | 65 | ||||
-rw-r--r-- | socketConnection.js | 11 |
4 files changed, 82 insertions, 7 deletions
diff --git a/features/improvements/index.js b/features/improvements/index.js index 4d003f3..32b1641 100644 --- a/features/improvements/index.js +++ b/features/improvements/index.js @@ -15,6 +15,7 @@ class Improvements extends Feature { this.registerChat("${color}-----------------------------------------------------&r", (color, event)=>{ if(this.betterLineBreaks.getValue()){ + if(color.length > 6) return cancel(event) ChatLib.chat(color + "&m" + ChatLib.getChatBreak(" ") + "&r"); } diff --git a/features/soopyGui/index.js b/features/soopyGui/index.js index 8dc52de..cb5b241 100644 --- a/features/soopyGui/index.js +++ b/features/soopyGui/index.js @@ -161,12 +161,12 @@ class SoopyGui extends Feature { this.pages.forEach((p)=>{ Object.values(p.pages).forEach((e, i)=>{ - e.location.location.x.set(i-pageNum+1, animate?1000:0) + e.location.location.x.set(i-pageNum+1, animate?500:0) }) }) - this.categoryPage.location.location.x.set(-pageNum, animate?1000:0) + this.categoryPage.location.location.x.set(-pageNum, animate?500:0) - this.backButton.location.location.y.set((pageNum === 0 || !this.currCategory.showBackButton)?-0.2:0, animate?1000:0) + this.backButton.location.location.y.set((pageNum === 0 || !this.currCategory.showBackButton)?-0.2:0, animate?500:0) } goToPageNum(pageNum, animate=true){ if(pageNum<0) return; @@ -179,12 +179,12 @@ class SoopyGui extends Feature { this.pages.forEach((p)=>{ Object.values(p.pages).forEach((e, i)=>{ - e.location.location.x.set(i-pageNum+1, animate?1000:0) + e.location.location.x.set(i-pageNum+1, animate?500:0) }) }) - this.categoryPage.location.location.x.set(-pageNum, animate?1000:0) + this.categoryPage.location.location.x.set(-pageNum, animate?500:0) - this.backButton.location.location.y.set((pageNum === 0 || !this.currCategory.showBackButton)?-0.2:0, animate?1000:0) + this.backButton.location.location.y.set((pageNum === 0 || !this.currCategory.showBackButton)?-0.2:0, animate?500:0) } openSidebarPage(child){ this.sidebarPage.location.location.x.set(0.625, 500) diff --git a/features/stat_next_to_name/index.js b/features/stat_next_to_name/index.js index ee8d7d2..014006c 100644 --- a/features/stat_next_to_name/index.js +++ b/features/stat_next_to_name/index.js @@ -1,6 +1,7 @@ /// <reference types="../../../CTAutocomplete" /> /// <reference lib="es2015" /> import Feature from "../../featureClass/class"; +import soopyV2Server from "../../socketConnection"; import SettingBase from "../settings/settingThings/settingBase"; class StatNextToName extends Feature { @@ -9,10 +10,72 @@ class StatNextToName extends Feature { } onEnable(){ - new SettingBase("NOTE: this does not work", "COMING SOON(tm) (sooner than sb 1.0)", true, "stat_next_to_name_description", this) + new SettingBase("(ONLY WEIGHT ATM) NOTE: A pink star thing (&d⚝§0)", "Means that player is also using SoopyV2", true, "stat_next_to_name_description", this) + + this.userStats = {} + + this.loadingStats = [] + + this.statsThing = "weight" + this.decimalPlaces = 0 + + soopyV2Server.onPlayerStatsLoaded = (stats)=>{this.playerStatsLoaded.call(this, stats)} + + this.registerStep(false, 5, this.loadPlayerStatsTick) + } + + loadPlayerStatsTick(){ + let nearestPlayer = undefined + let nearestDistance = Infinity + + World.getAllPlayers().forEach(player => { + if(this.userStats[player.getUUID().toString().replace(/-/g, "")]){ + this.updatePlayerNametag(player) + return + } + if(this.loadingStats.includes(player.getUUID().toString().replace(/-/g, ""))) 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){ + nearestDistance = dist + nearestPlayer = player.getUUID().toString().replace(/-/g, "") + } + }) + + if(nearestPlayer){ + this.loadPlayerStats(nearestPlayer) + } + } + + updatePlayerNametag(player){ + let stats = this.userStats[player.getUUID().toString().replace(/-/g, "")] + + let nameTagString = player.getName() + + nameTagString += " &2[" + if(stats.usingSoopyv2) nameTagString += "&d⚝&2" + if(stats.exists && stats[this.statsThing]){ + nameTagString +=stats[this.statsThing].toFixed(this.decimalPlaces) + }else{ + nameTagString += "?" + } + nameTagString += "]" + player.setNametagName(new TextComponent(nameTagString)); + } + + loadPlayerStats(uuid){ + // console.log("loading stats for " + uuid) + soopyV2Server.requestPlayerStats(uuid) + this.loadingStats.push(uuid) + } + + playerStatsLoaded(stats){ + // console.log(JSON.stringify(stats, undefined, 2)) + this.userStats[stats.uuid] = stats } onDisable(){ + this.userStats = undefined } } diff --git a/socketConnection.js b/socketConnection.js index a7524a9..f8c61b4 100644 --- a/socketConnection.js +++ b/socketConnection.js @@ -13,6 +13,8 @@ class SoopyV2Server extends WebsiteCommunicator { this.errorsToReport = [] this.reportErrorsSetting = undefined + + this.onPlayerStatsLoaded = undefined } onData(data){ @@ -22,6 +24,9 @@ class SoopyV2Server extends WebsiteCommunicator { if(data.type === "spammedmessage"){ this.spammedMessages.push(...data.messages) } + if(data.type === "playerStatsQuick"){ + if(this.onPlayerStatsLoaded) this.onPlayerStatsLoaded(data.data) + } } onConnect(){ @@ -73,6 +78,12 @@ class SoopyV2Server extends WebsiteCommunicator { } } + requestPlayerStats(uuid){ + this.sendData({ + type: "loadStatsQuick", + uuid: uuid + }) + } } let soopyV2Server = new SoopyV2Server() |