package eu.mhsl.minenet.minigames.instance.hub;

import eu.mhsl.minenet.minigames.Resource;
import eu.mhsl.minenet.minigames.instance.MineNetInstance;
import eu.mhsl.minenet.minigames.instance.hub.entity.RoomSelector;
import eu.mhsl.minenet.minigames.util.CommonEventHandles;
import eu.mhsl.minenet.minigames.instance.Spawnable;
import eu.mhsl.minenet.minigames.instance.Dimension;
import net.minestom.server.MinecraftServer;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.event.player.*;
import net.minestom.server.instance.anvil.AnvilLoader;

import java.nio.file.Path;

public class Hub extends MineNetInstance implements Spawnable {
    public static final Hub INSTANCE = new Hub();

    static {
        MinecraftServer.getInstanceManager().registerInstance(INSTANCE);

        INSTANCE.setChunkLoader(new AnvilLoader(Resource.HUB_MAP.getPath()));

        INSTANCE.eventNode()
                .addListener(PlayerBlockBreakEvent.class, CommonEventHandles::cancel)
                .addListener(PlayerBlockPlaceEvent.class, CommonEventHandles::cancel)
                .addListener(PlayerBlockInteractEvent.class, CommonEventHandles::cancel);

        new RoomSelector().setInstance(INSTANCE, new Pos(0.5, 11, 4.5));
    }

    private Hub() {
        super(Dimension.THE_END.key);
        setChunkLoader(new AnvilLoader(Path.of("maps/hub")));

        setTime(18000);
        setTimeRate(0);
    }


    @Override
    public Pos getSpawn() {
        return new Pos(0.5, 11, 0.5);
    }

}
