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

/**
 * Registers Learn Move Points + unlocked move lists as PLAYER dynamic properties.
 * Safe: wrapped in try/catch; if already registered elsewhere, registration will be skipped.
 */
world.afterEvents.worldInitialize.subscribe((ev) => {
  try {
    const def = new DynamicPropertiesDefinition();

    // Team slots are 1..6 in this pack.
    for (let i = 1; i <= 6; i++) {
      try { def.defineNumber(`pr:slot_${i}_learn_points`); } catch (e) {}
      // Keep this conservative to avoid max-length issues on some runtimes.
      try { def.defineString(`pr:slot_${i}_unlocked_moves`, 1024); } catch (e) {}
    }

    ev.propertyRegistry.registerPlayerDynamicProperties(def);
  } catch (e) {
    // Ignore to avoid crashing on older runtimes / if already registered.
  }
});
