Add IDhApiConfigValue.addChangeListener()

This commit is contained in:
James Seibel
2023-08-26 13:11:16 -05:00
parent 2cb1e32817
commit 2cd2941cbe
5 changed files with 36 additions and 3 deletions
@@ -1,5 +1,7 @@
package com.seibel.distanthorizons.api.interfaces.config;
import java.util.function.Consumer;
/**
* An interface for Distant Horizon's Config.
*
@@ -48,4 +50,8 @@ public interface IDhApiConfigValue<T>
/** Returns the min value for this config, null if there is no min. */
T getMinValue();
/** Adds a {@link Consumer} that will be called whenever the config changes to a new value. */
void addChangeListener(Consumer<T> onValueChangeFunc);
//void removeListener(Consumer<T> onValueChangeFunc); // not currently implemented
}
@@ -5,6 +5,8 @@ import com.seibel.distanthorizons.coreapi.interfaces.config.IConfigEntry;
import com.seibel.distanthorizons.coreapi.interfaces.config.IConverter;
import com.seibel.distanthorizons.coreapi.util.converters.DefaultConverter;
import java.util.function.Consumer;
/**
* A wrapper used to interface with Distant Horizon's Config. <br> <br>
*
@@ -68,8 +70,18 @@ public class DhApiConfigValue<coreType, apiType> implements IDhApiConfigValue<ap
public boolean getCanBeOverrodeByApi() { return this.configEntry.getAllowApiOverride(); }
public apiType getDefaultValue() { return this.configConverter.convertToApiType(configEntry.getDefaultValue()); }
public apiType getDefaultValue() { return this.configConverter.convertToApiType(this.configEntry.getDefaultValue()); }
public apiType getMaxValue() { return this.configConverter.convertToApiType(this.configEntry.getMax()); }
public apiType getMinValue() { return this.configConverter.convertToApiType(this.configEntry.getMin()); }
public void addChangeListener(Consumer<apiType> onValueChangeFunc)
{
this.configEntry.addValueChangeListener((coreValue) ->
{
apiType apiValue = this.configConverter.convertToApiType(coreValue);
onValueChangeFunc.accept(apiValue);
});
}
}
@@ -1,6 +1,8 @@
package com.seibel.distanthorizons.coreapi.interfaces.config;
import java.util.function.Consumer;
/**
* Use for making the config variables
*
@@ -56,4 +58,6 @@ public interface IConfigEntry<T>
/** Is the value of this equal to another */
boolean equals(IConfigEntry<?> obj);
void addValueChangeListener(Consumer<T> onValueChangeFunc);
}