2019-03-20 02:46:00 +01:00
From 3d84f674a2ca7d83d43d9aebb1df9661077f5d01 Mon Sep 17 00:00:00 2001
2018-08-18 00:05:00 +02:00
From: Mystiflow <mystiflow@gmail.com>
Date: Fri, 6 Jul 2018 13:21:30 +0100
Subject: [PATCH] Send nearby packets from world player list not server list
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
2019-03-20 02:46:00 +01:00
index ddaa73e83..ec760325b 100644
2018-08-18 00:05:00 +02:00
--- a/src/main/java/net/minecraft/server/PlayerList.java
+++ b/src/main/java/net/minecraft/server/PlayerList.java
2019-01-01 04:15:55 +01:00
@@ -1201,8 +1201,25 @@ public abstract class PlayerList {
2018-08-18 00:05:00 +02:00
}
2018-08-26 20:11:49 +02:00
public void sendPacketNearby(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, double d3, DimensionManager dimensionmanager, Packet<?> packet) {
- for (int i = 0; i < this.players.size(); ++i) {
- EntityPlayer entityplayer = (EntityPlayer) this.players.get(i);
2018-08-18 00:05:00 +02:00
+ // Paper start - Use world list instead of server list where preferable
2018-08-26 20:11:49 +02:00
+ sendPacketNearby(entityhuman, d0, d1, d2, d3, dimensionmanager, null, packet); // Retained for compatibility
2018-08-18 00:05:00 +02:00
+ }
+
+ public void sendPacketNearby(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, double d3, WorldServer world, Packet<?> packet) {
+ sendPacketNearby(entityhuman, d0, d1, d2, d3, world.dimension, world, packet);
+ }
+
2018-08-26 20:11:49 +02:00
+ public void sendPacketNearby(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, double d3, DimensionManager dimensionmanager, @Nullable WorldServer world, Packet<?> packet) {
2018-08-18 00:05:00 +02:00
+ if (world == null && entityhuman != null && entityhuman.world instanceof WorldServer) {
+ 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;
2018-08-26 20:11:49 +02:00
+ EntityPlayer entityplayer = (EntityPlayer) entity;
2018-08-18 00:05:00 +02:00
+ // Paper end
// CraftBukkit start - Test if player receiving packet can see the source of the packet
if (entityhuman != null && entityhuman instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer) entityhuman).getBukkitEntity())) {
2019-01-01 04:15:55 +01:00
@@ -1210,7 +1227,7 @@ public abstract class PlayerList {
2018-08-18 00:05:00 +02:00
}
// CraftBukkit end
2018-08-26 20:11:49 +02:00
- if (entityplayer != entityhuman && entityplayer.dimension == dimensionmanager) {
+ if (entityplayer != entityhuman && (world != null || entityplayer.dimension == dimensionmanager)) { // Paper
2018-08-18 00:05:00 +02:00
double d4 = d0 - entityplayer.locX;
double d5 = d1 - entityplayer.locY;
double d6 = d2 - entityplayer.locZ;
diff --git a/src/main/java/net/minecraft/server/WorldManager.java b/src/main/java/net/minecraft/server/WorldManager.java
2019-03-20 02:46:00 +01:00
index b4225b58e..0ba0eb661 100644
2018-08-18 00:05:00 +02:00
--- a/src/main/java/net/minecraft/server/WorldManager.java
+++ b/src/main/java/net/minecraft/server/WorldManager.java
@@ -35,8 +35,8 @@ public class WorldManager implements IWorldAccess {
}
public void a(@Nullable EntityHuman entityhuman, SoundEffect soundeffect, SoundCategory soundcategory, double d0, double d1, double d2, float f, float f1) {
- // CraftBukkit - this.world.dimension
- this.a.getPlayerList().sendPacketNearby(entityhuman, d0, d1, d2, f > 1.0F ? (double) (16.0F * f) : 16.0D, this.world.dimension, new PacketPlayOutNamedSoundEffect(soundeffect, soundcategory, d0, d1, d2, f, f1));
+ // CraftBukkit - this.world.dimension, // Paper - this.world.dimension -> this.world
+ this.a.getPlayerList().sendPacketNearby(entityhuman, d0, d1, d2, f > 1.0F ? (double) (16.0F * f) : 16.0D, this.world, new PacketPlayOutNamedSoundEffect(soundeffect, soundcategory, d0, d1, d2, f, f1));
}
public void a(int i, int j, int k, int l, int i1, int j1) {}
@@ -51,7 +51,7 @@ public class WorldManager implements IWorldAccess {
public void a(EntityHuman entityhuman, int i, BlockPosition blockposition, int j) {
// CraftBukkit - this.world.dimension
- this.a.getPlayerList().sendPacketNearby(entityhuman, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), 64.0D, this.world.dimension, new PacketPlayOutWorldEvent(i, blockposition, j, false));
+ this.a.getPlayerList().sendPacketNearby(entityhuman, (double) blockposition.getX(), (double) blockposition.getY(), (double) blockposition.getZ(), 64.0D, this.world, new PacketPlayOutWorldEvent(i, blockposition, j, false));
}
public void a(int i, BlockPosition blockposition, int j) {
@@ -59,7 +59,7 @@ public class WorldManager implements IWorldAccess {
}
public void b(int i, BlockPosition blockposition, int j) {
- Iterator iterator = this.a.getPlayerList().v().iterator();
+ // Iterator iterator = this.a.getPlayerList().v().iterator(); // Paper
// CraftBukkit start
EntityHuman entityhuman = null;
2018-08-18 10:58:53 +02:00
@@ -67,8 +67,14 @@ public class WorldManager implements IWorldAccess {
2018-08-18 00:05:00 +02:00
if (entity instanceof EntityHuman) entityhuman = (EntityHuman) entity;
// CraftBukkit end
+ // Paper start
+ java.util.List<? extends EntityHuman> list = entity != null ? entity.world.players : this.a.getPlayerList().v();
+ Iterator<? extends EntityHuman> iterator = list.iterator();
while (iterator.hasNext()) {
2018-08-18 10:58:53 +02:00
- EntityPlayer entityplayer = (EntityPlayer) iterator.next();
2018-08-18 00:05:00 +02:00
+ EntityHuman human = iterator.next();
+ if (!(human instanceof EntityPlayer)) continue;
2018-08-18 10:58:53 +02:00
+ EntityPlayer entityplayer = (EntityPlayer) human;
2018-08-18 00:05:00 +02:00
+ // Paper end
if (entityplayer != null && entityplayer.world == this.world && entityplayer.getId() != i) {
2018-08-18 10:58:53 +02:00
double d0 = (double) blockposition.getX() - entityplayer.locX;
2018-08-18 00:05:00 +02:00
diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
2019-03-20 02:46:00 +01:00
index 4cda6cee2..0ff3fe03d 100644
2018-08-18 00:05:00 +02:00
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
2019-02-26 02:38:55 +01:00
@@ -1064,7 +1064,7 @@ public class WorldServer extends World implements IAsyncTaskHandler {
2018-08-18 00:05:00 +02:00
}
// CraftBukkit end
if (super.strikeLightning(entity)) {
- this.server.getPlayerList().sendPacketNearby((EntityHuman) null, entity.locX, entity.locY, entity.locZ, 512.0D, dimension, new PacketPlayOutSpawnEntityWeather(entity)); // CraftBukkit - Use dimension
+ this.server.getPlayerList().sendPacketNearby((EntityHuman) null, entity.locX, entity.locY, entity.locZ, 512.0D, this, new PacketPlayOutSpawnEntityWeather(entity)); // CraftBukkit - Use dimension, // Paper - use world instead of dimension
return true;
} else {
return false;
2019-02-26 02:38:55 +01:00
@@ -1124,8 +1124,8 @@ public class WorldServer extends World implements IAsyncTaskHandler {
2018-08-18 10:59:57 +02:00
BlockActionData blockactiondata = (BlockActionData) this.d.removeFirst();
2018-08-18 00:05:00 +02:00
2018-08-18 10:59:57 +02:00
if (this.a(blockactiondata)) {
- // CraftBukkit - this.worldProvider.dimension -> this.dimension
- this.server.getPlayerList().sendPacketNearby((EntityHuman) null, (double) blockactiondata.a().getX(), (double) blockactiondata.a().getY(), (double) blockactiondata.a().getZ(), 64.0D, dimension, new PacketPlayOutBlockAction(blockactiondata.a(), blockactiondata.b(), blockactiondata.c(), blockactiondata.d()));
+ // CraftBukkit - this.worldProvider.dimension -> this.dimension, // Paper - dimension -> world
+ this.server.getPlayerList().sendPacketNearby((EntityHuman) null, (double) blockactiondata.a().getX(), (double) blockactiondata.a().getY(), (double) blockactiondata.a().getZ(), 64.0D, this, new PacketPlayOutBlockAction(blockactiondata.a(), blockactiondata.b(), blockactiondata.c(), blockactiondata.d()));
2018-08-18 00:05:00 +02:00
}
2018-08-18 10:59:57 +02:00
}
2018-08-18 00:05:00 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2019-03-20 02:46:00 +01:00
index 3fdd12ec0..e0b466d0c 100644
2018-08-18 00:05:00 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2019-01-01 04:15:55 +01:00
@@ -1636,7 +1636,7 @@ public class CraftWorld implements World {
2018-08-18 00:05:00 +02:00
double z = loc.getZ();
2018-08-18 10:59:57 +02:00
PacketPlayOutCustomSoundEffect packet = new PacketPlayOutCustomSoundEffect(new MinecraftKey(sound), SoundCategory.valueOf(category.name()), new Vec3D(x, y, z), volume, pitch);
2018-08-18 00:05:00 +02:00
- world.getMinecraftServer().getPlayerList().sendPacketNearby(null, x, y, z, volume > 1.0F ? 16.0F * volume : 16.0D, this.world.dimension, packet);
+ world.getMinecraftServer().getPlayerList().sendPacketNearby(null, x, y, z, volume > 1.0F ? 16.0F * volume : 16.0D, this.world, packet); // Paper - this.world.dimension -> this.world
}
public String getGameRuleValue(String rule) {
--
2019-03-20 02:46:00 +01:00
2.21.0
2018-08-18 00:05:00 +02:00