summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server
diff options
context:
space:
mode:
authorase34 <asehrm34@gmail.com>2013-12-01 12:40:34 +0100
committerturt2live <travpc@gmail.com>2014-08-04 12:27:50 -0600
commit87f6fa7bc94c3647a6e1651369f2a4787fbd9dab (patch)
tree0de34af5f4d5b91e33a4a6a8b6e228f84c225028 /src/main/java/net/minecraft/server
parent971329c42b2a4242da1f5789ce6759c810779a6f (diff)
downloadcraftbukkit-87f6fa7bc94c3647a6e1651369f2a4787fbd9dab.tar
craftbukkit-87f6fa7bc94c3647a6e1651369f2a4787fbd9dab.tar.gz
craftbukkit-87f6fa7bc94c3647a6e1651369f2a4787fbd9dab.tar.lz
craftbukkit-87f6fa7bc94c3647a6e1651369f2a4787fbd9dab.tar.xz
craftbukkit-87f6fa7bc94c3647a6e1651369f2a4787fbd9dab.zip
Fix cancelling PlayerDropItemEvent. Fixes BUKKIT-3313
Up until this commit the PlayerDropItemEvent, if cancelled, would return items to the first available slot in the inventory - which is clearly undesirable as a player and plugin author to deal with. This commit changes that by ensuring that the item is returned to where it came from in the player's inventory. This still supports modifying the drop from the player and will default to "first available slot" if the item has changed since the event was fired. Other remaining behaviour of the event is still in tact and has not been modified.
Diffstat (limited to 'src/main/java/net/minecraft/server')
-rw-r--r--src/main/java/net/minecraft/server/EntityHuman.java14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
index 03485fea..331dbac1 100644
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
@@ -514,6 +514,7 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen
}
public EntityItem a(boolean flag) {
+ // Called only when dropped by Q or CTRL-Q
return this.a(this.inventory.splitStack(this.inventory.itemInHandIndex, flag && this.inventory.getItemInHand() != null ? this.inventory.getItemInHand().count : 1), false, true);
}
@@ -565,7 +566,18 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen
this.world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
- player.getInventory().addItem(drop.getItemStack());
+ org.bukkit.inventory.ItemStack cur = player.getInventory().getItemInHand();
+ if (flag1 && (cur == null || cur.getAmount() == 0)) {
+ // The complete stack was dropped
+ player.getInventory().setItemInHand(drop.getItemStack());
+ } else if (flag1 && cur.isSimilar(drop.getItemStack()) && drop.getItemStack().getAmount() == 1) {
+ // Only one item is dropped
+ cur.setAmount(cur.getAmount() + 1);
+ player.getInventory().setItemInHand(cur);
+ } else {
+ // Fallback
+ player.getInventory().addItem(drop.getItemStack());
+ }
return null;
}
// CraftBukkit end