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-09-15 21:39:53 +02:00
index e4fab101b2d10759b9bd65d35715e377236a5989..99ff052c1935b9eba5fc519ae18c335893595337 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-07-18 10:13:20 +02:00
@@ -1181,9 +1181,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-07-18 10:13:20 +02:00
@@ -1309,7 +1315,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-07-18 10:13:20 +02:00
@@ -1405,6 +1411,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-08-19 11:41:55 +02:00
index 481aeb922952578ea68ce2425c84e1a93eff0cf9..b075d4b21b53a3f39094444e4024556b23e399f2 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-07-19 13:08:08 +02:00
@@ -516,6 +516,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