summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorZNickq <ZNickq@ZNickq-PC>2012-02-25 14:58:21 +0200
committerEvilSeph <evilseph@gmail.com>2012-02-29 14:45:18 -0500
commitbf01e93ab6d702a1134918de13d8d2087075620e (patch)
tree61696f410e74b39317d4874ca4d3a6dbfffc7bc2 /src
parentcd90cec48c5f13b1856350dd3675a9bb5b8171ed (diff)
downloadcraftbukkit-bf01e93ab6d702a1134918de13d8d2087075620e.tar
craftbukkit-bf01e93ab6d702a1134918de13d8d2087075620e.tar.gz
craftbukkit-bf01e93ab6d702a1134918de13d8d2087075620e.tar.lz
craftbukkit-bf01e93ab6d702a1134918de13d8d2087075620e.tar.xz
craftbukkit-bf01e93ab6d702a1134918de13d8d2087075620e.zip
Added EntityTargetEvent for Experience Orbs, happens when it starts moving towards a human entity! Addresses BUKKIT-820
Diffstat (limited to 'src')
-rw-r--r--src/main/java/net/minecraft/server/EntityExperienceOrb.java28
-rw-r--r--src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java6
2 files changed, 23 insertions, 11 deletions
diff --git a/src/main/java/net/minecraft/server/EntityExperienceOrb.java b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
index 26e2204b..ec80a9a4 100644
--- a/src/main/java/net/minecraft/server/EntityExperienceOrb.java
+++ b/src/main/java/net/minecraft/server/EntityExperienceOrb.java
@@ -56,17 +56,23 @@ public class EntityExperienceOrb extends Entity {
EntityHuman entityhuman = this.world.findNearbyPlayer(this, d0);
if (entityhuman != null) {
- double d1 = (entityhuman.locX - this.locX) / d0;
- double d2 = (entityhuman.locY + (double) entityhuman.y() - this.locY) / d0;
- double d3 = (entityhuman.locZ - this.locZ) / d0;
- double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3);
- double d5 = 1.0D - d4;
-
- if (d5 > 0.0D) {
- d5 *= d5;
- this.motX += d1 / d4 * d5 * 0.1D;
- this.motY += d2 / d4 * d5 * 0.1D;
- this.motZ += d3 / d4 * d5 * 0.1D;
+ // CraftBukkit start
+ org.bukkit.event.entity.EntityTargetEvent event = CraftEventFactory.callEntityTargetEvent(this, entityhuman, org.bukkit.event.entity.EntityTargetEvent.TargetReason.CLOSEST_PLAYER);
+ Entity target = event.getTarget() == null ? null : ((org.bukkit.craftbukkit.entity.CraftEntity) event.getTarget()).getHandle();
+
+ if (!event.isCancelled() && target != null) {
+ double d1 = (target.locX - this.locX) / d0;
+ double d2 = (target.locY + (double) target.y() - this.locY) / d0;
+ double d3 = (target.locZ - this.locZ) / d0;
+ double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3);
+ double d5 = 1.0D - d4;
+ if (d5 > 0.0D) {
+ d5 *= d5;
+ this.motX += d1 / d4 * d5 * 0.1D;
+ this.motY += d2 / d4 * d5 * 0.1D;
+ this.motZ += d3 / d4 * d5 * 0.1D;
+ }
+ // CraftBukkit end
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index 80f4e3db..13105652 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -407,4 +407,10 @@ public class CraftEventFactory {
creeper.getBukkitEntity().getServer().getPluginManager().callEvent(event);
return event;
}
+
+ public static EntityTargetEvent callEntityTargetEvent(Entity entity, Entity target, EntityTargetEvent.TargetReason reason) {
+ EntityTargetEvent event = new EntityTargetEvent(entity.getBukkitEntity(), target.getBukkitEntity(), reason);
+ entity.getBukkitEntity().getServer().getPluginManager().callEvent(event);
+ return event;
+ }
}