From 116514c162035ff7fd99e97fe70b7af9f055ec6d Mon Sep 17 00:00:00 2001 From: FearThe1337 Date: Sun, 15 Feb 2015 12:24:14 +1100 Subject: [PATCH] Implement armor stand event. --- nms-patches/EntityArmorStand.patch | 47 +++++++++++++++++-- .../craftbukkit/CraftEquipmentSlot.java | 35 ++++++++++++++ 2 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/bukkit/craftbukkit/CraftEquipmentSlot.java diff --git a/nms-patches/EntityArmorStand.patch b/nms-patches/EntityArmorStand.patch index 07de6e30fb..622528ba6f 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 0000000000..a33f446fc5 --- /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()]; + } +}