Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
166 changes: 166 additions & 0 deletions patches/api/0384-Deprecate-world-names.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Mon, 30 May 2022 15:32:46 -0700
Subject: [PATCH] Deprecate world names


diff --git a/src/main/java/co/aikar/timings/TimingHistory.java b/src/main/java/co/aikar/timings/TimingHistory.java
index 203cda0f9a4dea4f28a21ea9ee8db7a7369842e3..e643ae6a46d9083548635315423799c70fa325f8 100644
--- a/src/main/java/co/aikar/timings/TimingHistory.java
+++ b/src/main/java/co/aikar/timings/TimingHistory.java
@@ -129,7 +129,7 @@ public class TimingHistory {
}
}
return pair(
- worldMap.get(world.getName()),
+ worldMap.get(world.getKey().toString()), // Paper
toArrayMapper(regions.values(),new Function<RegionData, Object>() {
@NotNull
@Override
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index d8666481f9a407403d0114ff02024fd3c50c27c4..0b374e3bc3397e497571f29e9c70a1aa11143127 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -794,8 +794,10 @@ public final class Bukkit {
*
* @param name the name of the world to retrieve
* @return a world with the given name, or null if none exists
+ * @deprecated use {@link #getWorld(NamespacedKey)}. In the future, worlds may have the same "name".
*/
@Nullable
+ @Deprecated(forRemoval = true) // Paper
public static World getWorld(@NotNull String name) {
return server.getWorld(name);
}
diff --git a/src/main/java/org/bukkit/ChunkSnapshot.java b/src/main/java/org/bukkit/ChunkSnapshot.java
index fb3e166ec48b8c0ebb7d541eaa1761b03a140610..9118325d085a8b721c3b73f4053bcb9a6d4c333b 100644
--- a/src/main/java/org/bukkit/ChunkSnapshot.java
+++ b/src/main/java/org/bukkit/ChunkSnapshot.java
@@ -30,10 +30,21 @@ public interface ChunkSnapshot {
* Gets name of the world containing this chunk
*
* @return Parent World Name
+ * @deprecated use {@link #getKey()}
*/
+ @Deprecated(forRemoval = true)
@NotNull
String getWorldName();

+ // Paper start
+ /**
+ * Gets the key for the world containing this chunk.
+ *
+ * @return the parent world key
+ */
+ @NotNull NamespacedKey getWorldKey();
+ // Paper end
+
/**
* Get block type for block at corresponding coordinate in the chunk
*
diff --git a/src/main/java/org/bukkit/Location.java b/src/main/java/org/bukkit/Location.java
index ef0cb00ca4cb7d2f5e4ec1c950cce036566d1ae4..68414944b611072993d8b816cd4e20b924bac295 100644
--- a/src/main/java/org/bukkit/Location.java
+++ b/src/main/java/org/bukkit/Location.java
@@ -507,7 +507,7 @@ public class Location implements Cloneable, ConfigurationSerializable {
} else if (o.getWorld() == null || getWorld() == null) {
throw new IllegalArgumentException("Cannot measure distance to a null world");
} else if (o.getWorld() != getWorld()) {
- throw new IllegalArgumentException("Cannot measure distance between " + getWorld().getName() + " and " + o.getWorld().getName());
+ throw new IllegalArgumentException("Cannot measure distance between " + getWorld().getKey() + " and " + o.getWorld().getKey()); // Paper
}

return NumberConversions.square(x - o.x) + NumberConversions.square(y - o.y) + NumberConversions.square(z - o.z);
@@ -1110,6 +1110,7 @@ public class Location implements Cloneable, ConfigurationSerializable {

if (this.world != null) {
data.put("world", getWorld().getName());
+ data.put("worldKey", getWorld().getKey().toString());
}

data.put("x", this.x);
@@ -1138,6 +1139,13 @@ public class Location implements Cloneable, ConfigurationSerializable {
if (world == null) {
throw new IllegalArgumentException("unknown world");
}
+ // Paper start
+ } else if (args.containsKey("worldKey")) {
+ final NamespacedKey key = NamespacedKey.fromString((String) args.get("worldKey"));
+ if (key != null) {
+ world = Bukkit.getWorld(key);
+ }
+ // Paper end
}

return new Location(world, NumberConversions.toDouble(args.get("x")), NumberConversions.toDouble(args.get("y")), NumberConversions.toDouble(args.get("z")), NumberConversions.toFloat(args.get("yaw")), NumberConversions.toFloat(args.get("pitch")));
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 79b26045a68ebb9b01e5bd06abbccaaef5489777..d919b7f94310689889b351b551f313656146dfd4 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -657,8 +657,10 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
*
* @param name the name of the world to retrieve
* @return a world with the given name, or null if none exists
+ * @deprecated use {@link #getWorld(NamespacedKey)}. In the future, worlds may have the same "name".
*/
@Nullable
+ @Deprecated(forRemoval = true) // Paper
public World getWorld(@NotNull String name);

/**
diff --git a/src/main/java/org/bukkit/WorldCreator.java b/src/main/java/org/bukkit/WorldCreator.java
index 355f9f27d29c65efebf099a72c37892a309edef1..bd2390a1cd11e90324f56b83b7f31f4326174f2c 100644
--- a/src/main/java/org/bukkit/WorldCreator.java
+++ b/src/main/java/org/bukkit/WorldCreator.java
@@ -28,7 +28,9 @@ public class WorldCreator {
* Creates an empty WorldCreationOptions for the given world name
*
* @param name Name of the world that will be created
+ * @deprecated use {@link #WorldCreator(NamespacedKey)}
*/
+ @Deprecated(forRemoval = true) // Paper
public WorldCreator(@NotNull String name) {
// Paper start
this(name, getWorldKey(name));
@@ -52,7 +54,9 @@ public class WorldCreator {
*
* @param levelName LevelName of the world that will be created
* @param worldKey NamespacedKey of the world that will be created
+ * @deprecated use {@link #WorldCreator(NamespacedKey)}
*/
+ @Deprecated(forRemoval = true) // Paper
public WorldCreator(@NotNull String levelName, @NotNull NamespacedKey worldKey) {
if (levelName == null || worldKey == null) {
throw new IllegalArgumentException("World name and key cannot be null");
@@ -156,7 +160,9 @@ public class WorldCreator {
* Gets the name of the world that is to be loaded or created.
*
* @return World name
+ * @deprecated use {@link #key()}
*/
+ @Deprecated(forRemoval = true) // Paper
@NotNull
public String name() {
return name;
diff --git a/src/main/java/org/bukkit/generator/WorldInfo.java b/src/main/java/org/bukkit/generator/WorldInfo.java
index 5067f1371433cccd3287af7f03e152f2c3c1ece3..56481f64e6ecbbbb16967a20116802ea63eed185 100644
--- a/src/main/java/org/bukkit/generator/WorldInfo.java
+++ b/src/main/java/org/bukkit/generator/WorldInfo.java
@@ -7,14 +7,16 @@ import org.jetbrains.annotations.NotNull;
/**
* Holds various information of a World
*/
-public interface WorldInfo {
+public interface WorldInfo extends org.bukkit.Keyed { // Paper - moved Keyed interface from World to WorldInfo

/**
* Gets the unique name of this world
*
* @return Name of this world
+ * @deprecated use {@link #getKey()} as an identifier
*/
@NotNull
+ @Deprecated(forRemoval = true) // Paper
String getName();

/**
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ index df955666723a8cb1e612311f0b8e77fb577d6be5..01aefce226ae82d707b38b0d56d2580d
biomeProvider = gen.getDefaultBiomeProvider(worldInfo);
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 2747a420f2c1ba4cf103f6340c5db671af3ade81..7dc79e7c552d7ebc2dea9248c2d5647b5a6895e0 100644
index 825a3b688099a3021ff422dd123038b6cca3e14f..168893fe1790edac8fee884b1fae4e6b7a1bd5c6 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1217,7 +1217,7 @@ public final class CraftServer implements Server {
Expand Down Expand Up @@ -67,28 +67,26 @@ index 0ebacc6f35591b3f1fc740d484f30c7c2337392a..bd24cf74dfc0974f5bc132994deac45b

private static final Random rand = new Random();
diff --git a/src/main/java/org/bukkit/craftbukkit/generator/CraftWorldInfo.java b/src/main/java/org/bukkit/craftbukkit/generator/CraftWorldInfo.java
index aeffb30cd91d4b21850059d33070c537bd5cb25e..3918c24dfb6cda4cff18016cca807c2dbc2a9156 100644
index aeffb30cd91d4b21850059d33070c537bd5cb25e..c5ae71a01c9e7c2a127ac4ddc842700298cc1299 100644
--- a/src/main/java/org/bukkit/craftbukkit/generator/CraftWorldInfo.java
+++ b/src/main/java/org/bukkit/craftbukkit/generator/CraftWorldInfo.java
@@ -17,8 +17,17 @@ public class CraftWorldInfo implements WorldInfo {
@@ -17,8 +17,14 @@ public class CraftWorldInfo implements WorldInfo {
private final long seed;
private final int minHeight;
private final int maxHeight;
+ // Paper start
+ private final net.minecraft.world.level.chunk.ChunkGenerator vanillaChunkGenerator;
+ private final net.minecraft.core.Registry<net.minecraft.world.level.biome.Biome> biomeRegistry;

public CraftWorldInfo(ServerLevelData worldDataServer, LevelStorageSource.LevelStorageAccess session, World.Environment environment, DimensionType dimensionManager) {
+ this(worldDataServer, session, environment, dimensionManager, null, null);
+ }
- public CraftWorldInfo(ServerLevelData worldDataServer, LevelStorageSource.LevelStorageAccess session, World.Environment environment, DimensionType dimensionManager) {
+ public CraftWorldInfo(ServerLevelData worldDataServer, LevelStorageSource.LevelStorageAccess session, World.Environment environment, DimensionType dimensionManager, net.minecraft.world.level.chunk.ChunkGenerator chunkGenerator, net.minecraft.core.Registry<net.minecraft.world.level.biome.Biome> biomeRegistry) {
+ this.biomeRegistry = biomeRegistry;
+ this.vanillaChunkGenerator = chunkGenerator;
+ // Paper end
this.name = worldDataServer.getLevelName();
this.uuid = WorldUUID.getUUID(session.levelPath.toFile());
this.environment = environment;
@@ -28,6 +37,10 @@ public class CraftWorldInfo implements WorldInfo {
@@ -28,6 +34,10 @@ public class CraftWorldInfo implements WorldInfo {
}

public CraftWorldInfo(String name, UUID uuid, World.Environment environment, long seed, int minHeight, int maxHeight) {
Expand All @@ -99,7 +97,7 @@ index aeffb30cd91d4b21850059d33070c537bd5cb25e..3918c24dfb6cda4cff18016cca807c2d
this.name = name;
this.uuid = uuid;
this.environment = environment;
@@ -65,4 +78,24 @@ public class CraftWorldInfo implements WorldInfo {
@@ -65,4 +75,24 @@ public class CraftWorldInfo implements WorldInfo {
public int getMaxHeight() {
return this.maxHeight;
}
Expand Down
Loading