diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/NonFunction.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/NonFunction.java deleted file mode 100644 index 917088400..000000000 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/NonFunction.java +++ /dev/null @@ -1,5 +0,0 @@ -package net.modificationstation.stationapi.impl.config; - -public interface NonFunction { - R apply(A a, B b, C c, D d, E e, F f, G g, H h, I i); -} diff --git a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/factory/DefaultFactoryProvider.java b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/factory/DefaultFactoryProvider.java index e546fd994..c47ce205e 100644 --- a/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/factory/DefaultFactoryProvider.java +++ b/glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/factory/DefaultFactoryProvider.java @@ -3,7 +3,6 @@ import com.google.common.collect.ImmutableMap; import net.modificationstation.stationapi.api.config.ConfigFactoryProvider; import net.modificationstation.stationapi.api.config.ConfigEntry; -import net.modificationstation.stationapi.impl.config.NonFunction; import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler; import net.modificationstation.stationapi.impl.config.object.entry.BooleanConfigEntryHandler; import net.modificationstation.stationapi.impl.config.object.entry.FloatConfigEntryHandler; @@ -12,7 +11,6 @@ import net.modificationstation.stationapi.impl.config.object.entry.IntegerListConfigEntryHandler; import net.modificationstation.stationapi.impl.config.object.entry.StringConfigEntryHandler; import net.modificationstation.stationapi.impl.config.object.entry.StringListConfigEntryHandler; -import uk.co.benjiweber.expressions.function.OctFunction; import uk.co.benjiweber.expressions.function.SeptFunction; import java.lang.reflect.*; @@ -28,9 +26,9 @@ public void provideLoadFactories(ImmutableMap.Builder new IntegerConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, Integer.valueOf(String.valueOf(value)), Integer.valueOf(String.valueOf(defaultValue))))); immutableBuilder.put(Float.class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new FloatConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, Float.valueOf(String.valueOf(value)), Float.valueOf(String.valueOf(defaultValue))))); immutableBuilder.put(Boolean.class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new BooleanConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, (boolean) value, (boolean) defaultValue))); - immutableBuilder.put(String[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new StringListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, ((ArrayList) value).toArray(new String[0]), (String[]) defaultValue))); // the new ArrayList is required or it returns java.util.Arrays.ArrayList, which is fucking dumb. - immutableBuilder.put(Integer[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new IntegerListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, ((ArrayList) value).toArray(new Integer[0]), (Integer[]) defaultValue))); - immutableBuilder.put(Float[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new FloatListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, ((ArrayList) value).toArray(new Float[0]), (Float[]) defaultValue))); + immutableBuilder.put(String[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new StringListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, listOrArrayToArray(value, new String[0]), (String[]) defaultValue))); + immutableBuilder.put(Integer[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new IntegerListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, listOrArrayToArray(value, new Integer[0]), (Integer[]) defaultValue))); + immutableBuilder.put(Float[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new FloatListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, listOrArrayToArray(value, new Float[0]), (Float[]) defaultValue))); } @Override @@ -44,7 +42,15 @@ public void provideSaveFactories(ImmutableMap.Builder T justPass(T object) { + public static T justPass(T object) { return object; } + + public static T[] listOrArrayToArray(Object object, T[] type) { + if (object instanceof List list) { + return list.toArray(type); + } + //noinspection unchecked // If this isn't right, we're fucked anyways + return (T[]) object; + } } diff --git a/src/test/resources/fabric.mod.json b/src/test/resources/fabric.mod.json index b95b2e039..5f5088e0b 100644 --- a/src/test/resources/fabric.mod.json +++ b/src/test/resources/fabric.mod.json @@ -51,7 +51,6 @@ "net.modificationstation.sltest.gcapi.ExampleConfig" ], "gcapi:factory_provider": [ - "net.modificationstation.stationapi.impl.config.factory.DefaultFactoryProvider", "net.modificationstation.sltest.gcapi.ExampleConfigEnumFactories" ], "gcapi:postload": [