Removed config entries from checking their own types as its already done in the config base

This commit is contained in:
coolGi
2023-08-06 17:30:27 +09:30
parent 7ccb5c1806
commit 475e4da4a7
2 changed files with 3 additions and 27 deletions
@@ -112,6 +112,8 @@ public class ConfigFileHandling {
@SuppressWarnings("unchecked")
public void saveEntry(ConfigEntry<?> entry, CommentedFileConfig workConfig) {
if (!entry.getAppearance().showInFile) return;
if (entry.getTrueValue() == null)
throw new IllegalArgumentException("Entry ["+ entry.getNameWCategory() +"] is null, this may be a problem with ["+ configBase.modName +"]. Please contact the authors");
if (ConfigTypeConverters.convertObjects.containsKey(entry.getType())) {
workConfig.set(entry.getNameWCategory(), ConfigTypeConverters.convertToString(entry.getType(), entry.getTrueValue()));
@@ -7,12 +7,8 @@ import com.seibel.distanthorizons.core.config.types.enums.EConfigEntryAppearance
import com.seibel.distanthorizons.core.config.types.enums.EConfigEntryPerformance;
import com.seibel.distanthorizons.coreapi.interfaces.config.IConfigEntry;
import java.time.temporal.Temporal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static com.electronwill.nightconfig.core.NullObject.NULL_OBJECT;
/**
* Use for making the config variables
@@ -44,29 +40,7 @@ public class ConfigEntry<T> extends AbstractConfigType<T, ConfigEntry<T>> implem
private ConfigEntry(EConfigEntryAppearance appearance, T value, String comment, T min, T max, boolean allowApiOverride, EConfigEntryPerformance performance, ArrayList<IConfigListener> listenerList)
{
super(appearance, value);
// runtime check to make sure the config value is supported by NightConfig,
// unfortunately we can't do this type of check statically without Java 16
if (value == null)
{
throw new IllegalArgumentException("ConfigEntry setup failure. TOML doesn't support saving null values.");
}
// all of these types were taken from NightConfig's writing code
else if (!(value instanceof List)
&& !(value instanceof CharSequence) // String
&& !(value instanceof Enum)
&& !(value instanceof Temporal) // Date or DateTime
&& !(value instanceof Float || value instanceof Double)
&& !(value instanceof Number)
&& !(value instanceof Boolean)
// optional type that is specific to NightConfig, currently commented out so we aren't tied quite so tightly to NightConfig
//&& !(value instanceof Config) // NightConfig interface
)
{
throw new IllegalArgumentException("ConfigEntry setup failure. Value type ["+value.getClass()+"] is not supported by NightConfig.");
}
this.defaultValue = value;
this.comment = comment;
this.min = min;