diff --git a/src/Timings.ts b/src/Timings.ts index 70cc8b6..5efa08b 100644 --- a/src/Timings.ts +++ b/src/Timings.ts @@ -1,10 +1,9 @@ import { Logger } from "./Logging"; - -const log = Logger.getLogger("Timings", 'timings'); /** * A simple class to measure the time it takes to perform an operation. */ export default class Timings { + private static readonly log = Logger.getLogger("Timings", 'timings'); static lastTime = -1; static lastOperation = ""; @@ -29,7 +28,7 @@ export default class Timings { static end() { const time = new Date().getTime(); if (this.lastTime > 0) { - log.debug(`Operation ${this.lastOperation} took ${time - this.lastTime}ms`); + Timings.log.debug(`Operation ${this.lastOperation} took ${time - this.lastTime}ms`); } this.lastTime = -1; } diff --git a/src/Vec3.ts b/src/Vec3.ts index ed94099..63d07de 100644 --- a/src/Vec3.ts +++ b/src/Vec3.ts @@ -1,11 +1,10 @@ import { Vector3, Direction } from "@minecraft/server"; import { Logger } from "./Logging"; -const log = Logger.getLogger("vec3", "vec3", "bedrock-boost"); - type VectorLike = Vector3 | Vec3 | Direction | number[] | number export default class Vec3 implements Vector3 { + private static readonly log = Logger.getLogger("vec3", "vec3", "bedrock-boost"); public static readonly Zero = new Vec3(0, 0, 0); public static readonly Down = new Vec3(Direction.Down); public static readonly Up = new Vec3(Direction.Up); @@ -61,7 +60,7 @@ export default class Vec3 implements Vector3 { this.z = x.z; } else { if (!x || (!x.x && x.x !== 0) || (!x.y && x.y !== 0) || (!x.z && x.z !== 0)) { - log.error(new Error("Invalid vector"), x); + Vec3.log.error(new Error("Invalid vector"), x); throw new Error("Invalid vector"); } this.x = x.x; @@ -93,7 +92,7 @@ export default class Vec3 implements Vector3 { if (x === Direction.East) return Vec3.East; if (x === Direction.West) return Vec3.West; if (!x || (!(x as any).x && (x as any).x !== 0) || (!(x as any).y && (x as any).y !== 0) || (!(x as any).z && (x as any).z !== 0)) { - log.error(new Error('Invalid arguments'), x, y, z); + Vec3.log.error(new Error('Invalid arguments'), x, y, z); throw new Error('Invalid arguments'); } return new Vec3((x as any).x as number, (x as any).y as number, (x as any).z as number); @@ -113,7 +112,7 @@ export default class Vec3 implements Vector3 { if (x === Direction.East) return Vec3.East; if (x === Direction.West) return Vec3.West; if (!x || (!(x as any).x && (x as any).x !== 0) || (!(x as any).y && (x as any).y !== 0) || (!(x as any).z && (x as any).z !== 0)) { - log.error(new Error('Invalid arguments'), x, y, z); + Vec3.log.error(new Error('Invalid arguments'), x, y, z); throw new Error('Invalid arguments'); } return new Vec3((x as any).x as number, (x as any).y as number, (x as any).z as number); @@ -221,7 +220,7 @@ export default class Vec3 implements Vector3 { */ normalize(): Vec3 { if (this.isZero()) { - log.error(new Error("Cannot normalize zero-length vector")); + Vec3.log.error(new Error("Cannot normalize zero-length vector")); throw new Error("Cannot normalize zero-length vector"); } const len = this.length(); @@ -627,7 +626,7 @@ export default class Vec3 implements Vector3 { */ toDirection(): Direction { if (this.isZero()) { - log.error(new Error("Cannot convert zero-length vector to direction")); + Vec3.log.error(new Error("Cannot convert zero-length vector to direction")); throw new Error("Cannot convert zero-length vector to direction"); } const normalized = this.normalize(); @@ -639,7 +638,7 @@ export default class Vec3 implements Vector3 { if (maxValue === normalized.z) return Direction.North; if (maxValue === -normalized.z) return Direction.South; // This should never happen - log.error(new Error("Cannot convert vector to direction"), this); + Vec3.log.error(new Error("Cannot convert vector to direction"), this); throw new Error("Cannot convert vector to direction"); } /** diff --git a/src/scheduling/PlayerPulseScheduler.ts b/src/scheduling/PlayerPulseScheduler.ts index b20918c..6888a0a 100644 --- a/src/scheduling/PlayerPulseScheduler.ts +++ b/src/scheduling/PlayerPulseScheduler.ts @@ -2,13 +2,13 @@ import { Player, system, world } from "@minecraft/server"; import PulseScheduler from "./PulseScheduler"; import { Logger } from "../Logging"; -const log = Logger.getLogger("PlayerPulseScheduler", "bedrock-boost", "player-pulse-scheduler"); - /** * Represents a PulseScheduler that processes players. */ export default class PlayerPulseScheduler extends PulseScheduler { + private static readonly log = Logger.getLogger("PlayerPulseScheduler", "bedrock-boost", "player-pulse-scheduler"); + /** * Creates a new EntityPulseScheduler instance. * @param period The period of the scheduler. @@ -35,7 +35,7 @@ export default class PlayerPulseScheduler extends PulseScheduler { const pushPlayer = () => { attempts++; if (attempts > 10) { - log.warn("Failed to push player to scheduler after 10 attempts."); + PlayerPulseScheduler.log.warn("Failed to push player to scheduler after 10 attempts."); return; } try { @@ -47,7 +47,7 @@ export default class PlayerPulseScheduler extends PulseScheduler { this.push(player); } } catch (e) { - log.debug("Failed to push player to scheduler.", e); + PlayerPulseScheduler.log.debug("Failed to push player to scheduler.", e); system.runTimeout(pushPlayer, 1); } } diff --git a/src/scheduling/PulseScheduler.ts b/src/scheduling/PulseScheduler.ts index ef4959a..97ec8d9 100644 --- a/src/scheduling/PulseScheduler.ts +++ b/src/scheduling/PulseScheduler.ts @@ -1,13 +1,13 @@ import { system } from "@minecraft/server"; import { Logger } from "../Logging"; -const log: Logger = Logger.getLogger("PulseScheduler", "bedrock-boost", "pulse-scheduler"); - /** * Represents a scheduler that executes a processor function at regular intervals for each item in the list. * @template T The type of items in the scheduler. */ export default class PulseScheduler { + + private static readonly log: Logger = Logger.getLogger("PulseScheduler", "bedrock-boost", "pulse-scheduler"); protected items: T[] = []; private period: number; private currentTick: number = 0; @@ -120,13 +120,13 @@ export default class PulseScheduler { private tick() { if (this.items.length === 0) { - log.trace("No items to process."); + PulseScheduler.log.trace("No items to process."); return; } // Number of items to process this tick const scheduledExecutions = this.executionSchedule[this.currentTick]; if (scheduledExecutions === 0) { - log.trace("No items to process this tick."); + PulseScheduler.log.trace("No items to process this tick."); // Increment the tick counter this.currentTick = (this.currentTick + 1) % this.period; // Reset the index if we're at the end of the period @@ -145,7 +145,7 @@ export default class PulseScheduler { try { this.processor(this.items[this.nextIndex]); } catch (e) { - log.error("Error processing item", e); + PulseScheduler.log.error("Error processing item", e); } executed++; }