This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed config management, switched to pb4 placeholders in new custom…
… chat formats
- Loading branch information
Showing
24 changed files
with
218 additions
and
149 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/cc/reconnected/server/config/ConfigManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package cc.reconnected.server.config; | ||
|
||
import cc.reconnected.server.RccServer; | ||
import com.google.gson.FieldNamingPolicy; | ||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileReader; | ||
import java.io.FileWriter; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Path; | ||
|
||
public class ConfigManager { | ||
private static final Gson gson = new GsonBuilder() | ||
.disableHtmlEscaping() | ||
.setPrettyPrinting() | ||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX") | ||
.create(); | ||
private static final Path configFilePath = FabricLoader.getInstance().getConfigDir().resolve(RccServer.MOD_ID + ".json"); | ||
private static Config config = null; | ||
|
||
public static Config load() { | ||
if (!configFilePath.toFile().exists()) { | ||
config = new Config(); | ||
save(); | ||
return config; | ||
} | ||
try (var bf = new BufferedReader(new FileReader(configFilePath.toFile(), StandardCharsets.UTF_8))) { | ||
config = gson.fromJson(bf, Config.class); | ||
save(); | ||
} catch (Exception e) { | ||
RccServer.LOGGER.error("Error loading the RccServer config file.", e); | ||
} | ||
return config; | ||
} | ||
|
||
public static void save() { | ||
var json = gson.toJson(config); | ||
try (var fw = new FileWriter(configFilePath.toFile(), StandardCharsets.UTF_8)) { | ||
fw.write(json); | ||
} catch (Exception e) { | ||
RccServer.LOGGER.error("Error saving the RccServer config file.", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.