Record Class ScenarioSetting

java.lang.Object
java.lang.Record
dev.itsharshxd.zentrix.api.scenario.ScenarioSetting
Record Components:
key - the setting key, unique within its scenario
type - how the value is validated and edited
defaultValue - the value used until an administrator configures one; never null
minimum - the lowest accepted number, for ScenarioSettingType.INTEGER and ScenarioSettingType.DECIMAL
maximum - the highest accepted number, for the same two types
allowedValues - the accepted values of an ScenarioSettingType.ENUM setting
displayName - the label shown in the GUI; falls back to the key when blank
description - the lines shown under the label in the GUI
entrySchema - the shape of one entry of a ScenarioSettingType.STRUCTURED_LIST setting, and null for every other type

public record ScenarioSetting(@NotNull String key, @NotNull ScenarioSettingType type, @NotNull Object defaultValue, double minimum, double maximum, @NotNull Set<String> allowedValues, @NotNull String displayName, @NotNull List<String> description, @Nullable ScenarioEntrySchema entrySchema) extends Record
One configurable value of a scenario.

A scenario declares its settings once, in its ScenarioDescriptor. Zentrix uses the declaration to validate values, to render an editor in the management GUI, and to supply the default whenever no administrator has configured the setting.

Declaring a setting never writes anything to disk. A value only reaches scenarios.yml once an administrator edits it, which keeps a dynamically registered scenario out of the main configuration until somebody deliberately configures it.

Since:
1.6.0
  • Constructor Details

    • ScenarioSetting

      public ScenarioSetting(@NotNull @NotNull String key, @NotNull @NotNull ScenarioSettingType type, @NotNull @NotNull Object defaultValue, double minimum, double maximum, @NotNull @NotNull Set<String> allowedValues, @NotNull @NotNull String displayName, @NotNull @NotNull List<String> description, @Nullable @Nullable ScenarioEntrySchema entrySchema)
      Creates an instance of a ScenarioSetting record class.
      Parameters:
      key - the value for the key record component
      type - the value for the type record component
      defaultValue - the value for the defaultValue record component
      minimum - the value for the minimum record component
      maximum - the value for the maximum record component
      allowedValues - the value for the allowedValues record component
      displayName - the value for the displayName record component
      description - the value for the description record component
      entrySchema - the value for the entrySchema record component
    • ScenarioSetting

      public ScenarioSetting(@NotNull @NotNull String key, @NotNull @NotNull ScenarioSettingType type, @NotNull @NotNull Object defaultValue, double minimum, double maximum, @NotNull @NotNull Set<String> allowedValues, @NotNull @NotNull String displayName, @NotNull @NotNull List<String> description)
      The pre-1.6.0 constructor, kept so anything compiled against an earlier API still links.

      Declares no entry schema, which is exactly right: ScenarioSettingType.STRUCTURED_LIST did not exist before the schema did.

  • Method Details

    • bool

      @NotNull public static @NotNull ScenarioSetting bool(@NotNull @NotNull String key, boolean defaultValue)
      A toggle.
    • integer

      @NotNull public static @NotNull ScenarioSetting integer(@NotNull @NotNull String key, int defaultValue, int minimum, int maximum)
      A whole number between minimum and maximum, inclusive.
    • decimal

      @NotNull public static @NotNull ScenarioSetting decimal(@NotNull @NotNull String key, double defaultValue, double minimum, double maximum)
      A fractional number between minimum and maximum, inclusive.
    • text

      @NotNull public static @NotNull ScenarioSetting text(@NotNull @NotNull String key, @NotNull @NotNull String defaultValue)
      Free text.
    • choice

      @NotNull public static @NotNull ScenarioSetting choice(@NotNull @NotNull String key, @NotNull @NotNull String defaultValue, @NotNull @NotNull String... choices)
      One of a fixed set of choices.
    • materials

      @NotNull public static @NotNull ScenarioSetting materials(@NotNull @NotNull String key, @NotNull @NotNull List<String> defaultValue)
      A list of Bukkit material names.
    • entries

      @NotNull public static @NotNull ScenarioSetting entries(@NotNull @NotNull String key, @NotNull @NotNull ScenarioEntrySchema schema, @NotNull @NotNull List<ScenarioEntry> defaultValue)
      A list of entries shaped by schema.

      The schema decides what one entry holds: a single field for a plain list, two for a list of pairs, more for anything else the scenario needs. Zentrix stays unaware of what the fields mean, so the same setting type serves any scenario.

      Parameters:
      schema - the fields every entry of this setting carries
      defaultValue - the entries used until an administrator configures the setting
    • entries

      @NotNull public static @NotNull ScenarioSetting entries(@NotNull @NotNull String key, @NotNull @NotNull ScenarioEntrySchema schema)
      A list of entries shaped by schema, empty until an administrator adds one.
    • builder

      @NotNull public static @NotNull ScenarioSetting.Builder builder(@NotNull @NotNull String key, @NotNull @NotNull ScenarioSettingType type, @NotNull @NotNull Object defaultValue)
    • isNumeric

      public boolean isNumeric()
      Whether this setting accepts numeric bounds.
    • isStructured

      public boolean isStructured()
      Whether this setting holds a list of entries shaped by entrySchema().
    • defaultEntries

      @NotNull public @NotNull List<ScenarioEntry> defaultEntries()
      The declared entry defaults of a ScenarioSettingType.STRUCTURED_LIST setting.

      Empty for every other type, and for a structured setting whose default was declared in a shape this version no longer understands, so a caller never has to guard the declaration.

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • key

      @NotNull public @NotNull String key()
      Returns the value of the key record component.
      Returns:
      the value of the key record component
    • type

      @NotNull public @NotNull ScenarioSettingType type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • defaultValue

      @NotNull public @NotNull Object defaultValue()
      Returns the value of the defaultValue record component.
      Returns:
      the value of the defaultValue record component
    • minimum

      public double minimum()
      Returns the value of the minimum record component.
      Returns:
      the value of the minimum record component
    • maximum

      public double maximum()
      Returns the value of the maximum record component.
      Returns:
      the value of the maximum record component
    • allowedValues

      @NotNull public @NotNull Set<String> allowedValues()
      Returns the value of the allowedValues record component.
      Returns:
      the value of the allowedValues record component
    • displayName

      @NotNull public @NotNull String displayName()
      Returns the value of the displayName record component.
      Returns:
      the value of the displayName record component
    • description

      @NotNull public @NotNull List<String> description()
      Returns the value of the description record component.
      Returns:
      the value of the description record component
    • entrySchema

      @Nullable public @Nullable ScenarioEntrySchema entrySchema()
      Returns the value of the entrySchema record component.
      Returns:
      the value of the entrySchema record component