Class WorldRule<T>

java.lang.Object
me.croabeast.common.WorldRule<T>
Type Parameters:
T - the type of the game rule value (e.g., Boolean or Integer)

public abstract class WorldRule<T> extends Object
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.

This class also maintains a registry of all defined game rules within a static map.

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 Details

    • COMMAND_BLOCK_OUTPUT

      public static final WorldRule<Boolean> COMMAND_BLOCK_OUTPUT
      Game rule: commandBlockOutput. Indicates whether command blocks should output their command results.
    • DO_FIRE_TICK

      public static final WorldRule<Boolean> DO_FIRE_TICK
      Game rule: doFireTick. Indicates whether fire should naturally progress (tick) in the world.
    • DO_MOB_LOOT

      public static final WorldRule<Boolean> DO_MOB_LOOT
      Game rule: doMobLoot. Indicates whether mobs should drop loot when killed.
    • DO_MOB_SPAWNING

      public static final WorldRule<Boolean> DO_MOB_SPAWNING
      Game rule: doMobSpawning. Indicates whether mobs should spawn naturally.
    • DO_TILE_DROPS

      public static final WorldRule<Boolean> DO_TILE_DROPS
      Game rule: doTileDrops. Indicates whether blocks should drop items when broken.
    • KEEP_INVENTORY

      public static final WorldRule<Boolean> KEEP_INVENTORY
      Game rule: keepInventory. Indicates whether players keep their inventory upon death.
    • MOB_GRIEFING

      public static final WorldRule<Boolean> MOB_GRIEFING
      Game rule: mobGriefing. Indicates whether mobs can modify blocks (e.g., creepers destroying blocks).
    • DO_DAYLIGHT_CYCLE

      public static final WorldRule<Boolean> DO_DAYLIGHT_CYCLE
      Game rule: doDaylightCycle. Indicates whether the day-night cycle should progress.
    • NATURAL_REGENERATION

      public static final WorldRule<Boolean> NATURAL_REGENERATION
      Game rule: naturalRegeneration. Indicates whether players naturally regenerate health.
    • LOG_ADMIN_COMMANDS

      public static final WorldRule<Boolean> LOG_ADMIN_COMMANDS
      Game rule: logAdminCommands. Indicates whether admin command executions should be logged.
    • RANDOM_TICK_SPEED

      public static final WorldRule<Integer> RANDOM_TICK_SPEED
      Game rule: randomTickSpeed. Controls the rate at which random block ticks occur (affecting crop growth, etc.).
    • REDUCED_DEBUG_INFO

      public static final WorldRule<Boolean> REDUCED_DEBUG_INFO
      Game rule: reducedDebugInfo. Indicates whether the debug information should be reduced.
    • SEND_COMMAND_FEEDBACK

      public static final WorldRule<Boolean> SEND_COMMAND_FEEDBACK
      Game rule: sendCommandFeedback. Indicates whether command feedback should be sent to the command sender.
    • SHOW_DEATH_MESSAGES

      public static final WorldRule<Boolean> SHOW_DEATH_MESSAGES
      Game rule: showDeathMessages. Indicates whether death messages should be broadcast.
    • DO_ENTITY_DROPS

      public static final WorldRule<Boolean> DO_ENTITY_DROPS
      Game rule: doEntityDrops. Indicates whether entities drop items when killed.
    • DISABLE_ELYTRA_MOVEMENT_CHECK

      public static final WorldRule<Boolean> DISABLE_ELYTRA_MOVEMENT_CHECK
      Game rule: disableElytraMovementCheck. Disables the elytra movement check to allow for freer flight.
    • SPAWN_RADIUS

      public static final WorldRule<Integer> SPAWN_RADIUS
      Game rule: spawnRadius. Controls the radius around the world spawn where players will spawn.
    • SPECTATORS_GENERATE_CHUNKS

      public static final WorldRule<Boolean> SPECTATORS_GENERATE_CHUNKS
      Game rule: spectatorsGenerateChunks. Determines whether spectators can generate chunks by moving.
    • DO_WEATHER_CYCLE

      public static final WorldRule<Boolean> DO_WEATHER_CYCLE
      Game rule: doWeatherCycle. Indicates whether weather should change naturally.
    • MAX_ENTITY_CRAMMING

      public static final WorldRule<Integer> MAX_ENTITY_CRAMMING
      Game rule: maxEntityCramming. Determines the maximum number of entities allowed in a single block space.
    • ANNOUNCE_ADVANCEMENTS

      public static final WorldRule<Boolean> ANNOUNCE_ADVANCEMENTS
      Game rule: announceAdvancements. Indicates whether advancements should be announced to chat.
    • DO_LIMITED_CRAFTING

      public static final WorldRule<Boolean> DO_LIMITED_CRAFTING
      Game rule: doLimitedCrafting. Limits the crafting recipes available to players.
    • MAX_COMMAND_CHAIN_LENGTH

      public static final WorldRule<Integer> MAX_COMMAND_CHAIN_LENGTH
      Game rule: maxCommandChainLength. Sets the maximum allowed length of command chains.
    • DISABLE_RAIDS

      public static final WorldRule<Boolean> DISABLE_RAIDS
      Game rule: disableRaids. Disables raid spawning in the world.
    • DO_IMMEDIATE_RESPAWN

      public static final WorldRule<Boolean> DO_IMMEDIATE_RESPAWN
      Game rule: doImmediateRespawn. Controls whether players respawn immediately upon death.
    • DO_INSOMNIA

      public static final WorldRule<Boolean> DO_INSOMNIA
      Game rule: doInsomnia. Controls whether players experience the insomnia effect (related to phantoms).
    • DROWNING_DAMAGE

      public static final WorldRule<Boolean> DROWNING_DAMAGE
      Game rule: drowningDamage. Indicates whether players take damage from drowning.
    • FALL_DAMAGE

      public static final WorldRule<Boolean> FALL_DAMAGE
      Game rule: fallDamage. Indicates whether players take damage from falling.
    • FIRE_DAMAGE

      public static final WorldRule<Boolean> FIRE_DAMAGE
      Game rule: fireDamage. Indicates whether players take damage from fire.
    • DO_PATROL_SPAWNING

      public static final WorldRule<Boolean> DO_PATROL_SPAWNING
      Game rule: doPatrolSpawning. Controls whether patrols are allowed to spawn.
    • DO_TRADER_SPAWNING

      public static final WorldRule<Boolean> DO_TRADER_SPAWNING
      Game rule: doTraderSpawning. Controls whether trader villagers can spawn.
    • FORGIVE_DEAD_PLAYERS

      public static final WorldRule<Boolean> FORGIVE_DEAD_PLAYERS
      Game rule: forgiveDeadPlayers. Indicates whether mobs will forgive players after they die.
    • UNIVERSAL_ANGER

      public static final WorldRule<Boolean> UNIVERSAL_ANGER
      Game rule: universalAnger. Determines whether all hostile mobs become angry when a player is attacked.
    • FREEZE_DAMAGE

      public static final WorldRule<Boolean> FREEZE_DAMAGE
      Game rule: freezeDamage. Indicates whether players take damage from freezing.
    • PLAYERS_SLEEPING_PERCENTAGE

      public static final WorldRule<Integer> PLAYERS_SLEEPING_PERCENTAGE
      Game rule: playersSleepingPercentage. The percentage of players that must sleep to change the time.
    • DO_WARDEN_SPAWNING

      public static final WorldRule<Boolean> DO_WARDEN_SPAWNING
      Game rule: doWardenSpawning. Controls whether the Warden can spawn.
    • BLOCK_EXPLOSION_DROP_DECAY

      public static final WorldRule<Boolean> BLOCK_EXPLOSION_DROP_DECAY
      Game rule: blockExplosionDropDecay. Determines if block explosion drops are decayed.
    • GLOBAL_SOUND_EVENTS

      public static final WorldRule<Boolean> GLOBAL_SOUND_EVENTS
      Game rule: globalSoundEvents. Controls whether sound events are global.
    • LAVA_SOURCE_CONVERSION

      public static final WorldRule<Boolean> LAVA_SOURCE_CONVERSION
      Game rule: lavaSourceConversion. Controls whether lava converts into a source block.
    • MOB_EXPLOSION_DROP_DECAY

      public static final WorldRule<Boolean> MOB_EXPLOSION_DROP_DECAY
      Game rule: mobExplosionDropDecay. Determines if mob explosion drops are decayed.
    • SNOW_ACCUMULATION_HEIGHT

      public static final WorldRule<Integer> SNOW_ACCUMULATION_HEIGHT
      Game rule: snowAccumulationHeight. Determines the height at which snow can accumulate.
    • TNT_EXPLOSION_DROP_DECAY

      public static final WorldRule<Boolean> TNT_EXPLOSION_DROP_DECAY
      Game rule: tntExplosionDropDecay. Determines if TNT explosion drops are decayed.
    • WATER_SOURCE_CONVERSION

      public static final WorldRule<Boolean> WATER_SOURCE_CONVERSION
      Game rule: waterSourceConversion. Controls whether water converts into a source block.
    • COMMAND_MODIFICATION_BLOCK_LIMIT

      public static final WorldRule<Integer> COMMAND_MODIFICATION_BLOCK_LIMIT
      Game rule: commandModificationBlockLimit. Sets a limit for command modifications via blocks.
    • DO_VINES_SPREAD

      public static final WorldRule<Boolean> DO_VINES_SPREAD
      Game rule: doVinesSpread. Indicates whether vines should spread naturally.
    • ENDER_PEARLS_VANISH_ON_DEATH

      public static final WorldRule<Boolean> ENDER_PEARLS_VANISH_ON_DEATH
      Game rule: enderPearlsVanishOnDeath. Indicates whether ender pearls vanish upon player death.
    • MAX_COMMAND_FORK_COUNT

      public static final WorldRule<Integer> MAX_COMMAND_FORK_COUNT
      Game rule: maxCommandForkCount. Sets the maximum number of forks in a command chain.
    • PLAYERS_NETHER_PORTAL_CREATIVE_DELAY

      public static final WorldRule<Integer> PLAYERS_NETHER_PORTAL_CREATIVE_DELAY
      Game rule: playersNetherPortalCreativeDelay. The creative mode delay for nether portal usage.
    • PLAYERS_NETHER_PORTAL_DEFAULT_DELAY

      public static final WorldRule<Integer> PLAYERS_NETHER_PORTAL_DEFAULT_DELAY
      Game rule: playersNetherPortalDefaultDelay. The default delay for nether portal usage.
    • PROJECTILES_CAN_BREAK_BLOCKS

      public static final WorldRule<Boolean> PROJECTILES_CAN_BREAK_BLOCKS
      Game rule: projectilesCanBreakBlocks. Indicates whether projectiles are allowed to break blocks.
    • SPAWN_CHUNK_RADIUS

      public static final WorldRule<Integer> SPAWN_CHUNK_RADIUS
      Game rule: spawnChunkRadius. Determines the radius of spawn chunks.
    • MINECART_MAX_SPEED

      public static final WorldRule<Integer> MINECART_MAX_SPEED
      Game rule: minecartMaxSpeed. Sets the maximum speed for mine carts.
    • DISABLE_PLAYER_MOVEMENT_CHECK

      public static final WorldRule<Boolean> DISABLE_PLAYER_MOVEMENT_CHECK
      Game rule: disablePlayerMovementCheck. Disables movement checks for players.
    • ALLOW_FIRE_TICKS_AWAY_FROM_PLAYER

      public static final WorldRule<Boolean> ALLOW_FIRE_TICKS_AWAY_FROM_PLAYER
      Game rule: allowFireTicksAwayFromPlayer. Controls fire tick behavior away from players.
    • TNT_EXPLODES

      public static final WorldRule<Boolean> TNT_EXPLODES
      Game rule: tntExplodes. Indicates whether TNT should explode.
    • USE_LOCATOR_BAR

      public static final WorldRule<Boolean> USE_LOCATOR_BAR
      Game rule: useLocatorBar. Enables the locator bar feature.
  • Method Details

    • getName

      @NotNull public @NotNull String getName()
      Returns the name of this world rule.
      Returns:
      the rule name
    • getType

      @NotNull public @NotNull Class<T> getType()
      Returns the type of this world rule (e.g., Boolean.class or Integer.class).
      Returns:
      the class representing the type of the rule's value
    • getValue

      @Nullable public abstract T getValue(org.bukkit.World world) throws Exception
      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 null if unavailable
      Throws:
      Exception - if the value cannot be retrieved
    • getDefault

      public T getDefault()
      Returns the default value for this game rule.
      Returns:
      the default value
    • setValue

      public boolean setValue(org.bukkit.World world, T value)
      Sets a new value for this game rule in the given world.
      Parameters:
      world - the world where the rule should be set
      value - the new value to assign
      Returns:
      true if the rule was successfully updated; false otherwise
    • isDefault

      public boolean isDefault(org.bukkit.World world) throws Exception
      Determines if the game rule in the given world is set to its default value.
      Parameters:
      world - the world to check
      Returns:
      true if the current value equals the default; false otherwise
      Throws:
      Exception - if the value cannot be retrieved
    • asBukkit

      @NotNull public @NotNull org.bukkit.GameRule<T> asBukkit()
      Retrieves the corresponding Bukkit GameRule object for this world rule.
      Returns:
      the Bukkit GameRule for this rule
      Throws:
      NullPointerException - if no matching GameRule is found
    • values

      public static Set<WorldRule<?>> values()
      Returns a set of all registered world rules.
      Returns:
      a set of WorldRule objects