mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-30 04:02:50 +01:00
71c84c8132
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: 9a80d38c SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-722: Add EntityRemoveEvent 258086d9 SPIGOT-7417, PR-967: Add Sign#getTargetSide and Sign#getAllowedEditor ffaba051 SPIGOT-7584: Add missing Tag.ITEMS_NON_FLAMMABLE_WOOD CraftBukkit Changes: 98b6c1ac7 SPIGOT-7589 Fix NullPointerException when bans expire a2736ddb0 SPIGOT-336, SPIGOT-3366, SPIGOT-5768, SPIGOT-6409, SPIGOT-6861, PR-1008: Add EntityRemoveEvent 5bf12cb89 SPIGOT-7565: Throw a more descriptive error message when a developer tries to spawn an entity from a CraftBukkit class 76d95fe7e SPIGOT-7417, PR-1343: Add Sign#getTargetSide and Sign#getAllowedEditor Spigot Changes: e9ec5485 Rebuild patches f1b62e0c Rebuild patches
122 lines
7.1 KiB
Diff
122 lines
7.1 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 c5614cc12789fdfad3519434e115a50c12844b3b..d0e158235915e4efc8bda99d552d029cd8680035 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -195,7 +195,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");
|
|
@@ -203,15 +203,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);
|
|
@@ -220,6 +247,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;
|
|
}
|
|
@@ -227,6 +255,10 @@ public abstract class PlayerList {
|
|
// Paper start - Entity#getEntitySpawnReason
|
|
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 - reset to main world spawn if first spawn or invalid world
|
|
player.fudgeSpawnLocation(worldserver1); // Paper - Don't move existing players to world spawn
|
|
}
|
|
// Paper end - Entity#getEntitySpawnReason
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index c113175f392710d2032f03a08e0243a02efe0709..97dd8b932426496694b50984b1dcff390711e4c9 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -2286,27 +2286,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");
|