mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-16 08:56:04 +01:00
Funnel all gson calls into helper functions
Add deprecated getGsonFactory for plugin compat until 3.0
This commit is contained in:
@@ -3,7 +3,6 @@ package emu.grasscutter;
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
import emu.grasscutter.auth.AuthenticationSystem;
|
||||
import emu.grasscutter.auth.DefaultAuthentication;
|
||||
@@ -56,7 +55,6 @@ public final class Grasscutter {
|
||||
|
||||
private static Language language;
|
||||
|
||||
private static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
public static final File configFile = new File("./config.json");
|
||||
|
||||
private static int day; // Current day of week.
|
||||
@@ -203,8 +201,8 @@ public final class Grasscutter {
|
||||
}
|
||||
|
||||
// If the file already exists, we attempt to load it.
|
||||
try (FileReader file = new FileReader(configFile)) {
|
||||
config = gson.fromJson(file, ConfigContainer.class);
|
||||
try {
|
||||
config = Utils.loadJsonToClass(configFile.getPath(), ConfigContainer.class);
|
||||
} catch (Exception exception) {
|
||||
getLogger().error("There was an error while trying to load the configuration from config.json. Please make sure that there are no syntax errors. If you want to start with a default configuration, delete your existing config.json.");
|
||||
System.exit(1);
|
||||
@@ -220,7 +218,7 @@ public final class Grasscutter {
|
||||
if (config == null) config = new ConfigContainer();
|
||||
|
||||
try (FileWriter file = new FileWriter(configFile)) {
|
||||
file.write(gson.toJson(config));
|
||||
file.write(Utils.jsonEncode(config));
|
||||
} catch (IOException ignored) {
|
||||
Grasscutter.getLogger().error("Unable to write to config file.");
|
||||
} catch (Exception e) {
|
||||
@@ -272,8 +270,9 @@ public final class Grasscutter {
|
||||
return consoleLineReader;
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public static Gson getGsonFactory() {
|
||||
return gson;
|
||||
return Utils.getGsonFactory();
|
||||
}
|
||||
|
||||
public static HttpServer getHttpServer() {
|
||||
|
||||
Reference in New Issue
Block a user