Files
Purpur/patches/server/0155-Spread-out-and-optimise-player-list-ticks.patch
jmp 0bae78d9c3 Drop async advancements patch for now
Dropped per the advice of Proximyst. Has possible issues if players log in while they are still logging out from another location, with increased risk during lag spikes. A fix/workaround is possible in the future, but for the time being we will just drop this patch to avoid any potential problems.
2020-12-28 02:50:53 -08:00

77 lines
3.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: James Lyne <jim+github@not-null.co.uk>
Date: Mon, 7 Dec 2020 17:52:36 +0000
Subject: [PATCH] Spread out and optimise player list ticks
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
index 7b385eb43e4cf565d500d0250f3c5e4dbebae986..f055fd0aff86d04677d0bd256c9e7c12f94bfbcc 100644
--- a/src/main/java/net/minecraft/server/PlayerList.java
+++ b/src/main/java/net/minecraft/server/PlayerList.java
@@ -71,7 +71,7 @@ public abstract class PlayerList {
private int viewDistance;
private EnumGamemode u;
private boolean v;
- private int w;
+ private int w; private int getTick() { return this.w; } private int setTick(int i) { return this.w = i; } // Purpur - OBFHELPER
// CraftBukkit start
private CraftServer cserver;
@@ -919,22 +919,23 @@ public abstract class PlayerList {
}
public void tick() {
- if (++this.w > 600) {
- // CraftBukkit start
- for (int i = 0; i < this.players.size(); ++i) {
- final EntityPlayer target = (EntityPlayer) this.players.get(i);
-
- target.playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_LATENCY, Iterables.filter(this.players, new Predicate<EntityPlayer>() {
- @Override
- public boolean apply(EntityPlayer input) {
- return target.getBukkitEntity().canSee(input.getBukkitEntity());
- }
- })));
+ // Purpur start
+ int tick = getTick();
+ if (tick < this.players.size()) {
+ final org.bukkit.craftbukkit.entity.CraftPlayer target = this.players.get(tick).getBukkitEntity();
+ final java.util.List<EntityPlayer> list = new java.util.ArrayList<>();
+ for (EntityPlayer entityplayer : this.players) {
+ if (target.canSee(entityplayer.getUniqueID())) {
+ list.add(entityplayer);
+ }
}
- // CraftBukkit end
- this.w = 0;
+ target.getHandle().playerConnection.sendPacket(new PacketPlayOutPlayerInfo(PacketPlayOutPlayerInfo.EnumPlayerInfoAction.UPDATE_LATENCY, list));
}
-
+ if (++tick > 600) {
+ tick = 0;
+ }
+ setTick(tick);
+ // Purpur end
}
public void sendAll(Packet<?> packet) {
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index e781ae267d4c546261a1dcdfc24d9924eb5044fd..4f42bc21839086b2a40a35910a08d9b11c7649f9 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -1382,7 +1382,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public boolean canSee(Player player) {
- return !hiddenPlayers.containsKey(player.getUniqueId());
+ // Purpur start
+ return canSee(player.getUniqueId());
+ }
+
+ public boolean canSee(UUID uuid) {
+ return !hiddenPlayers.containsKey(uuid);
+ // Purpur end
}
@Override