2020-05-23 21:15:40 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sat, 23 May 2020 17:03:41 -0400
|
|
|
|
Subject: [PATCH] Optimize sending packets to nearby locations (sounds/effects)
|
|
|
|
|
|
|
|
Instead of using the entire world or player list, use the distance
|
|
|
|
maps to only iterate players who are even seeing the chunk the packet
|
|
|
|
is originating from.
|
|
|
|
|
|
|
|
This will drastically cut down on packet sending cost for worlds with
|
|
|
|
lots of players in them.
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
|
2020-05-24 02:27:37 +00:00
|
|
|
index 9b726de6daeba42120f3a948fbdcf080d0e72917..269580ae2a6edca979ccc1e46df144468ea70a18 100644
|
2020-05-23 21:15:40 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
2020-05-24 02:27:37 +00:00
|
|
|
@@ -1027,11 +1027,27 @@ public abstract class PlayerList {
|
2020-05-23 21:15:40 +00:00
|
|
|
world = (WorldServer) entityhuman.world;
|
|
|
|
}
|
|
|
|
|
|
|
|
- List<? extends EntityHuman> players1 = world == null ? players : world.players;
|
|
|
|
- for (int j = 0; j < players1.size(); ++j) {
|
|
|
|
- EntityHuman entity = players1.get(j);
|
|
|
|
- if (!(entity instanceof EntityPlayer)) continue;
|
|
|
|
- EntityPlayer entityplayer = (EntityPlayer) entity;
|
|
|
|
+ // Paper start
|
|
|
|
+ if (world == null && dimensionmanager != null) {
|
|
|
|
+ world = dimensionmanager.world;
|
|
|
|
+ }
|
|
|
|
+ if (world == null) {
|
|
|
|
+ LOGGER.error("Sending packet to invalid world" + entityhuman + " " + dimensionmanager + " - " + packet.getClass().getName(), new Throwable());
|
|
|
|
+ return; // ??? shouldn't happen...
|
|
|
|
+ }
|
2020-05-24 02:27:37 +00:00
|
|
|
+ ChunkProviderServer chunkProvider = (ChunkProviderServer) world.chunkProvider;
|
|
|
|
+ if (chunkProvider == null) {
|
|
|
|
+ // ??? Shouldn't be possible but seem some hacky plugins apparently do hack things.
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ com.destroystokyo.paper.util.misc.PooledLinkedHashSets.PooledObjectLinkedOpenHashSet<EntityPlayer> nearbyPlayers = chunkProvider.playerChunkMap.playerViewDistanceBroadcastMap.getObjectsInRange(MCUtil.fastFloor(d0) >> 4, MCUtil.fastFloor(d2) >> 4);
|
2020-05-23 21:15:40 +00:00
|
|
|
+ if (nearbyPlayers == null) {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ Object[] backingSet = nearbyPlayers.getBackingSet();
|
|
|
|
+ for (Object object : backingSet) {
|
|
|
|
+ if (!(object instanceof EntityPlayer)) continue;
|
|
|
|
+ EntityPlayer entityplayer = (EntityPlayer) object;
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
// CraftBukkit start - Test if player receiving packet can see the source of the packet
|