Package dev.cwhead.GravesX.compatibility
Class CompatibilityGameRule
java.lang.Object
dev.cwhead.GravesX.compatibility.CompatibilityGameRule
Handles compatibility for GameRules to prevent runtime errors across versions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleangetBoolean(org.bukkit.World world, String ruleName) Retrieves a boolean gamerule value from a world.static org.bukkit.GameRuleRetrieves theGameRulevalue associated with the given gamerule name.static intRetrieves an integer gamerule value from a world.static ObjectRetrieves a gamerule value from a world using the best available API.static voidSets a gamerule value on a world using the best available API.
-
Constructor Details
-
CompatibilityGameRule
public CompatibilityGameRule()
-
-
Method Details
-
getByName
Retrieves theGameRulevalue 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
GameRuletype so it works on older APIs whereGameRulewas not generic.- Parameters:
ruleName- The gamerule name (e.g., "keepInventory", "randomTickSpeed").- Returns:
- The corresponding
GameRule, ornullif not found.
-
getValue
Retrieves a gamerule value from a world using the best available API.Prefers
World.getGameRuleValue(GameRule)when available, otherwise falls back toWorld.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
nullif unavailable.
-
getBoolean
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
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
Sets a gamerule value on a world using the best available API.Prefers
World.setGameRule(GameRule, T)when available, otherwise falls back toWorld.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.).
-