Class GameRuleManager

java.lang.Object
net.glowstone.util.GameRuleManager
All Implemented Interfaces:
DynamicallyTypedMap<String>

public final class GameRuleManager extends Object implements DynamicallyTypedMap<String>
Container for the game rule map for worlds.
  • Constructor Details

    • GameRuleManager

      public GameRuleManager()
      Creates an instance with the vanilla game rules.
  • Method Details

    • getKeys

      public String[] getKeys()
      Gets all of the game rules defined.
      Returns:
      the game rules defined, may be empty
    • setValue

      public boolean setValue(@NonNls @NonNls String rule, Object value)

      Sets the value of a game rule.

      The actual object value is never stored, only the string value.

      The helper methods provided in this class may be used to retrieve the value, such as getBoolean(String).

      Parameters:
      rule - the rule to set, cannot be null
      value - the value to set, cannot be null or be represented as null
      Returns:
      true if set, false otherwise
    • isGameRule

      public boolean isGameRule(@NonNls @NonNls String rule)
      Gets whether or not the supplied rule is defined.
      Parameters:
      rule - the rule to lookup
      Returns:
      true if defined, false otherwise
    • getString

      public String getString(String rule)
      Gets the game rule value as a string. If the value does not exist, then this will return null.
      Specified by:
      getString in interface DynamicallyTypedMap<String>
      Parameters:
      rule - the rule to look up
      Returns:
      the string value, or null if not defined
    • getBoolean

      public boolean getBoolean(@NonNls @NonNls String rule)
      Gets the game rule value as a boolean. If the value cannot be parsed or does not exist, then this will return false.
      Specified by:
      getBoolean in interface DynamicallyTypedMap<String>
      Parameters:
      rule - the rule to look up
      Returns:
      the boolean value, or false
    • getInt

      public int getInt(@NonNls @NonNls String key)
      Description copied from interface: DynamicallyTypedMap
      Retrieves an entry as an int.
      Specified by:
      getInt in interface DynamicallyTypedMap<String>
      Parameters:
      key - the key to look up
      Returns:
      the value as an int
    • getInt

      public int getInt(@NonNls @NonNls String rule, int def)
      Gets the game rule value as an integer. If the value cannot be parsed or does not exist then the default will be returned.
      Parameters:
      rule - the rule to look up
      def - the default value
      Returns:
      the integer value of the rule, or the default