summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityArmorStand.patch
blob: c2691b1bd3fca992ee65e5f1a0721ff52779ad2f (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
--- a/net/minecraft/server/EntityArmorStand.java
+++ b/net/minecraft/server/EntityArmorStand.java
@@ -5,6 +5,15 @@
 import java.util.List;
 import javax.annotation.Nullable;
 
+// CraftBukkit start
+import org.bukkit.inventory.EquipmentSlot;
+import org.bukkit.craftbukkit.CraftEquipmentSlot;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.entity.ArmorStand;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.PlayerArmorStandManipulateEvent;
+// CraftBukkit end
+
 public class EntityArmorStand extends EntityLiving {
 
     private static final Vector3f bq = new Vector3f(0.0F, 0.0F, 0.0F);
@@ -364,6 +373,21 @@
         if (itemstack1.isEmpty() || (this.bA & 1 << enumitemslot.c() + 8) == 0) {
             if (!itemstack1.isEmpty() || (this.bA & 1 << enumitemslot.c() + 16) == 0) {
                 ItemStack itemstack2;
+                // CraftBukkit start
+                org.bukkit.inventory.ItemStack armorStandItem = CraftItemStack.asCraftMirror(itemstack1);
+                org.bukkit.inventory.ItemStack playerHeldItem = CraftItemStack.asCraftMirror(itemstack);
+
+                Player player = (Player) entityhuman.getBukkitEntity();
+                ArmorStand self = (ArmorStand) this.getBukkitEntity();
+
+                EquipmentSlot slot = CraftEquipmentSlot.getSlot(enumitemslot);
+                PlayerArmorStandManipulateEvent armorStandManipulateEvent = new PlayerArmorStandManipulateEvent(player,self,playerHeldItem,armorStandItem,slot);
+                this.world.getServer().getPluginManager().callEvent(armorStandManipulateEvent);
+
+                if (armorStandManipulateEvent.isCancelled()) {
+                    return;
+                }
+                // CraftBukkit end
 
                 if (entityhuman.abilities.canInstantlyBuild && itemstack1.isEmpty() && !itemstack.isEmpty()) {
                     itemstack2 = itemstack.cloneItemStack();
@@ -385,14 +409,19 @@
     }
 
     public boolean damageEntity(DamageSource damagesource, float f) {
+        // CraftBukkit start
+        if (org.bukkit.craftbukkit.event.CraftEventFactory.handleNonLivingEntityDamageEvent(this, damagesource, f)) {
+            return false;
+        }
+        // CraftBukkit end
         if (!this.world.isClientSide && !this.dead) {
             if (DamageSource.OUT_OF_WORLD.equals(damagesource)) {
-                this.die();
+                this.Q(); // CraftBukkit - this.die() -> this.Q()
                 return false;
             } else if (!this.isInvulnerable(damagesource) && !this.bz && !this.isMarker()) {
                 if (damagesource.isExplosion()) {
                     this.G();
-                    this.die();
+                    this.Q(); // CraftBukkit - this.die() -> this.Q()
                     return false;
                 } else if (DamageSource.FIRE.equals(damagesource)) {
                     if (this.isBurning()) {
@@ -421,7 +450,7 @@
                         } else if (damagesource.u()) {
                             this.I();
                             this.D();
-                            this.die();
+                            this.Q(); // CraftBukkit - this.die() -> this.Q()
                             return false;
                         } else {
                             long i = this.world.getTime();
@@ -432,7 +461,7 @@
                             } else {
                                 this.E();
                                 this.D();
-                                this.die();
+                                this.Q(); // CraftBukkit - this.die() -> this.Q()
                             }
 
                             return false;
@@ -460,19 +489,19 @@
         f1 -= f;
         if (f1 <= 0.5F) {
             this.G();
-            this.die();
+            this.Q(); // CraftBukkit - this.die() -> this.Q()
         } else {
             this.setHealth(f1);
         }
 
     }
 
-    private void E() {
-        Block.a(this.world, new BlockPosition(this), new ItemStack(Items.ARMOR_STAND));
+    private void E() { // PAIL: Rename dropLoot
+        drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(new ItemStack(Items.ARMOR_STAND))); // CraftBukkit - add to drops
         this.G();
     }
 
-    private void G() {
+    private void G() { // PAIL: Rename dropEquippedItems
         this.I();
 
         int i;
@@ -481,7 +510,7 @@
         for (i = 0; i < this.bx.size(); ++i) {
             itemstack = (ItemStack) this.bx.get(i);
             if (!itemstack.isEmpty()) {
-                Block.a(this.world, (new BlockPosition(this)).up(), itemstack);
+                drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack)); // CraftBukkit - add to drops
                 this.bx.set(i, ItemStack.a);
             }
         }
@@ -489,7 +518,7 @@
         for (i = 0; i < this.by.size(); ++i) {
             itemstack = (ItemStack) this.by.get(i);
             if (!itemstack.isEmpty()) {
-                Block.a(this.world, (new BlockPosition(this)).up(), itemstack);
+                drops.add(org.bukkit.craftbukkit.inventory.CraftItemStack.asBukkitCopy(itemstack)); // CraftBukkit - add to drops
                 this.by.set(i, ItemStack.a);
             }
         }
@@ -600,7 +629,8 @@
         return this.isSmall();
     }
 
-    public void Q() {
+    public void Q() { // PAIL: Rename killEntity (super)
+        org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDeathEvent(this, drops); // CraftBukkit - call event
         this.die();
     }