Class GameRuleChangeEvent

java.lang.Object
fr.fidorial.event.server.GameRuleChangeEvent
All Implemented Interfaces:
Cancellable, Event

public final class GameRuleChangeEvent extends Object implements Event, Cancellable
Fired right before a game rule changes.
Since:
0.1.0
  • Constructor Details

    • GameRuleChangeEvent

      public GameRuleChangeEvent(GameRuleDefinition rule, @Nullable World world, String previousValue, String newValue, boolean removesOverride, GameRuleChangeEvent.Cause cause, @Nullable CommandSender source)
      Creates an event.
      Parameters:
      rule - the rule about to change
      world - the world whose override changes, or null for the base value
      previousValue - the value in effect before the change
      newValue - the value about to be in effect
      removesOverride - whether the world is about to drop its override
      cause - what requested the change
      source - who requested the change, or null when a plugin did
      Since:
      0.1.0
  • Method Details

    • rule

      @Contract(pure=true) public GameRuleDefinition rule()
      Gets the rule about to change.
      Returns:
      the rule, compare its key with GameRuleKeys
      Since:
      0.1.0
    • world

      @Contract(pure=true) public Optional<World> world()
      Gets the world whose override is changing.
      Returns:
      the world, or empty when the base value changes, which every world without an override of this rule follows
      Since:
      0.1.0
    • removesOverride

      @Contract(pure=true) public boolean removesOverride()
      Checks whether the world is about to drop its override and follow the base value again.
      Returns:
      true when the override of world() is being removed; calling setNewValue(String) keeps an override instead
      Since:
      0.1.0
    • previousValue

      @Contract(pure=true) public String previousValue()
      Gets the value of the rule before the change.
      Returns:
      the current value
      Since:
      0.1.0
    • newValue

      @Contract(pure=true) public String newValue()
      Gets the value about to be applied.
      Returns:
      the new value, possibly replaced by a previous listener
      Since:
      0.1.0
    • setNewValue

      public void setNewValue(String value)
      Applies another value instead.
      Parameters:
      value - true/false for boolean rules, a number within range otherwise
      Throws:
      IllegalArgumentException - if the value is not valid for this rule
      Since:
      0.1.0
    • setNewValue

      public void setNewValue(boolean value)
      Applies another value instead, for a boolean rule.
      Parameters:
      value - the value to apply
      Throws:
      IllegalArgumentException - if the rule is not a boolean rule
      Since:
      0.1.0
    • setNewValue

      public void setNewValue(int value)
      Applies another value instead, for an integer rule.
      Parameters:
      value - the value to apply
      Throws:
      IllegalArgumentException - if the rule is not an integer rule, or the value is out of range
      Since:
      0.1.0
    • cause

      Gets what requested the change.
      Returns:
      the cause
      Since:
      0.1.0
    • source

      @Contract(pure=true) public Optional<CommandSender> source()
      Gets who requested the change.
      Returns:
      the player or the console that ran /gamerule or used the game rule screen, or empty when a plugin changed the rule through the API
      Since:
      0.1.0
    • isCancelled

      public boolean isCancelled()
      Description copied from interface: Cancellable
      Returns true if the action this event describes will not happen.
      Specified by:
      isCancelled in interface Cancellable
      Returns:
      true if the action this event describes will not happen
    • setCancelled

      public void setCancelled(boolean cancelled)
      Refuses or re-allows the change. A refused change leaves the rule untouched, and /gamerule tells its sender the change was cancelled.
      Specified by:
      setCancelled in interface Cancellable
      Parameters:
      cancelled - whether the change should be refused