mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-16 14:33:09 +01:00
Don't move existing players to world spawn
This can cause a nasty server lag the spawn chunks are not kept loaded or they aren't finished loading yet, or if the world spawn radius is larger than the keep loaded range. By skipping this, we avoid potential for a large spike on server start. == AT == public net.minecraft.server.level.ServerPlayer fudgeSpawnLocation(Lnet/minecraft/server/level/ServerLevel;)V
This commit is contained in:
parent
6242e1dad0
commit
7659c20386
2 changed files with 44 additions and 39 deletions
|
@ -171,8 +171,12 @@
|
|||
};
|
||||
this.textFilter = server.createTextFilterForPlayer(this);
|
||||
this.gameMode = server.createGameModeForPlayer(this);
|
||||
@@ -352,14 +420,68 @@
|
||||
this.moveTo(this.adjustSpawnLocation(world, world.getSharedSpawnPos()).getBottomCenter(), 0.0F, 0.0F);
|
||||
@@ -349,17 +417,71 @@
|
||||
this.server = server;
|
||||
this.stats = server.getPlayerList().getPlayerStats(this);
|
||||
this.advancements = server.getPlayerList().getPlayerAdvancements(this);
|
||||
- this.moveTo(this.adjustSpawnLocation(world, world.getSharedSpawnPos()).getBottomCenter(), 0.0F, 0.0F);
|
||||
+ // this.moveTo(this.adjustSpawnLocation(world, world.getSharedSpawnPos()).getBottomCenter(), 0.0F, 0.0F); // Paper - Don't move existing players to world spawn
|
||||
this.updateOptions(clientOptions);
|
||||
this.object = null;
|
||||
+
|
||||
|
@ -412,7 +416,7 @@
|
|||
+ position = Vec3.atCenterOf(world.getSharedSpawnPos());
|
||||
+ }
|
||||
+ this.setLevel(world);
|
||||
+ this.setPos(position);
|
||||
+ this.setPosRaw(position.x(), position.y(), position.z()); // Paper - don't register to chunks yet
|
||||
+ }
|
||||
+ this.gameMode.setLevel((ServerLevel) world);
|
||||
+ }
|
||||
|
@ -1103,11 +1107,11 @@
|
|||
|
||||
this.nextContainerCounter();
|
||||
AbstractContainerMenu container = factory.createMenu(this.containerCounter, this.getInventory(), this);
|
||||
+
|
||||
|
||||
+ // CraftBukkit start - Inventory open hook
|
||||
+ if (container != null) {
|
||||
+ container.setTitle(factory.getDisplayName());
|
||||
|
||||
+
|
||||
+ boolean cancelled = false;
|
||||
+ container = CraftEventFactory.callInventoryOpenEvent(this, container, cancelled);
|
||||
+ if (container == null && !cancelled) { // Let pre-cancelled events fall through
|
||||
|
|
|
@ -134,13 +134,14 @@
|
|||
ServerLevel worldserver = this.server.getLevel(resourcekey);
|
||||
ServerLevel worldserver1;
|
||||
|
||||
@@ -179,13 +223,35 @@
|
||||
@@ -179,13 +223,36 @@
|
||||
worldserver1 = worldserver;
|
||||
}
|
||||
|
||||
+ // Paper start - Entity#getEntitySpawnReason
|
||||
+ if (optional.isEmpty()) {
|
||||
+ player.spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT; // set Player SpawnReason to DEFAULT on first login
|
||||
+ player.moveTo(player.adjustSpawnLocation(worldserver1, worldserver1.getSharedSpawnPos()).getBottomCenter(), 0.0F, 0.0F);
|
||||
+ }
|
||||
+ // Paper end - Entity#getEntitySpawnReason
|
||||
player.setServerLevel(worldserver1);
|
||||
|
@ -172,7 +173,7 @@
|
|||
ServerGamePacketListenerImpl playerconnection = new ServerGamePacketListenerImpl(this.server, connection, player, clientData);
|
||||
|
||||
connection.setupInboundProtocol(GameProtocols.SERVERBOUND_TEMPLATE.bind(RegistryFriendlyByteBuf.decorator(this.server.registryAccess())), playerconnection);
|
||||
@@ -194,7 +260,9 @@
|
||||
@@ -194,7 +261,9 @@
|
||||
boolean flag1 = gamerules.getBoolean(GameRules.RULE_REDUCEDDEBUGINFO);
|
||||
boolean flag2 = gamerules.getBoolean(GameRules.RULE_LIMITED_CRAFTING);
|
||||
|
||||
|
@ -183,7 +184,7 @@
|
|||
playerconnection.send(new ClientboundChangeDifficultyPacket(worlddata.getDifficulty(), worlddata.isDifficultyLocked()));
|
||||
playerconnection.send(new ClientboundPlayerAbilitiesPacket(player.getAbilities()));
|
||||
playerconnection.send(new ClientboundSetHeldSlotPacket(player.getInventory().selected));
|
||||
@@ -213,8 +281,10 @@
|
||||
@@ -213,8 +282,10 @@
|
||||
} else {
|
||||
ichatmutablecomponent = Component.translatable("multiplayer.player.joined.renamed", player.getDisplayName(), s);
|
||||
}
|
||||
|
@ -195,7 +196,7 @@
|
|||
playerconnection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
|
||||
ServerStatus serverping = this.server.getStatus();
|
||||
|
||||
@@ -222,17 +292,77 @@
|
||||
@@ -222,17 +293,77 @@
|
||||
player.sendServerStatus(serverping);
|
||||
}
|
||||
|
||||
|
@ -277,7 +278,7 @@
|
|||
}
|
||||
|
||||
public void updateEntireScoreboard(ServerScoreboard scoreboard, ServerPlayer player) {
|
||||
@@ -269,30 +399,31 @@
|
||||
@@ -269,30 +400,31 @@
|
||||
}
|
||||
|
||||
public void addWorldborderListener(ServerLevel world) {
|
||||
|
@ -314,7 +315,7 @@
|
|||
}
|
||||
|
||||
@Override
|
||||
@@ -319,14 +450,15 @@
|
||||
@@ -319,14 +451,15 @@
|
||||
}
|
||||
|
||||
protected void save(ServerPlayer player) {
|
||||
|
@ -332,7 +333,7 @@
|
|||
|
||||
if (advancementdataplayer != null) {
|
||||
advancementdataplayer.save();
|
||||
@@ -334,95 +466,186 @@
|
||||
@@ -334,95 +467,186 @@
|
||||
|
||||
}
|
||||
|
||||
|
@ -557,7 +558,7 @@
|
|||
|
||||
if (entityplayer1 != null) {
|
||||
set.add(entityplayer1);
|
||||
@@ -431,72 +654,160 @@
|
||||
@@ -431,72 +655,160 @@
|
||||
Iterator iterator1 = set.iterator();
|
||||
|
||||
while (iterator1.hasNext()) {
|
||||
|
@ -571,11 +572,6 @@
|
|||
+ */
|
||||
+ return player == null;
|
||||
+ // CraftBukkit end
|
||||
+ }
|
||||
+
|
||||
+ // CraftBukkit start
|
||||
+ public ServerPlayer respawn(ServerPlayer entityplayer, boolean flag, Entity.RemovalReason entity_removalreason, RespawnReason reason) {
|
||||
+ return this.respawn(entityplayer, flag, entity_removalreason, reason, null);
|
||||
}
|
||||
|
||||
- public ServerPlayer respawn(ServerPlayer player, boolean alive, Entity.RemovalReason removalReason) {
|
||||
|
@ -584,6 +580,15 @@
|
|||
- TeleportTransition teleporttransition = player.findRespawnPositionAndUseSpawnBlock(!alive, TeleportTransition.DO_NOTHING);
|
||||
- ServerLevel worldserver = teleporttransition.newLevel();
|
||||
- ServerPlayer entityplayer1 = new ServerPlayer(this.server, worldserver, player.getGameProfile(), player.clientInformation());
|
||||
+ // CraftBukkit start
|
||||
+ public ServerPlayer respawn(ServerPlayer entityplayer, boolean flag, Entity.RemovalReason entity_removalreason, RespawnReason reason) {
|
||||
+ return this.respawn(entityplayer, flag, entity_removalreason, reason, null);
|
||||
+ }
|
||||
|
||||
- entityplayer1.connection = player.connection;
|
||||
- entityplayer1.restoreFrom(player, alive);
|
||||
- entityplayer1.setId(player.getId());
|
||||
- entityplayer1.setMainArm(player.getMainArm());
|
||||
+ public ServerPlayer respawn(ServerPlayer entityplayer, boolean flag, Entity.RemovalReason entity_removalreason, RespawnReason reason, Location location) {
|
||||
+ entityplayer.stopRiding(); // CraftBukkit
|
||||
+ this.players.remove(entityplayer);
|
||||
|
@ -598,11 +603,7 @@
|
|||
+ Level fromWorld = entityplayer.level();
|
||||
+ entityplayer.wonGame = false;
|
||||
+ // CraftBukkit end
|
||||
|
||||
- entityplayer1.connection = player.connection;
|
||||
- entityplayer1.restoreFrom(player, alive);
|
||||
- entityplayer1.setId(player.getId());
|
||||
- entityplayer1.setMainArm(player.getMainArm());
|
||||
+
|
||||
+ entityplayer1.connection = entityplayer.connection;
|
||||
+ entityplayer1.restoreFrom(entityplayer, flag);
|
||||
+ entityplayer1.setId(entityplayer.getId());
|
||||
|
@ -739,7 +740,7 @@
|
|||
return entityplayer1;
|
||||
}
|
||||
|
||||
@@ -516,15 +827,32 @@
|
||||
@@ -516,15 +828,32 @@
|
||||
}
|
||||
|
||||
public void sendPlayerPermissionLevel(ServerPlayer player) {
|
||||
|
@ -774,7 +775,7 @@
|
|||
this.sendAllPlayerInfoIn = 0;
|
||||
}
|
||||
|
||||
@@ -541,6 +869,25 @@
|
||||
@@ -541,6 +870,25 @@
|
||||
|
||||
}
|
||||
|
||||
|
@ -800,7 +801,7 @@
|
|||
public void broadcastAll(Packet<?> packet, ResourceKey<Level> dimension) {
|
||||
Iterator iterator = this.players.iterator();
|
||||
|
||||
@@ -554,7 +901,7 @@
|
||||
@@ -554,7 +902,7 @@
|
||||
|
||||
}
|
||||
|
||||
|
@ -809,7 +810,7 @@
|
|||
PlayerTeam scoreboardteam = source.getTeam();
|
||||
|
||||
if (scoreboardteam != null) {
|
||||
@@ -573,7 +920,7 @@
|
||||
@@ -573,7 +921,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -818,7 +819,7 @@
|
|||
PlayerTeam scoreboardteam = source.getTeam();
|
||||
|
||||
if (scoreboardteam == null) {
|
||||
@@ -619,7 +966,7 @@
|
||||
@@ -619,7 +967,7 @@
|
||||
}
|
||||
|
||||
public void deop(GameProfile profile) {
|
||||
|
@ -827,7 +828,7 @@
|
|||
ServerPlayer entityplayer = this.getPlayer(profile.getId());
|
||||
|
||||
if (entityplayer != null) {
|
||||
@@ -643,36 +990,51 @@
|
||||
@@ -643,36 +991,51 @@
|
||||
player.connection.send(new ClientboundEntityEventPacket(player, b0));
|
||||
}
|
||||
|
||||
|
@ -892,7 +893,7 @@
|
|||
if (entityplayer != player && entityplayer.level().dimension() == worldKey) {
|
||||
double d4 = x - entityplayer.getX();
|
||||
double d5 = y - entityplayer.getY();
|
||||
@@ -687,10 +1049,12 @@
|
||||
@@ -687,10 +1050,12 @@
|
||||
}
|
||||
|
||||
public void saveAll() {
|
||||
|
@ -905,7 +906,7 @@
|
|||
}
|
||||
|
||||
public UserWhiteList getWhiteList() {
|
||||
@@ -712,15 +1076,19 @@
|
||||
@@ -712,15 +1077,19 @@
|
||||
public void reloadWhiteList() {}
|
||||
|
||||
public void sendLevelInfo(ServerPlayer player, ServerLevel world) {
|
||||
|
@ -929,7 +930,7 @@
|
|||
}
|
||||
|
||||
player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.LEVEL_CHUNKS_LOAD_START, 0.0F));
|
||||
@@ -729,8 +1097,16 @@
|
||||
@@ -729,8 +1098,16 @@
|
||||
|
||||
public void sendAllPlayerInfo(ServerPlayer player) {
|
||||
player.inventoryMenu.sendAllDataToRemote();
|
||||
|
@ -947,7 +948,7 @@
|
|||
}
|
||||
|
||||
public int getPlayerCount() {
|
||||
@@ -746,6 +1122,7 @@
|
||||
@@ -746,6 +1123,7 @@
|
||||
}
|
||||
|
||||
public void setUsingWhiteList(boolean whitelistEnabled) {
|
||||
|
@ -955,7 +956,7 @@
|
|||
this.doWhiteList = whitelistEnabled;
|
||||
}
|
||||
|
||||
@@ -786,12 +1163,36 @@
|
||||
@@ -786,12 +1164,36 @@
|
||||
}
|
||||
|
||||
public void removeAll() {
|
||||
|
@ -994,7 +995,7 @@
|
|||
public void broadcastSystemMessage(Component message, boolean overlay) {
|
||||
this.broadcastSystemMessage(message, (entityplayer) -> {
|
||||
return message;
|
||||
@@ -819,24 +1220,43 @@
|
||||
@@ -819,24 +1221,43 @@
|
||||
}
|
||||
|
||||
public void broadcastChatMessage(PlayerChatMessage message, ServerPlayer sender, ChatType.Bound params) {
|
||||
|
@ -1041,7 +1042,7 @@
|
|||
}
|
||||
|
||||
if (flag1 && sender != null) {
|
||||
@@ -845,20 +1265,27 @@
|
||||
@@ -845,20 +1266,27 @@
|
||||
|
||||
}
|
||||
|
||||
|
@ -1074,7 +1075,7 @@
|
|||
Path path = file2.toPath();
|
||||
|
||||
if (FileUtil.isPathNormalized(path) && FileUtil.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) {
|
||||
@@ -867,7 +1294,7 @@
|
||||
@@ -867,7 +1295,7 @@
|
||||
}
|
||||
|
||||
serverstatisticmanager = new ServerStatsCounter(this.server, file1);
|
||||
|
@ -1083,7 +1084,7 @@
|
|||
}
|
||||
|
||||
return serverstatisticmanager;
|
||||
@@ -875,13 +1302,13 @@
|
||||
@@ -875,13 +1303,13 @@
|
||||
|
||||
public PlayerAdvancements getPlayerAdvancements(ServerPlayer player) {
|
||||
UUID uuid = player.getUUID();
|
||||
|
@ -1099,7 +1100,7 @@
|
|||
}
|
||||
|
||||
advancementdataplayer.setPlayer(player);
|
||||
@@ -932,15 +1359,28 @@
|
||||
@@ -932,15 +1360,28 @@
|
||||
}
|
||||
|
||||
public void reloadResources() {
|
||||
|
|
Loading…
Reference in a new issue