Skip to content

Commit 0d2389b

Browse files
committed
Code fixup
1 parent 70fb0fd commit 0d2389b

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/NonFunction.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

glass-config-api-v3/src/main/java/net/modificationstation/stationapi/impl/config/factory/DefaultFactoryProvider.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.google.common.collect.ImmutableMap;
44
import net.modificationstation.stationapi.api.config.ConfigFactoryProvider;
55
import net.modificationstation.stationapi.api.config.ConfigEntry;
6-
import net.modificationstation.stationapi.impl.config.NonFunction;
76
import net.modificationstation.stationapi.impl.config.object.ConfigEntryHandler;
87
import net.modificationstation.stationapi.impl.config.object.entry.BooleanConfigEntryHandler;
98
import net.modificationstation.stationapi.impl.config.object.entry.FloatConfigEntryHandler;
@@ -12,7 +11,6 @@
1211
import net.modificationstation.stationapi.impl.config.object.entry.IntegerListConfigEntryHandler;
1312
import net.modificationstation.stationapi.impl.config.object.entry.StringConfigEntryHandler;
1413
import net.modificationstation.stationapi.impl.config.object.entry.StringListConfigEntryHandler;
15-
import uk.co.benjiweber.expressions.function.OctFunction;
1614
import uk.co.benjiweber.expressions.function.SeptFunction;
1715

1816
import java.lang.reflect.*;
@@ -28,9 +26,9 @@ public void provideLoadFactories(ImmutableMap.Builder<Type, SeptFunction<String,
2826
immutableBuilder.put(Integer.class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new IntegerConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, Integer.valueOf(String.valueOf(value)), Integer.valueOf(String.valueOf(defaultValue)))));
2927
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)))));
3028
immutableBuilder.put(Boolean.class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new BooleanConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, (boolean) value, (boolean) defaultValue)));
31-
immutableBuilder.put(String[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new StringListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, ((ArrayList<String>) value).toArray(new String[0]), (String[]) defaultValue))); // the new ArrayList is required or it returns java.util.Arrays.ArrayList, which is fucking dumb.
32-
immutableBuilder.put(Integer[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new IntegerListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, ((ArrayList<Integer>) value).toArray(new Integer[0]), (Integer[]) defaultValue)));
33-
immutableBuilder.put(Float[].class, ((id, configEntry, parentField, parentObject, isMultiplayerSynced, value, defaultValue) -> new FloatListConfigEntryHandler(id, configEntry, parentField, parentObject, isMultiplayerSynced, ((ArrayList<Float>) value).toArray(new Float[0]), (Float[]) defaultValue)));
29+
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)));
30+
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)));
31+
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)));
3432
}
3533

3634
@Override
@@ -44,7 +42,15 @@ public void provideSaveFactories(ImmutableMap.Builder<Type, Function<Object, Obj
4442
immutableBuilder.put(Float[].class, DefaultFactoryProvider::justPass);
4543
}
4644

47-
private static <T> T justPass(T object) {
45+
public static <T> T justPass(T object) {
4846
return object;
4947
}
48+
49+
public static <T> T[] listOrArrayToArray(Object object, T[] type) {
50+
if (object instanceof List<?> list) {
51+
return list.toArray(type);
52+
}
53+
//noinspection unchecked // If this isn't right, we're fucked anyways
54+
return (T[]) object;
55+
}
5056
}

src/test/resources/fabric.mod.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"net.modificationstation.sltest.gcapi.ExampleConfig"
5252
],
5353
"gcapi:factory_provider": [
54-
"net.modificationstation.stationapi.impl.config.factory.DefaultFactoryProvider",
5554
"net.modificationstation.sltest.gcapi.ExampleConfigEnumFactories"
5655
],
5756
"gcapi:postload": [

0 commit comments

Comments
 (0)