import { world, DynamicPropertiesDefinition } from "@minecraft/server";

/**
 * Registers Learn Point + unlocked-moves dynamic properties on players.
 * If registration fails (older API), we silently ignore to avoid crashing.
 */
world.afterEvents.worldInitialize.subscribe((ev) => {
  try {
    const def = new DynamicPropertiesDefinition();

    // One learn point counter per team slot (1..6)
    for (let i = 1; i <= 6; i++) {
      def.defineNumber(`pr:slot_${i}_learn_points`);
      // Encoded move set string for unlocked moves per slot.
      // Keep size conservative to avoid crashes on some runtimes.
      def.defineString(`pr:slot_${i}_unlocked_moves`, 4096);
    }

    // Optional boot flag used by some builds; stored as a number (0/1).
    def.defineNumber("pr:_learnpoints_boot");

    ev.propertyRegistry.registerPlayerDynamicProperties(def);
  } catch (e) {
    // ignore
  }
});
