SPIGOT-3143: Don't decrease item stack size if VehicleCreateEvent is cancelled

This commit is contained in:
BlackHole 2017-03-21 23:03:20 +01:00 committed by md_5
parent 257d6cd04f
commit cf05cccd1b
3 changed files with 22 additions and 2 deletions

View File

@ -498,8 +498,9 @@
entityboat.setType(this.c);
entityboat.yaw = enumdirection.l();
world.addEntity(entityboat);
- world.addEntity(entityboat);
- itemstack.subtract(1);
+ if (!world.addEntity(entityboat)) itemstack.add(1); // CraftBukkit
+ // itemstack.subtract(1); // CraftBukkit - handled during event processing
return itemstack;
}

View File

@ -14,3 +14,12 @@
Block block = world.getType(movingobjectposition.a()).getBlock();
boolean flag1 = block == Blocks.WATER || block == Blocks.FLOWING_WATER;
EntityBoat entityboat = new EntityBoat(world, movingobjectposition.pos.x, flag1 ? movingobjectposition.pos.y - 0.12D : movingobjectposition.pos.y, movingobjectposition.pos.z);
@@ -66,7 +73,7 @@
return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack);
} else {
if (!world.isClientSide) {
- world.addEntity(entityboat);
+ if (!world.addEntity(entityboat)) return new InteractionResultWrapper(EnumInteractionResult.PASS, itemstack); // CraftBukkit
}
if (!entityhuman.abilities.canInstantlyBuild) {

View File

@ -50,10 +50,20 @@
entityminecartabstract.setCustomName(itemstack.getName());
}
world.addEntity(entityminecartabstract);
- world.addEntity(entityminecartabstract);
- itemstack.subtract(1);
+ if (!world.addEntity(entityminecartabstract)) itemstack.add(1);
+ // itemstack.subtract(1); // CraftBukkit - handled during event processing
+ // CraftBukkit end
return itemstack;
}
@@ -83,7 +117,7 @@
entityminecartabstract.setCustomName(itemstack.getName());
}
- world.addEntity(entityminecartabstract);
+ if (!world.addEntity(entityminecartabstract)) return EnumInteractionResult.PASS; // CraftBukkit
}
itemstack.subtract(1);