From 6eb67be749de3e1992f8362cc445c00c383b3ac2 Mon Sep 17 00:00:00 2001 From: 1Paul2 <160780913+1Paul2@users.noreply.github.com> Date: Sat, 5 Dec 2026 09:45:53 -0600 Subject: [PATCH 1/3] Ignore undefined scoreboard participants in JaylyDB Fixes #334. Before, when the database read the scoreboard, it assumed every entry returned by getParticipants() was valid. In some cases the game returns an empty (undefined) entry for an identity that was already removed, and the script crashed trying to read its type, which stopped the database from loading its data. Now those empty entries are skipped and the rest of the data loads normally. --- scripts/jaylydb/index.js | 4 +++- scripts/jaylydb/index.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/jaylydb/index.js b/scripts/jaylydb/index.js index 0f3b1ab1..38457156 100644 --- a/scripts/jaylydb/index.js +++ b/scripts/jaylydb/index.js @@ -114,10 +114,12 @@ class JaylyDB { * Sync between objective and local state * @internal */ + // Correccion - Poll: skip undefined participants returned by getParticipants() (#334) 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]; diff --git a/scripts/jaylydb/index.ts b/scripts/jaylydb/index.ts index e767613c..02afdb8a 100644 --- a/scripts/jaylydb/index.ts +++ b/scripts/jaylydb/index.ts @@ -129,10 +129,12 @@ class JaylyDB implements Map { * Sync between objective and local state * @internal */ + // Correccion - Poll: skip undefined participants returned by getParticipants() (#334) 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]; From d99c8856a4388325f35331738f83ed0ce20743c7 Mon Sep 17 00:00:00 2001 From: 1Paul2 <160780913+1Paul2@users.noreply.github.com> Date: Sat, 5 Dec 2026 09:46:01 -0600 Subject: [PATCH 2/3] Sync JaylyDB with the scoreboard once per second Refs #311. Before, every open database re-read the whole scoreboard on every game tick (20 times per second), rebuilding its local copy each time. With large databases or several of them this used a lot of processing time and could slow the world down. Now the sync runs every 20 ticks, once per second, using the new SYNC_INTERVAL constant. Reads and writes made by the script are not affected, since they use the local copy directly. Only changes made to the scoreboard from outside the script (for example, with commands) may take up to one second to appear. The single full read done when the database is first created is unchanged, so this reduces the ongoing cost but may not remove the startup spike reported in the issue on its own. --- scripts/jaylydb/index.js | 5 ++++- scripts/jaylydb/index.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/jaylydb/index.js b/scripts/jaylydb/index.js index 38457156..30ccfdb9 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, @@ -136,6 +138,7 @@ class JaylyDB { * @param id An identifier for the database * @param encrypted whether this database is encrypted or not, note that encryption state cannot be changed after creation */ + // Correccion - Poll: run the sync every 20 ticks instead of every tick (#311) constructor(id, encrypted = false) { this.objective = world.scoreboard.getObjective("jaylydb:" + id) ?? world.scoreboard.addObjective("jaylydb:" + id, uuid()); this.encrypted = encrypted; @@ -159,7 +162,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 02afdb8a..6ade889a 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, @@ -149,6 +151,7 @@ class JaylyDB implements Map { * @param id An identifier for the database * @param encrypted whether this database is encrypted or not, note that encryption state cannot be changed after creation */ + // Correccion - Poll: run the sync every 20 ticks instead of every tick (#311) constructor(id: string, encrypted: boolean = false) { this.objective = world.scoreboard.getObjective("jaylydb:" + id) ?? world.scoreboard.addObjective("jaylydb:" + id, uuid()); this.encrypted = encrypted; @@ -173,7 +176,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. From cd0e05f63ce45a21bcd582b2bda0f8f3e1fe341e Mon Sep 17 00:00:00 2001 From: 1Paul2 <160780913+1Paul2@users.noreply.github.com> Date: Sat, 5 Dec 2026 09:49:30 -0600 Subject: [PATCH 3/3] Remove personal correction notes from JaylyDB Before, the two functions changed in this branch had an extra comment above them marking who made the correction. That note is not useful to the project and repeated what the inline comments already explain. Now only the inline comments that describe each fix (#334 and #311) remain. --- scripts/jaylydb/index.js | 2 -- scripts/jaylydb/index.ts | 2 -- 2 files changed, 4 deletions(-) diff --git a/scripts/jaylydb/index.js b/scripts/jaylydb/index.js index 30ccfdb9..67c3ab07 100644 --- a/scripts/jaylydb/index.js +++ b/scripts/jaylydb/index.js @@ -116,7 +116,6 @@ class JaylyDB { * Sync between objective and local state * @internal */ - // Correccion - Poll: skip undefined participants returned by getParticipants() (#334) updateParticipants() { this.localState.clear(); for (const participant of this.objective.getParticipants()) { @@ -138,7 +137,6 @@ class JaylyDB { * @param id An identifier for the database * @param encrypted whether this database is encrypted or not, note that encryption state cannot be changed after creation */ - // Correccion - Poll: run the sync every 20 ticks instead of every tick (#311) constructor(id, encrypted = false) { this.objective = world.scoreboard.getObjective("jaylydb:" + id) ?? world.scoreboard.addObjective("jaylydb:" + id, uuid()); this.encrypted = encrypted; diff --git a/scripts/jaylydb/index.ts b/scripts/jaylydb/index.ts index 6ade889a..4d0b805a 100644 --- a/scripts/jaylydb/index.ts +++ b/scripts/jaylydb/index.ts @@ -131,7 +131,6 @@ class JaylyDB implements Map { * Sync between objective and local state * @internal */ - // Correccion - Poll: skip undefined participants returned by getParticipants() (#334) private updateParticipants() { this.localState.clear(); for (const participant of this.objective.getParticipants()) { @@ -151,7 +150,6 @@ class JaylyDB implements Map { * @param id An identifier for the database * @param encrypted whether this database is encrypted or not, note that encryption state cannot be changed after creation */ - // Correccion - Poll: run the sync every 20 ticks instead of every tick (#311) constructor(id: string, encrypted: boolean = false) { this.objective = world.scoreboard.getObjective("jaylydb:" + id) ?? world.scoreboard.addObjective("jaylydb:" + id, uuid()); this.encrypted = encrypted;