// Priority: 1
/**
 * @file Server - Default Gamerules + Occultism Reload Fix
 * @description Applies gamerules once and runs a one-time /reload for Occultism fix.
 */

ServerEvents.loaded(event => {

  const defaultGamerules = [
    { rule: 'doFireTick', value: 'false' },
    { rule: 'doImmediateRespawn', value: 'true' },
    { rule: 'playersSleepingPercentage', value: '1' },
  ]

  // Apply gamerules once
  defaultGamerules.forEach(gamerule => {
    if (!event.server.persistentData.get(gamerule.rule)) {
      event.server.runCommandSilent(`/gamerule ${gamerule.rule} ${gamerule.value}`)
      event.server.persistentData.put(gamerule.rule, gamerule.value)
      console.log(`[Gamerules] Applied default: ${gamerule.rule} = ${gamerule.value}`)
    }
  })

  // Occultism reload fix (run once per server session)
  event.server.scheduleInTicks(40, () => {
    console.log("[Occultism Fix] Reloading")
    event.server.runCommandSilent("reload")
  })

})