Use single player info update packet on join

This commit is contained in:
Jake Potrebic 2023-01-08 17:38:28 -08:00
parent a03610401b
commit 3af4592f2a
2 changed files with 58 additions and 52 deletions

View File

@ -48,7 +48,7 @@
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level;
@@ -192,12 +196,73 @@
@@ -192,11 +196,72 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
@ -59,7 +59,7 @@
import net.minecraft.world.phys.shapes.VoxelShape;
+import org.bukkit.NamespacedKey;
import org.slf4j.Logger;
+
+// CraftBukkit start
+import io.papermc.paper.adventure.ChatProcessor; // Paper
+import io.papermc.paper.adventure.PaperAdventure; // Paper
@ -118,10 +118,9 @@
+import org.bukkit.inventory.InventoryView;
+import org.bukkit.inventory.SmithingInventory;
+// CraftBukkit end
+
public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl implements ServerGamePacketListener, ServerPlayerConnection, TickablePacketListener {
static final Logger LOGGER = LogUtils.getLogger();
@@ -212,7 +277,9 @@
private int tickCount;
private int ackBlockChangesUpTo = -1;
@ -324,7 +323,7 @@
boolean flag1 = entity.verticalCollisionBelow;
if (entity instanceof LivingEntity) {
@@ -449,20 +599,73 @@
@@ -449,19 +599,72 @@
d10 = d6 * d6 + d7 * d7 + d8 * d8;
boolean flag2 = false;
@ -343,8 +342,8 @@
+ this.player.absMoveTo(d0, d1, d2, this.player.getYRot(), this.player.getXRot()); // CraftBukkit
this.send(ClientboundMoveVehiclePacket.fromEntity(entity));
return;
}
+ }
+
+ // CraftBukkit start - fire PlayerMoveEvent
+ Player player = this.getCraftPlayer();
+ if (!this.hasMoved) {
@ -393,12 +392,11 @@
+ this.justTeleported = false;
+ return;
+ }
+ }
}
+ // CraftBukkit end
+
this.player.serverLevel().getChunkSource().move(this.player);
entity.recordMovementThroughBlocks(new Vec3(d0, d1, d2), entity.position());
Vec3 vec3d = new Vec3(entity.getX() - d0, entity.getY() - d1, entity.getZ() - d2);
@@ -489,16 +692,17 @@
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
if (packet.getId() == this.awaitingTeleport) {
@ -1155,12 +1153,10 @@
if (this.player.hasClientLoaded()) {
this.ackBlockChangesUpTo(packet.getSequence());
ServerLevel worldserver = this.player.serverLevel();
@@ -1294,8 +1924,49 @@
if (f1 != this.player.getXRot() || f != this.player.getYRot()) {
@@ -1296,6 +1926,47 @@
this.player.absRotateTo(f, f1);
+ }
+
}
+ // CraftBukkit start
+ // Raytrace to look for 'rogue armswings'
+ double d0 = this.player.getX();
@ -1191,8 +1187,8 @@
+ cancelled = event.useItemInHand() == Event.Result.DENY;
+ }
+ this.player.gameMode.firedInteract = false;
}
+ }
+
+ if (cancelled) {
+ this.player.getBukkitEntity().updateInventory(); // SPIGOT-2524
+ return;
@ -1448,12 +1444,10 @@
}
return optional;
@@ -1564,8 +2326,129 @@
@@ -1566,6 +2328,127 @@
return false;
}
return false;
+ }
+
+ // CraftBukkit start - add method
+ public void chat(String s, PlayerChatMessage original, boolean async) {
+ if (s.isEmpty() || this.player.getChatVisibility() == ChatVisiblity.HIDDEN) {
@ -1546,8 +1540,8 @@
+ this.server.console.sendMessage(s);
+ }
+ }
}
+ }
+
+ private void handleCommand(String s) {
+ org.spigotmc.AsyncCatcher.catchOp("Command Dispatched Async: " + s); // Paper - Add async catcher
+ if ( org.spigotmc.SpigotConfig.logCommands ) // Spigot
@ -2318,7 +2312,7 @@
this.player.resetLastActionTime();
if (this.player.containerMenu.containerId == packet.containerId() && !this.player.isSpectator()) {
if (!this.player.containerMenu.stillValid(this.player)) {
@@ -1945,6 +3338,43 @@
@@ -1945,7 +3338,44 @@
boolean flag1 = packet.slotNum() >= 1 && packet.slotNum() <= 45;
boolean flag2 = itemstack.isEmpty() || itemstack.getCount() <= itemstack.getMaxStackSize();
@ -2326,7 +2320,7 @@
+ // CraftBukkit start - Call click event
+ InventoryView inventory = this.player.inventoryMenu.getBukkitView();
+ org.bukkit.inventory.ItemStack item = CraftItemStack.asBukkitCopy(packet.itemStack());
+
+ SlotType type = SlotType.QUICKBAR;
+ if (flag) {
+ type = SlotType.OUTSIDE;
@ -2359,9 +2353,10 @@
+ }
+ }
+ // CraftBukkit end
+
if (flag1 && flag2) {
this.player.inventoryMenu.getSlot(packet.slotNum()).setByPlayer(itemstack);
this.player.inventoryMenu.setRemoteSlot(packet.slotNum(), itemstack);
@@ -1964,7 +3394,19 @@
@Override
@ -2464,7 +2459,12 @@
}
}
@@ -2083,8 +3544,10 @@
@@ -2079,12 +3540,14 @@
this.signedMessageDecoder = session.createMessageDecoder(this.player.getUUID());
this.chatMessageChain.append(() -> {
this.player.setChatSession(session);
- this.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.INITIALIZE_CHAT), List.of(this.player)));
+ this.server.getPlayerList().broadcastAll(new ClientboundPlayerInfoUpdatePacket(EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.INITIALIZE_CHAT), List.of(this.player)), this.player); // Paper - Use single player info update packet on join
});
}

View File

@ -235,7 +235,7 @@
playerconnection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
ServerStatus serverping = this.server.getStatus();
@@ -222,17 +327,95 @@
@@ -222,17 +327,101 @@
player.sendServerStatus(serverping);
}
@ -281,6 +281,7 @@
+ // CraftBukkit start - sendAll above replaced with this loop
+ ClientboundPlayerInfoUpdatePacket packet = ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(player));
+
+ final List<ServerPlayer> onlinePlayers = Lists.newArrayListWithExpectedSize(this.players.size() - 1); // Paper - Use single player info update packet on join
+ for (int i = 0; i < this.players.size(); ++i) {
+ ServerPlayer entityplayer1 = (ServerPlayer) this.players.get(i);
+
@ -288,12 +289,17 @@
+ entityplayer1.connection.send(packet);
+ }
+
+ if (!bukkitPlayer.canSee(entityplayer1.getBukkitEntity())) {
+ if (entityplayer1 == player || !bukkitPlayer.canSee(entityplayer1.getBukkitEntity())) { // Paper - Use single player info update packet on join; Don't include joining player
+ continue;
+ }
+
+ player.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(List.of(entityplayer1)));
+ onlinePlayers.add(entityplayer1); // Paper - Use single player info update packet on join
+ }
+ // Paper start - Use single player info update packet on join
+ if (!onlinePlayers.isEmpty()) {
+ player.connection.send(ClientboundPlayerInfoUpdatePacket.createPlayerInitializing(onlinePlayers));
+ }
+ // Paper end - Use single player info update packet on join
+ 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
@ -336,7 +342,7 @@
}
public void updateEntireScoreboard(ServerScoreboard scoreboard, ServerPlayer player) {
@@ -269,30 +452,31 @@
@@ -269,30 +458,31 @@
}
public void addWorldborderListener(ServerLevel world) {
@ -373,7 +379,7 @@
}
@Override
@@ -319,14 +503,15 @@
@@ -319,14 +509,15 @@
}
protected void save(ServerPlayer player) {
@ -391,7 +397,7 @@
if (advancementdataplayer != null) {
advancementdataplayer.save();
@@ -334,95 +519,209 @@
@@ -334,95 +525,209 @@
}
@ -639,7 +645,7 @@
if (entityplayer1 != null) {
set.add(entityplayer1);
@@ -431,72 +730,160 @@
@@ -431,72 +736,160 @@
Iterator iterator1 = set.iterator();
while (iterator1.hasNext()) {
@ -821,7 +827,7 @@
return entityplayer1;
}
@@ -516,15 +903,32 @@
@@ -516,15 +909,32 @@
}
public void sendPlayerPermissionLevel(ServerPlayer player) {
@ -856,7 +862,7 @@
this.sendAllPlayerInfoIn = 0;
}
@@ -541,6 +945,25 @@
@@ -541,6 +951,25 @@
}
@ -882,7 +888,7 @@
public void broadcastAll(Packet<?> packet, ResourceKey<Level> dimension) {
Iterator iterator = this.players.iterator();
@@ -554,7 +977,7 @@
@@ -554,7 +983,7 @@
}
@ -891,7 +897,7 @@
PlayerTeam scoreboardteam = source.getTeam();
if (scoreboardteam != null) {
@@ -573,7 +996,7 @@
@@ -573,7 +1002,7 @@
}
}
@ -900,7 +906,7 @@
PlayerTeam scoreboardteam = source.getTeam();
if (scoreboardteam == null) {
@@ -619,7 +1042,7 @@
@@ -619,7 +1048,7 @@
}
public void deop(GameProfile profile) {
@ -909,7 +915,7 @@
ServerPlayer entityplayer = this.getPlayer(profile.getId());
if (entityplayer != null) {
@@ -629,6 +1052,11 @@
@@ -629,6 +1058,11 @@
}
private void sendPlayerPermissionLevel(ServerPlayer player, int permissionLevel) {
@ -921,7 +927,7 @@
if (player.connection != null) {
byte b0;
@@ -643,36 +1071,53 @@
@@ -643,36 +1077,53 @@
player.connection.send(new ClientboundEntityEventPacket(player, b0));
}
@ -988,7 +994,7 @@
if (entityplayer != player && entityplayer.level().dimension() == worldKey) {
double d4 = x - entityplayer.getX();
double d5 = y - entityplayer.getY();
@@ -687,10 +1132,12 @@
@@ -687,10 +1138,12 @@
}
public void saveAll() {
@ -1001,7 +1007,7 @@
}
public UserWhiteList getWhiteList() {
@@ -712,15 +1159,19 @@
@@ -712,15 +1165,19 @@
public void reloadWhiteList() {}
public void sendLevelInfo(ServerPlayer player, ServerLevel world) {
@ -1025,7 +1031,7 @@
}
player.connection.send(new ClientboundGameEventPacket(ClientboundGameEventPacket.LEVEL_CHUNKS_LOAD_START, 0.0F));
@@ -729,8 +1180,16 @@
@@ -729,8 +1186,16 @@
public void sendAllPlayerInfo(ServerPlayer player) {
player.inventoryMenu.sendAllDataToRemote();
@ -1043,7 +1049,7 @@
}
public int getPlayerCount() {
@@ -746,6 +1205,7 @@
@@ -746,6 +1211,7 @@
}
public void setUsingWhiteList(boolean whitelistEnabled) {
@ -1051,7 +1057,7 @@
this.doWhiteList = whitelistEnabled;
}
@@ -786,12 +1246,36 @@
@@ -786,12 +1252,36 @@
}
public void removeAll() {
@ -1090,7 +1096,7 @@
public void broadcastSystemMessage(Component message, boolean overlay) {
this.broadcastSystemMessage(message, (entityplayer) -> {
return message;
@@ -819,24 +1303,43 @@
@@ -819,24 +1309,43 @@
}
public void broadcastChatMessage(PlayerChatMessage message, ServerPlayer sender, ChatType.Bound params) {
@ -1137,7 +1143,7 @@
}
if (flag1 && sender != null) {
@@ -845,20 +1348,27 @@
@@ -845,20 +1354,27 @@
}
@ -1170,7 +1176,7 @@
Path path = file2.toPath();
if (FileUtil.isPathNormalized(path) && FileUtil.isPathPortable(path) && path.startsWith(file.getPath()) && file2.isFile()) {
@@ -867,7 +1377,7 @@
@@ -867,7 +1383,7 @@
}
serverstatisticmanager = new ServerStatsCounter(this.server, file1);
@ -1179,7 +1185,7 @@
}
return serverstatisticmanager;
@@ -875,13 +1385,13 @@
@@ -875,13 +1391,13 @@
public PlayerAdvancements getPlayerAdvancements(ServerPlayer player) {
UUID uuid = player.getUUID();
@ -1195,7 +1201,7 @@
}
advancementdataplayer.setPlayer(player);
@@ -932,15 +1442,28 @@
@@ -932,15 +1448,28 @@
}
public void reloadResources() {