mirror of
https://github.com/PaperMC/Paper.git
synced 2024-09-12 15:08:27 +02:00
Previously, Entity Activation Range only applied to the root entity of a vehicle chain. If that vehicle is active, every entity as it's passenger would then tick. This creates scenarios where EAR does not apply your desired ranges to passengers. Additionally, any entity that was a passenger never had its inactiveTick method called when the parent was inactive, creating behavioral desyncs. This could of been a source of many villager issues when those villagers were in minecarts as players commonly do. Now we will process passengers checking their activation state independently of their vehicle and if they are inactive, call their inactiveTick() method to ensure state remains consistent. This also helps improve any desync issues with entity position of passengers too. This also removes immunity for passenger/vehicles, so it should improve performance of these minecart villagers too for EAR.
269 lines
15 KiB
Diff
269 lines
15 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Sun, 19 Apr 2020 04:28:29 -0400
|
|
Subject: [PATCH] Load Chunks for Login Asynchronously
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
index 4c4e6e154e0db23662484d6aa03f1d762a48badb..893a835593af2ea95a50607c8c2f2cdb9af6c944 100644
|
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
@@ -605,7 +605,7 @@ public class ChunkProviderServer extends IChunkProvider {
|
|
return this.serverThreadQueue.executeNext();
|
|
}
|
|
|
|
- private boolean tickDistanceManager() {
|
|
+ public boolean tickDistanceManager() { // Paper - private -> public
|
|
boolean flag = this.chunkMapDistance.a(this.playerChunkMap);
|
|
boolean flag1 = this.playerChunkMap.b();
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
|
index 19749ae61a3b71f92e64f472bc1575bdcbd1c086..a1da42cb757cec0114e1c4f435e342291c9143d8 100644
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
|
@@ -1281,7 +1281,7 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
|
this.lastY = d1;
|
|
this.lastZ = d4;
|
|
this.setPosition(d3, d1, d4);
|
|
- world.getChunkAt((int) Math.floor(this.locX()) >> 4, (int) Math.floor(this.locZ()) >> 4); // CraftBukkit
|
|
+ if (valid) world.getChunkAt((int) Math.floor(this.locX()) >> 4, (int) Math.floor(this.locZ()) >> 4); // CraftBukkit // Paper
|
|
}
|
|
|
|
public void d(Vec3D vec3d) {
|
|
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
index 8b0037594df8d76c98c2285f5a63662aef4e3202..6db4d587c69af406d949c3d1ed73724a5bd2889d 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
@@ -44,6 +44,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
|
public PlayerConnection playerConnection;
|
|
+ public NetworkManager networkManager; // Paper
|
|
public final MinecraftServer server;
|
|
public final PlayerInteractManager playerInteractManager;
|
|
public final Deque<Integer> removeQueue = new ArrayDeque<>(); // Paper
|
|
@@ -107,6 +108,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
public boolean joining = true;
|
|
public boolean sentListPacket = false;
|
|
public boolean supressTrackerForLogin = false; // Paper
|
|
+ public boolean didPlayerJoinEvent = false; // Paper
|
|
public Integer clientViewDistance;
|
|
// CraftBukkit end
|
|
public PlayerNaturallySpawnCreaturesEvent playerNaturallySpawnedEvent; // Paper
|
|
diff --git a/src/main/java/net/minecraft/server/LoginListener.java b/src/main/java/net/minecraft/server/LoginListener.java
|
|
index 0cb8f5a4a5cc5e302815af4c1ed325dfbc75235b..456cb9feebc8afef50cefb85b4d4c1dacd880ad2 100644
|
|
--- a/src/main/java/net/minecraft/server/LoginListener.java
|
|
+++ b/src/main/java/net/minecraft/server/LoginListener.java
|
|
@@ -66,7 +66,7 @@ public class LoginListener implements PacketLoginInListener {
|
|
}
|
|
// Paper end
|
|
} else if (this.g == LoginListener.EnumProtocolState.DELAY_ACCEPT) {
|
|
- EntityPlayer entityplayer = this.server.getPlayerList().getPlayer(this.i.getId());
|
|
+ EntityPlayer entityplayer = this.server.getPlayerList().getActivePlayer(this.i.getId()); // Paper
|
|
|
|
if (entityplayer == null) {
|
|
this.g = LoginListener.EnumProtocolState.READY_TO_ACCEPT;
|
|
@@ -165,7 +165,7 @@ public class LoginListener implements PacketLoginInListener {
|
|
}
|
|
|
|
this.networkManager.sendPacket(new PacketLoginOutSuccess(this.i));
|
|
- EntityPlayer entityplayer = this.server.getPlayerList().getPlayer(this.i.getId());
|
|
+ EntityPlayer entityplayer = this.server.getPlayerList().getActivePlayer(this.i.getId()); // Paper
|
|
|
|
if (entityplayer != null) {
|
|
this.g = LoginListener.EnumProtocolState.DELAY_ACCEPT;
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
index 0a08705bebce75888806ecd35b53de4397ae0bac..c7d88d9c190f0604189e6bfabc0250453b1a68c9 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
|
|
@@ -70,6 +70,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
private static final Logger LOGGER = LogManager.getLogger();
|
|
public final NetworkManager networkManager;
|
|
private final MinecraftServer minecraftServer;
|
|
+ Runnable playerJoinReady; // Paper
|
|
public EntityPlayer player;
|
|
private int e;
|
|
private long lastKeepAlive = SystemUtils.getMonotonicMillis(); private void setLastPing(long lastPing) { this.lastKeepAlive = lastPing;}; private long getLastPing() { return this.lastKeepAlive;}; // Paper - OBFHELPER
|
|
@@ -143,6 +144,15 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
// CraftBukkit end
|
|
|
|
public void tick() {
|
|
+ // Paper start - login async
|
|
+ Runnable playerJoinReady = this.playerJoinReady;
|
|
+ if (playerJoinReady != null) {
|
|
+ this.playerJoinReady = null;
|
|
+ playerJoinReady.run();
|
|
+ }
|
|
+ // Don't tick if not valid (dead), otherwise we load chunks below
|
|
+ if (this.player.valid) {
|
|
+ // Paper end
|
|
this.syncPosition();
|
|
this.player.lastX = this.player.locX();
|
|
this.player.lastY = this.player.locY();
|
|
@@ -184,7 +194,7 @@ public class PlayerConnection implements PacketListenerPlayIn {
|
|
this.r = null;
|
|
this.D = false;
|
|
this.E = 0;
|
|
- }
|
|
+ }} // Paper - end if (valid)
|
|
|
|
this.minecraftServer.getMethodProfiler().enter("keepAlive");
|
|
// Paper Start - give clients a longer time to respond to pings as per pre 1.12.2 timings
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
|
|
index 4995fa3fda87dfb47c8050e57ca29a895b809482..40f2984e5ba7627ef4ce87133bed5df51a68fd65 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
|
@@ -54,11 +54,12 @@ public abstract class PlayerList {
|
|
private static final SimpleDateFormat g = new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
|
|
private final MinecraftServer server;
|
|
public final List<EntityPlayer> players = new java.util.concurrent.CopyOnWriteArrayList(); // CraftBukkit - ArrayList -> CopyOnWriteArrayList: Iterator safety
|
|
- private final Map<UUID, EntityPlayer> j = Maps.newHashMap();
|
|
+ private final Map<UUID, EntityPlayer> j = Maps.newHashMap();Map<UUID, EntityPlayer> getUUIDMap() { return j; } // Paper - OBFHELPER
|
|
private final GameProfileBanList k;
|
|
private final IpBanList l;
|
|
private final OpList operators;
|
|
private final WhiteList whitelist;
|
|
+ private final Map<UUID, EntityPlayer> pendingPlayers = Maps.newHashMap(); // Paper
|
|
// CraftBukkit start
|
|
// private final Map<UUID, ServerStatisticManager> o;
|
|
// private final Map<UUID, AdvancementDataPlayer> p;
|
|
@@ -97,6 +98,11 @@ public abstract class PlayerList {
|
|
}
|
|
|
|
public void a(NetworkManager networkmanager, EntityPlayer entityplayer) {
|
|
+ EntityPlayer prev = pendingPlayers.put(entityplayer.getUniqueID(), entityplayer);// Paper
|
|
+ if (prev != null) {
|
|
+ disconnectPendingPlayer(prev);
|
|
+ }
|
|
+ entityplayer.networkManager = networkmanager; // Paper
|
|
entityplayer.loginTime = System.currentTimeMillis(); // Paper
|
|
GameProfile gameprofile = entityplayer.getProfile();
|
|
UserCache usercache = this.server.getUserCache();
|
|
@@ -110,7 +116,7 @@ public abstract class PlayerList {
|
|
if (nbttagcompound != null && nbttagcompound.hasKey("bukkit")) {
|
|
NBTTagCompound bukkit = nbttagcompound.getCompound("bukkit");
|
|
s = bukkit.hasKeyOfType("lastKnownName", 8) ? bukkit.getString("lastKnownName") : s;
|
|
- }
|
|
+ }String lastKnownName = s; // Paper
|
|
// CraftBukkit end
|
|
|
|
if (nbttagcompound != null) {
|
|
@@ -183,6 +189,51 @@ public abstract class PlayerList {
|
|
entityplayer.getRecipeBook().a(entityplayer);
|
|
this.sendScoreboard(worldserver1.getScoreboard(), entityplayer);
|
|
this.server.invalidatePingSample();
|
|
+ // Paper start - async load spawn in chunk
|
|
+ WorldServer finalWorldserver = worldserver1;
|
|
+ int chunkX = loc.getBlockX() >> 4;
|
|
+ int chunkZ = loc.getBlockZ() >> 4;
|
|
+ final ChunkCoordIntPair pos = new ChunkCoordIntPair(chunkX, chunkZ);
|
|
+ PlayerChunkMap playerChunkMap = worldserver1.getChunkProvider().playerChunkMap;
|
|
+ playerChunkMap.chunkDistanceManager.addTicketAtLevel(TicketType.LOGIN, pos, 31, pos.pair());
|
|
+ worldserver1.getChunkProvider().tickDistanceManager();
|
|
+ worldserver1.getChunkProvider().getChunkAtAsynchronously(chunkX, chunkZ, true, true).thenApply(chunk -> {
|
|
+ PlayerChunk updatingChunk = playerChunkMap.getUpdatingChunk(pos.pair());
|
|
+ if (updatingChunk != null) {
|
|
+ return updatingChunk.getEntityTickingFuture();
|
|
+ } else {
|
|
+ return java.util.concurrent.CompletableFuture.completedFuture(chunk);
|
|
+ }
|
|
+ }).thenAccept(chunk -> {
|
|
+ playerconnection.playerJoinReady = () -> {
|
|
+ postChunkLoadJoin(
|
|
+ entityplayer, finalWorldserver, networkmanager, playerconnection,
|
|
+ nbttagcompound, networkmanager.getSocketAddress().toString(), lastKnownName
|
|
+ );
|
|
+ };
|
|
+ });
|
|
+ }
|
|
+
|
|
+ EntityPlayer getActivePlayer(UUID uuid) {
|
|
+ EntityPlayer player = this.getUUIDMap().get(uuid);
|
|
+ return player != null ? player : pendingPlayers.get(uuid);
|
|
+ }
|
|
+
|
|
+ void disconnectPendingPlayer(EntityPlayer entityplayer) {
|
|
+ ChatMessage msg = new ChatMessage("multiplayer.disconnect.duplicate_login", new Object[0]);
|
|
+ entityplayer.networkManager.sendPacket(new PacketPlayOutKickDisconnect(msg), (future) -> {
|
|
+ entityplayer.networkManager.close(msg);
|
|
+ entityplayer.networkManager = null;
|
|
+ });
|
|
+ }
|
|
+
|
|
+ private void postChunkLoadJoin(EntityPlayer entityplayer, WorldServer worldserver1, NetworkManager networkmanager, PlayerConnection playerconnection, NBTTagCompound nbttagcompound, String s1, String s) {
|
|
+ pendingPlayers.remove(entityplayer.getUniqueID(), entityplayer);
|
|
+ if (!networkmanager.isConnected()) {
|
|
+ return;
|
|
+ }
|
|
+ entityplayer.didPlayerJoinEvent = true;
|
|
+ // Paper end
|
|
ChatMessage chatmessage;
|
|
|
|
if (entityplayer.getProfile().getName().equalsIgnoreCase(s)) {
|
|
@@ -419,6 +470,7 @@ public abstract class PlayerList {
|
|
|
|
protected void savePlayerFile(EntityPlayer entityplayer) {
|
|
if (!entityplayer.getBukkitEntity().isPersistent()) return; // CraftBukkit
|
|
+ if (!entityplayer.didPlayerJoinEvent) return; // Paper - If we never fired PJE, we disconnected during login. Data has not changed, and additionally, our saved vehicle is not loaded! If we save now, we will lose our vehicle (CraftBukkit bug)
|
|
this.playerFileData.save(entityplayer);
|
|
ServerStatisticManager serverstatisticmanager = (ServerStatisticManager) entityplayer.getStatisticManager(); // CraftBukkit
|
|
|
|
@@ -443,7 +495,7 @@ public abstract class PlayerList {
|
|
entityplayer.closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.DISCONNECT); // Paper
|
|
|
|
PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(cserver.getPlayer(entityplayer), "\u00A7e" + entityplayer.getName() + " left the game");
|
|
- cserver.getPluginManager().callEvent(playerQuitEvent);
|
|
+ if (entityplayer.didPlayerJoinEvent) cserver.getPluginManager().callEvent(playerQuitEvent); // Paper - if we disconnected before join ever fired, don't fire quit
|
|
entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());
|
|
|
|
if (server.isMainThread()) entityplayer.playerTick(); // SPIGOT-924 // Paper - don't tick during emergency shutdowns (Watchdog)
|
|
@@ -496,6 +548,13 @@ public abstract class PlayerList {
|
|
// this.p.remove(uuid);
|
|
// CraftBukkit end
|
|
}
|
|
+ // Paper start
|
|
+ entityplayer1 = pendingPlayers.get(uuid);
|
|
+ if (entityplayer1 == entityplayer) {
|
|
+ pendingPlayers.remove(uuid);
|
|
+ }
|
|
+ entityplayer.networkManager = null;
|
|
+ // Paper end
|
|
|
|
// CraftBukkit start
|
|
// this.sendAll(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.REMOVE_PLAYER, new EntityPlayer[]{entityplayer}));
|
|
@@ -513,7 +572,7 @@ public abstract class PlayerList {
|
|
cserver.getScoreboardManager().removePlayer(entityplayer.getBukkitEntity());
|
|
// CraftBukkit end
|
|
|
|
- return playerQuitEvent.getQuitMessage(); // CraftBukkit
|
|
+ return entityplayer.didPlayerJoinEvent ? playerQuitEvent.getQuitMessage() : null; // CraftBukkit // Paper - don't print quit if we never printed join
|
|
}
|
|
|
|
// CraftBukkit start - Whole method, SocketAddress to LoginListener, added hostname to signature, return EntityPlayer
|
|
@@ -532,6 +591,13 @@ public abstract class PlayerList {
|
|
list.add(entityplayer);
|
|
}
|
|
}
|
|
+ // Paper start - check pending players too
|
|
+ entityplayer = pendingPlayers.get(uuid);
|
|
+ if (entityplayer != null) {
|
|
+ this.pendingPlayers.remove(uuid);
|
|
+ disconnectPendingPlayer(entityplayer);
|
|
+ }
|
|
+ // Paper end
|
|
|
|
Iterator iterator = list.iterator();
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/TicketType.java b/src/main/java/net/minecraft/server/TicketType.java
|
|
index 8055f5998213ab1c6c10d03d88d2b14d220a5e40..d7b9d9fd3a3b607278a3d72b0b306b0be2aa30ad 100644
|
|
--- a/src/main/java/net/minecraft/server/TicketType.java
|
|
+++ b/src/main/java/net/minecraft/server/TicketType.java
|
|
@@ -17,6 +17,7 @@ public class TicketType<T> {
|
|
public static final TicketType<ChunkCoordIntPair> FORCED = a("forced", Comparator.comparingLong(ChunkCoordIntPair::pair));
|
|
public static final TicketType<ChunkCoordIntPair> LIGHT = a("light", Comparator.comparingLong(ChunkCoordIntPair::pair));
|
|
public static final TicketType<BlockPosition> PORTAL = a("portal", BaseBlockPosition::compareTo, 300);
|
|
+ public static final TicketType<Long> LOGIN = a("login", Long::compareTo, 100); // Paper
|
|
public static final TicketType<Integer> POST_TELEPORT = a("post_teleport", Integer::compareTo, 5);
|
|
public static final TicketType<ChunkCoordIntPair> UNKNOWN = a("unknown", Comparator.comparingLong(ChunkCoordIntPair::pair), 1);
|
|
public static final TicketType<Unit> PLUGIN = a("plugin", (a, b) -> 0); // CraftBukkit
|