Package me.hackware.api.setting.impl
Class MapSetting<K,V>
- Type Parameters:
K- the type of keys in the map (e.g., EntityType)V- the type of values in the map (e.g., Integer for colors)
A setting that stores a map of selected items to values from a fixed list of keys.
This is like ListSetting but each selected key also has an associated value.
For example, a MapSetting<EntityType<?>, Integer> with valueType(MapValueType.COLOR)
would show each selected entity type with a color picker instead of a boolean toggle.
Usage example:
MapSetting<EntityType<?>, Integer> entityColors = new MapSetting<EntityType<?>, Integer>("Entity Colors")
.options(new ArrayList<>(BuiltInRegistries.ENTITY_TYPE.stream().toList()))
.nameMapper(e -> e.getDescription().getString())
.idMapper(e -> BuiltInRegistries.ENTITY_TYPE.getKey(e).toString())
.valueType(MapValueType.COLOR)
.defaultEntryValue(0xFFFFFF);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe type of value editor to display per entry. -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionMapSetting<K, V> alpha()Enable alpha channel for color values (applicable when valueType is COLOR).booleancontainsKey(K key) Check if a key is in the map.booleanCheck if a key is in the map by its string id.MapSetting<K, V> defaultEntryValue(V defaultEntryValue) Set the default value assigned when a new key is added to the map.MapSetting<K, V> description(String description) MapSetting<K, V> displayName(String displayName) displayName(K item) intNumber of entries in the map.Resolve a key from its serialized id, ornullif unknown.intGet the alpha component of a color entry (0–255).intGet the blue component of a color entry (0–255).intgetColorARGB(K key) Get the color for a key as ARGB (for rendering).Get the map as an unmodifiable view.Get the value for a key, ornullif not present.getEntryById(String id) Get the value for a key by id, ornullif not present.intGet the green component of a color entry (0–255).intGet the red component of a color entry (0–255).Get a serializable map of string ids to values.MapSetting<K, V> MapSetting<K, V> Set the function that converts a key to a unique string id (for serialization).booleanMapSetting<K, V> nameMapper(Function<K, String> nameMapper) Set the function that converts a key to its user-facing display name.MapSetting<K, V> Set a dynamic supplier for key options (re-evaluated onrefreshOptions()).MapSetting<K, V> Set the available key options for this map.voidPut a key-value pair into the map and save.voidRe-evaluate the dynamic options supplier, if set.voidRemove a key from the map and save.Serialize the map for config storage.voidsetFromIdMap(Map<String, Object> map) Restore map entries from serialized string id → value map.voidvoidToggle: if key exists, remove it; if not, add it with the default value.MapSetting<K, V> valueType(MapSetting.MapValueType valueType) Set the type of value editor to show per entry.MapSetting<K, V> visible(boolean visible) MapSetting<K, V> visible(BooleanSupplier visible) Methods inherited from class me.hackware.api.setting.Setting
defaultValue, get, getDefaultValue, getDescription, getDisplayName, getGroup, getName, getOwner, isBulkLoading, isVisible, onChanged, setBulkLoadProbe, setOwner
-
Constructor Details
-
MapSetting
-
MapSetting
-
-
Method Details
-
options
Set the available key options for this map. -
options
Set a dynamic supplier for key options (re-evaluated onrefreshOptions()). -
refreshOptions
public void refreshOptions()Re-evaluate the dynamic options supplier, if set. -
nameMapper
Set the function that converts a key to its user-facing display name. -
idMapper
Set the function that converts a key to a unique string id (for serialization). -
valueType
Set the type of value editor to show per entry. -
defaultEntryValue
Set the default value assigned when a new key is added to the map. -
alpha
Enable alpha channel for color values (applicable when valueType is COLOR). -
displayName
- Overrides:
displayNamein classSetting<Map<K,V>>
-
description
- Overrides:
descriptionin classSetting<Map<K,V>>
-
group
-
visible
-
visible
-
getOptions
-
getNameMapper
-
getIdMapper
-
getValueType
-
getDefaultEntryValue
-
isAlphaEnabled
public boolean isAlphaEnabled() -
displayName
-
itemId
-
fromId
Resolve a key from its serialized id, ornullif unknown. -
containsKey
Check if a key is in the map. -
containsKeyById
Check if a key is in the map by its string id. -
getEntry
Get the value for a key, ornullif not present. -
getEntryById
Get the value for a key by id, ornullif not present. -
put
Put a key-value pair into the map and save. -
remove
Remove a key from the map and save. -
toggle
Toggle: if key exists, remove it; if not, add it with the default value. -
entryCount
public int entryCount()Number of entries in the map. -
getEntries
Get the map as an unmodifiable view. -
getSerializableEntries
Get a serializable map of string ids to values. -
setFromIdMap
Restore map entries from serialized string id → value map. -
serializeEntries
Serialize the map for config storage. -
setValue
-
getColorARGB
Get the color for a key as ARGB (for rendering). Only valid when valueType is COLOR. -
getRed
Get the red component of a color entry (0–255). -
getGreen
Get the green component of a color entry (0–255). -
getBlue
Get the blue component of a color entry (0–255). -
getAlpha
Get the alpha component of a color entry (0–255).
-