aboutsummaryrefslogtreecommitdiff
path: root/features
diff options
context:
space:
mode:
authorSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2022-01-14 15:27:29 +0800
committerSoopyboo32 <49228220+Soopyboo32@users.noreply.github.com>2022-01-14 15:27:29 +0800
commit0e7e9de0418d7b13ec693d55efd2b4b9ceb7ca01 (patch)
tree5c41db369b8b0232483c9b93e84e670a61dfe034 /features
parent6e9f2b22b7d91131ffaa08cac394d714eb4a72d9 (diff)
downloadSoopyV2-0e7e9de0418d7b13ec693d55efd2b4b9ceb7ca01.tar.gz
SoopyV2-0e7e9de0418d7b13ec693d55efd2b4b9ceb7ca01.tar.bz2
SoopyV2-0e7e9de0418d7b13ec693d55efd2b4b9ceb7ca01.zip
make stat next to name load in a lot faster some of the time
Diffstat (limited to 'features')
-rw-r--r--features/stat_next_to_name/index.js31
1 files changed, 29 insertions, 2 deletions
diff --git a/features/stat_next_to_name/index.js b/features/stat_next_to_name/index.js
index c38fcc7..76e9f7b 100644
--- a/features/stat_next_to_name/index.js
+++ b/features/stat_next_to_name/index.js
@@ -33,14 +33,28 @@ class StatNextToName extends Feature {
this.userStats = {}
this.loadingStats = []
+ this.lastWorldLoad = undefined
soopyV2Server.onPlayerStatsLoaded = (stats)=>{this.playerStatsLoaded.call(this, stats)}
this.registerStep(false, 5, this.loadPlayerStatsTick)
this.registerEvent("worldLoad", this.worldLoad)
+
+ this.registerEvent("playerJoined", this.playerJoined)
+
+ this.worldLoad()
}
loadPlayerStatsTick(){
+
+ if(this.lastWorldLoad && Date.now() - this.lastWorldLoad > 1000){
+ World.getAllPlayers().forEach(player => {
+ if(Player.getUUID().replace(/-/g, "").toString().substr(12, 1) !== "4") return
+ this.loadPlayerStatsCache(player.getUUID().toString().replace(/-/g, ""), player.getName())
+ })
+ this.lastWorldLoad = undefined
+ }
+
let nearestPlayer = undefined
let nearestPlayerName = undefined
let nearestDistance = Infinity
@@ -74,6 +88,16 @@ class StatNextToName extends Feature {
if(playerStats){
this.userStats[Player.getUUID().toString().replace(/-/g, "")] = playerStats
}
+
+ this.lastWorldLoad = Date.now()
+ }
+
+ playerJoined(player){
+ if(player.getUUID().toString().replace(/-/g,"") === Player.getUUID().toString().replace(/-/g,"")) return
+
+ if(Player.getUUID().replace(/-/g, "").toString().substr(12, 1) !== "4") return
+
+ this.loadPlayerStatsCache(player.getUUID().toString().replace(/-/g, ""), player.getName())
}
updatePlayerNametag(player){
@@ -102,10 +126,13 @@ class StatNextToName extends Feature {
this.loadingStats.push(uuid)
}
+ loadPlayerStatsCache(uuid, username){
+ // console.log("loading stats for " + uuid)
+ soopyV2Server.requestPlayerStatsCache(uuid, username)
+ }
+
playerStatsLoaded(stats){
- // console.log(JSON.stringify(stats, undefined, 2))
this.userStats[stats.uuid] = stats
-
}
onDisable(){