Bläddra i källkod

Minor changes

Lortseam 4 år sedan
förälder
incheckning
4cc8160cf3

+ 11 - 2
src/main/java/me/lortseam/completeconfig/ModController.java

@@ -1,12 +1,14 @@
 package me.lortseam.completeconfig;
 
 import lombok.Getter;
-import me.lortseam.completeconfig.data.ColorEntry;
 import me.lortseam.completeconfig.data.Config;
 import me.lortseam.completeconfig.util.TypeUtils;
 import net.fabricmc.loader.api.FabricLoader;
 import net.fabricmc.loader.api.ModContainer;
 import net.fabricmc.loader.api.metadata.ModMetadata;
+import net.minecraft.text.TextColor;
+import org.spongepowered.configurate.serialize.CoercionFailedException;
+import org.spongepowered.configurate.serialize.TypeSerializer;
 import org.spongepowered.configurate.serialize.TypeSerializerCollection;
 
 import java.util.HashMap;
@@ -17,7 +19,14 @@ public final class ModController {
 
     private static final Map<String, ModController> controllers = new HashMap<>();
     private static final TypeSerializerCollection GLOBAL_TYPE_SERIALIZERS = TypeSerializerCollection.builder()
-            .registerExact(ColorEntry.Serializers.TEXT_COLOR)
+            .registerExact(TypeSerializer.of(TextColor.class, (item, typeSupported) -> {
+                return item.getRgb();
+            }, value -> {
+                if (value instanceof Integer) {
+                    return TextColor.fromRgb((int) value);
+                }
+                throw new CoercionFailedException(value, "TextColor");
+            }))
             .build();
 
     /**

+ 0 - 20
src/main/java/me/lortseam/completeconfig/data/ColorEntry.java

@@ -1,13 +1,7 @@
 package me.lortseam.completeconfig.data;
 
-import lombok.AccessLevel;
 import lombok.Getter;
-import lombok.NoArgsConstructor;
 import me.lortseam.completeconfig.data.entry.EntryOrigin;
-import net.minecraft.text.TextColor;
-import org.spongepowered.configurate.serialize.CoercionFailedException;
-import org.spongepowered.configurate.serialize.ScalarSerializer;
-import org.spongepowered.configurate.serialize.TypeSerializer;
 
 public class ColorEntry<T> extends Entry<T> {
 
@@ -19,18 +13,4 @@ public class ColorEntry<T> extends Entry<T> {
         this.alphaMode = alphaMode;
     }
 
-    @NoArgsConstructor(access = AccessLevel.PRIVATE)
-    public static final class Serializers {
-
-        public static final ScalarSerializer<TextColor> TEXT_COLOR = TypeSerializer.of(TextColor.class, (item, typeSupported) -> {
-            return item.getRgb();
-        }, value -> {
-            if (value instanceof Integer) {
-                return TextColor.fromRgb((int) value);
-            }
-            throw new CoercionFailedException(value, "TextColor");
-        });
-
-    }
-
 }

+ 2 - 2
src/main/java/me/lortseam/completeconfig/data/Entry.java

@@ -100,14 +100,14 @@ public class Entry<T> extends EntryBase<T> implements DataPart {
 
     private T getFieldValue() {
         try {
-            return (T) Objects.requireNonNull(field.get(parentObject), "Entry field value may never be null: " + field);
+            return (T) Objects.requireNonNull(field.get(parentObject), "Entry field value must never be null: " + field);
         } catch (IllegalAccessException e) {
             throw new RuntimeException(e);
         }
     }
 
     public void setValue(T value) {
-        update(Objects.requireNonNull(value, "Entry value may never be null: " + field));
+        update(Objects.requireNonNull(value, "Entry value must never be null: " + field));
     }
 
     private boolean update() {

+ 1 - 1
src/main/java/me/lortseam/completeconfig/data/entry/Transformation.java

@@ -15,7 +15,7 @@ import java.lang.reflect.Type;
 import java.util.function.Predicate;
 
 @RequiredArgsConstructor(access = AccessLevel.PRIVATE)
-public class Transformation<O extends EntryOrigin> {
+public final class Transformation<O extends EntryOrigin> {
 
     public static Transformation<EntryOrigin> of(Predicate<EntryBase<?>> predicate, Transformer<EntryOrigin> transformer) {
         return new Transformation<>(predicate, EntryOrigin::new, transformer);