package top.r3944realms.lib39.core.event;

import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.server.level.ServerLevel;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.level.LevelEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import top.r3944realms.lib39.Lib39;
import top.r3944realms.lib39.util.ILevelHelper;

/**
 * The type Server handler.
 */
public class ServerEventHandler {
    /**
     * The type Mod.
     */
    public static class Mod extends ServerEventHandler {}

    /**
     * The type Game.
     */
    @net.minecraftforge.fml.common.Mod.EventBusSubscriber(value = Dist.DEDICATED_SERVER, bus = net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus.FORGE, modid = Lib39.MOD_ID)
    public static class Game extends ServerEventHandler {
        /**
         * Register layer definitions.
         *
         * @param event the event
         */
        @SubscribeEvent
        public static void registerLayerDefinitions(LevelEvent.Load event) {
            if (event.getLevel() != null && event.getLevel() instanceof ServerLevel level) {
                ILevelHelper.LevelHelper.SERVER.setLevel(level);
            }
        }

        /**
         * Register layer definitions.
         *
         * @param event the event
         */
        @SubscribeEvent
        public static void registerLayerDefinitions(LevelEvent.Unload event) {
            if (event.getLevel() != null && event.getLevel() instanceof ServerLevel) {
                ILevelHelper.LevelHelper.SERVER.setLevel(null);
            }
        }
    }
}
