Class GameRuleChangeEvent
java.lang.Object
fr.fidorial.event.server.GameRuleChangeEvent
- All Implemented Interfaces:
Cancellable, Event
Fired right before a game rule changes.
- Since:
- 0.1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumWhat requested a game rule change. -
Constructor Summary
ConstructorsConstructorDescriptionGameRuleChangeEvent(GameRuleDefinition rule, @Nullable World world, String previousValue, String newValue, boolean removesOverride, GameRuleChangeEvent.Cause cause, @Nullable CommandSender source) Creates an event. -
Method Summary
Modifier and TypeMethodDescriptioncause()Gets what requested the change.booleanReturnstrueif the action this event describes will not happen.newValue()Gets the value about to be applied.Gets the value of the rule before the change.booleanChecks whether the world is about to drop its override and follow the base value again.rule()Gets the rule about to change.voidsetCancelled(boolean cancelled) Refuses or re-allows the change.voidsetNewValue(boolean value) Applies another value instead, for a boolean rule.voidsetNewValue(int value) Applies another value instead, for an integer rule.voidsetNewValue(String value) Applies another value instead.source()Gets who requested the change.world()Gets the world whose override is changing.
-
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 changeworld- the world whose override changes, ornullfor the base valuepreviousValue- the value in effect before the changenewValue- the value about to be in effectremovesOverride- whether the world is about to drop its overridecause- what requested the changesource- who requested the change, ornullwhen a plugin did- Since:
- 0.1.0
-
-
Method Details
-
rule
Gets the rule about to change.- Returns:
- the rule, compare its
keywithGameRuleKeys - Since:
- 0.1.0
-
world
-
removesOverride
Checks whether the world is about to drop its override and follow the base value again.- Returns:
truewhen the override ofworld()is being removed; callingsetNewValue(String)keeps an override instead- Since:
- 0.1.0
-
previousValue
-
newValue
-
setNewValue
Applies another value instead.- Parameters:
value-true/falsefor 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
Gets who requested the change.- Returns:
- the player or the console that ran
/gameruleor 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:CancellableReturnstrueif the action this event describes will not happen.- Specified by:
isCancelledin interfaceCancellable- Returns:
trueif 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/gameruletells its sender the change was cancelled.- Specified by:
setCancelledin interfaceCancellable- Parameters:
cancelled- whether the change should be refused
-