summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityArrow.patch
blob: ef051dd026b92b6110b2760ab0dc24d01576424d (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
--- a/net/minecraft/server/EntityArrow.java
+++ b/net/minecraft/server/EntityArrow.java
@@ -5,6 +5,12 @@
 import java.util.List;
 import javax.annotation.Nullable;
 
+// CraftBukkit start
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.event.entity.EntityCombustByEntityEvent;
+import org.bukkit.event.player.PlayerPickupArrowEvent;
+// CraftBukkit end
+
 public abstract class EntityArrow extends Entity implements IProjectile {
 
     private static final Predicate<Entity> f = Predicates.and(new Predicate[] { IEntitySelector.e, IEntitySelector.a, new Predicate() {
@@ -50,6 +56,7 @@
     public EntityArrow(World world, EntityLiving entityliving) {
         this(world, entityliving.locX, entityliving.locY + (double) entityliving.getHeadHeight() - 0.10000000149011612D, entityliving.locZ);
         this.shooter = entityliving;
+        this.projectileSource = (LivingEntity) entityliving.getBukkitEntity(); // CraftBukkit
         if (entityliving instanceof EntityHuman) {
             this.fromPlayer = EntityArrow.PickupStatus.ALLOWED;
         }
@@ -236,7 +243,7 @@
 
     protected void a(MovingObjectPosition movingobjectposition) {
         Entity entity = movingobjectposition.entity;
-
+        org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(this); // CraftBukkit - Call event
         if (entity != null) {
             float f = MathHelper.sqrt(this.motX * this.motX + this.motY * this.motY + this.motZ * this.motZ);
             int i = MathHelper.f((double) f * this.damage);
@@ -254,7 +261,13 @@
             }
 
             if (this.isBurning() && !(entity instanceof EntityEnderman)) {
-                entity.setOnFire(5);
+                // CraftBukkit start
+                EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), entity.getBukkitEntity(), 5);
+                org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);
+                if (!combustEvent.isCancelled()) {
+                    entity.setOnFire(combustEvent.getDuration());
+                }
+                // CraftBukkit end
             }
 
             if (entity.damageEntity(damagesource, (float) i)) {
@@ -410,6 +423,20 @@
 
     public void d(EntityHuman entityhuman) {
         if (!this.world.isClientSide && this.inGround && this.shake <= 0) {
+            // CraftBukkit start
+            ItemStack itemstack = new ItemStack(Items.ARROW);
+            if (this.fromPlayer == PickupStatus.ALLOWED && entityhuman.inventory.canHold(itemstack) > 0) {
+                EntityItem item = new EntityItem(this.world, this.locX, this.locY, this.locZ, itemstack);
+
+                PlayerPickupArrowEvent event = new PlayerPickupArrowEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), new org.bukkit.craftbukkit.entity.CraftItem(this.world.getServer(), this, item), (org.bukkit.entity.Arrow) this.getBukkitEntity());
+                // event.setCancelled(!entityhuman.canPickUpLoot); TODO
+                this.world.getServer().getPluginManager().callEvent(event);
+
+                if (event.isCancelled()) {
+                    return;
+                }
+            }
+            // CraftBukkit end
             boolean flag = this.fromPlayer == EntityArrow.PickupStatus.ALLOWED || this.fromPlayer == EntityArrow.PickupStatus.CREATIVE_ONLY && entityhuman.abilities.canInstantlyBuild;
 
             if (this.fromPlayer == EntityArrow.PickupStatus.ALLOWED && !entityhuman.inventory.pickup(this.j())) {
@@ -468,6 +495,12 @@
         return (b0 & 1) != 0;
     }
 
+    // CraftBukkit start
+    public boolean isInGround() {
+        return inGround;
+    }
+    // CraftBukkit end
+
     public static enum PickupStatus {
 
         DISALLOWED, ALLOWED, CREATIVE_ONLY;