-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Preliminary example of WorldUnloadEvent #8399
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,29 @@ | ||
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
| From: Shane Freeder <theboyetronic@gmail.com> | ||
| Date: Wed, 28 Sep 2022 05:09:05 +0100 | ||
| Subject: [PATCH] Add WorldUnloadResult | ||
|
|
||
|
|
||
| diff --git a/src/main/java/io/papermc/paper/world/WorldUnloadResult.java b/src/main/java/io/papermc/paper/world/WorldUnloadResult.java | ||
| new file mode 100644 | ||
| index 0000000000000000000000000000000000000000..d8b190dfb44e3f4712f0b2e5677cb0b9893fe5ec | ||
| --- /dev/null | ||
| +++ b/src/main/java/io/papermc/paper/world/WorldUnloadResult.java | ||
| @@ -0,0 +1,17 @@ | ||
| +package io.papermc.paper.world; | ||
| + | ||
| +import net.kyori.adventure.text.Component; | ||
| + | ||
| +import org.jetbrains.annotations.NotNull; | ||
| + | ||
| +public record WorldUnloadResult(boolean success, @NotNull Component message) { | ||
| + | ||
| + public static final WorldUnloadResult SUCCESS = new WorldUnloadResult(true, Component.text("Success")); | ||
| + public static final WorldUnloadResult NOT_LOADED = new WorldUnloadResult(false, Component.text("Cannot unload unloaded world")); | ||
| + public static final WorldUnloadResult UNSUPPORTED = new WorldUnloadResult(false, Component.text("Unloading this world is not supported")); | ||
| + public static final WorldUnloadResult NOT_EMPTY = new WorldUnloadResult(false, Component.text("Unable to load world with players!")); | ||
| + public static final WorldUnloadResult PENDING_LOGIN = new WorldUnloadResult(false, Component.text("Unable to load world with pending login!")); | ||
| + public static final WorldUnloadResult PLUGIN = new WorldUnloadResult(false, Component.text("World unload cancelled by plugin")); | ||
| + public static final WorldUnloadResult NULL = new WorldUnloadResult(false, Component.text("Cannot unload null world")); | ||
| + | ||
| +} | ||
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,67 @@ | ||
| From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 | ||
| From: Shane Freeder <theboyetronic@gmail.com> | ||
| Date: Wed, 28 Sep 2022 05:09:11 +0100 | ||
| Subject: [PATCH] Add WorldUnloadResult | ||
|
|
||
|
|
||
| diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java | ||
| index 111f8276f26350a5c62a7b8577b4598978b5355d..8843c966eeeb8cc009df43cf04aae713466dbda0 100644 | ||
| --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java | ||
| +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java | ||
| @@ -1269,30 +1269,41 @@ public final class CraftServer implements Server { | ||
|
|
||
| @Override | ||
| public boolean unloadWorld(World world, boolean save) { | ||
| + // Paper start | ||
| + return unloadWorld_(world, save).isSuccess(); | ||
| + } | ||
| + | ||
| + public io.papermc.paper.world.WorldUnloadResult unloadWorld_(World world, boolean save) { | ||
| + // paper end | ||
| //Preconditions.checkState(!this.console.isIteratingOverLevels, "Cannot unload a world while worlds are being ticked"); // Paper - Cat - Temp disable. We'll see how this goes. | ||
| if (world == null) { | ||
| - return false; | ||
| + return io.papermc.paper.world.WorldUnloadResult.NULL; // Just, why... // paper | ||
| } | ||
|
|
||
| ServerLevel handle = ((CraftWorld) world).getHandle(); | ||
|
|
||
| if (this.console.getLevel(handle.dimension()) == null) { | ||
| - return false; | ||
| + return io.papermc.paper.world.WorldUnloadResult.NOT_LOADED; // paper | ||
| } | ||
|
|
||
| if (handle.dimension() == net.minecraft.world.level.Level.OVERWORLD) { | ||
| - return false; | ||
| + return io.papermc.paper.world.WorldUnloadResult.UNSUPPORTED; // Paper | ||
| } | ||
|
|
||
| - if (handle.players().size() > 0 || handle.pendingLogin.size() > 0) { // Paper | ||
| - return false; | ||
| + // Paper start - replace return, and differentiante | ||
| + if (handle.players().size() > 0) { | ||
| + return io.papermc.paper.world.WorldUnloadResult.NOT_EMPTY; | ||
| + } | ||
| + if (handle.pendingLogin.size() > 0) { | ||
| + return io.papermc.paper.world.WorldUnloadResult.PENDING_LOGIN; | ||
| } | ||
| + // Paper end | ||
|
|
||
| WorldUnloadEvent e = new WorldUnloadEvent(handle.getWorld()); | ||
| this.pluginManager.callEvent(e); | ||
|
|
||
| if (e.isCancelled()) { | ||
| - return false; | ||
| + return io.papermc.paper.world.WorldUnloadResult.PLUGIN; | ||
| } | ||
|
|
||
| try { | ||
| @@ -1309,7 +1320,7 @@ public final class CraftServer implements Server { | ||
|
|
||
| this.worlds.remove(world.getName().toLowerCase(java.util.Locale.ENGLISH)); | ||
| this.console.removeLevel(handle); | ||
| - return true; | ||
| + return io.papermc.paper.world.WorldUnloadResult.SUCCESS; | ||
| } | ||
|
|
||
| public DedicatedServer getServer() { |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you have a typo on "load" (you meant "unload" right ?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, I was honestly just rushing this to get it down, been meaning to look into this one for a good while, general improvements to the messages welcome, etc