Class CompatibilityGameRule

java.lang.Object
dev.cwhead.GravesX.compatibility.CompatibilityGameRule

public final class CompatibilityGameRule extends Object
Handles compatibility for GameRules to prevent runtime errors across versions.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    getBoolean(org.bukkit.World world, String ruleName)
    Retrieves a boolean gamerule value from a world.
    static org.bukkit.GameRule
    getByName(String ruleName)
    Retrieves the GameRule value associated with the given gamerule name.
    static int
    getInt(org.bukkit.World world, String ruleName)
    Retrieves an integer gamerule value from a world.
    static Object
    getValue(org.bukkit.World world, String ruleName)
    Retrieves a gamerule value from a world using the best available API.
    static void
    setValue(org.bukkit.World world, String ruleName, Object value)
    Sets a gamerule value on a world using the best available API.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CompatibilityGameRule

      public CompatibilityGameRule()
  • Method Details

    • getByName

      public static org.bukkit.GameRule getByName(String ruleName)
      Retrieves the GameRule value associated with the given gamerule name.

      This calls GameRule.getByName(String) via reflection to avoid bytecode linkage issues (e.g., IncompatibleClassChangeError) on mismatched compile/runtime environments.

      Uses the raw GameRule type so it works on older APIs where GameRule was not generic.

      Parameters:
      ruleName - The gamerule name (e.g., "keepInventory", "randomTickSpeed").
      Returns:
      The corresponding GameRule, or null if not found.
    • getValue

      public static Object getValue(org.bukkit.World world, String ruleName)
      Retrieves a gamerule value from a world using the best available API.

      Prefers World.getGameRuleValue(GameRule) when available, otherwise falls back to World.getGameRuleValue(String).

      Parameters:
      world - The world to read the gamerule from.
      ruleName - The gamerule name (e.g., "keepInventory").
      Returns:
      The gamerule value (Boolean/Integer/etc.), or null if unavailable.
    • getBoolean

      public static boolean getBoolean(org.bukkit.World world, String ruleName)
      Retrieves a boolean gamerule value from a world.
      Parameters:
      world - The world to read the gamerule from.
      ruleName - The gamerule name.
      Returns:
      The boolean gamerule value.
    • getInt

      public static int getInt(org.bukkit.World world, String ruleName)
      Retrieves an integer gamerule value from a world.
      Parameters:
      world - The world to read the gamerule from.
      ruleName - The gamerule name.
      Returns:
      The integer gamerule value.
    • setValue

      public static void setValue(org.bukkit.World world, String ruleName, Object value)
      Sets a gamerule value on a world using the best available API.

      Prefers World.setGameRule(GameRule, T) when available, otherwise falls back to World.setGameRuleValue(String, String).

      Parameters:
      world - The world to set the gamerule on.
      ruleName - The gamerule name.
      value - The value to set (Boolean/Integer/String/etc.).