Record Class GameRuleDefinition

java.lang.Object
java.lang.Record
fr.fidorial.gamerule.GameRuleDefinition
Record Components:
key - the registry key, for instance minecraft:keep_inventory
type - the kind of value the rule holds
defaultValue - the vanilla default (0/1 for boolean rules)
minValue - the smallest accepted value, inclusive
maxValue - the largest accepted value, inclusive
implemented - whether the server wires this rule into its gameplay; rules that are not implemented are still stored and saved, but have no built-in effect and are not offered by /gamerule

public record GameRuleDefinition(TypedKey<GameRule> key, GameRuleType type, int defaultValue, int minValue, int maxValue, boolean implemented) extends Record
Describes one entry of the minecraft:game_rule registry: its type, its vanilla default and the range of values it accepts.
Since:
0.1.0
  • Constructor Details

    • GameRuleDefinition

      public GameRuleDefinition(TypedKey<GameRule> key, GameRuleType type, int defaultValue, int minValue, int maxValue, boolean implemented)
      Creates an instance of a GameRuleDefinition 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
      minValue - the value for the minValue record component
      maxValue - the value for the maxValue record component
      implemented - the value for the implemented record component
  • Method Details

    • ofBoolean

      public static GameRuleDefinition ofBoolean(TypedKey<GameRule> key, boolean defaultValue, boolean implemented)
      Creates a boolean rule definition.
      Parameters:
      key - the registry key
      defaultValue - the vanilla default
      implemented - whether the server wires the rule into its gameplay
      Returns:
      the definition
      Since:
      0.1.0
    • ofInteger

      public static GameRuleDefinition ofInteger(TypedKey<GameRule> key, int defaultValue, int minValue, int maxValue, boolean implemented)
      Creates an integer rule definition.
      Parameters:
      key - the registry key
      defaultValue - the vanilla default
      minValue - the smallest accepted value, inclusive
      maxValue - the largest accepted value, inclusive
      implemented - whether the server wires the rule into its gameplay
      Returns:
      the definition
      Since:
      0.1.0
    • id

      @Contract(pure=true) public String id()
      Returns:
      the identifier without its namespace, for instance keep_inventory
      Since:
      0.1.0
    • isBoolean

      @Contract(pure=true) public boolean isBoolean()
      Returns:
      true if the rule holds a boolean
      Since:
      0.1.0
    • accepts

      @Contract(pure=true) public boolean accepts(int value)
      Parameters:
      value - a raw value
      Returns:
      true if value lies within minValue() and maxValue()
      Since:
      0.1.0
    • format

      @Contract(pure=true) public String format(int value)
      Formats a raw value the way the vanilla command prints it.
      Parameters:
      value - a raw value
      Returns:
      "true"/"false" for boolean rules, the number otherwise
      Since:
      0.1.0
    • parse

      @Contract(pure=true) public @Nullable Integer parse(String text)
      Parses a value typed by a player or read from a legacy save.

      Boolean rules accept true/false (any case); integer rules accept a decimal number within range.

      Parameters:
      text - the text to parse
      Returns:
      the raw value, or null if the text is not valid for this rule
      Since:
      0.1.0
    • 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 the compare method from their corresponding wrapper classes.
      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

      public TypedKey<GameRule> key()
      Returns the value of the key record component.
      Returns:
      the value of the key record component
    • type

      public GameRuleType type()
      Returns the value of the type record component.
      Returns:
      the value of the type record component
    • defaultValue

      public int defaultValue()
      Returns the value of the defaultValue record component.
      Returns:
      the value of the defaultValue record component
    • minValue

      public int minValue()
      Returns the value of the minValue record component.
      Returns:
      the value of the minValue record component
    • maxValue

      public int maxValue()
      Returns the value of the maxValue record component.
      Returns:
      the value of the maxValue record component
    • implemented

      public boolean implemented()
      Returns the value of the implemented record component.
      Returns:
      the value of the implemented record component