package com.watschman.betterenhancement.config; import com.watschman.betterenhancement.reference.Reference; import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Property; public class ConfigEntry { private Property property; private String identifier; private String category; private String comment; private ConfigType configType; private Object defaultValue; private ConfigEntry(String identifier, Object defaultValue, String comment, String category) { this.identifier = identifier; this.defaultValue = defaultValue; this.category = category; this.comment = comment; } public static ConfigEntry createConfigEntryObject(String identifier, Object defaultValue) { return createConfigEntryObject(identifier, defaultValue, ""); } public static ConfigEntry createConfigEntryObject(String identifier, Object defaultValue, String comment) { return createConfigEntryObject(identifier, defaultValue, comment, Configuration.CATEGORY_GENERAL); } public static ConfigEntry createConfigEntryObject(String identifier, Object defaultValue, String comment, String category) { ConfigEntry configObject = new ConfigEntry(identifier, defaultValue, comment, category); configObject.initializeProperty(); configObject.addConfigRegistration(); return configObject; } public ConfigEntry setProperty(Property property) { this.property = property; return this; } public ConfigEntry setIdentifier(String identifier) { this.identifier = identifier; return this; } public ConfigEntry setCategory(String category) { this.category = category; return this; } public ConfigEntry setComment(String comment) { this.comment = comment; return this; } public ConfigEntry setDefaultValue(String defaultValue) { this.defaultValue = defaultValue; return this; } public ConfigEntry setConfigType(ConfigType configType) { this.configType = configType; return this; } public Property getProperty() { return this.property; } public String getIdentifier() { return this.identifier; } public String getCategory() { return this.category; } public String getComment() { return this.comment; } public Object getDefaultValue() { return this.defaultValue; } public ConfigType getConfigType() { return this.configType; } public Object getCurrentValue() { try { switch (this.configType) { case INT: return this.property.getInt(); case DOUBLE: return this.property.getDouble(); case BOOLEAN: return this.property.getBoolean(); case STRING: return this.property.getString(); case INT_ARRAY: return this.property.getIntList(); case DOUBLE_ARRAY: return this.property.getDoubleList(); case BOOLEAN_ARRAY: return this.property.getBooleanList(); case STRING_ARRAY: return this.property.getStringList(); default: return null; } } catch (NullPointerException e) { Reference.MOD_LOGGER.info("NPE: returning default Value..."); return this.defaultValue; } } public void addConfigRegistration() { Reference.MOD_CONFIGS.add(this); } private void initializeProperty() { if(this.defaultValue instanceof Integer) { this.configType = ConfigType.INT; this.property = Reference.CONFIG_INSTANCE.configuration.get(this.category, this.identifier, ConfigUtil.getPrimitiveInteger(this.defaultValue), this.comment); } else if(this.defaultValue instanceof Double) { this.configType = ConfigType.DOUBLE; this.property = Reference.CONFIG_INSTANCE.configuration.get(this.category, this.identifier, ConfigUtil.getPrimitiveDouble(this.defaultValue), this.comment); } else if(this.defaultValue instanceof Boolean) { this.configType = ConfigType.BOOLEAN; this.property = Reference.CONFIG_INSTANCE.configuration.get(this.category, this.identifier, ConfigUtil.getPrimitiveBoolean(this.defaultValue), this.comment); } else if(this.defaultValue instanceof String) { this.configType = ConfigType.STRING; this.property = Reference.CONFIG_INSTANCE.configuration.get(this.category, this.identifier, ConfigUtil.getPrimitiveString(this.defaultValue), this.comment); } else if(this.defaultValue instanceof Integer[]) { this.configType = ConfigType.INT_ARRAY; this.property = Reference.CONFIG_INSTANCE.configuration.get(this.category, this.identifier, ConfigUtil.getPrimitiveBooleanArray(this.defaultValue), this.comment); } else if(this.defaultValue instanceof Double[]) { this.configType = ConfigType.DOUBLE_ARRAY; this.property = Reference.CONFIG_INSTANCE.configuration.get(this.category, this.identifier, ConfigUtil.getPrimitiveDoubleArray(this.defaultValue), this.comment); } else if(this.defaultValue instanceof Boolean[]) { this.configType = ConfigType.BOOLEAN_ARRAY; this.property = Reference.CONFIG_INSTANCE.configuration.get(this.category, this.identifier, ConfigUtil.getPrimitiveBooleanArray(this.defaultValue), this.comment); } else if(this.defaultValue instanceof String[]) { this.configType = ConfigType.STRING_ARRAY; this.property = Reference.CONFIG_INSTANCE.configuration.get(this.category, this.identifier, ConfigUtil.getPrimitiveStringArray(this.defaultValue), this.comment); } else { Reference.MOD_LOGGER.error("Detected unknown PropertyValue... Not initializing it." + this.defaultValue.getClass().getSimpleName()); } } }