mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-01 20:50:41 +01:00
730882fca9
Chunk system patch was refactored to take advantage of newer ConcurrentUtil's concurrent long hash table (which fixes hash collisions caused by chaining fastutil's long hash and CHM's hash) plus some other minor improvements. The chunk system was also merged with Starlight, which mostly provides a small improvement to ThreadedLevelLightEngine#checkBlock as the scheduling was rewritten.
105 lines
6.4 KiB
Diff
105 lines
6.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Sun, 19 Apr 2020 00:05:46 -0400
|
|
Subject: [PATCH] Fire PlayerJoinEvent when Player is actually ready
|
|
|
|
For years, plugin developers have had to delay many things they do
|
|
inside of the PlayerJoinEvent by 1 tick to make it actually work.
|
|
|
|
This all boiled down to 1 reason why: The event fired before the
|
|
player was fully ready and joined to the world!
|
|
|
|
Additionally, if that player logged out on a vehicle, the event
|
|
fired before the vehicle was even loaded, so that plugins had no
|
|
access to the vehicle during this event either.
|
|
|
|
This change finally fixes this issue, fully preparing the player
|
|
into the world as a fully ready entity, vehicle included.
|
|
|
|
There should be no plugins that break because of this change, but might
|
|
improve consistency with other plugins instead.
|
|
|
|
For example, if 2 plugins listens to this event, and the first one
|
|
teleported the player in the event, then the 2nd plugin actually
|
|
would be getting a valid player!
|
|
|
|
This was very non deterministic. This change will ensure every plugin
|
|
receives a deterministic result, and should no longer require 1 tick
|
|
delays anymore.
|
|
|
|
== AT ==
|
|
public net.minecraft.server.level.ChunkMap addEntity(Lnet/minecraft/world/entity/Entity;)V
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
index 1709821c73362b2ae54681ec1d59b40bfa9335b3..68a1cc5f4f7f5997dfb7d40647e3e027c23ffb14 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
|
|
@@ -1315,6 +1315,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
|
|
return;
|
|
}
|
|
// Paper end - ignore and warn about illegal addEntity calls instead of crashing server
|
|
+ if (entity instanceof ServerPlayer && ((ServerPlayer) entity).supressTrackerForLogin) return; // Paper - Fire PlayerJoinEvent when Player is actually ready; Delay adding to tracker until after list packets
|
|
if (!(entity instanceof EnderDragonPart)) {
|
|
EntityType<?> entitytypes = entity.getType();
|
|
int i = entitytypes.clientTrackingRange() * 16;
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index 8554ee1636416d9fb1aee2051e4a4d08b0c6d636..9cba3ac95318f1a4b680b541ce5d825fc5c4ad02 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -288,6 +288,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
|
|
public double maxHealthCache;
|
|
public boolean joining = true;
|
|
public boolean sentListPacket = false;
|
|
+ public boolean supressTrackerForLogin = false; // Paper - Fire PlayerJoinEvent when Player is actually ready
|
|
public String kickLeaveMessage = null; // SPIGOT-3034: Forward leave message to PlayerQuitEvent
|
|
// CraftBukkit end
|
|
public boolean isRealPlayer; // Paper
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 8b0c098c795c5a57fce96ad5d98ac8436024cda9..ed0ffff1cfc25f66e1947e40008c6c7259b17019 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -297,6 +297,12 @@ public abstract class PlayerList {
|
|
this.playersByUUID.put(player.getUUID(), player);
|
|
// this.broadcastAll(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(entityplayer))); // CraftBukkit - replaced with loop below
|
|
|
|
+ // Paper start - Fire PlayerJoinEvent when Player is actually ready; correctly register player BEFORE PlayerJoinEvent, so the entity is valid and doesn't require tick delay hacks
|
|
+ player.supressTrackerForLogin = true;
|
|
+ worldserver1.addNewPlayer(player);
|
|
+ this.server.getCustomBossEvents().onPlayerConnect(player); // see commented out section below worldserver.addPlayerJoin(entityplayer);
|
|
+ this.mountSavedVehicle(player, worldserver1, optional);
|
|
+ // Paper end - Fire PlayerJoinEvent when Player is actually ready
|
|
// CraftBukkit start
|
|
CraftPlayer bukkitPlayer = player.getBukkitEntity();
|
|
|
|
@@ -335,6 +341,8 @@ public abstract class PlayerList {
|
|
player.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(entityplayer1)));
|
|
}
|
|
player.sentListPacket = true;
|
|
+ player.supressTrackerForLogin = false; // Paper - Fire PlayerJoinEvent when Player is actually ready
|
|
+ ((ServerLevel)player.level()).getChunkSource().chunkMap.addEntity(player); // Paper - Fire PlayerJoinEvent when Player is actually ready; track entity now
|
|
// CraftBukkit end
|
|
|
|
player.refreshEntityData(player); // CraftBukkit - BungeeCord#2321, send complete data to self on spawn
|
|
@@ -350,6 +358,11 @@ public abstract class PlayerList {
|
|
worldserver1 = player.serverLevel(); // CraftBukkit - Update in case join event changed it
|
|
// CraftBukkit end
|
|
this.sendActivePlayerEffects(player);
|
|
+ // Paper start - Fire PlayerJoinEvent when Player is actually ready; move vehicle into method so it can be called above - short circuit around that code
|
|
+ this.onPlayerJoinFinish(player, worldserver1, s1);
|
|
+ }
|
|
+ private void mountSavedVehicle(ServerPlayer player, ServerLevel worldserver1, Optional<CompoundTag> optional) {
|
|
+ // Paper end - Fire PlayerJoinEvent when Player is actually ready
|
|
if (optional.isPresent() && ((CompoundTag) optional.get()).contains("RootVehicle", 10)) {
|
|
CompoundTag nbttagcompound = ((CompoundTag) optional.get()).getCompound("RootVehicle");
|
|
ServerLevel finalWorldServer = worldserver1; // CraftBukkit - decompile error
|
|
@@ -396,6 +409,10 @@ public abstract class PlayerList {
|
|
}
|
|
}
|
|
|
|
+ // Paper start - Fire PlayerJoinEvent when Player is actually ready
|
|
+ }
|
|
+ public void onPlayerJoinFinish(ServerPlayer player, ServerLevel worldserver1, String s1) {
|
|
+ // Paper end - Fire PlayerJoinEvent when Player is actually ready
|
|
player.initInventoryMenu();
|
|
// CraftBukkit - Moved from above, added world
|
|
// Paper start - Configurable player collision; Add to collideRule team if needed
|