graddle update

This commit is contained in:
lukasabbe
2025-03-25 17:43:17 +01:00
parent eb2636bd5c
commit 670fe1328b
23 changed files with 793 additions and 0 deletions
@@ -0,0 +1,71 @@
package me.lukasabbe.bookshelfinspector.config;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.loader.api.FabricLoader;
import org.yaml.snakeyaml.Yaml;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Map;
@Environment(EnvType.CLIENT)
public class Config {
public boolean lecternToggle = true;
public int scale = 10;
public boolean useRoman = false;
public void loadConfig(){
Path configPath = FabricLoader.getInstance().getConfigDir().resolve("bookshelfinspector-config.yml");
if(!Files.exists(configPath))createConfig(configPath);
Yaml yaml = new Yaml();
try{
Map<String, Object> configMap = yaml.load(new FileReader(configPath.toFile()));
if(configMap.containsKey("lectern-toggle")){
lecternToggle = (boolean) configMap.get("lectern-toggle");
}
if(configMap.containsKey("scale")){
scale = (int) configMap.get("scale");
}
if(configMap.containsKey("roman")){
useRoman = (boolean) configMap.get("roman");
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
private void createConfig(Path configPath){
FabricLoader.getInstance().getModContainer("bookshelfinspector").ifPresent(modContainer -> {
Path path = modContainer.findPath("bookshelfinspector-config.yml").orElseThrow();
try {
Files.copy(path,configPath);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}
public void saveConfig(){
Path configPath = FabricLoader.getInstance().getConfigDir().resolve("bookshelfinspector-config.yml");
if(!Files.exists(configPath))createConfig(configPath);
Yaml yaml = new Yaml();
try{
Map<String, Object> configMap = yaml.load(new FileReader(configPath.toFile()));
configMap.put("lectern-toggle",lecternToggle);
configMap.put("scale",scale);
configMap.put("roman", useRoman);
FileWriter writer = new FileWriter(configPath.toString());
yaml.dump(configMap,writer);
writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}