// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale;

import java.util.function.Function;
import com.hypixel.hytale.server.core.HytaleServerConfig;
import java.util.Iterator;
import io.sentry.Sentry;
import com.hypixel.hytale.logger.sentry.SkipSentryException;
import com.hypixel.hytale.logger.backend.HytaleLoggerBackend;
import joptsimple.OptionSpec;
import com.hypixel.hytale.server.core.HytaleServer;
import java.util.logging.Level;
import java.util.Map;
import com.hypixel.hytale.logger.backend.HytaleFileHandler;
import com.hypixel.hytale.logger.HytaleLogger;
import com.hypixel.hytale.server.core.Options;

public class LateMain
{
    public static void lateMain(final String[] args) {
        try {
            if (Options.parse(args)) {
                return;
            }
            HytaleLogger.init();
            HytaleFileHandler.INSTANCE.enable();
            HytaleLogger.replaceStd();
            HytaleLoggerBackend.LOG_LEVEL_LOADER = (Function<String, Level>)(name -> {
                for (final Map.Entry<String, Level> e : Options.getOptionSet().valuesOf(Options.LOG_LEVELS)) {
                    if (name.equals(e.getKey())) {
                        return (Level)e.getValue();
                    }
                }
                final HytaleServer hytaleServer = HytaleServer.get();
                if (hytaleServer != null) {
                    final HytaleServerConfig config = hytaleServer.getConfig();
                    if (config != null) {
                        final Level configLevel = config.getLogLevels().get(name);
                        if (configLevel != null) {
                            return configLevel;
                        }
                    }
                }
                if (Options.getOptionSet().has(Options.SHUTDOWN_AFTER_VALIDATE)) {
                    return Level.WARNING;
                }
                else {
                    return null;
                }
            });
            if (Options.getOptionSet().has(Options.SHUTDOWN_AFTER_VALIDATE)) {
                HytaleLoggerBackend.reloadLogLevels();
            }
            new HytaleServer();
        }
        catch (final Throwable t) {
            if (!SkipSentryException.hasSkipSentry(t)) {
                Sentry.captureException(t);
            }
            t.printStackTrace();
            throw new RuntimeException("Failed to create HytaleServer", t);
        }
    }
}
