package eu.mhsl.minenet.minigames.command.anonymous;

import eu.mhsl.minenet.minigames.util.MoveInstance;
import eu.mhsl.minenet.minigames.instance.hub.Hub;
import eu.mhsl.minenet.minigames.instance.room.Room;
import net.minestom.server.command.builder.Command;
import net.minestom.server.entity.Player;

public class HubCommand extends Command {
    public HubCommand() {
        super("hub");

        setCondition(
            (sender, commandString) ->
                ((Player) sender).getInstance() instanceof Room room && !room.apiDriven
        );

        setDefaultExecutor((sender, context) -> {
            if(Room.getRoom((Player) sender).orElseThrow().apiDriven) return;
            Room.unsetRoom((Player) sender);
            MoveInstance.move((Player) sender, Hub.INSTANCE);
        });
    }
}
