Successful default config load in Fabric

This commit is contained in:
dfsek
2020-12-13 02:00:15 -07:00
parent a3add9b20f
commit 2c15a9fc0c
19 changed files with 70 additions and 600 deletions

View File

@@ -1,31 +1,34 @@
package com.dfsek.terra.api.gaea.lang;
import com.dfsek.tectonic.config.Configuration;
import com.dfsek.terra.api.generic.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Language {
private final Configuration configuration;
public Language(File file) throws IOException {
load(file);
}
public void load(@NotNull File file) throws IOException {
configuration = new Configuration(new FileInputStream(file));
}
@SuppressWarnings("unchecked")
public Message getMessage(String id) {
Object m = null;
Message temp;
if(m instanceof List) {
temp = new MultiLineMessage((List<String>) m);
} else if(m instanceof String) {
temp = new SingleLineMessage((String) m);
} else return new SingleLineMessage("message:" + id + ":translation_undefined");
if(temp.isEmpty()) return new SingleLineMessage("message:" + id + ":translation_undefined");
Message temp = null;
if(configuration.contains(id)) {
Object m = configuration.get(id);
if(m instanceof List) {
temp = new MultiLineMessage((List<String>) m);
} else if(m instanceof String) {
temp = new SingleLineMessage((String) m);
} else return new SingleLineMessage("message:" + id + ":translation_undefined");
}
if(temp == null || temp.isEmpty()) return new SingleLineMessage("message:" + id + ":translation_undefined");
return temp;
}
public void log(String messageID, Level level, Logger logger, String... args) {

View File

@@ -29,7 +29,10 @@ public final class LangUtil {
Debug.error("Report this to Terra!");
}
try {
language = new Language(new File(main.getDataFolder(), "lang" + File.separator + langID + ".yml"));
File file1 = new File(file, langID + ".yml");
logger.info(file1.getAbsolutePath());
language = new Language(file1);
logger.info("Loaded language " + langID);
} catch(IOException e) {
logger.severe("Unable to load language: " + langID);
e.printStackTrace();