2021-06-15 04:59:31 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Wed, 6 Jan 2021 00:34:04 -0800
2022-06-05 22:51:44 +02:00
Subject: [PATCH] Expand world key API
2021-06-15 04:59:31 +02:00
2022-06-05 22:51:44 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
2024-06-13 23:42:02 +02:00
index 1963e826548c5a8859c50f57654784c3aef50e44..04a39cb6c13c26e2cb1d73a9da98df5d04df69bc 100644
2022-06-05 22:51:44 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java
2024-06-13 23:42:02 +02:00
@@ -515,5 +515,10 @@ public abstract class CraftRegionAccessor implements RegionAccessor {
2022-06-05 22:51:44 +02:00
public io.papermc.paper.world.MoonPhase getMoonPhase() {
return io.papermc.paper.world.MoonPhase.getPhase(this.getHandle().dayTime() / 24000L);
}
+
+ @Override
+ public org.bukkit.NamespacedKey getKey() {
+ return org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(this.getHandle().getLevel().dimension().location());
+ }
// Paper end
}
2021-06-15 04:59:31 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2024-10-21 00:06:54 +02:00
index f402ef662779e096ee354b9edd66cca785b85f33..a9c6f53c7e828a4b7d0cefbaa98e50ff1db9354a 100644
2021-06-15 04:59:31 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
2024-10-21 00:06:54 +02:00
@@ -1183,9 +1183,15 @@ public final class CraftServer implements Server {
2022-05-26 19:59:53 +02:00
File folder = new File(this.getWorldContainer(), name);
World world = this.getWorld(name);
- if (world != null) {
- return world;
+ // Paper start
+ World worldByKey = this.getWorld(creator.key());
+ if (world != null || worldByKey != null) {
+ if (world == worldByKey) {
+ return world;
+ }
+ throw new IllegalArgumentException("Cannot create a world with key " + creator.key() + " and name " + name + " one (or both) already match a world that exists");
}
+ // Paper end
2023-06-13 01:51:45 +02:00
if (folder.exists()) {
Preconditions.checkArgument(folder.isDirectory(), "File (%s) exists and isn't a folder", name);
2024-10-21 00:06:54 +02:00
@@ -1311,7 +1317,7 @@ public final class CraftServer implements Server {
2021-06-15 04:59:31 +02:00
} else if (name.equals(levelName + "_the_end")) {
worldKey = net.minecraft.world.level.Level.END;
} else {
2024-06-13 23:42:02 +02:00
- worldKey = ResourceKey.create(Registries.DIMENSION, ResourceLocation.withDefaultNamespace(name.toLowerCase(Locale.ROOT)));
+ worldKey = ResourceKey.create(Registries.DIMENSION, ResourceLocation.fromNamespaceAndPath(creator.key().namespace(), creator.key().value()));
2021-06-15 04:59:31 +02:00
}
2024-04-24 15:46:45 +02:00
// If set to not keep spawn in memory (changed from default) then adjust rule accordingly
2024-10-21 00:06:54 +02:00
@@ -1407,6 +1413,15 @@ public final class CraftServer implements Server {
2021-06-15 04:59:31 +02:00
return null;
}
+ // Paper start
+ @Override
2024-08-19 11:41:55 +02:00
+ public World getWorld(net.kyori.adventure.key.Key worldKey) {
+ ServerLevel worldServer = console.getLevel(ResourceKey.create(net.minecraft.core.registries.Registries.DIMENSION, io.papermc.paper.adventure.PaperAdventure.asVanilla(worldKey)));
2021-06-15 04:59:31 +02:00
+ if (worldServer == null) return null;
+ return worldServer.getWorld();
+ }
+ // Paper end
+
public void addWorld(World world) {
// Check if a World already exists with the UID.
if (this.getWorld(world.getUID()) != null) {
2022-05-27 17:42:36 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
2024-10-21 00:06:54 +02:00
index 66249c5caefb0879e13c02d5553b09b4122418b9..79915a93b36ddf2925444369a5df4e8f4fd5610e 100644
2022-05-27 17:42:36 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
2024-10-21 00:06:54 +02:00
@@ -522,6 +522,11 @@ public final class CraftMagicNumbers implements UnsafeValues {
2023-02-28 17:36:01 +01:00
public int nextEntityId() {
return net.minecraft.world.entity.Entity.nextEntityId();
2022-05-27 17:42:36 +02:00
}
+
+ @Override
+ public String getMainLevelName() {
+ return ((net.minecraft.server.dedicated.DedicatedServer) net.minecraft.server.MinecraftServer.getServer()).getProperties().levelName;
+ }
// Paper end
2024-05-11 23:48:37 +02:00
@Override