diff options
Diffstat (limited to 'features/dataLoader')
| -rw-r--r-- | features/dataLoader/index.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/features/dataLoader/index.js b/features/dataLoader/index.js index 6f71f08..23cf744 100644 --- a/features/dataLoader/index.js +++ b/features/dataLoader/index.js @@ -30,6 +30,27 @@ class DataLoader extends Feature { this.api_loaded_event = this.createCustomEvent("apiLoad") + this.checkingPing = false; + this.lastPingCheck = 0; + this.lastPings = [undefined, undefined, undefined]; + this.ping = 0; + this.pingI = 0; + + this.registerChat("&b&bYou are currently connected to server &6${*}&r", (e) => { + if (this.checkingPing) { + this.lastPings[this.pingI % 3] = Date.now() - this.lastPingCheck; + cancel(e); + this.checkingPing = false; + + if (this.lastPings.includes(undefined)) { + this.ping = this.lastPings[this.pingI % 3]; + } else { + this.ping = [...this.lastPings].sort((a, b) => a - b)[1]; + } + this.pingI++; + } + }); + this.lastServer = undefined this.lastSentServer = 0 @@ -93,6 +114,15 @@ class DataLoader extends Feature { }) } + getPing() { + if (Date.now() - this.lastPingCheck > 60000 * 30 || (Date.now() - this.lastPingCheck > 60000 && this.lastPings.includes(undefined) && this.bloodX !== -1)) { + this.lastPingCheck = Date.now(); + ChatLib.command("whereami"); + this.checkingPing = true; + } + return this.ping || 0 + } + step_5min() { fetch("http://soopy.dev/api/v2/mayor").json(data => { if (!data.success) return |
