SSCL Wiki

List Value

ListValue stores a list of values in an array.

SSCL supports flat arrays containing one of the supported value types:

  • Boolean
  • Integer
  • Double
  • String
  • Enum

All elements in a list must use the same type.


Creating a List Value

List values are created from a ConfigCategory.

Boolean

public static final ListValue<Boolean> FEATURES = GENERAL
		.boolList("features", List.of(true, false));

Integer

public static final ListValue<Integer> DIMENSIONS = GENERAL
		.intList("dimensions", List.of(1, 2, 3));

Double

public static final ListValue<Double> SCALES = GENERAL
		.doubleList("scales", List.of(0.5, 1.0, 2.0));

String

public static final ListValue<String> NAMES = GENERAL
		.stringList("names", List.of("Steve", "Alex"));

Enum

public static final ListValue<Mode> MODES = GENERAL
		.enumList(
				"modes",
				Mode.class,
				List.of(Mode.NORMAL, Mode.FAST)
		);

TOML

List values are saved as normal TOML arrays.

For example:

features = [true, false]
dimensions = [1, 2, 3]
scales = [0.5, 1.0, 2.0]
names = ["Steve", "Alex"]
modes = ["NORMAL", "FAST"]

ListValue API

get()

Returns the current list.

List<String> names = NAMES.get();

The returned list should be treated as read-only. Use set() to change it.

set(List<T>)

Replaces the current list.

NAMES.set(List.of("Steve", "Alex", "Herobrine"));

getDefault()

Returns the default list defined when the value was created.

List<String> defaults = NAMES.getDefault();

resetToDefault()

Resets the value to its default list.

NAMES.resetToDefault();

elementType()

Returns the Java class used by the list elements.

Class<String> type = NAMES.elementType();

Common APIs

ListValue also supports the common ConfigValue methods:

NAMES
		.comment("Names used by the mod.")
		.tooltip("Names available to the feature.");

The common methods are:

  • get()
  • set()
  • getDefault()
  • resetToDefault()
  • comment()
  • tooltip()

See Config Value Common APIs for details.


Mod Menu

List values are displayed as individual edit boxes in Mod Menu.

Each element has its own input field and a - button for removing that element. A + Add button is shown below the list for adding a new element using the list's element type.

For example:

Names      [ Steve             ] [ - ]
           [ Alex              ] [ - ]
           [ Herobrine         ] [ - ]
                             [ + Add ]

Invalid or empty entries are discarded when the configuration is committed.

For example:

Names      [ Steve             ] [ - ]
           [                   ] [ - ]
           [ Alex              ] [ - ]
           [ invalid ???       ] [ - ]

becomes:

names = ["Steve", "Alex"]

Elements can also be removed manually with their - button.

If every entry is removed or invalid, the value becomes an empty list:

names = []

Nested arrays and mixed-type arrays are not supported.