From 312cf6b1d2990d7632807dfa5ef93b8dd2cbb865 Mon Sep 17 00:00:00 2001 From: Anthony Hilyard Date: Mon, 31 Jan 2022 17:58:26 -0800 Subject: Fixed config registration bug. --- .../anthonyhilyard/iceberg/config/IcebergConfig.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/main') diff --git a/src/main/java/com/anthonyhilyard/iceberg/config/IcebergConfig.java b/src/main/java/com/anthonyhilyard/iceberg/config/IcebergConfig.java index cc48c2c..0ce0670 100644 --- a/src/main/java/com/anthonyhilyard/iceberg/config/IcebergConfig.java +++ b/src/main/java/com/anthonyhilyard/iceberg/config/IcebergConfig.java @@ -1,9 +1,12 @@ package com.anthonyhilyard.iceberg.config; +import java.util.Set; + import javax.annotation.Nonnull; import com.anthonyhilyard.iceberg.Loader; import com.electronwill.nightconfig.core.Config; +import com.google.common.collect.Sets; import org.apache.commons.lang3.tuple.Pair; @@ -18,7 +21,7 @@ public abstract class IcebergConfig> private static IcebergConfigSpec SPEC = null; private static IcebergConfig INSTANCE = null; private static String modId = null; - private static boolean registered = false; + private static Set> registeredClasses = Sets.newHashSet(); protected abstract > void setInstance(I instance); protected void onLoad() {} @@ -49,8 +52,9 @@ public abstract class IcebergConfig> public static final boolean register(Class> superClass, @Nonnull String modId) { - if (registered) + if (registeredClasses.contains(superClass)) { + Loader.LOGGER.warn("Failed to register configuration: {} is already registered!", superClass.getName()); return false; } @@ -72,8 +76,15 @@ public abstract class IcebergConfig> return result; }); - if (specPair.getRight() == null || specPair.getLeft() == null) + if (specPair.getRight() == null) + { + Loader.LOGGER.warn("Failed to register configuration: Generated spec was null!"); + return false; + } + + if (specPair.getLeft() == null) { + Loader.LOGGER.warn("Failed to register configuration: Generated configuration instance was null!"); return false; } @@ -83,7 +94,7 @@ public abstract class IcebergConfig> ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, SPEC); - registered = true; + registeredClasses.add(superClass); return true; } } -- cgit