From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Martijn Muijsers Date: Tue, 29 Nov 2022 23:30:38 +0100 Subject: [PATCH] Optimize player list for sending player info License: MIT (https://opensource.org/licenses/MIT) Gale - https://galemc.org This patch is based on the following patch: "Spread out and optimise player list ticksSpread out and optimise player list ticks" By: James Lyne As part of: Purpur (https://github.com/PurpurMC/Purpur) Licensed under: MIT (https://opensource.org/licenses/MIT) * Purpur copyright * MIT License Copyright (c) 2019-2022 PurpurMC Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java index 44990dfc60126bf6bb88679dfbebb09d3ca1473a..98efc69c911dd7cdce6c945d1bfebbefc0bbd154 100644 --- a/src/main/java/net/minecraft/server/players/PlayerList.java +++ b/src/main/java/net/minecraft/server/players/PlayerList.java @@ -1018,14 +1018,18 @@ public abstract class PlayerList { // Gale start - Purpur - spread out sending all player info ServerPlayer[] sendAllPlayerInfoBucket = this.sendAllPlayerInfoBuckets[this.sendAllPlayerInfoIn]; if (sendAllPlayerInfoBucket != null) { - for (ServerPlayer target : sendAllPlayerInfoBucket) { + // Gale start - Purpur - optimize player list for sending player info + for (ServerPlayer targetPlayer : sendAllPlayerInfoBucket) { // Gale end - Purpur - spread out sending all player info - target.connection.send(new ClientboundPlayerInfoUpdatePacket(EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY), this.players.stream().filter(new Predicate() { - @Override - public boolean test(ServerPlayer input) { - return target.getBukkitEntity().canSee(input.getBukkitEntity()); + var target = targetPlayer.getBukkitEntity();; + final List list = new java.util.ArrayList<>(this.players.size()); + for (ServerPlayer player : this.players) { + if (target.canSeePlayer(player.getUUID())) { + list.add(player); } - }).collect(Collectors.toList()))); + } + target.getHandle().connection.send(new ClientboundPlayerInfoUpdatePacket(EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.UPDATE_LATENCY), list)); + // Gale end - Purpur - optimize player list for sending player info // Gale start - Purpur - spread out sending all player info } }