/** * This writes the the language yml file. * * @throws IOException */ private void writeLanguageConfig() throws IOException { for (Language g : Language.values()) { String path = g.getPath(); this.configLanguage.set(path, g.getSentence()); } String contentToSave = this.configLanguage.saveToString(); Writer out = new OutputStreamWriter(new FileOutputStream(this.fileLanguage), "UTF-8"); out.write(contentToSave); out.flush(); out.close(); }
/** Loads the language file, that is setted in conig.yml */ public void loadLanguageConfig() throws Exception { if (!new File(this.getDataFolder() + File.separator + "language").exists()) { new File(this.getDataFolder() + File.separator + "language").mkdirs(); } String encoding = "UTF-8"; if (!this.fileLanguage.exists()) { this.fileLanguage.createNewFile(); // create file this.writeLanguageConfig(); // write standard language } else { Scanner scanner = new Scanner(new FileInputStream(this.fileLanguage), encoding); String contentToRead = ""; while (scanner.hasNextLine()) { contentToRead += scanner.nextLine() + System.getProperty("line.separator"); } scanner.close(); try { this.configLanguage.loadFromString(contentToRead); } catch (InvalidConfigurationException e) { encoding = "Cp1252"; scanner = new Scanner(new FileInputStream(this.fileLanguage), encoding); contentToRead = ""; while (scanner.hasNextLine()) { contentToRead += scanner.nextLine() + System.getProperty("line.separator"); } scanner.close(); this.configLanguage.loadFromString(contentToRead); } boolean missing = false; for (Language g : Language.values()) { String path = g.getPath(); if (!this.configLanguage.contains(path)) { this.configLanguage.set(path, g.getSentence()); missing = true; } else { g.setSentence(this.replaceColor(this.configLanguage.getString(path))); } } if (missing) { String contentToSave = this.configLanguage.saveToString(); Writer out = new OutputStreamWriter(new FileOutputStream(this.fileLanguage), encoding); out.write(contentToSave); out.flush(); out.close(); } } SkyBlockMultiplayer.getInstance().getSkyBlockWorld(); }