Record Class ScenarioEntryField

java.lang.Object
java.lang.Record
dev.itsharshxd.zentrix.api.scenario.ScenarioEntryField
Record Components:
key - the field key, unique within its schema
type - how the value is validated and edited
defaultValue - the value used while nothing is stored; null for a required field
required - whether an entry without this field is rejected
minimum - the lowest accepted number, for ScenarioFieldType.INTEGER and ScenarioFieldType.DECIMAL
maximum - the highest accepted number, for the same two types
allowedValues - the accepted values of a ScenarioFieldType.ENUM field
displayName - the label shown in the GUI; falls back to the key when blank
description - the lines shown under the label in the GUI

public record ScenarioEntryField(@NotNull String key, @NotNull ScenarioFieldType type, @Nullable Object defaultValue, boolean required, double minimum, double maximum, @NotNull Set<String> allowedValues, @NotNull String displayName, @NotNull List<String> description) extends Record
One field of a structured entry.

A scenario declares the fields of its entries once, in a ScenarioEntrySchema. Zentrix uses the declaration to validate what an administrator types, to render one row per field in the entry editor, and to fill in the value of an optional field that was left out.

A field is either required or optional. A required field has no default: an entry missing it is rejected as a whole, which is what keeps a half-filled entry out of scenarios.yml. An optional field falls back to its default whenever no value is stored, exactly like a ScenarioSetting does.

Since:
1.6.0
  • Constructor Details

    • ScenarioEntryField

      public ScenarioEntryField(@NotNull @NotNull String key, @NotNull @NotNull ScenarioFieldType type, @Nullable @Nullable Object defaultValue, boolean required, double minimum, double maximum, @NotNull @NotNull Set<String> allowedValues, @NotNull @NotNull String displayName, @NotNull @NotNull List<String> description)
      Creates an instance of a ScenarioEntryField 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
      required - the value for the required 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
  • Method Details

    • required

      @NotNull public static @NotNull ScenarioEntryField required(@NotNull @NotNull String key, @NotNull @NotNull ScenarioFieldType type)
      A required field of any type.
    • item

      @NotNull public static @NotNull ScenarioEntryField item(@NotNull @NotNull String key)
      A required item identifier, resolvable through vanilla, ItemsAdder, Nexo or items.yml.
    • block

      @NotNull public static @NotNull ScenarioEntryField block(@NotNull @NotNull String key)
      A required block identifier, resolvable through vanilla, ItemsAdder or Nexo.
    • integer

      @NotNull public static @NotNull ScenarioEntryField integer(@NotNull @NotNull String key, int defaultValue, int minimum, int maximum)
      An optional whole number between minimum and maximum, inclusive.
    • bool

      @NotNull public static @NotNull ScenarioEntryField bool(@NotNull @NotNull String key, boolean defaultValue)
      An optional toggle.
    • choice

      @NotNull public static @NotNull ScenarioEntryField choice(@NotNull @NotNull String key, @NotNull @NotNull String defaultValue, @NotNull @NotNull String... choices)
      An optional choice out of a fixed set.
    • builder

      @NotNull public static @NotNull ScenarioEntryField.Builder builder(@NotNull @NotNull String key, @NotNull @NotNull ScenarioFieldType type)
    • 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 ScenarioFieldType type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • defaultValue

      @Nullable public @Nullable Object defaultValue()
      Returns the value of the defaultValue record component.
      Returns:
      the value of the defaultValue record component
    • required

      public boolean required()
      Returns the value of the required record component.
      Returns:
      the value of the required 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