Archiviert
13
0

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.
Dieser Commit ist enthalten in:
ase34 2013-12-01 12:40:34 +01:00 committet von turt2live
Ursprung 971329c42b
Commit 87f6fa7bc9

Datei anzeigen

@ -514,6 +514,7 @@ public abstract class EntityHuman extends EntityLiving implements ICommandListen
} }
public EntityItem a(boolean flag) { 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); 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); this.world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) { 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; return null;
} }
// CraftBukkit end // CraftBukkit end