summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authormbax <matt@phozop.net>2012-09-10 20:42:26 -0400
committerEvilSeph <evilseph@gmail.com>2012-09-14 01:53:42 -0400
commit4b1f6aff3f2a4a85bea4cca2e92e8164187bfb7a (patch)
tree01103ed4bfb89afc609488e33f3b0c6574f5dc80 /src/main
parent349cb0bba61c82e1adc6afc32c1ff8efc375c68a (diff)
downloadcraftbukkit-4b1f6aff3f2a4a85bea4cca2e92e8164187bfb7a.tar
craftbukkit-4b1f6aff3f2a4a85bea4cca2e92e8164187bfb7a.tar.gz
craftbukkit-4b1f6aff3f2a4a85bea4cca2e92e8164187bfb7a.tar.lz
craftbukkit-4b1f6aff3f2a4a85bea4cca2e92e8164187bfb7a.tar.xz
craftbukkit-4b1f6aff3f2a4a85bea4cca2e92e8164187bfb7a.zip
[Bleeding] Check visibility API for sounds. Fixes BUKKIT-2210
This implementation of a visibility API check for sounds was created by adding extra methods carrying the source entity in WorldManager and ServerConfigurationManagerAbstract and adding a test for canSee in the SCMA sendPacketNearby method. This approach involves no logic copying, just method addition. I opted to cast to WorldManager as: 1) IWorldAccess is not in CraftBukkit at the moment 2) There is no other IWorldAccess implemented in CraftBukkit, nor is there likely to be one soon. If that day comes, easy fix.
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/net/minecraft/server/ServerConfigurationManagerAbstract.java15
-rw-r--r--src/main/java/net/minecraft/server/World.java2
-rw-r--r--src/main/java/net/minecraft/server/WorldManager.java6
3 files changed, 22 insertions, 1 deletions
diff --git a/src/main/java/net/minecraft/server/ServerConfigurationManagerAbstract.java b/src/main/java/net/minecraft/server/ServerConfigurationManagerAbstract.java
index aa9c317a..c3aa44a1 100644
--- a/src/main/java/net/minecraft/server/ServerConfigurationManagerAbstract.java
+++ b/src/main/java/net/minecraft/server/ServerConfigurationManagerAbstract.java
@@ -601,12 +601,27 @@ public abstract class ServerConfigurationManagerAbstract {
this.sendPacketNearby((EntityHuman) null, d0, d1, d2, d3, i, packet);
}
+ // CraftBukkit start - Add support for entity who caused the packet
public void sendPacketNearby(EntityHuman entityhuman, double d0, double d1, double d2, double d3, int i, Packet packet) {
+ this.sendPacketNearby(entityhuman, d0, d1, d2, d3, i, packet, null);
+ }
+
+ public void sendPacketNearby(double d0, double d1, double d2, double d3, int i, Packet packet, Entity sourceentity) {
+ this.sendPacketNearby(null, d0, d1, d2, d3, i, packet, sourceentity);
+ }
+ // CraftBukkit end
+
+ public void sendPacketNearby(EntityHuman entityhuman, double d0, double d1, double d2, double d3, int i, Packet packet, Entity sourceentity) { // CraftBukkit - added sourceentity
Iterator iterator = this.players.iterator();
while (iterator.hasNext()) {
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
+ // CraftBukkit start - Test if player receiving packet can see the source of the packet
+ if (sourceentity != null && sourceentity instanceof EntityPlayer && !entityplayer.getBukkitEntity().canSee(((EntityPlayer)sourceentity).getBukkitEntity())) {
+ continue;
+ }
+ // CraftBukkit end
if (entityplayer != entityhuman && entityplayer.dimension == i) {
double d4 = d0 - entityplayer.locX;
double d5 = d1 - entityplayer.locY;
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index cee4d42c..7b97740c 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -766,7 +766,7 @@ public abstract class World implements IBlockAccess {
while (iterator.hasNext()) {
IWorldAccess iworldaccess = (IWorldAccess) iterator.next();
- iworldaccess.a(s, entity.locX, entity.locY - (double) entity.height, entity.locZ, f, f1);
+ ((WorldManager) iworldaccess).a(s, entity.locX, entity.locY - (double) entity.height, entity.locZ, f, f1, entity); // CraftBukkit - Cast to WorldManager, add sourceentity
}
}
}
diff --git a/src/main/java/net/minecraft/server/WorldManager.java b/src/main/java/net/minecraft/server/WorldManager.java
index e70e5abb..ba67e77d 100644
--- a/src/main/java/net/minecraft/server/WorldManager.java
+++ b/src/main/java/net/minecraft/server/WorldManager.java
@@ -22,6 +22,12 @@ public class WorldManager implements IWorldAccess {
this.world.getTracker().untrackEntity(entity);
}
+ // CraftBukkit start - Add source entity for a sound.
+ public void a(String s, double d0, double d1, double d2, float f, float f1, Entity sourceentity) {
+ this.server.getServerConfigurationManager().sendPacketNearby(d0, d1, d2, f > 1.0F ? (double) (16.0F * f) : 16.0D, this.world.dimension, new Packet62NamedSoundEffect(s, d0, d1, d2, f, f1), sourceentity);
+ }
+ // CraftBukkit end
+
public void a(String s, double d0, double d1, double d2, float f, float f1) {
// CraftBukkit - this.world.dimension
this.server.getServerConfigurationManager().sendPacketNearby(d0, d1, d2, f > 1.0F ? (double) (16.0F * f) : 16.0D, this.world.dimension, new Packet62NamedSoundEffect(s, d0, d1, d2, f, f1));