diff --git a/scripts/jaylydb/index.js b/scripts/jaylydb/index.js index 0f3b1ab1..67c3ab07 100644 --- a/scripts/jaylydb/index.js +++ b/scripts/jaylydb/index.js @@ -23,6 +23,8 @@ */ import { ScoreboardIdentityType, system, world } from "@minecraft/server"; const version = "1.1.3"; +/** Ticks between each sync with the scoreboard (20 ticks = 1 second) */ +const SYNC_INTERVAL = 20; const str = () => ('00000000000000000' + (Math.random() * 0xffffffffffffffff).toString(16)).slice(-16); /** * A rough mechanism for create a random uuid. Not as secure as uuid without as much of a guarantee of uniqueness, @@ -117,7 +119,8 @@ class JaylyDB { updateParticipants() { this.localState.clear(); for (const participant of this.objective.getParticipants()) { - if (participant.type !== ScoreboardIdentityType.FakePlayer) + // getParticipants() can contain undefined entries for removed identities (#334) + if (!participant || participant.type !== ScoreboardIdentityType.FakePlayer) continue; const data = DisplayName.parse(participant.displayName, this.objective, this.salt); const key = Object.keys(data)[0]; @@ -157,7 +160,7 @@ class JaylyDB { console.error(`[JaylyDB] There is a sync issue with database '${id}'.`); this.SYNC_OK = false; } - }); + }, SYNC_INTERVAL); // #311: sync once per second instead of every tick } /** * @returns the number of elements in the database. diff --git a/scripts/jaylydb/index.ts b/scripts/jaylydb/index.ts index e767613c..4d0b805a 100644 --- a/scripts/jaylydb/index.ts +++ b/scripts/jaylydb/index.ts @@ -26,6 +26,8 @@ import { ScoreboardIdentity, ScoreboardIdentityType, ScoreboardObjective, system, world } from "@minecraft/server"; const version = "1.1.3"; +/** Ticks between each sync with the scoreboard (20 ticks = 1 second) */ +const SYNC_INTERVAL = 20; const str = () => ('00000000000000000' + (Math.random() * 0xffffffffffffffff).toString(16)).slice(-16); /** * A rough mechanism for create a random uuid. Not as secure as uuid without as much of a guarantee of uniqueness, @@ -132,7 +134,8 @@ class JaylyDB implements Map { private updateParticipants() { this.localState.clear(); for (const participant of this.objective.getParticipants()) { - if (participant.type !== ScoreboardIdentityType.FakePlayer) continue; + // getParticipants() can contain undefined entries for removed identities (#334) + if (!participant || participant.type !== ScoreboardIdentityType.FakePlayer) continue; const data = DisplayName.parse(participant.displayName, this.objective, this.salt); const key = Object.keys(data)[0]; const value = data[key]; @@ -171,7 +174,7 @@ class JaylyDB implements Map { console.error(`[JaylyDB] There is a sync issue with database '${id}'.`); this.SYNC_OK = false; } - }); + }, SYNC_INTERVAL); // #311: sync once per second instead of every tick } /** * @returns the number of elements in the database.