Class MapSetting<K,V>

java.lang.Object
me.hackware.api.setting.Setting<Map<K,V>>
me.hackware.api.setting.impl.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)

public class MapSetting<K,V> extends Setting<Map<K,V>>
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);
 
  • Constructor Details

    • MapSetting

      public MapSetting(String name)
    • MapSetting

      public MapSetting(String name, String description)
  • Method Details

    • options

      public MapSetting<K,V> options(List<K> options)
      Set the available key options for this map.
    • options

      public MapSetting<K,V> options(Supplier<List<K>> supplier)
      Set a dynamic supplier for key options (re-evaluated on refreshOptions()).
    • refreshOptions

      public void refreshOptions()
      Re-evaluate the dynamic options supplier, if set.
    • nameMapper

      public MapSetting<K,V> nameMapper(Function<K,String> nameMapper)
      Set the function that converts a key to its user-facing display name.
    • idMapper

      public MapSetting<K,V> idMapper(Function<K,String> idMapper)
      Set the function that converts a key to a unique string id (for serialization).
    • valueType

      public MapSetting<K,V> valueType(MapSetting.MapValueType valueType)
      Set the type of value editor to show per entry.
    • defaultEntryValue

      public MapSetting<K,V> defaultEntryValue(V defaultEntryValue)
      Set the default value assigned when a new key is added to the map.
    • alpha

      public MapSetting<K,V> alpha()
      Enable alpha channel for color values (applicable when valueType is COLOR).
    • displayName

      public MapSetting<K,V> displayName(String displayName)
      Overrides:
      displayName in class Setting<Map<K,V>>
    • description

      public MapSetting<K,V> description(String description)
      Overrides:
      description in class Setting<Map<K,V>>
    • group

      public MapSetting<K,V> group(String group)
      Overrides:
      group in class Setting<Map<K,V>>
    • visible

      public MapSetting<K,V> visible(boolean visible)
      Overrides:
      visible in class Setting<Map<K,V>>
    • visible

      public MapSetting<K,V> visible(BooleanSupplier visible)
      Overrides:
      visible in class Setting<Map<K,V>>
    • getOptions

      public List<K> getOptions()
    • getNameMapper

      public Function<K,String> getNameMapper()
    • getIdMapper

      public Function<K,String> getIdMapper()
    • getValueType

      public MapSetting.MapValueType getValueType()
    • getDefaultEntryValue

      public V getDefaultEntryValue()
    • isAlphaEnabled

      public boolean isAlphaEnabled()
    • displayName

      public String displayName(K item)
    • itemId

      public String itemId(K item)
    • fromId

      public K fromId(String id)
      Resolve a key from its serialized id, or null if unknown.
    • containsKey

      public boolean containsKey(K key)
      Check if a key is in the map.
    • containsKeyById

      public boolean containsKeyById(String id)
      Check if a key is in the map by its string id.
    • getEntry

      public V getEntry(K key)
      Get the value for a key, or null if not present.
    • getEntryById

      public V getEntryById(String id)
      Get the value for a key by id, or null if not present.
    • put

      public void put(K key, V val)
      Put a key-value pair into the map and save.
    • remove

      public void remove(K key)
      Remove a key from the map and save.
    • toggle

      public void toggle(K key)
      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

      public Map<K,V> getEntries()
      Get the map as an unmodifiable view.
    • getSerializableEntries

      public Map<String,V> getSerializableEntries()
      Get a serializable map of string ids to values.
    • setFromIdMap

      public void setFromIdMap(Map<String,Object> map)
      Restore map entries from serialized string id → value map.
    • serializeEntries

      public Map<String,Object> serializeEntries()
      Serialize the map for config storage.
    • setValue

      public void setValue(Map<K,V> value)
      Overrides:
      setValue in class Setting<Map<K,V>>
    • getColorARGB

      public int getColorARGB(K key)
      Get the color for a key as ARGB (for rendering). Only valid when valueType is COLOR.
    • getRed

      public int getRed(K key)
      Get the red component of a color entry (0–255).
    • getGreen

      public int getGreen(K key)
      Get the green component of a color entry (0–255).
    • getBlue

      public int getBlue(K key)
      Get the blue component of a color entry (0–255).
    • getAlpha

      public int getAlpha(K key)
      Get the alpha component of a color entry (0–255).