package net.minecraft.launcher;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.yaml.snakeyaml.Yaml;

public class Language {
   private static final Logger LOGGER = LogManager.getLogger();
   public static Map<String, Object> data;
   public static Map<String, String> langs = new HashMap();
   private static String lang = "en";

   public static String get(String id) {
      return (String)data.get(id);
   }

   public static Boolean getBoolean(String id) {
      return (Boolean)data.get(id);
   }

   public static String getLanguage() {
      return lang;
   }

   public void loadFileNames() throws URISyntaxException {
      String path = "langs";
      File jarFile = new File(NetLauncherMain.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
      if (jarFile.isFile()) {
         try {
            JarFile jar = new JarFile(jarFile);
            Enumeration entries = jar.entries();

            while(entries.hasMoreElements()) {
               String name = ((JarEntry)entries.nextElement()).getName();
               if (name.startsWith(path + "/")) {
                  System.out.println(name);

                  try {
                     Yaml yaml = new Yaml();
                     Map<String, Object> data2 = (Map)yaml.load(this.getClass().getResourceAsStream("/" + name));
                     langs.put((String)data2.get("langcode"), (String)data2.get("description"));
                     LOGGER.info("[Skaia Launcher Log] SUCCESSFULLY LOADED LANGUAGE: " + (String)data2.get("langcode") + " " + (String)data2.get("description"));
                  } catch (Exception var12) {
                     System.out.println("Exception " + var12.getLocalizedMessage());
                  }
               }
            }

            jar.close();
         } catch (IOException var15) {
            java.util.logging.Logger.getLogger(Language.class.getName()).log(Level.SEVERE, (String)null, var15);
         }
      } else {
         URL url = Launcher.class.getResource("/" + path);
         if (url != null) {
            try {
               File apps = new File(url.toURI());
               File[] var8;
               int var20 = (var8 = apps.listFiles()).length;

               for(int var19 = 0; var19 < var20; ++var19) {
                  File app = var8[var19];
                  Yaml yaml = new Yaml();
                  InputStream ios = new FileInputStream(app);
                  System.out.println("Trying to load: " + app);
                  Map<String, Object> data2 = (Map)yaml.load((InputStream)ios);
                  langs.put((String)data2.get("langcode"), (String)data2.get("description"));
                  System.out.println("LOADED LANGUAGE: " + (String)data2.get("langcode") + " " + (String)data2.get("description"));
               }
            } catch (URISyntaxException var13) {
            } catch (FileNotFoundException var14) {
               java.util.logging.Logger.getLogger(Language.class.getName()).log(Level.SEVERE, (String)null, var14);
            }
         }
      }

   }

   public void load(String lang) {
      Language.lang = lang;

      try {
         Yaml yaml = new Yaml();
         data = (Map)yaml.load(this.getClass().getResourceAsStream("/langs/" + lang + ".yml"));
         System.out.println("LOADED LANGUAGES");
      } catch (Exception var3) {
      }

   }
}
