Paper/patches/server/0375-Move-player-to-spawn-point-if-spawn-in-unloaded-worl.patch
Jake Potrebic de04cbced5
Updated Upstream (Bukkit/CraftBukkit) (#10034)
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:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries

CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion

Spigot Changes:
06d602e7 Rebuild patches
2023-12-16 18:09:28 -08:00

123 lines
7.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: 2277 <38501234+2277@users.noreply.github.com>
Date: Tue, 31 Mar 2020 10:33:55 +0100
Subject: [PATCH] Move player to spawn point if spawn in unloaded world
If the playerdata contains an invalid world (missing, unloaded, invalid,
etc.), spawn the player at the spawn point of the main world.
Co-authored-by: Wyatt Childers <wchilders@nearce.com>
Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
index 3986d49b0e3405248913a685c44b27d091c4152e..6d61e70d1d5ad5bce6432f91d3b23c1734ad629c 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -194,7 +194,7 @@ public abstract class PlayerList {
}
CompoundTag nbttagcompound = this.load(player);
- ResourceKey resourcekey;
+ ResourceKey<Level> resourcekey = null; // Paper
// CraftBukkit start - Better rename detection
if (nbttagcompound != null && nbttagcompound.contains("bukkit")) {
CompoundTag bukkit = nbttagcompound.getCompound("bukkit");
@@ -202,15 +202,42 @@ public abstract class PlayerList {
}
// CraftBukkit end
+ // Paper start - move logic in Entity to here, to use bukkit supplied world UUID & reset to main world spawn if no valid world is found
+ boolean invalidPlayerWorld = false;
+ bukkitData: if (nbttagcompound != null) {
+ // The main way for bukkit worlds to store the world is the world UUID despite mojang adding custom worlds
+ final org.bukkit.World bWorld;
+ if (nbttagcompound.contains("WorldUUIDMost") && nbttagcompound.contains("WorldUUIDLeast")) {
+ bWorld = org.bukkit.Bukkit.getServer().getWorld(new UUID(nbttagcompound.getLong("WorldUUIDMost"), nbttagcompound.getLong("WorldUUIDLeast")));
+ } else if (nbttagcompound.contains("world", net.minecraft.nbt.Tag.TAG_STRING)) { // Paper - legacy bukkit world name
+ bWorld = org.bukkit.Bukkit.getServer().getWorld(nbttagcompound.getString("world"));
+ } else {
+ break bukkitData; // if neither of the bukkit data points exist, proceed to the vanilla migration section
+ }
+ if (bWorld != null) {
+ resourcekey = ((CraftWorld) bWorld).getHandle().dimension();
+ } else {
+ resourcekey = Level.OVERWORLD;
+ invalidPlayerWorld = true;
+ }
+ }
+ if (resourcekey == null) { // only run the vanilla logic if we haven't found a world from the bukkit data
+ // Below is the vanilla way of getting the dimension, this is for migration from vanilla servers
+ // Paper end
if (nbttagcompound != null) {
DataResult<ResourceKey<Level>> dataresult = DimensionType.parseLegacy(new Dynamic(NbtOps.INSTANCE, nbttagcompound.get("Dimension"))); // CraftBukkit - decompile error
Logger logger = PlayerList.LOGGER;
Objects.requireNonNull(logger);
- resourcekey = (ResourceKey) dataresult.resultOrPartial(logger::error).orElse(player.serverLevel().dimension()); // CraftBukkit - SPIGOT-7507: If no dimension, fall back to existing dimension loaded from "WorldUUID", which in turn defaults to World.OVERWORLD
+ // Paper start - reset to main world spawn if no valid world is found
+ final Optional<ResourceKey<Level>> result = dataresult.resultOrPartial(logger::error);
+ invalidPlayerWorld = result.isEmpty();
+ resourcekey = result.orElse(Level.OVERWORLD);
+ // Paper end
} else {
- resourcekey = player.serverLevel().dimension(); // CraftBukkit - SPIGOT-7507: If no dimension, fall back to existing dimension loaded from "WorldUUID", which in turn defaults to World.OVERWORLD
+ resourcekey = Level.OVERWORLD; // Paper - revert to vanilla default main world, this isn't an "invalid world" since no player data existed
}
+ } // Paper
ResourceKey<Level> resourcekey1 = resourcekey;
ServerLevel worldserver = this.server.getLevel(resourcekey1);
@@ -219,6 +246,7 @@ public abstract class PlayerList {
if (worldserver == null) {
PlayerList.LOGGER.warn("Unknown respawn dimension {}, defaulting to overworld", resourcekey1);
worldserver1 = this.server.overworld();
+ invalidPlayerWorld = true; // Paper - reset to main world if no world with parsed value is found
} else {
worldserver1 = worldserver;
}
@@ -226,6 +254,10 @@ public abstract class PlayerList {
// Paper start
if (nbttagcompound == null) {
player.spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT; // set Player SpawnReason to DEFAULT on first login
+ // Paper start - reset to main world spawn if first spawn or invalid world
+ }
+ if (nbttagcompound == null || invalidPlayerWorld) {
+ // Paper end
player.fudgeSpawnLocation(worldserver1); // only move to spawn on first login, otherwise, stay where you are....
}
// Paper end
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 2e45aef27d9a9f224779357c649df796ddc16b8e..88aa0ef38590c291d02b930e86d7e9f8e8958422 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2335,27 +2335,8 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
}
// CraftBukkit end
- // CraftBukkit start - Reset world
- if (this instanceof ServerPlayer) {
- Server server = Bukkit.getServer();
- org.bukkit.World bworld = null;
-
- // TODO: Remove World related checks, replaced with WorldUID
- String worldName = nbt.getString("world");
-
- if (nbt.contains("WorldUUIDMost") && nbt.contains("WorldUUIDLeast")) {
- UUID uid = new UUID(nbt.getLong("WorldUUIDMost"), nbt.getLong("WorldUUIDLeast"));
- bworld = server.getWorld(uid);
- } else {
- bworld = server.getWorld(worldName);
- }
-
- if (bworld == null) {
- bworld = ((org.bukkit.craftbukkit.CraftServer) server).getServer().getLevel(Level.OVERWORLD).getWorld();
- }
-
- ((ServerPlayer) this).setLevel(bworld == null ? null : ((CraftWorld) bworld).getHandle());
- }
+ // CraftBukkit start
+ // Paper - move world parsing/loading to PlayerList#placeNewPlayer
this.getBukkitEntity().readBukkitValues(nbt);
if (nbt.contains("Bukkit.invisible")) {
boolean bukkitInvisible = nbt.getBoolean("Bukkit.invisible");