Package me.croabeast.common
Class WorldRule<T>
java.lang.Object
me.croabeast.common.WorldRule<T>
- Type Parameters:
T- the type of the game rule value (e.g.,BooleanorInteger)
Represents a game rule for a Minecraft world.
WorldRule is an abstraction over Bukkit's game rules, allowing you to get and set specific
rules by name, while also providing default values and minimum server version requirements.
Each WorldRule is associated with a rule name, a type (Boolean or Integer),
a default value, and a minimum version number from which the rule is available.
Example usage:
// Retrieve the "doFireTick" game rule value from a world
WorldRule fireTickRule = WorldRule.DO_FIRE_TICK;
Boolean currentValue = fireTickRule.getValue(world);
// Set a new value for the game rule if allowed
boolean success = fireTickRule.setValue(world, false);
-
Field Summary
FieldsModifier and TypeFieldDescriptionGame rule: allowFireTicksAwayFromPlayer.Game rule: announceAdvancements.Game rule: blockExplosionDropDecay.Game rule: commandBlockOutput.Game rule: commandModificationBlockLimit.Game rule: disableElytraMovementCheck.Game rule: disablePlayerMovementCheck.Game rule: disableRaids.Game rule: doDaylightCycle.Game rule: doEntityDrops.Game rule: doFireTick.Game rule: doImmediateRespawn.Game rule: doInsomnia.Game rule: doLimitedCrafting.Game rule: doMobLoot.Game rule: doMobSpawning.Game rule: doPatrolSpawning.Game rule: doTileDrops.Game rule: doTraderSpawning.Game rule: doVinesSpread.Game rule: doWardenSpawning.Game rule: doWeatherCycle.Game rule: drowningDamage.Game rule: enderPearlsVanishOnDeath.Game rule: fallDamage.Game rule: fireDamage.Game rule: forgiveDeadPlayers.Game rule: freezeDamage.Game rule: globalSoundEvents.Game rule: keepInventory.Game rule: lavaSourceConversion.Game rule: logAdminCommands.Game rule: maxCommandChainLength.Game rule: maxCommandForkCount.Game rule: maxEntityCramming.Game rule: minecartMaxSpeed.Game rule: mobExplosionDropDecay.Game rule: mobGriefing.Game rule: naturalRegeneration.Game rule: playersNetherPortalCreativeDelay.Game rule: playersNetherPortalDefaultDelay.Game rule: playersSleepingPercentage.Game rule: projectilesCanBreakBlocks.Game rule: randomTickSpeed.Game rule: reducedDebugInfo.Game rule: sendCommandFeedback.Game rule: showDeathMessages.Game rule: snowAccumulationHeight.Game rule: spawnChunkRadius.Game rule: spawnRadius.Game rule: spectatorsGenerateChunks.Game rule: tntExplodes.Game rule: tntExplosionDropDecay.Game rule: universalAnger.Game rule: useLocatorBar.Game rule: waterSourceConversion. -
Method Summary
Modifier and TypeMethodDescription@NotNull org.bukkit.GameRule<T> asBukkit()Retrieves the corresponding BukkitGameRuleobject for this world rule.Returns the default value for this game rule.@NotNull StringgetName()Returns the name of this world rule.getType()Returns the type of this world rule (e.g.,Boolean.classorInteger.class).abstract TgetValue(org.bukkit.World world) Retrieves the current value of this game rule from the specified world.booleanisDefault(org.bukkit.World world) Determines if the game rule in the given world is set to its default value.booleanSets a new value for this game rule in the given world.values()Returns a set of all registered world rules.
-
Field Details
-
COMMAND_BLOCK_OUTPUT
Game rule: commandBlockOutput. Indicates whether command blocks should output their command results. -
DO_FIRE_TICK
Game rule: doFireTick. Indicates whether fire should naturally progress (tick) in the world. -
DO_MOB_LOOT
Game rule: doMobLoot. Indicates whether mobs should drop loot when killed. -
DO_MOB_SPAWNING
Game rule: doMobSpawning. Indicates whether mobs should spawn naturally. -
DO_TILE_DROPS
Game rule: doTileDrops. Indicates whether blocks should drop items when broken. -
KEEP_INVENTORY
Game rule: keepInventory. Indicates whether players keep their inventory upon death. -
MOB_GRIEFING
Game rule: mobGriefing. Indicates whether mobs can modify blocks (e.g., creepers destroying blocks). -
DO_DAYLIGHT_CYCLE
Game rule: doDaylightCycle. Indicates whether the day-night cycle should progress. -
NATURAL_REGENERATION
Game rule: naturalRegeneration. Indicates whether players naturally regenerate health. -
LOG_ADMIN_COMMANDS
Game rule: logAdminCommands. Indicates whether admin command executions should be logged. -
RANDOM_TICK_SPEED
Game rule: randomTickSpeed. Controls the rate at which random block ticks occur (affecting crop growth, etc.). -
REDUCED_DEBUG_INFO
Game rule: reducedDebugInfo. Indicates whether the debug information should be reduced. -
SEND_COMMAND_FEEDBACK
Game rule: sendCommandFeedback. Indicates whether command feedback should be sent to the command sender. -
SHOW_DEATH_MESSAGES
Game rule: showDeathMessages. Indicates whether death messages should be broadcast. -
DO_ENTITY_DROPS
Game rule: doEntityDrops. Indicates whether entities drop items when killed. -
DISABLE_ELYTRA_MOVEMENT_CHECK
Game rule: disableElytraMovementCheck. Disables the elytra movement check to allow for freer flight. -
SPAWN_RADIUS
Game rule: spawnRadius. Controls the radius around the world spawn where players will spawn. -
SPECTATORS_GENERATE_CHUNKS
Game rule: spectatorsGenerateChunks. Determines whether spectators can generate chunks by moving. -
DO_WEATHER_CYCLE
Game rule: doWeatherCycle. Indicates whether weather should change naturally. -
MAX_ENTITY_CRAMMING
Game rule: maxEntityCramming. Determines the maximum number of entities allowed in a single block space. -
ANNOUNCE_ADVANCEMENTS
Game rule: announceAdvancements. Indicates whether advancements should be announced to chat. -
DO_LIMITED_CRAFTING
Game rule: doLimitedCrafting. Limits the crafting recipes available to players. -
MAX_COMMAND_CHAIN_LENGTH
Game rule: maxCommandChainLength. Sets the maximum allowed length of command chains. -
DISABLE_RAIDS
Game rule: disableRaids. Disables raid spawning in the world. -
DO_IMMEDIATE_RESPAWN
Game rule: doImmediateRespawn. Controls whether players respawn immediately upon death. -
DO_INSOMNIA
Game rule: doInsomnia. Controls whether players experience the insomnia effect (related to phantoms). -
DROWNING_DAMAGE
Game rule: drowningDamage. Indicates whether players take damage from drowning. -
FALL_DAMAGE
Game rule: fallDamage. Indicates whether players take damage from falling. -
FIRE_DAMAGE
Game rule: fireDamage. Indicates whether players take damage from fire. -
DO_PATROL_SPAWNING
Game rule: doPatrolSpawning. Controls whether patrols are allowed to spawn. -
DO_TRADER_SPAWNING
Game rule: doTraderSpawning. Controls whether trader villagers can spawn. -
FORGIVE_DEAD_PLAYERS
Game rule: forgiveDeadPlayers. Indicates whether mobs will forgive players after they die. -
UNIVERSAL_ANGER
Game rule: universalAnger. Determines whether all hostile mobs become angry when a player is attacked. -
FREEZE_DAMAGE
Game rule: freezeDamage. Indicates whether players take damage from freezing. -
PLAYERS_SLEEPING_PERCENTAGE
Game rule: playersSleepingPercentage. The percentage of players that must sleep to change the time. -
DO_WARDEN_SPAWNING
Game rule: doWardenSpawning. Controls whether the Warden can spawn. -
BLOCK_EXPLOSION_DROP_DECAY
Game rule: blockExplosionDropDecay. Determines if block explosion drops are decayed. -
GLOBAL_SOUND_EVENTS
Game rule: globalSoundEvents. Controls whether sound events are global. -
LAVA_SOURCE_CONVERSION
Game rule: lavaSourceConversion. Controls whether lava converts into a source block. -
MOB_EXPLOSION_DROP_DECAY
Game rule: mobExplosionDropDecay. Determines if mob explosion drops are decayed. -
SNOW_ACCUMULATION_HEIGHT
Game rule: snowAccumulationHeight. Determines the height at which snow can accumulate. -
TNT_EXPLOSION_DROP_DECAY
Game rule: tntExplosionDropDecay. Determines if TNT explosion drops are decayed. -
WATER_SOURCE_CONVERSION
Game rule: waterSourceConversion. Controls whether water converts into a source block. -
COMMAND_MODIFICATION_BLOCK_LIMIT
Game rule: commandModificationBlockLimit. Sets a limit for command modifications via blocks. -
DO_VINES_SPREAD
Game rule: doVinesSpread. Indicates whether vines should spread naturally. -
ENDER_PEARLS_VANISH_ON_DEATH
Game rule: enderPearlsVanishOnDeath. Indicates whether ender pearls vanish upon player death. -
MAX_COMMAND_FORK_COUNT
Game rule: maxCommandForkCount. Sets the maximum number of forks in a command chain. -
PLAYERS_NETHER_PORTAL_CREATIVE_DELAY
Game rule: playersNetherPortalCreativeDelay. The creative mode delay for nether portal usage. -
PLAYERS_NETHER_PORTAL_DEFAULT_DELAY
Game rule: playersNetherPortalDefaultDelay. The default delay for nether portal usage. -
PROJECTILES_CAN_BREAK_BLOCKS
Game rule: projectilesCanBreakBlocks. Indicates whether projectiles are allowed to break blocks. -
SPAWN_CHUNK_RADIUS
Game rule: spawnChunkRadius. Determines the radius of spawn chunks. -
MINECART_MAX_SPEED
Game rule: minecartMaxSpeed. Sets the maximum speed for mine carts. -
DISABLE_PLAYER_MOVEMENT_CHECK
Game rule: disablePlayerMovementCheck. Disables movement checks for players. -
ALLOW_FIRE_TICKS_AWAY_FROM_PLAYER
Game rule: allowFireTicksAwayFromPlayer. Controls fire tick behavior away from players. -
TNT_EXPLODES
Game rule: tntExplodes. Indicates whether TNT should explode. -
USE_LOCATOR_BAR
Game rule: useLocatorBar. Enables the locator bar feature.
-
-
Method Details
-
getName
Returns the name of this world rule.- Returns:
- the rule name
-
getType
Returns the type of this world rule (e.g.,Boolean.classorInteger.class).- Returns:
- the class representing the type of the rule's value
-
getValue
Retrieves the current value of this game rule from the specified world.- Parameters:
world- the world from which to get the game rule value- Returns:
- the current value of the rule, or
nullif unavailable - Throws:
Exception- if the value cannot be retrieved
-
getDefault
Returns the default value for this game rule.- Returns:
- the default value
-
setValue
Sets a new value for this game rule in the given world.- Parameters:
world- the world where the rule should be setvalue- the new value to assign- Returns:
trueif the rule was successfully updated;falseotherwise
-
isDefault
Determines if the game rule in the given world is set to its default value.- Parameters:
world- the world to check- Returns:
trueif the current value equals the default;falseotherwise- Throws:
Exception- if the value cannot be retrieved
-
asBukkit
Retrieves the corresponding BukkitGameRuleobject for this world rule.- Returns:
- the Bukkit
GameRulefor this rule - Throws:
NullPointerException- if no matching GameRule is found
-
values
Returns a set of all registered world rules.- Returns:
- a set of
WorldRuleobjects
-