diff options
author | FearThe1337 <admin@fearthe1337.com> | 2015-02-15 12:24:14 +1100 |
---|---|---|
committer | md_5 <git@md-5.net> | 2015-02-15 12:24:14 +1100 |
commit | 116514c162035ff7fd99e97fe70b7af9f055ec6d (patch) | |
tree | a828a7c4c250c63adff1402c3e17992ce1ada43a | |
parent | 9648edfa6136394153d524fa89c347d86f455641 (diff) | |
download | craftbukkit-116514c162035ff7fd99e97fe70b7af9f055ec6d.tar craftbukkit-116514c162035ff7fd99e97fe70b7af9f055ec6d.tar.gz craftbukkit-116514c162035ff7fd99e97fe70b7af9f055ec6d.tar.lz craftbukkit-116514c162035ff7fd99e97fe70b7af9f055ec6d.tar.xz craftbukkit-116514c162035ff7fd99e97fe70b7af9f055ec6d.zip |
Implement armor stand event.
-rw-r--r-- | nms-patches/EntityArmorStand.patch | 47 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java | 35 |
2 files changed, 78 insertions, 4 deletions
diff --git a/nms-patches/EntityArmorStand.patch b/nms-patches/EntityArmorStand.patch index 07de6e30..622528ba 100644 --- a/nms-patches/EntityArmorStand.patch +++ b/nms-patches/EntityArmorStand.patch @@ -1,6 +1,45 @@ ---- ../work/decompile-8eb82bde/net/minecraft/server/EntityArmorStand.java 2015-02-01 18:12:22.718390345 +1100 -+++ src/main/java/net/minecraft/server/EntityArmorStand.java 2015-02-01 18:12:22.718390345 +1100 -@@ -343,6 +343,11 @@ +--- ../work/decompile-8eb82bde/net/minecraft/server/EntityArmorStand.java 2015-02-15 12:22:56.729511128 +1100 ++++ src/main/java/net/minecraft/server/EntityArmorStand.java 2015-02-15 12:22:56.729511128 +1100 +@@ -2,6 +2,15 @@ + + import java.util.List; + ++// CraftBukkit start ++import org.bukkit.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 a = new Vector3f(0.0F, 0.0F, 0.0F); +@@ -323,6 +332,22 @@ + ItemStack itemstack1 = entityhuman.inventory.getItem(j); + ItemStack itemstack2; + ++ // CraftBukkit start ++ org.bukkit.inventory.ItemStack armorStandItem = CraftItemStack.asCraftMirror(itemstack); ++ org.bukkit.inventory.ItemStack playerHeldItem = CraftItemStack.asCraftMirror(itemstack1); ++ ++ Player player = (Player) entityhuman.getBukkitEntity(); ++ ArmorStand self = (ArmorStand) this.getBukkitEntity(); ++ ++ EquipmentSlot slot = CraftEquipmentSlot.getSlot(i); ++ 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 && (itemstack == null || itemstack.getItem() == Item.getItemOf(Blocks.AIR)) && itemstack1 != null) { + itemstack2 = itemstack1.cloneItemStack(); + itemstack2.count = 1; +@@ -343,6 +368,11 @@ } public boolean damageEntity(DamageSource damagesource, float f) { @@ -12,7 +51,7 @@ if (!this.world.isStatic && !this.h) { if (DamageSource.OUT_OF_WORLD.equals(damagesource)) { this.die(); -@@ -542,6 +547,8 @@ +@@ -542,6 +572,8 @@ } this.datawatcher.watch(10, Byte.valueOf(b0)); diff --git a/src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java b/src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java new file mode 100644 index 00000000..a33f446f --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java @@ -0,0 +1,35 @@ +package org.bukkit.craftbukkit; + +import org.bukkit.inventory.EquipmentSlot; + +public class CraftEquipmentSlot { + + private static final int[] slots = new int[EquipmentSlot.values().length]; + private static final EquipmentSlot[] enums = new EquipmentSlot[EquipmentSlot.values().length]; + + static { + set(EquipmentSlot.HAND, 0); + set(EquipmentSlot.FEET, 1); + set(EquipmentSlot.LEGS, 2); + set(EquipmentSlot.CHEST, 3); + set(EquipmentSlot.HEAD, 4); + } + + private static void set(EquipmentSlot type, int value) { + slots[type.ordinal()] = value; + if (value < enums.length) { + enums[value] = type; + } + } + + public static EquipmentSlot getSlot(int magic) { + if (magic > 0 && magic < enums.length) { + return enums[magic]; + } + return null; + } + + public static int getSlotIndex(EquipmentSlot slot) { + return slots[slot.ordinal()]; + } +} |