Use correct itemstack for dispenser behavior chaining. Fixes BUKKIT-2886

When an event changes the item to be dispensed we check to see if the new
item has special behavior for dispensing and if so pass it on to that
behavior handler. However, we are actually checking the old itemstack and
passing the new itemstack so this check fails.
This commit is contained in:
James Clarke 2012-11-08 00:26:35 +00:00 committed by Travis Watkins
parent 293474d99b
commit a575e6b075
8 changed files with 27 additions and 29 deletions

View file

@ -56,9 +56,10 @@ public class DispenseBehaviorBoat extends DispenseBehaviorItem {
if (!event.getItem().equals(bukkitItem)) {
itemstack.count++;
// Chain to handler for new item
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(itemstack.getItem());
ItemStack eventStack = CraftItemStack.createNMSItemStack(event.getItem());
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem());
if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) {
idispensebehavior.a(isourceblock, CraftItemStack.createNMSItemStack(event.getItem()));
idispensebehavior.a(isourceblock, eventStack);
return itemstack;
}
}

View file

@ -51,9 +51,10 @@ public class DispenseBehaviorEmptyBucket extends DispenseBehaviorItem {
if (!event.getItem().equals(bukkitItem)) {
// Chain to handler for new item
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(itemstack.getItem());
ItemStack eventStack = CraftItemStack.createNMSItemStack(event.getItem());
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem());
if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) {
idispensebehavior.a(isourceblock, CraftItemStack.createNMSItemStack(event.getItem()));
idispensebehavior.a(isourceblock, eventStack);
return itemstack;
}
}

View file

@ -42,9 +42,10 @@ public class DispenseBehaviorFilledBucket extends DispenseBehaviorItem {
if (!event.getItem().equals(bukkitItem)) {
// Chain to handler for new item
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(itemstack.getItem());
ItemStack eventStack = CraftItemStack.createNMSItemStack(event.getItem());
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem());
if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) {
idispensebehavior.a(isourceblock, CraftItemStack.createNMSItemStack(event.getItem()));
idispensebehavior.a(isourceblock, eventStack);
return itemstack;
}
}

View file

@ -45,9 +45,10 @@ public class DispenseBehaviorFireball extends DispenseBehaviorItem {
if (!event.getItem().equals(bukkitItem)) {
itemstack.count++;
// Chain to handler for new item
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(itemstack.getItem());
ItemStack eventStack = CraftItemStack.createNMSItemStack(event.getItem());
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem());
if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) {
idispensebehavior.a(isourceblock, CraftItemStack.createNMSItemStack(event.getItem()));
idispensebehavior.a(isourceblock, eventStack);
return itemstack;
}
}

View file

@ -65,30 +65,21 @@ public class DispenseBehaviorItem implements IDispenseBehavior {
entityitem.motX = event.getVelocity().getX();
entityitem.motY = event.getVelocity().getY();
entityitem.motZ = event.getVelocity().getZ();
// CraftBukkit end
world.addEntity(entityitem);
// CraftBukkit start
if (!event.getItem().equals(bukkitItem)) {
if (event.getItem().getTypeId() == Item.BUCKET.id) {
int x = isourceblock.getBlockX() + enumfacing.c();
int y = isourceblock.getBlockY();
int z = isourceblock.getBlockZ() + enumfacing.e();
Material material = world.getMaterial(x, y, z);
int data = world.getData(x, y, z);
if (!(Material.WATER.equals(material) || Material.LAVA.equals(material)) || data != 0) {
return true;
}
}
// Chain to handler for new item
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(itemstack.getItem());
ItemStack eventStack = CraftItemStack.createNMSItemStack(event.getItem());
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem());
if (idispensebehavior != IDispenseBehavior.a && idispensebehavior.getClass() != DispenseBehaviorItem.class) {
idispensebehavior.a(isourceblock, CraftItemStack.createNMSItemStack(event.getItem()));
idispensebehavior.a(isourceblock, eventStack);
} else {
world.addEntity(entityitem);
}
return false;
}
world.addEntity(entityitem);
return true;
// CraftBukkit end
}

View file

@ -56,9 +56,10 @@ public class DispenseBehaviorMinecart extends DispenseBehaviorItem {
if (!event.getItem().equals(bukkitItem)) {
itemstack.count++;
// Chain to handler for new item
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(itemstack.getItem());
ItemStack eventStack = CraftItemStack.createNMSItemStack(event.getItem());
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem());
if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) {
idispensebehavior.a(isourceblock, CraftItemStack.createNMSItemStack(event.getItem()));
idispensebehavior.a(isourceblock, eventStack);
return itemstack;
}
}

View file

@ -38,9 +38,10 @@ public class DispenseBehaviorMonsterEgg extends DispenseBehaviorItem {
if (!event.getItem().equals(bukkitItem)) {
itemstack.count++;
// Chain to handler for new item
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(itemstack.getItem());
ItemStack eventStack = CraftItemStack.createNMSItemStack(event.getItem());
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem());
if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) {
idispensebehavior.a(isourceblock, CraftItemStack.createNMSItemStack(event.getItem()));
idispensebehavior.a(isourceblock, eventStack);
return itemstack;
}
}

View file

@ -33,7 +33,8 @@ public abstract class DispenseBehaviorProjectile extends DispenseBehaviorItem {
if (!event.getItem().equals(bukkitItem)) {
itemstack.count++;
// Chain to handler for new item
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(itemstack.getItem());
ItemStack eventStack = CraftItemStack.createNMSItemStack(event.getItem());
IDispenseBehavior idispensebehavior = (IDispenseBehavior) BlockDispenser.a.a(eventStack.getItem());
if (idispensebehavior != IDispenseBehavior.a && idispensebehavior != this) {
idispensebehavior.a(isourceblock, CraftItemStack.createNMSItemStack(event.getItem()));
return itemstack;