mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 18:48:20 +08:00
feat: Split MapSection and MemorySection
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>easyconfiguration-parent</artifactId>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<version>4.0.3</version>
|
||||
<version>4.0.4</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
@@ -2,7 +2,7 @@ package cc.carm.lib.configuration.source.json;
|
||||
|
||||
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||
import cc.carm.lib.configuration.source.file.FileConfigSource;
|
||||
import cc.carm.lib.configuration.source.section.MapSection;
|
||||
import cc.carm.lib.configuration.source.section.MemorySection;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonSerializer;
|
||||
@@ -14,17 +14,17 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class JSONSource extends FileConfigSource<MapSection, Map<String, Object>, JSONSource> {
|
||||
public class JSONSource extends FileConfigSource<MemorySection, Map<String, Object>, JSONSource> {
|
||||
|
||||
public static final @NotNull Gson DEFAULT_GSON = new GsonBuilder()
|
||||
.serializeNulls().disableHtmlEscaping().setPrettyPrinting()
|
||||
.registerTypeAdapter(
|
||||
MapSection.class,
|
||||
(JsonSerializer<MapSection>) (src, t, c) -> c.serialize(src.data())
|
||||
MemorySection.class,
|
||||
(JsonSerializer<MemorySection>) (src, t, c) -> c.serialize(src.data())
|
||||
).create();
|
||||
|
||||
protected final @NotNull Gson gson;
|
||||
protected @Nullable MapSection rootSection;
|
||||
protected @Nullable MemorySection rootSection;
|
||||
|
||||
protected JSONSource(@NotNull ConfigurationHolder<? extends JSONSource> holder,
|
||||
@NotNull File file, @Nullable String resourcePath) {
|
||||
@@ -58,7 +58,7 @@ public class JSONSource extends FileConfigSource<MapSection, Map<String, Object>
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull MapSection section() {
|
||||
public @NotNull MemorySection section() {
|
||||
return Objects.requireNonNull(this.rootSection, "Root section is not initialized");
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ public class JSONSource extends FileConfigSource<MapSection, Map<String, Object>
|
||||
@Override
|
||||
protected void onReload() throws Exception {
|
||||
Map<?, ?> data = fileReader(reader -> gson.fromJson(reader, LinkedHashMap.class));
|
||||
this.rootSection = MapSection.root(this, data);
|
||||
this.rootSection = MemorySection.root(this, data);
|
||||
this.lastUpdateMillis = System.currentTimeMillis(); // 更新时间
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user