summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityArrow.patch
blob: fcd2199376423694b62225cc2d56adc94b03d96d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
--- ../work/decompile-8eb82bde//net/minecraft/server/EntityArrow.java	2014-11-28 17:43:43.061707436 +0000
+++ src/main/java/net/minecraft/server/EntityArrow.java	2014-11-28 17:38:20.000000000 +0000
@@ -2,6 +2,12 @@
 
 import java.util.List;
 
+// CraftBukkit start
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
+import org.bukkit.event.player.PlayerPickupItemEvent;
+// CraftBukkit end
+
 public class EntityArrow extends Entity implements IProjectile {
 
     private int d = -1;
@@ -35,6 +41,7 @@
         super(world);
         this.j = 10.0D;
         this.shooter = entityliving;
+        this.projectileSource = (LivingEntity) entityliving.getBukkitEntity(); // CraftBukkit
         if (entityliving instanceof EntityHuman) {
             this.fromPlayer = 1;
         }
@@ -62,6 +69,7 @@
         super(world);
         this.j = 10.0D;
         this.shooter = entityliving;
+        this.projectileSource = (LivingEntity) entityliving.getBukkitEntity(); // CraftBukkit
         if (entityliving instanceof EntityHuman) {
             this.fromPlayer = 1;
         }
@@ -175,7 +183,7 @@
                     MovingObjectPosition movingobjectposition1 = axisalignedbb1.a(vec3d, vec3d1);
 
                     if (movingobjectposition1 != null) {
-                        double d1 = vec3d.f(movingobjectposition1.pos);
+                        double d1 = vec3d.distanceSquared(movingobjectposition1.pos); // CraftBukkit
 
                         if (d1 < d0 || d0 == 0.0D) {
                             entity = entity1;
@@ -202,6 +210,8 @@
             float f4;
 
             if (movingobjectposition != null) {
+                org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this); // CraftBukkit - Call event
+                
                 if (movingobjectposition.entity != null) {
                     f2 = MathHelper.sqrt(this.motX * this.motX + this.motY * this.motY + this.motZ * this.motZ);
                     int k = MathHelper.f((double) f2 * this.damage);
@@ -217,12 +227,20 @@
                     } else {
                         damagesource = DamageSource.arrow(this, this.shooter);
                     }
+                    
+                    // CraftBukkit start - Moved damage call
+                    if (movingobjectposition.entity.damageEntity(damagesource, (float) k)) {
+                    if (this.isBurning() && !(movingobjectposition.entity instanceof EntityEnderman) && (!(movingobjectposition.entity instanceof EntityPlayer) || !(this.shooter instanceof EntityPlayer) || this.world.pvpMode)) { // CraftBukkit - abide by pvp setting if destination is a player
+                        EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), 5);
+                        org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
 
-                    if (this.isBurning() && !(movingobjectposition.entity instanceof EntityEnderman)) {
-                        movingobjectposition.entity.setOnFire(5);
+                        if (!combustEvent.isCancelled()) {
+                            movingobjectposition.entity.setOnFire(combustEvent.getDuration());
+                        }
+                        // CraftBukkit end
                     }
 
-                    if (movingobjectposition.entity.damageEntity(damagesource, (float) k)) {
+                    // if (movingobjectposition.entity.damageEntity(damagesource, (float) k)) { // CraftBukkit - moved up
                         if (movingobjectposition.entity instanceof EntityLiving) {
                             EntityLiving entityliving = (EntityLiving) movingobjectposition.entity;
 
@@ -382,6 +400,21 @@
 
     public void d(EntityHuman entityhuman) {
         if (!this.world.isStatic && this.inGround && this.shake <= 0) {
+            // CraftBukkit start
+            ItemStack itemstack = new ItemStack(Items.ARROW);
+            if (this.fromPlayer == 1 && entityhuman.inventory.canHold(itemstack) > 0) {
+                EntityItem item = new EntityItem(this.world, this.locX, this.locY, this.locZ, itemstack);
+
+                PlayerPickupItemEvent event = new PlayerPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), new org.bukkit.craftbukkit.entity.CraftItem(this.world.getServer(), this, item), 0);
+                // event.setCancelled(!entityhuman.canPickUpLoot); TODO
+                this.world.getServer().getPluginManager().callEvent(event);
+
+                if (event.isCancelled()) {
+                    return;
+                }
+            }
+            // CraftBukkit end
+        
             boolean flag = this.fromPlayer == 1 || this.fromPlayer == 2 && entityhuman.abilities.canInstantlyBuild;
 
             if (this.fromPlayer == 1 && !entityhuman.inventory.pickup(new ItemStack(Items.ARROW, 1))) {
@@ -433,4 +466,10 @@
 
         return (b0 & 1) != 0;
     }
+
+    // CraftBukkit start
+    public boolean isInGround() {
+        return inGround;
+    }
+    // CraftBukkit end
 }