Interface GameRules

All Known Subinterfaces:
WorldGameRules

public interface GameRules
A service for reading and changing the game rules of the server, as /gamerule does.

These are the base values, held by the overworld and followed by every world that does not override them; see World.gameRules().

Since:
0.1.0
  • Method Details

    • definitions

      Gets every known rule.
      Returns:
      the definitions, sorted by identifier
      Since:
      0.1.0
    • definition

      Looks a rule up by identifier. The namespace is optional: keep_inventory and minecraft:keep_inventory name the same rule.
      Parameters:
      id - the identifier
      Returns:
      the definition, or empty when no rule has this identifier
      Since:
      0.1.0
    • definition

      @Contract(pure=true) Optional<GameRuleDefinition> definition(Key key)
      Looks a rule up by registry key.
      Parameters:
      key - the registry key
      Returns:
      the definition, or empty when no rule has this key
      Since:
      0.1.0
    • getBoolean

      @Contract(pure=true) boolean getBoolean(TypedKey<GameRule> rule)
      Gets the value of a boolean rule.
      Parameters:
      rule - a boolean rule
      Returns:
      its current value
      Throws:
      IllegalArgumentException - if the rule is unknown or is not a boolean rule
      Since:
      0.1.0
    • getInt

      @Contract(pure=true) int getInt(TypedKey<GameRule> rule)
      Gets the value of an integer rule.
      Parameters:
      rule - an integer rule
      Returns:
      its current value
      Throws:
      IllegalArgumentException - if the rule is unknown or is not an integer rule
      Since:
      0.1.0
    • getAsString

      @Contract(pure=true) String getAsString(TypedKey<GameRule> rule)
      Gets the value of any rule, formatted like /gamerule prints it.
      Parameters:
      rule - any rule
      Returns:
      "true"/"false" for boolean rules, the number otherwise
      Throws:
      IllegalArgumentException - if the rule is unknown
      Since:
      0.1.0
    • setBoolean

      boolean setBoolean(TypedKey<GameRule> rule, boolean value)
      Changes a boolean rule.
      Parameters:
      rule - a boolean rule
      value - the new value
      Returns:
      true when the value actually changed, false when it already had this value or a listener cancelled the change
      Throws:
      IllegalArgumentException - if the rule is unknown or is not a boolean rule
      Since:
      0.1.0
    • setInt

      boolean setInt(TypedKey<GameRule> rule, int value)
      Changes an integer rule.
      Parameters:
      rule - an integer rule
      value - the new value
      Returns:
      true when the value actually changed, false when it already had this value or a listener cancelled the change
      Throws:
      IllegalArgumentException - if the rule is unknown, is not an integer rule, or the value is out of range
      Since:
      0.1.0
    • set

      boolean set(TypedKey<GameRule> rule, String value)
      Changes any rule from text, the way the client's game rule screen sends values.
      Parameters:
      rule - any rule
      value - true/false (any case) or a number within range
      Returns:
      true when the value actually changed, false when it already had this value or a listener cancelled the change
      Throws:
      IllegalArgumentException - if the rule is unknown or the value is not valid for it
      Since:
      0.1.0
    • reset

      boolean reset(TypedKey<GameRule> rule)
      Puts a rule back to its vanilla default.
      Parameters:
      rule - any rule
      Returns:
      true when the value actually changed
      Throws:
      IllegalArgumentException - if the rule is unknown
      Since:
      0.1.0