2019-08-15 02:47:38 +00:00
From 1a129cf6f70425f43daa049512ac51538a11e780 Mon Sep 17 00:00:00 2001
2018-08-17 22:05:00 +00: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-08-15 02:47:38 +00:00
index 9e5cd22d7..049d702cb 100644
2018-08-17 22:05:00 +00:00
--- a/src/main/java/net/minecraft/server/PlayerList.java
+++ b/src/main/java/net/minecraft/server/PlayerList.java
2019-05-14 02:20:58 +00:00
@@ -922,8 +922,25 @@ public abstract class PlayerList {
2018-08-17 22:05:00 +00:00
}
2018-08-26 18:11:49 +00: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-17 22:05:00 +00:00
+ // Paper start - Use world list instead of server list where preferable
2018-08-26 18:11:49 +00:00
+ sendPacketNearby(entityhuman, d0, d1, d2, d3, dimensionmanager, null, packet); // Retained for compatibility
2018-08-17 22:05:00 +00:00
+ }
+
+ public void sendPacketNearby(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, double d3, WorldServer world, Packet<?> packet) {
2019-05-14 02:20:58 +00:00
+ sendPacketNearby(entityhuman, d0, d1, d2, d3, world.worldProvider.getDimensionManager(), world, packet);
2018-08-17 22:05:00 +00:00
+ }
+
2018-08-26 18:11:49 +00:00
+ public void sendPacketNearby(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, double d3, DimensionManager dimensionmanager, @Nullable WorldServer world, Packet<?> packet) {
2018-08-17 22:05:00 +00: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 18:11:49 +00:00
+ EntityPlayer entityplayer = (EntityPlayer) entity;
2018-08-17 22:05:00 +00: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-05-14 02:20:58 +00:00
@@ -931,7 +948,7 @@ public abstract class PlayerList {
2018-08-17 22:05:00 +00:00
}
// CraftBukkit end
2018-08-26 18:11:49 +00:00
- if (entityplayer != entityhuman && entityplayer.dimension == dimensionmanager) {
+ if (entityplayer != entityhuman && (world != null || entityplayer.dimension == dimensionmanager)) { // Paper
2018-08-17 22:05:00 +00: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/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java
2019-08-15 02:47:38 +00:00
index 24f1a6442..0025e4ecf 100644
2018-08-17 22:05:00 +00:00
--- a/src/main/java/net/minecraft/server/WorldServer.java
+++ b/src/main/java/net/minecraft/server/WorldServer.java
2019-08-15 02:37:07 +00:00
@@ -1205,7 +1205,7 @@ public class WorldServer extends World {
2018-08-17 22:05:00 +00:00
}
// CraftBukkit end
2019-05-05 02:23:25 +00:00
this.globalEntityList.add(entitylightning);
- this.server.getPlayerList().sendPacketNearby((EntityHuman) null, entitylightning.locX, entitylightning.locY, entitylightning.locZ, 512.0D, this.worldProvider.getDimensionManager(), new PacketPlayOutSpawnEntityWeather(entitylightning));
+ this.server.getPlayerList().sendPacketNearby((EntityHuman) null, entitylightning.locX, entitylightning.locY, entitylightning.locZ, 512.0D, this, new PacketPlayOutSpawnEntityWeather(entitylightning)); // Paper - use world instead of dimension
}
@Override
2019-08-15 02:37:07 +00:00
@@ -1337,7 +1337,7 @@ public class WorldServer extends World {
2019-07-20 04:01:24 +00:00
BlockActionData blockactiondata = (BlockActionData) this.I.removeFirst();
2018-08-17 22:05:00 +00:00
2018-08-18 08:59:57 +00:00
if (this.a(blockactiondata)) {
2019-05-14 02:20:58 +00:00
- this.server.getPlayerList().sendPacketNearby((EntityHuman) null, (double) blockactiondata.a().getX(), (double) blockactiondata.a().getY(), (double) blockactiondata.a().getZ(), 64.0D, this.worldProvider.getDimensionManager(), new PacketPlayOutBlockAction(blockactiondata.a(), blockactiondata.b(), blockactiondata.c(), blockactiondata.d()));
2018-08-18 08:59:57 +00:00
+ 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-17 22:05:00 +00:00
}
2018-08-18 08:59:57 +00:00
}
2018-08-17 22:05:00 +00:00
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2019-08-15 02:47:38 +00:00
index 4ed4dfdde..80d75bf02 100644
2018-08-17 22:05:00 +00:00
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
2019-08-15 02:47:38 +00:00
@@ -2011,7 +2011,7 @@ public class CraftWorld implements World {
2018-08-17 22:05:00 +00:00
double z = loc.getZ();
2018-08-18 08:59:57 +00:00
PacketPlayOutCustomSoundEffect packet = new PacketPlayOutCustomSoundEffect(new MinecraftKey(sound), SoundCategory.valueOf(category.name()), new Vec3D(x, y, z), volume, pitch);
2019-05-14 02:20:58 +00:00
- world.getMinecraftServer().getPlayerList().sendPacketNearby(null, x, y, z, volume > 1.0F ? 16.0F * volume : 16.0D, this.world.getWorldProvider().getDimensionManager(), packet);
2018-08-17 22:05:00 +00:00
+ 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
}
2019-06-25 01:47:58 +00:00
private static Map<String, GameRules.GameRuleKey<?>> gamerules;
2018-08-17 22:05:00 +00:00
--
2019-06-16 10:15:21 +00:00
2.22.0
2018-08-17 22:05:00 +00:00