Paper/patches/server/0343-Fire-PlayerJoinEvent-when-Player-is-actually-ready.patch

106 lines
6.4 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-08-31 20:29:50 +02:00
index 8206ec366b429858d9582e437781191e5aa0fa02..d91279f3bd009e1542e73354aadd6a16c80965e2 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
@@ -1248,6 +1248,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-08-31 20:29:50 +02:00
index 8938f90c53de8aef71aa70522a66a69edb467e73..e6e7dc17d1196a8211a565355f34b5dcfd478852 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
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11102) 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: 3a3bea52 SPIGOT-7829: Increase maximum outgoing plugin message size to match Vanilla intention 5cd1c8cb SPIGOT-7831: Add CreatureSpawnEvent.SpawnReason#POTION_EFFECT a8e278f0 SPIGOT-7827: Sync EntityPortalEvent with PlayerPortalEvent since non-players can now create portals 53729d12 Remove spurious ApiStatus.Internal annotation b9f57486 SPIGOT-7799, PR-1039: Expose explosion world interaction in EntityExplodeEvent and BlockExplodeEvent 7983b966 PR-1029: Trial changing a small number of inner enums to classes/interfaces to better support custom values CraftBukkit Changes: 403accd56 SPIGOT-7831: Add CreatureSpawnEvent.SpawnReason#POTION_EFFECT 812761660 Increase outdated build delay bed1e3ff6 SPIGOT-7827: Sync EntityPortalEvent with PlayerPortalEvent since non-players can now create portals 2444c8b23 SPIGOT-7823: Suspicious sand and gravel material are not marked as having gravity correctly aceddcd0b SPIGOT-7820: Enum changes - duplicate method name a0d2d6a84 SPIGOT-7813: Material#isInteractable() always returns false 8fd64b091 SPIGOT-7806: Handle both loot and inventory item drop behaviour in PlayerDeathEvent a4ee40b74 SPIGOT-7799, PR-1436: Expose explosion world interaction in EntityExplodeEvent and BlockExplodeEvent 082aa51c5 PR-1424: Trial changing a small number of inner enums to classes/interfaces to better support custom values 66e78a96b SPIGOT-7815: Consider EntityDamageEvent status for Wolf armor damage Spigot Changes: 5bbef5ad SPIGOT-7834: Modify max value for generic.max_absorption
2024-07-18 10:13:20 +02:00
@@ -289,6 +289,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-08-31 20:29:50 +02:00
index d29885aabcead3d410329ba3056a48bb29ff75cf..9da65c0d3e8398d018da28a8668481aaf9ded472 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-04-24 08:05:14 +02:00
@@ -297,6 +297,12 @@ 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-04-24 08:05:14 +02:00
+ this.mountSavedVehicle(player, worldserver1, 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-04-24 08:05:14 +02:00
@@ -335,6 +341,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-06-13 22:14:13 +02:00
@@ -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
2024-04-24 08:05:14 +02:00
+ this.onPlayerJoinFinish(player, worldserver1, s1);
2021-06-11 14:02:28 +02:00
+ }
2024-04-24 08:05:14 +02:00
+ private void mountSavedVehicle(ServerPlayer player, ServerLevel worldserver1, Optional<CompoundTag> optional) {
+ // Paper end - Fire PlayerJoinEvent when Player is actually ready
2024-04-24 08:05:14 +02:00
if (optional.isPresent() && ((CompoundTag) optional.get()).contains("RootVehicle", 10)) {
CompoundTag nbttagcompound = ((CompoundTag) optional.get()).getCompound("RootVehicle");
ServerLevel finalWorldServer = worldserver1; // CraftBukkit - decompile error
2024-06-13 22:14:13 +02:00
@@ -396,6 +409,10 @@ public abstract class PlayerList {
2021-06-11 14:02:28 +02:00
}
}
+ // Paper start - Fire PlayerJoinEvent when Player is actually ready
2021-06-11 14:02:28 +02:00
+ }
+ 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