-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Add WorldDifficultyChangeEvent #12471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
61a04c8
call WorldDifficultyChangeEvent
NonSwag 73f2020
add difficulty change event
NonSwag 2e39f47
add file patches
NonSwag 42e6e6a
move utility methods to CraftWorld
NonSwag d9e7607
move difficulty utility methods to their own class
NonSwag 947814d
[ci skip] Removed comment in setDifficulty method
NonSwag e849cae
[ci skip] Updated Javadocs for WorldDifficultyChangeEvent
NonSwag 9552f25
Merge branch 'main' into difficulty-change-event
NonSwag 0bc30b5
rebase
NonSwag 28c629d
Merge branch 'main' into difficulty-change-event
NonSwag 332aa8b
rebase
NonSwag b84cb75
Merge branch 'main' into difficulty-change-event
NonSwag 887acf5
rebased
NonSwag b8a9d51
Merge branch 'main' into difficulty-change-event
NonSwag 5e5bdb2
made difficulty final and changed command sender to command source stack
NonSwag ee8b1a2
made event non-cancellable
NonSwag cb7cf6f
mark constructor as internal
NonSwag File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
paper-api/src/main/java/io/papermc/paper/event/world/WorldDifficultyChangeEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| package io.papermc.paper.event.world; | ||
|
|
||
| import io.papermc.paper.command.brigadier.CommandSourceStack; | ||
| import org.bukkit.Difficulty; | ||
| import org.bukkit.World; | ||
| import org.bukkit.event.HandlerList; | ||
| import org.bukkit.event.world.WorldEvent; | ||
| import org.jetbrains.annotations.ApiStatus; | ||
| import org.jspecify.annotations.NullMarked; | ||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| /** | ||
| * Called when a world's difficulty is changed, either by command or by api. | ||
| * <p> | ||
| * If the world is in {@link World#isHardcore() hardcore} | ||
| * the resulting difficulty will always be {@link Difficulty#HARD} | ||
| */ | ||
| @NullMarked | ||
| public class WorldDifficultyChangeEvent extends WorldEvent { | ||
|
|
||
| private static final HandlerList HANDLER_LIST = new HandlerList(); | ||
|
|
||
| private final @Nullable CommandSourceStack commandSource; | ||
| private final Difficulty difficulty; | ||
|
|
||
| @ApiStatus.Internal | ||
| public WorldDifficultyChangeEvent(final World world, final @Nullable CommandSourceStack commandSource, final Difficulty difficulty) { | ||
| super(world); | ||
| this.commandSource = commandSource; | ||
| this.difficulty = difficulty; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the command source associated with this event. | ||
| * | ||
| * @return {@code null} if the difficulty was changed via api, otherwise the {@link CommandSourceStack}. | ||
| */ | ||
| public @Nullable CommandSourceStack getCommandSource() { | ||
| return commandSource; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the new difficulty of the world. | ||
| * | ||
| * @return the new difficulty. | ||
| */ | ||
| public Difficulty getDifficulty() { | ||
| return difficulty; | ||
| } | ||
|
|
||
| @Override | ||
| public HandlerList getHandlers() { | ||
| return HANDLER_LIST; | ||
| } | ||
|
|
||
| public static HandlerList getHandlerList() { | ||
| return HANDLER_LIST; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftDifficulty.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package org.bukkit.craftbukkit.util; | ||
|
|
||
| import org.jspecify.annotations.NullMarked; | ||
|
|
||
| @NullMarked | ||
| public final class CraftDifficulty { | ||
|
notTamion marked this conversation as resolved.
|
||
| public static org.bukkit.Difficulty toBukkit(net.minecraft.world.Difficulty difficulty) { | ||
| return switch (difficulty) { | ||
| case EASY -> org.bukkit.Difficulty.EASY; | ||
| case HARD -> org.bukkit.Difficulty.HARD; | ||
| case NORMAL -> org.bukkit.Difficulty.NORMAL; | ||
| case PEACEFUL -> org.bukkit.Difficulty.PEACEFUL; | ||
| }; | ||
| } | ||
|
|
||
| public static net.minecraft.world.Difficulty toMinecraft(org.bukkit.Difficulty difficulty) { | ||
| return switch (difficulty) { | ||
| case EASY -> net.minecraft.world.Difficulty.EASY; | ||
| case HARD -> net.minecraft.world.Difficulty.HARD; | ||
| case NORMAL -> net.minecraft.world.Difficulty.NORMAL; | ||
| case PEACEFUL -> net.minecraft.world.Difficulty.PEACEFUL; | ||
| }; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.