Reorganized Imports/Packages
This commit is contained in:
parent
cb9459f176
commit
3ee10482ab
721 changed files with 34873 additions and 33558 deletions
72
src/main/java/org/betterx/bclib/config/ConfigWriter.java
Normal file
72
src/main/java/org/betterx/bclib/config/ConfigWriter.java
Normal file
|
@ -0,0 +1,72 @@
|
|||
package org.betterx.bclib.config;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import org.betterx.bclib.util.JsonFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ConfigWriter {
|
||||
private final static Path GAME_CONFIG_DIR = FabricLoader.getInstance().getConfigDir();
|
||||
|
||||
private final File configFile;
|
||||
private JsonObject configObject;
|
||||
|
||||
public ConfigWriter(String modID, String configFile) {
|
||||
this.configFile = new File(GAME_CONFIG_DIR.resolve(modID).toFile(), configFile + ".json");
|
||||
File parent = this.configFile.getParentFile();
|
||||
if (!parent.exists()) {
|
||||
parent.mkdirs();
|
||||
}
|
||||
this.load();
|
||||
}
|
||||
|
||||
File getConfigFile() {
|
||||
return this.configFile;
|
||||
}
|
||||
|
||||
public JsonObject getConfig() {
|
||||
return configObject;
|
||||
}
|
||||
|
||||
public void save() {
|
||||
if (configObject == null) {
|
||||
return;
|
||||
}
|
||||
save(configFile, configObject);
|
||||
}
|
||||
|
||||
JsonObject reload() {
|
||||
configObject = load(configFile);
|
||||
return configObject;
|
||||
}
|
||||
|
||||
public JsonObject load() {
|
||||
if (configObject == null) {
|
||||
configObject = load(configFile);
|
||||
}
|
||||
return configObject;
|
||||
}
|
||||
|
||||
public void save(JsonElement config) {
|
||||
this.configObject = config.getAsJsonObject();
|
||||
save(configFile, config);
|
||||
}
|
||||
|
||||
public static JsonObject load(File configFile) {
|
||||
return JsonFactory.getJsonObject(configFile);
|
||||
}
|
||||
|
||||
public static void save(File configFile, JsonElement config) {
|
||||
JsonFactory.storeJson(configFile, config);
|
||||
}
|
||||
|
||||
public static String scrubFileName(String input) {
|
||||
input = input.replaceAll("[/\\ ]+", "_");
|
||||
input = input.replaceAll("[,:&\"\\|\\<\\>\\?\\*]", "_");
|
||||
return input;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue