Paper/patches/api/0282-Implement-Keyed-on-World.patch
Jason bc127ea819
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#6222)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
eec4aab0 SPIGOT-6657: Add getPlayer to SheepDyeWoolEvent
205213c6 SPIGOT-6656: CauldronLevelChangeEvent is not fired correctly when dripstone fills the cauldron

CraftBukkit Changes:
b8c522d5 SPIGOT-6657: Add getPlayer to SheepDyeWoolEvent
f04a77dc SPIGOT-6656: CauldronLevelChangeEvent is not fired correctly when dripstone fills the cauldron
d1dbcebc SPIGOT-6653: Canceling snow bucket placement removes snow from bucket
4f34a67b #891: Fix scheduler task ID overflow and duplication issues

Spigot Changes:
d03d7f12 BUILDTOOLS-604: Rebuild patches
2021-07-18 09:41:53 +02:00

165 lines
5.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Wed, 6 Jan 2021 00:34:10 -0800
Subject: [PATCH] Implement Keyed on World
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index cf7138a9251e92065fef8b0090eaaf779064e2fc..4bd7fee100800d0ede600afcde2277b1de9e52f2 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -663,6 +663,18 @@ public final class Bukkit {
public static World getWorld(@NotNull UUID uid) {
return server.getWorld(uid);
}
+ // Paper start
+ /**
+ * Gets the world from the given NamespacedKey
+ *
+ * @param worldKey the NamespacedKey of the world to retrieve
+ * @return a world with the given NamespacedKey, or null if none exists
+ */
+ @Nullable
+ public static World getWorld(@NotNull NamespacedKey worldKey) {
+ return server.getWorld(worldKey);
+ }
+ // Paper end
/**
* Gets the map from the given item ID.
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 724a32e4a4861f9f9a8ffc5b5a497b458efffc0f..dcdd0c3f3d03e4a3043909cf051faeb665115c34 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -561,6 +561,17 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
@Nullable
public World getWorld(@NotNull UUID uid);
+ // Paper start
+ /**
+ * Gets the world from the given NamespacedKey
+ *
+ * @param worldKey the NamespacedKey of the world to retrieve
+ * @return a world with the given NamespacedKey, or null if none exists
+ */
+ @Nullable
+ public World getWorld(@NotNull NamespacedKey worldKey);
+ // Paper end
+
/**
* Gets the map from the given item ID.
*
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index 27d97cde0fb5f6d727656c291e34dc468200f0c0..178a0853bd8136c6a7408f5d49604ceb2479f138 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -43,7 +43,7 @@ import org.jetbrains.annotations.Nullable;
/**
* Represents a world, which may contain entities, chunks and blocks
*/
-public interface World extends PluginMessageRecipient, Metadatable, net.kyori.adventure.audience.ForwardingAudience { // Paper
+public interface World extends PluginMessageRecipient, Metadatable, net.kyori.adventure.audience.ForwardingAudience, Keyed { // Paper
// Paper start
/**
@@ -1534,6 +1534,15 @@ public interface World extends PluginMessageRecipient, Metadatable, net.kyori.ad
@NotNull
java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsync(int x, int z, boolean gen, boolean urgent);
+
+ /**
+ * Get the world's key
+ *
+ * @return the world's key
+ */
+ @NotNull
+ @Override
+ NamespacedKey getKey();
// Paper end
/**
diff --git a/src/main/java/org/bukkit/WorldCreator.java b/src/main/java/org/bukkit/WorldCreator.java
index 6774c8176c44dea9cbff69aaf0f27c0a53a2bbb4..c0454d977119b28115b7698a2c4287f0f56efa55 100644
--- a/src/main/java/org/bukkit/WorldCreator.java
+++ b/src/main/java/org/bukkit/WorldCreator.java
@@ -11,6 +11,7 @@ import org.jetbrains.annotations.Nullable;
* Represents various types of options that may be used to create a world.
*/
public class WorldCreator {
+ private final NamespacedKey key; // Paper
private final String name;
private long seed;
private World.Environment environment = World.Environment.NORMAL;
@@ -26,13 +27,67 @@ public class WorldCreator {
* @param name Name of the world that will be created
*/
public WorldCreator(@NotNull String name) {
- if (name == null) {
- throw new IllegalArgumentException("World name cannot be null");
- }
+ // Paper start
+ this(name, NamespacedKey.minecraft(name.toLowerCase(java.util.Locale.ENGLISH).replace(" ", "_")));
+ }
- this.name = name;
+ /**
+ * Creates an empty WorldCreator for the given world name and key
+ *
+ * @param levelName LevelName of the world that will be created
+ * @param worldKey NamespacedKey of the world that will be created
+ */
+ public WorldCreator(@NotNull String levelName, @NotNull NamespacedKey worldKey) {
+ if (levelName == null || worldKey == null) {
+ throw new IllegalArgumentException("World name and key cannot be null");
+ }
+ this.name = levelName;
this.seed = (new Random()).nextLong();
+ this.key = worldKey;
+ }
+
+ /**
+ * Creates an empty WorldCreator for the given key.
+ * LevelName will be the Key part of the NamespacedKey.
+ *
+ * @param worldKey NamespacedKey of the world that will be created
+ */
+ public WorldCreator(@NotNull NamespacedKey worldKey) {
+ this(worldKey.getKey(), worldKey);
+ }
+
+ /**
+ * Gets the key for this WorldCreator
+ *
+ * @return the key
+ */
+ @NotNull
+ public NamespacedKey key() {
+ return key;
+ }
+
+ /**
+ * Creates an empty WorldCreator for the given world name and key
+ *
+ * @param levelName LevelName of the world that will be created
+ * @param worldKey NamespacedKey of the world that will be created
+ */
+ @NotNull
+ public static WorldCreator ofNameAndKey(@NotNull String levelName, @NotNull NamespacedKey worldKey) {
+ return new WorldCreator(levelName, worldKey);
+ }
+
+ /**
+ * Creates an empty WorldCreator for the given key.
+ * LevelName will be the Key part of the NamespacedKey.
+ *
+ * @param worldKey NamespacedKey of the world that will be created
+ */
+ @NotNull
+ public static WorldCreator ofKey(@NotNull NamespacedKey worldKey) {
+ return new WorldCreator(worldKey);
}
+ // Paper end
/**
* Copies the options from the specified world