summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTravis Watkins <amaranth@ubuntu.com>2013-03-02 00:15:22 -0600
committerTravis Watkins <amaranth@ubuntu.com>2013-03-02 00:33:46 -0600
commitf6c574dd04fb6c39510a0428e7effafc37093028 (patch)
tree67ab521f6883ca92b2b462fc9a9351a76d50f9eb /src
parent993e19b3fbaef793914f047a9ca6e8c2800c5988 (diff)
downloadcraftbukkit-f6c574dd04fb6c39510a0428e7effafc37093028.tar
craftbukkit-f6c574dd04fb6c39510a0428e7effafc37093028.tar.gz
craftbukkit-f6c574dd04fb6c39510a0428e7effafc37093028.tar.lz
craftbukkit-f6c574dd04fb6c39510a0428e7effafc37093028.tar.xz
craftbukkit-f6c574dd04fb6c39510a0428e7effafc37093028.zip
Implement PlayerItemConsumeEvent. Adds BUKKIT-2349
Diffstat (limited to 'src')
-rw-r--r--src/main/java/net/minecraft/server/EntityHuman.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
index 7afa68ef..ce0715b5 100644
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
@@ -6,11 +6,13 @@ import java.util.List;
// CraftBukkit start
import org.bukkit.craftbukkit.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.entity.CraftItem;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityCombustByEntityEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
+import org.bukkit.event.player.PlayerItemConsumeEvent;
// CraftBukkit end
public abstract class EntityHuman extends EntityLiving implements ICommandListener {
@@ -246,6 +248,32 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen
if (this.f != null) {
this.c(this.f, 16);
int i = this.f.count;
+
+ // CraftBukkit start
+ org.bukkit.inventory.ItemStack craftItem = CraftItemStack.asBukkitCopy(this.f);
+ PlayerItemConsumeEvent event = new PlayerItemConsumeEvent((Player) this.getBukkitEntity(), craftItem);
+ world.getServer().getPluginManager().callEvent(event);
+
+ if (event.isCancelled()) {
+ // Update client
+ if (this instanceof EntityPlayer) {
+ ((EntityPlayer) this).playerConnection.sendPacket(new Packet103SetSlot((byte) 0, activeContainer.a((IInventory) this.inventory, this.inventory.itemInHandIndex).index, this.f));
+ }
+ return;
+ }
+
+ // Plugin modified the item, process it but don't remove it
+ if (!craftItem.equals(event.getItem())) {
+ CraftItemStack.asNMSCopy(event.getItem()).b(this.world, this);
+
+ // Update client
+ if (this instanceof EntityPlayer) {
+ ((EntityPlayer) this).playerConnection.sendPacket(new Packet103SetSlot((byte) 0, activeContainer.a((IInventory) this.inventory, this.inventory.itemInHandIndex).index, this.f));
+ }
+ return;
+ }
+ // CraftBukkit end
+
ItemStack itemstack = this.f.b(this.world, this);
if (itemstack != this.f || itemstack != null && itemstack.count != i) {