From f0b4d5aa22672b95aedfaa401c38c5092d111f7c Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Fri, 27 May 2022 08:42:36 -0700 Subject: [PATCH] Fix cb's janky level name in WorldCreator (#7851) --- .../api/Add-methods-to-get-world-by-key.patch | 31 +++++++++++++++++-- patches/api/Item-Rarity-API.patch | 4 +-- .../Add-methods-to-get-world-by-key.patch | 16 ++++++++++ patches/server/Item-Rarity-API.patch | 4 +-- 4 files changed, 49 insertions(+), 6 deletions(-) diff --git a/patches/api/Add-methods-to-get-world-by-key.patch b/patches/api/Add-methods-to-get-world-by-key.patch index 369e91ed1d..6efd82d614 100644 --- a/patches/api/Add-methods-to-get-world-by-key.patch +++ b/patches/api/Add-methods-to-get-world-by-key.patch @@ -49,6 +49,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 /** * Create a new virtual {@link WorldBorder}. *

+diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/UnsafeValues.java ++++ b/src/main/java/org/bukkit/UnsafeValues.java +@@ -0,0 +0,0 @@ public interface UnsafeValues { + * @throws IllegalArgumentException if there isn't a registry for that type + */ + @org.jetbrains.annotations.NotNull Registry registryFor(Class classOfT); ++ ++ /** ++ * Just don't use it. ++ */ ++ @org.jetbrains.annotations.NotNull String getMainLevelName(); + // Paper end + } diff --git a/src/main/java/org/bukkit/WorldCreator.java b/src/main/java/org/bukkit/WorldCreator.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/WorldCreator.java @@ -67,9 +82,21 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 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, getWorldKey(name)); ++ } ++ ++ private static NamespacedKey getWorldKey(String name) { ++ final String mainLevelName = Bukkit.getUnsafe().getMainLevelName(); ++ if (name.equals(mainLevelName)) { ++ return NamespacedKey.minecraft("overworld"); ++ } else if (name.equals(mainLevelName + "_nether")) { ++ return NamespacedKey.minecraft("the_nether"); ++ } else if (name.equals(mainLevelName + "_the_end")) { ++ return NamespacedKey.minecraft("the_end"); ++ } else { ++ return NamespacedKey.minecraft(name.toLowerCase(java.util.Locale.ENGLISH).replace(" ", "_")); + } + } - this.name = name; diff --git a/patches/api/Item-Rarity-API.patch b/patches/api/Item-Rarity-API.patch index fa67b39d2b..808d3aa2c0 100644 --- a/patches/api/Item-Rarity-API.patch +++ b/patches/api/Item-Rarity-API.patch @@ -65,9 +65,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/org/bukkit/UnsafeValues.java +++ b/src/main/java/org/bukkit/UnsafeValues.java @@ -0,0 +0,0 @@ public interface UnsafeValues { - * @throws IllegalArgumentException if there isn't a registry for that type + * Just don't use it. */ - @org.jetbrains.annotations.NotNull Registry registryFor(Class classOfT); + @org.jetbrains.annotations.NotNull String getMainLevelName(); + + /** + * Gets the item rarity of a material. The material MUST be an item. diff --git a/patches/server/Add-methods-to-get-world-by-key.patch b/patches/server/Add-methods-to-get-world-by-key.patch index fa8ddb0e3b..85e91fcea1 100644 --- a/patches/server/Add-methods-to-get-world-by-key.patch +++ b/patches/server/Add-methods-to-get-world-by-key.patch @@ -51,3 +51,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 public void addWorld(World world) { // Check if a World already exists with the UID. if (this.getWorld(world.getUID()) != null) { +diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java ++++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +@@ -0,0 +0,0 @@ public final class CraftMagicNumbers implements UnsafeValues { + public Registry registryFor(Class classOfT) { + return io.papermc.paper.registry.PaperRegistry.getRegistry(classOfT); + } ++ ++ @Override ++ public String getMainLevelName() { ++ return ((net.minecraft.server.dedicated.DedicatedServer) net.minecraft.server.MinecraftServer.getServer()).getProperties().levelName; ++ } + // Paper end + + /** diff --git a/patches/server/Item-Rarity-API.patch b/patches/server/Item-Rarity-API.patch index 2e7b9ac642..7e1d6190e4 100644 --- a/patches/server/Item-Rarity-API.patch +++ b/patches/server/Item-Rarity-API.patch @@ -9,8 +9,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java +++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java @@ -0,0 +0,0 @@ public final class CraftMagicNumbers implements UnsafeValues { - public Registry registryFor(Class classOfT) { - return io.papermc.paper.registry.PaperRegistry.getRegistry(classOfT); + public String getMainLevelName() { + return ((net.minecraft.server.dedicated.DedicatedServer) net.minecraft.server.MinecraftServer.getServer()).getProperties().levelName; } + + @Override