From af0e5699e2b3db55e4c7646273e7ce7aaa46eecc Mon Sep 17 00:00:00 2001 From: James Seibel Date: Wed, 4 Feb 2026 07:19:50 -0600 Subject: [PATCH] Fix !1088 (API config.getApiValue() not returning null) --- .../core/config/ConfigHandler.java | 3 +- .../core/config/api/DhApiConfigValue.java | 42 +++++++++-- .../core/config/file/ConfigFileHandler.java | 3 +- .../core/config/types/ConfigEntry.java | 2 +- .../core/sql/DbConnectionClosedException.java | 1 - core/src/test/java/tests/DhApiConfigTest.java | 70 +++++++++++++++++++ 6 files changed, 109 insertions(+), 12 deletions(-) create mode 100644 core/src/test/java/tests/DhApiConfigTest.java diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/ConfigHandler.java b/core/src/main/java/com/seibel/distanthorizons/core/config/ConfigHandler.java index 2fd64dabd..5b039a06d 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/ConfigHandler.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/ConfigHandler.java @@ -62,7 +62,7 @@ public class ConfigHandler *
{@link String} *
*
// Below, "T" should be a value from above - *
// Note: This is not checked, so we trust that you are doing the right thing (TODO: Check it) + *
// Note: This is not checked, so we trust that you are doing the right thing *
List *
ArrayList *
Map @@ -261,7 +261,6 @@ public class ConfigHandler if (ConfigUIComment.class.isAssignableFrom(entry.getClass()) && ((ConfigUIComment)entry).parentConfigPath != null) { - // TODO this could potentially add the same item multiple times entryPrefix = "distanthorizons.config." + ((ConfigUIComment)entry).parentConfigPath; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/config/api/DhApiConfigValue.java b/core/src/main/java/com/seibel/distanthorizons/core/config/api/DhApiConfigValue.java index ffd835881..89a1e78bd 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/config/api/DhApiConfigValue.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/config/api/DhApiConfigValue.java @@ -46,6 +46,12 @@ public class DhApiConfigValue implements IDhApiConfigValue configConverter; + + //==============// + // constructors // + //==============// + //region + /** * This constructor should only be called internally.
* There is no reason for API users to create this object.

@@ -69,11 +75,29 @@ public class DhApiConfigValue implements IDhApiConfigValue implements IDhApiConfigValue implements IDhApiConfigValue onValueChangeFunc) { this.configBase.addValueChangeListener((coreValue) -> @@ -118,4 +144,6 @@ public class DhApiConfigValue implements IDhApiConfigValue extends AbstractConfigBase private final String comment; private T min; private T max; - private final ArrayList listenerList; // TODO make concurrent + private final ArrayList listenerList; private final String chatCommandName; /** diff --git a/core/src/main/java/com/seibel/distanthorizons/core/sql/DbConnectionClosedException.java b/core/src/main/java/com/seibel/distanthorizons/core/sql/DbConnectionClosedException.java index d6155a7c9..b302d042d 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/sql/DbConnectionClosedException.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/sql/DbConnectionClosedException.java @@ -18,7 +18,6 @@ public class DbConnectionClosedException extends SQLException public static boolean isClosedException(SQLException e) { - // TODO long term we should prevent using repos that are closed, but for now this is the easier solution String message = e.getMessage().toLowerCase(); return message.contains("connection closed") || message.contains("pointer is closed") diff --git a/core/src/test/java/tests/DhApiConfigTest.java b/core/src/test/java/tests/DhApiConfigTest.java new file mode 100644 index 000000000..4979d6eb4 --- /dev/null +++ b/core/src/test/java/tests/DhApiConfigTest.java @@ -0,0 +1,70 @@ +/* + * This file is part of the Distant Horizons mod + * licensed under the GNU LGPL v3 License. + * + * Copyright (C) 2020 James Seibel + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package tests; + +import com.seibel.distanthorizons.api.enums.rendering.EDhApiRendererMode; +import com.seibel.distanthorizons.core.config.api.DhApiConfigValue; +import com.seibel.distanthorizons.core.config.api.converters.RenderModeEnabledConverter; +import com.seibel.distanthorizons.core.config.types.ConfigEntry; +import org.junit.Assert; +import org.junit.Test; + +/** + * Quick test to confirm API config handling works correctly. + * + * @author James Seibel + * @version 2026-02-04 + */ +public class DhApiConfigTest +{ + + @Test + public void ConfigTest() + { + ConfigEntry coreConfig = new ConfigEntry.Builder() + .set(EDhApiRendererMode.DEBUG) + .build(); + + DhApiConfigValue apiConfig = new DhApiConfigValue<>(coreConfig, new RenderModeEnabledConverter()); + + // start with no API value + Assert.assertNull("API Value shouldn't be set yet", apiConfig.getApiValue()); + Assert.assertEquals("underlying config should be 'DEBUG'", EDhApiRendererMode.DEBUG, coreConfig.get()); + + + // set API value + apiConfig.setValue(true); + Assert.assertTrue("API Value should be 'true'", apiConfig.getApiValue()); + Assert.assertEquals("underlying config should be 'DEFAULT'", EDhApiRendererMode.DEFAULT, coreConfig.get()); + + // set API value again + apiConfig.setValue(false); + Assert.assertFalse("API Value should be 'false'", apiConfig.getApiValue()); + Assert.assertEquals("underlying config should be disabled", EDhApiRendererMode.DISABLED, coreConfig.get()); + + // clear API value + apiConfig.clearValue(); + Assert.assertNull("API Value should be null", apiConfig.getApiValue()); + Assert.assertEquals("underlying config should be 'DEBUG'", EDhApiRendererMode.DEBUG, coreConfig.get()); + + + } + +}