From d6341b61b0632abd85d522a1d74778cb3bc02e9a Mon Sep 17 00:00:00 2001
From: TexTrue <3140846162@qq.com>
Date: Sat, 1 Jun 2024 12:07:54 +0800
Subject: [PATCH] sync `1.20.4/dev`
---
README.md | 14 +-
build.gradle | 2 +-
common/build.gradle | 6 +-
.../impl/config/AzusaConfigImpl.java | 16 +-
.../impl/config/JsonFamilySerializer.java | 255 ------------------
.../impl/config/NightConfigSerializer.java | 165 ------------
fabric/build.gradle | 10 +-
.../fabric/AzusaConfigModFabric.java | 4 +-
forge/build.gradle | 6 +-
.../forge/AzusaConfigExpectPlatformImpl.java | 2 +-
.../forge/AzusaConfigModForge.java | 5 +-
.../api}/EntrypointContainer.java | 2 +-
.../api}/EntrypointLoadingException.java | 2 +-
.../impl}/EntrypointStorage.java | 6 +-
gradle.properties | 5 +-
settings.gradle | 1 -
16 files changed, 34 insertions(+), 467 deletions(-)
delete mode 100644 common/src/main/java/ho/artisan/azusaconfig/impl/config/JsonFamilySerializer.java
delete mode 100644 common/src/main/java/ho/artisan/azusaconfig/impl/config/NightConfigSerializer.java
rename forge/src/main/java/ho/artisan/azusaconfig/forge/{api/entrypoint => entrypoint/api}/EntrypointContainer.java (96%)
rename forge/src/main/java/ho/artisan/azusaconfig/forge/{api/entrypoint => entrypoint/api}/EntrypointLoadingException.java (96%)
rename forge/src/main/java/ho/artisan/azusaconfig/forge/{impl/entrypoint => entrypoint/impl}/EntrypointStorage.java (95%)
diff --git a/README.md b/README.md
index 528d449..1649b7b 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
-# AzusaConfig
+# AzusaConfig for 1.20.1
###### A library to bring the Quilt Loader's Config system into Fabric/Forge/NeoForge.
@@ -11,18 +11,6 @@
> [!NOTE]
> Quilt is not supported because the [Quilt Loader](https://github.com/QuiltMC/quilt-loader) contains these functions natively. you can think of AzusaConfig as a port of [Quilt's Config system (quilt-config)](https://github.com/QuiltMC/quilt-config) to the Fabric/Forge/NeoForge.
-## Use In Your Project
-
-```groovy
-repositories {
- maven { url "https://jitpack.io" }
-}
-
-dependencies {
- modImplementation "com.github.HO-Artisan:AzusaConfig:Tag"
-}
-```
-
## License
This mod under Apache-2.0 License.
Quilt Loader part under Apache-2.0 License.
diff --git a/build.gradle b/build.gradle
index 6d416b7..62302af 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
- id "dev.architectury.loom" version "1.4-SNAPSHOT" apply false
+ id "dev.architectury.loom" version "1.5-SNAPSHOT" apply false
id "com.hypherionmc.modutils.modpublisher" version "2.0.+" apply false
}
diff --git a/common/build.gradle b/common/build.gradle
index 4268db4..16f3e2a 100644
--- a/common/build.gradle
+++ b/common/build.gradle
@@ -10,9 +10,9 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
implementation "org.quiltmc:quilt-config:${rootProject.quiltconfig_version}"
- implementation "org.quiltmc.parsers:json:${project.quiltparsers_version}"
- implementation "com.electronwill.night-config:core:${rootProject.nightconfig_version}"
- implementation "com.electronwill.night-config:toml:${rootProject.nightconfig_version}"
+ implementation "org.quiltmc.parsers:json:${rootProject.quiltparsers_version}"
+ implementation "org.quiltmc.quilt-config.serializers:toml:${rootProject.quiltconfig_version}"
+ implementation "org.quiltmc.quilt-config.serializers:json5:${rootProject.quiltconfig_version}"
}
publishing {
diff --git a/common/src/main/java/ho/artisan/azusaconfig/impl/config/AzusaConfigImpl.java b/common/src/main/java/ho/artisan/azusaconfig/impl/config/AzusaConfigImpl.java
index 8d1318a..7c634fb 100644
--- a/common/src/main/java/ho/artisan/azusaconfig/impl/config/AzusaConfigImpl.java
+++ b/common/src/main/java/ho/artisan/azusaconfig/impl/config/AzusaConfigImpl.java
@@ -21,18 +21,18 @@
import java.util.LinkedHashMap;
import java.util.Map;
-import com.electronwill.nightconfig.toml.TomlParser;
-import com.electronwill.nightconfig.toml.TomlWriter;
import ho.artisan.azusaconfig.AzusaConfigExpectPlatform;
import ho.artisan.azusaconfig.AzusaConfigMod;
import org.quiltmc.config.api.ConfigEnvironment;
import org.quiltmc.config.api.Serializer;
+import org.quiltmc.config.api.serializers.Json5Serializer;
+import org.quiltmc.config.api.serializers.TomlSerializer;
import org.slf4j.Logger;
public final class AzusaConfigImpl {
private static ConfigEnvironment ENV;
private static final Path CONFIG_DIR = AzusaConfigExpectPlatform.getConfigDirectory();
- private static Logger LOGGER = AzusaConfigMod.LOGGER;
+ private static final Logger LOGGER = AzusaConfigMod.LOGGER;
private AzusaConfigImpl() {
}
@@ -40,8 +40,8 @@ private AzusaConfigImpl() {
public static void init() {
Map serializerMap = new LinkedHashMap<>();
- serializerMap.put("toml", new NightConfigSerializer<>("toml", new TomlParser(), new TomlWriter()));
- serializerMap.put("json5", JsonFamilySerializer.JSON5);
+ serializerMap.put("toml", TomlSerializer.INSTANCE);
+ serializerMap.put("json5", Json5Serializer.INSTANCE);
for (Serializer serializer : AzusaConfigExpectPlatform.getEntrypoints("config_serializer", Serializer.class)) {
Serializer oldValue = serializerMap.put(serializer.getFileExtension(), serializer);
@@ -51,8 +51,8 @@ public static void init() {
}
}
- String globalConfigExtension = System.getProperty("nakanoconfig.loader.globalConfigExtension"/*SystemProperties.GLOBAL_CONFIG_EXTENSION*/);
- String defaultConfigExtension = System.getProperty("nakanoconfig.loader.defaultConfigExtension"/*SystemProperties.DEFAULT_CONFIG_EXTENSION*/);
+ String globalConfigExtension = System.getProperty("azusaconfig.globalConfigExtension");
+ String defaultConfigExtension = System.getProperty("azusaconfig.defaultConfigExtension");
Serializer[] serializers = serializerMap.values().toArray(new Serializer[0]);
@@ -82,4 +82,4 @@ public static void init() {
public static ConfigEnvironment getConfigEnvironment() {
return ENV;
}
-}
+}
\ No newline at end of file
diff --git a/common/src/main/java/ho/artisan/azusaconfig/impl/config/JsonFamilySerializer.java b/common/src/main/java/ho/artisan/azusaconfig/impl/config/JsonFamilySerializer.java
deleted file mode 100644
index fd5bd90..0000000
--- a/common/src/main/java/ho/artisan/azusaconfig/impl/config/JsonFamilySerializer.java
+++ /dev/null
@@ -1,255 +0,0 @@
-/*
- * Copyright 2022, 2023 QuiltMC
- * Copyright 2024 HO-Artisan
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package ho.artisan.azusaconfig.impl.config;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.quiltmc.config.api.Config;
-import org.quiltmc.config.api.Constraint;
-import org.quiltmc.config.api.MarshallingUtils;
-import org.quiltmc.config.api.Serializer;
-import org.quiltmc.config.api.annotations.Comment;
-import org.quiltmc.config.api.exceptions.ConfigParseException;
-import org.quiltmc.config.api.values.CompoundConfigValue;
-import org.quiltmc.config.api.values.ConfigSerializableObject;
-import org.quiltmc.config.api.values.TrackedValue;
-import org.quiltmc.config.api.values.ValueList;
-import org.quiltmc.config.api.values.ValueMap;
-import org.quiltmc.config.api.values.ValueTreeNode;
-import org.quiltmc.config.impl.tree.TrackedValueImpl;
-import org.quiltmc.parsers.json.JsonFormat;
-import org.quiltmc.parsers.json.JsonReader;
-import org.quiltmc.parsers.json.JsonToken;
-import org.quiltmc.parsers.json.JsonWriter;
-
-final class JsonFamilySerializer implements Serializer {
- static final JsonFamilySerializer JSON5 = new JsonFamilySerializer(JsonFormat.JSON5, "json5");
- // could also add jsonc and/or json here
- // but what would the extension for JSONC be? .json or .jsonc?
- private final JsonFormat format;
- private final String extension;
-
- private JsonFamilySerializer(JsonFormat format, String extension) {
- this.format = format;
- this.extension = extension;
- }
-
- @Override
- public String getFileExtension() {
- return extension;
- }
-
- private void serialize(JsonWriter writer, Object value) throws IOException {
- if (value instanceof Integer) {
- writer.value((Integer) value);
- } else if (value instanceof Long) {
- writer.value((Long) value);
- } else if (value instanceof Float) {
- writer.value((Float) value);
- } else if (value instanceof Double) {
- writer.value((Double) value);
- } else if (value instanceof Boolean) {
- writer.value((Boolean) value);
- } else if (value instanceof String) {
- writer.value((String) value);
- } else if (value instanceof ValueList>) {
- writer.beginArray();
-
- for (Object v : (ValueList>) value) {
- serialize(writer, v);
- }
-
- writer.endArray();
- } else if (value instanceof ValueMap>) {
- writer.beginObject();
-
- for (Map.Entry entry : (ValueMap>) value) {
- writer.name(entry.getKey());
- serialize(writer, entry.getValue());
- }
-
- writer.endObject();
- } else if (value instanceof ConfigSerializableObject) {
- serialize(writer, ((ConfigSerializableObject>) value).getRepresentation());
- } else if (value == null) {
- writer.nullValue();
- } else if (value.getClass().isEnum()) {
- writer.value(((Enum>) value).name());
- } else {
- throw new ConfigParseException();
- }
- }
-
- private void serialize(JsonWriter writer, ValueTreeNode node) throws IOException {
- for (String comment : node.metadata(Comment.TYPE)) {
- writer.comment(comment);
- }
-
- if (node instanceof ValueTreeNode.Section) {
- writer.name(node.key().getLastComponent());
- writer.beginObject();
-
- for (ValueTreeNode child : ((ValueTreeNode.Section) node)) {
- serialize(writer, child);
- }
-
- writer.endObject();
- } else {
- TrackedValue> trackedValue = ((TrackedValue>) node);
- Object defaultValue = trackedValue.getDefaultValue();
-
- if (defaultValue.getClass().isEnum()) {
- StringBuilder options = new StringBuilder("options: ");
- Object[] enumConstants = defaultValue.getClass().getEnumConstants();
-
- for (int i = 0, enumConstantsLength = enumConstants.length; i < enumConstantsLength; i++) {
- Object o = enumConstants[i];
-
- options.append(o);
-
- if (i < enumConstantsLength - 1) {
- options.append(", ");
- }
- }
-
- writer.comment(options.toString());
- }
-
- for (Constraint> constraint : trackedValue.constraints()) {
- writer.comment(constraint.getRepresentation());
- }
-
- if (!(defaultValue instanceof CompoundConfigValue>)) {
- writer.comment("default: " + defaultValue);
- }
-
- writer.name(node.key().getLastComponent());
-
- serialize(writer, trackedValue.getRealValue());
- }
- }
-
- @Override
- public void serialize(Config config, OutputStream to) throws IOException {
- JsonWriter writer = JsonWriter.create(new OutputStreamWriter(to), format);
-
- for (String comment : config.metadata(Comment.TYPE)) {
- writer.comment(comment);
- }
-
- writer.beginObject();
-
- for (ValueTreeNode node : config.nodes()) {
- this.serialize(writer, node);
- }
-
- writer.endObject();
- writer.close();
- }
-
- @Override
- @SuppressWarnings({"unchecked", "rawtypes"})
- public void deserialize(Config config, InputStream from) {
- try {
- JsonReader reader = JsonReader.create(new InputStreamReader(from), format);
-
- Map values = parseObject(reader);
-
- for (TrackedValue> value : config.values()) {
- Map m = values;
-
- for (int i = 0; i < value.key().length(); ++i) {
- String k = value.key().getKeyComponent(i);
-
- if (m.containsKey(k) && i != value.key().length() - 1) {
- m = (Map) m.get(k);
- } else if (m.containsKey(k)) {
- ((TrackedValueImpl) value).setValue(MarshallingUtils.coerce(m.get(k), value.getDefaultValue(), (Map map, MarshallingUtils.MapEntryConsumer entryConsumer) ->
- map.forEach(entryConsumer::put)), false);
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private static Map parseObject(JsonReader reader) throws IOException {
- reader.beginObject();
-
- Map object = new LinkedHashMap<>();
-
- while (reader.hasNext() && reader.peek() == JsonToken.NAME) {
- object.put(reader.nextName(), parseElement(reader));
- }
-
- reader.endObject();
-
- return object;
- }
-
- public static List