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 Summary
Modifier and TypeMethodDescriptiondefinition(String id) Looks a rule up by identifier.definition(Key key) Looks a rule up by registry key.Gets every known rule.getAsString(TypedKey<GameRule> rule) Gets the value of any rule, formatted like/gameruleprints it.booleangetBoolean(TypedKey<GameRule> rule) Gets the value of a boolean rule.intGets the value of an integer rule.booleanPuts a rule back to its vanilla default.booleanChanges any rule from text, the way the client's game rule screen sends values.booleansetBoolean(TypedKey<GameRule> rule, boolean value) Changes a boolean rule.booleanChanges an integer rule.
-
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_inventoryandminecraft:keep_inventoryname the same rule.- Parameters:
id- the identifier- Returns:
- the definition, or empty when no rule has this identifier
- Since:
- 0.1.0
-
definition
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
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
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
-
setBoolean
Changes a boolean rule.- Parameters:
rule- a boolean rulevalue- the new value- Returns:
truewhen the value actually changed,falsewhen 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
Changes an integer rule.- Parameters:
rule- an integer rulevalue- the new value- Returns:
truewhen the value actually changed,falsewhen 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
Changes any rule from text, the way the client's game rule screen sends values.- Parameters:
rule- any rulevalue-true/false(any case) or a number within range- Returns:
truewhen the value actually changed,falsewhen 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
Puts a rule back to its vanilla default.- Parameters:
rule- any rule- Returns:
truewhen the value actually changed- Throws:
IllegalArgumentException- if the rule is unknown- Since:
- 0.1.0
-