PaperMC/patches/server/0339-Fire-PlayerJoinEvent-when-Player-is-actually-ready.patch

94 lines
5.5 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
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
2021-06-11 14:02:28 +02:00
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
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/level/ChunkMap.java b/src/main/java/net/minecraft/server/level/ChunkMap.java
2024-10-29 16:54:40 +01:00
index 396310a51480cf0d1ea4c0959d3f8e4ed77b99e3..0f8fc275af95750871aa6917aa12053f75c112f7 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ChunkMap.java
+++ b/src/main/java/net/minecraft/server/level/ChunkMap.java
2024-10-27 18:11:15 +01:00
@@ -1305,6 +1305,7 @@ public class ChunkMap extends ChunkStorage implements ChunkHolder.PlayerProvider
2021-06-11 14:02:28 +02:00
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
2021-06-11 14:02:28 +02:00
if (!(entity instanceof EnderDragonPart)) {
EntityType<?> entitytypes = entity.getType();
int i = entitytypes.clientTrackingRange() * 16;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2024-10-23 16:04:01 +02:00
index 9911e231ad021286f2da90057b06874f7b4e3b4d..807068fc6065f71961d34cb4f18b6eb39ae49637 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2024-10-23 16:04:01 +02:00
@@ -317,6 +317,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
2021-06-11 14:02:28 +02:00
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
2021-06-11 14:02:28 +02:00
// CraftBukkit end
2023-09-22 05:29:51 +02:00
public boolean isRealPlayer; // Paper
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
2024-10-27 18:11:15 +01:00
index ad4f5a4e00b9b517841acd0b4ff5088e45451bf4..4ff14dc6996634b0fcd365f76055023601ad2be0 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
2024-10-27 18:11:15 +01:00
@@ -299,6 +299,13 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
this.playersByUUID.put(player.getUUID(), player);
2022-12-07 21:16:54 +01:00
// this.broadcastAll(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(entityplayer))); // CraftBukkit - replaced with loop below
2021-06-11 14:02:28 +02:00
+ // 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
2021-06-11 14:02:28 +02:00
+ player.supressTrackerForLogin = true;
+ worldserver1.addNewPlayer(player);
+ this.server.getCustomBossEvents().onPlayerConnect(player); // see commented out section below worldserver.addPlayerJoin(entityplayer);
2024-10-23 16:04:01 +02:00
+ player.loadAndSpawnEnderpearls(optional);
+ player.loadAndSpawnParentVehicle(optional);
+ // Paper end - Fire PlayerJoinEvent when Player is actually ready
2021-06-11 14:02:28 +02:00
// CraftBukkit start
CraftPlayer bukkitPlayer = player.getBukkitEntity();
2024-10-27 18:11:15 +01:00
@@ -337,6 +344,8 @@ public abstract class PlayerList {
2022-12-07 21:16:54 +01:00
player.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(entityplayer1)));
2021-06-11 14:02:28 +02:00
}
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
2021-06-11 14:02:28 +02:00
// CraftBukkit end
2024-04-24 08:05:14 +02:00
player.refreshEntityData(player); // CraftBukkit - BungeeCord#2321, send complete data to self on spawn
2024-10-27 18:11:15 +01:00
@@ -352,8 +361,7 @@ public abstract class PlayerList {
2024-06-13 22:14:13 +02:00
worldserver1 = player.serverLevel(); // CraftBukkit - Update in case join event changed it
// CraftBukkit end
this.sendActivePlayerEffects(player);
2024-10-23 16:04:01 +02:00
- player.loadAndSpawnEnderpearls(optional);
- player.loadAndSpawnParentVehicle(optional);
+ // Paper - move loading pearls / parent vehicle up
player.initInventoryMenu();
// CraftBukkit - Moved from above, added world
// Paper start - Configurable player collision; Add to collideRule team if needed