summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Broes <erikbroes@grum.nl>2011-06-26 10:53:45 +0200
committerEvilSeph <evilseph@unaligned.org>2011-06-26 05:04:14 -0400
commitf0402d9d6c683a95f40ebb4e7634e3d814bbdf21 (patch)
treeefcf6c3c531e303fce14d7d5fd111f1054c98768
parentb4c0492b15e98775afc4e8d99ebcc439d2c565b9 (diff)
downloadcraftbukkit-f0402d9d6c683a95f40ebb4e7634e3d814bbdf21.tar
craftbukkit-f0402d9d6c683a95f40ebb4e7634e3d814bbdf21.tar.gz
craftbukkit-f0402d9d6c683a95f40ebb4e7634e3d814bbdf21.tar.lz
craftbukkit-f0402d9d6c683a95f40ebb4e7634e3d814bbdf21.tar.xz
craftbukkit-f0402d9d6c683a95f40ebb4e7634e3d814bbdf21.zip
Fixed cancelling the PlayerPickup event, getAmount(), item duping issue.
-rw-r--r--src/main/java/net/minecraft/server/EntityItem.java14
-rw-r--r--src/main/java/net/minecraft/server/InventoryPlayer.java16
2 files changed, 25 insertions, 5 deletions
diff --git a/src/main/java/net/minecraft/server/EntityItem.java b/src/main/java/net/minecraft/server/EntityItem.java
index 529dd327..f956cd4c 100644
--- a/src/main/java/net/minecraft/server/EntityItem.java
+++ b/src/main/java/net/minecraft/server/EntityItem.java
@@ -127,16 +127,20 @@ public class EntityItem extends Entity {
int i = this.itemStack.count;
// CraftBukkit start
- if (this.pickupDelay <= 0 && entityhuman.inventory.canHold(this.itemStack)) { // <-- == to <=
- Player player = (Player) entityhuman.getBukkitEntity();
- PlayerPickupItemEvent event = new PlayerPickupItemEvent(player, (org.bukkit.entity.Item) this.getBukkitEntity());
- world.getServer().getPluginManager().callEvent(event);
+ if (this.pickupDelay <= 0 && entityhuman.inventory.canPickup(this.itemStack) > 0) {
+ PlayerPickupItemEvent event = new PlayerPickupItemEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), (org.bukkit.entity.Item) this.getBukkitEntity());
+ this.world.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return;
}
- // CraftBukkit end
+ // Possibly < 0; fix here so we do not have to modify code below
+ this.pickupDelay = 0;
+ }
+ // CraftBukkit end
+
+ if (this.pickupDelay == 0 && entityhuman.inventory.canHold(this.itemStack)) {
if (this.itemStack.id == Block.LOG.id) {
entityhuman.a((Statistic) AchievementList.g);
}
diff --git a/src/main/java/net/minecraft/server/InventoryPlayer.java b/src/main/java/net/minecraft/server/InventoryPlayer.java
index eb30c3aa..d6199001 100644
--- a/src/main/java/net/minecraft/server/InventoryPlayer.java
+++ b/src/main/java/net/minecraft/server/InventoryPlayer.java
@@ -51,6 +51,22 @@ public class InventoryPlayer implements IInventory {
return -1;
}
+ // CraftBukkit start - watch method above! :D
+ public int canPickup(ItemStack itemstack) {
+ int remains = itemstack.count;
+ for (int i = 0; i < this.items.length; ++i) {
+ if (this.items[i] == null) return itemstack.count;
+
+ // Taken from d(ItemStack)I
+ if (this.items[i] != null && this.items[i].id == itemstack.id && this.items[i].c() && this.items[i].count < this.items[i].b() && this.items[i].count < this.getMaxStackSize() && (!this.items[i].e() || this.items[i].getData() == itemstack.getData())) {
+ remains -= (this.items[i].b() < this.getMaxStackSize() ? this.items[i].b() : this.getMaxStackSize()) - this.items[i].count;
+ }
+ if (remains <= 0) return itemstack.count;
+ }
+ return itemstack.count - remains;
+ }
+ // CraftBukkit end
+
private int k() {
for (int i = 0; i < this.items.length; ++i) {
if (this.items[i] == null) {