SPIGOT-5163: Cancelling PlayerBucketFillEvent visually removes the targeted block

This commit is contained in:
md_5 2019-07-13 12:07:15 +10:00
parent 5f88938850
commit 2349feb849

View File

@ -14,7 +14,7 @@
public class ItemBucket extends Item { public class ItemBucket extends Item {
@@ -30,12 +37,21 @@ @@ -30,12 +37,22 @@
if (this.fluidType == FluidTypes.EMPTY) { if (this.fluidType == FluidTypes.EMPTY) {
iblockdata = world.getType(blockposition); iblockdata = world.getType(blockposition);
if (iblockdata.getBlock() instanceof IFluidSource) { if (iblockdata.getBlock() instanceof IFluidSource) {
@ -23,6 +23,7 @@
+ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, blockposition.getX(), blockposition.getY(), blockposition.getZ(), null, itemstack, dummyFluid.b()); + PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, blockposition.getX(), blockposition.getY(), blockposition.getZ(), null, itemstack, dummyFluid.b());
+ +
+ if (event.isCancelled()) { + if (event.isCancelled()) {
+ ((EntityPlayer) entityhuman).playerConnection.sendPacket(new PacketPlayOutBlockChange(world, blockposition)); // SPIGOT-5163 (see PlayerInteractManager)
+ ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541 + ((EntityPlayer) entityhuman).getBukkitEntity().updateInventory(); // SPIGOT-4541
+ return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack); + return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack);
+ } + }
@ -37,7 +38,7 @@
if (!world.isClientSide) { if (!world.isClientSide) {
CriterionTriggers.j.a((EntityPlayer) entityhuman, new ItemStack(fluidtype.b())); CriterionTriggers.j.a((EntityPlayer) entityhuman, new ItemStack(fluidtype.b()));
@@ -50,7 +66,7 @@ @@ -50,7 +67,7 @@
iblockdata = world.getType(blockposition); iblockdata = world.getType(blockposition);
BlockPosition blockposition1 = iblockdata.getBlock() instanceof IFluidContainer && this.fluidType == FluidTypes.WATER ? blockposition : movingobjectpositionblock.getBlockPosition().shift(movingobjectpositionblock.getDirection()); BlockPosition blockposition1 = iblockdata.getBlock() instanceof IFluidContainer && this.fluidType == FluidTypes.WATER ? blockposition : movingobjectpositionblock.getBlockPosition().shift(movingobjectpositionblock.getDirection());
@ -46,7 +47,7 @@
this.a(world, itemstack, blockposition1); this.a(world, itemstack, blockposition1);
if (entityhuman instanceof EntityPlayer) { if (entityhuman instanceof EntityPlayer) {
CriterionTriggers.y.a((EntityPlayer) entityhuman, blockposition1, itemstack); CriterionTriggers.y.a((EntityPlayer) entityhuman, blockposition1, itemstack);
@@ -74,16 +90,19 @@ @@ -74,16 +91,19 @@
public void a(World world, ItemStack itemstack, BlockPosition blockposition) {} public void a(World world, ItemStack itemstack, BlockPosition blockposition) {}
@ -70,7 +71,7 @@
} }
return itemstack; return itemstack;
@@ -91,7 +110,13 @@ @@ -91,7 +111,13 @@
} }
} }
@ -84,7 +85,7 @@
if (!(this.fluidType instanceof FluidTypeFlowing)) { if (!(this.fluidType instanceof FluidTypeFlowing)) {
return false; return false;
} else { } else {
@@ -101,8 +126,18 @@ @@ -101,8 +127,18 @@
boolean flag1 = material.isReplaceable(); boolean flag1 = material.isReplaceable();
if (!world.isEmpty(blockposition) && !flag && !flag1 && (!(iblockdata.getBlock() instanceof IFluidContainer) || !((IFluidContainer) iblockdata.getBlock()).canPlace(world, blockposition, iblockdata, this.fluidType))) { if (!world.isEmpty(blockposition) && !flag && !flag1 && (!(iblockdata.getBlock() instanceof IFluidContainer) || !((IFluidContainer) iblockdata.getBlock()).canPlace(world, blockposition, iblockdata, this.fluidType))) {