2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/ItemBucket.java
+++ b/net/minecraft/server/ItemBucket.java
2016-05-10 13:47:39 +02:00
@@ -1,6 +1,12 @@
2014-11-25 22:32:16 +01:00
package net.minecraft.server;
2016-05-10 13:47:39 +02:00
import javax.annotation.Nullable;
2014-11-25 22:32:16 +01:00
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.player.PlayerBucketEmptyEvent;
+import org.bukkit.event.player.PlayerBucketFillEvent;
+// CraftBukkit end
2016-05-10 13:47:39 +02:00
2014-11-25 22:32:16 +01:00
public class ItemBucket extends Item {
2016-11-17 02:41:03 +01:00
@@ -34,15 +40,29 @@
2016-02-29 22:32:46 +01:00
Material material = iblockdata.getMaterial();
2014-11-25 22:32:16 +01:00
if (material == Material.WATER && ((Integer) iblockdata.get(BlockFluids.LEVEL)).intValue() == 0) {
+ // CraftBukkit start
+ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, blockposition.getX(), blockposition.getY(), blockposition.getZ(), null, itemstack, Items.WATER_BUCKET);
2016-02-29 22:32:46 +01:00
+
2014-11-25 22:32:16 +01:00
+ if (event.isCancelled()) {
2016-02-29 22:32:46 +01:00
+ return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack);
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
2016-02-29 22:32:46 +01:00
world.setTypeAndData(blockposition, Blocks.AIR.getBlockData(), 11);
entityhuman.b(StatisticList.b((Item) this));
2016-11-17 02:41:03 +01:00
entityhuman.a(SoundEffects.P, 1.0F, 1.0F);
2016-02-29 22:32:46 +01:00
- return new InteractionResultWrapper(EnumInteractionResult.SUCCESS, this.a(itemstack, entityhuman, Items.WATER_BUCKET));
2016-11-17 02:41:03 +01:00
+ return new InteractionResultWrapper(EnumInteractionResult.SUCCESS, this.a(itemstack, entityhuman, Items.WATER_BUCKET, event.getItemStack())); // CraftBukkit
2016-02-29 22:32:46 +01:00
} else if (material == Material.LAVA && ((Integer) iblockdata.get(BlockFluids.LEVEL)).intValue() == 0) {
2014-11-25 22:32:16 +01:00
+ // CraftBukkit start
+ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, blockposition.getX(), blockposition.getY(), blockposition.getZ(), null, itemstack, Items.LAVA_BUCKET);
+
+ if (event.isCancelled()) {
2016-02-29 22:32:46 +01:00
+ return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack);
2014-11-25 22:32:16 +01:00
+ }
+ // CraftBukkit end
2016-11-17 02:41:03 +01:00
entityhuman.a(SoundEffects.Q, 1.0F, 1.0F);
2016-02-29 22:32:46 +01:00
world.setTypeAndData(blockposition, Blocks.AIR.getBlockData(), 11);
entityhuman.b(StatisticList.b((Item) this));
- return new InteractionResultWrapper(EnumInteractionResult.SUCCESS, this.a(itemstack, entityhuman, Items.LAVA_BUCKET));
+ return new InteractionResultWrapper(EnumInteractionResult.SUCCESS, this.a(itemstack, entityhuman, Items.LAVA_BUCKET, event.getItemStack())); // CraftBukkit
} else {
return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack);
2014-11-25 22:32:16 +01:00
}
2016-11-17 02:41:03 +01:00
@@ -53,7 +73,7 @@
2014-11-25 22:32:16 +01:00
2016-02-29 22:32:46 +01:00
if (!entityhuman.a(blockposition1, movingobjectposition.direction, itemstack)) {
return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack);
- } else if (this.a(entityhuman, world, blockposition1)) {
2016-03-06 06:41:13 +01:00
+ } else if (this.a(entityhuman, world, blockposition1, movingobjectposition.direction, blockposition, itemstack)) { // CraftBukkit
2016-02-29 22:32:46 +01:00
entityhuman.b(StatisticList.b((Item) this));
return !entityhuman.abilities.canInstantlyBuild ? new InteractionResultWrapper(EnumInteractionResult.SUCCESS, new ItemStack(Items.BUCKET)) : new InteractionResultWrapper(EnumInteractionResult.SUCCESS, itemstack);
} else {
2016-11-17 02:41:03 +01:00
@@ -63,16 +83,19 @@
2014-11-25 22:32:16 +01:00
}
}
2015-02-26 23:41:06 +01:00
2014-11-25 22:32:16 +01:00
- private ItemStack a(ItemStack itemstack, EntityHuman entityhuman, Item item) {
+ // CraftBukkit - added ob.ItemStack result - TODO: Is this... the right way to handle this?
+ private ItemStack a(ItemStack itemstack, EntityHuman entityhuman, Item item, org.bukkit.inventory.ItemStack result) {
if (entityhuman.abilities.canInstantlyBuild) {
return itemstack;
} else {
2016-11-17 02:41:03 +01:00
itemstack.subtract(1);
if (itemstack.isEmpty()) {
- return new ItemStack(item);
+ // CraftBukkit start
+ return CraftItemStack.asNMSCopy(result);
} else {
- if (!entityhuman.inventory.pickup(new ItemStack(item))) {
- entityhuman.drop(new ItemStack(item), false);
+ if (!entityhuman.inventory.pickup(CraftItemStack.asNMSCopy(result))) {
+ entityhuman.drop(CraftItemStack.asNMSCopy(result), false);
+ // CraftBukkit end
}
2014-11-25 22:32:16 +01:00
2016-11-17 02:41:03 +01:00
return itemstack;
@@ -80,7 +103,13 @@
2016-02-29 22:32:46 +01:00
}
}
+ // CraftBukkit start
2016-05-10 13:47:39 +02:00
public boolean a(@Nullable EntityHuman entityhuman, World world, BlockPosition blockposition) {
2016-03-06 06:41:13 +01:00
+ return a(entityhuman, world, blockposition, null, blockposition, null);
2016-02-29 22:32:46 +01:00
+ }
+
2016-03-06 06:41:13 +01:00
+ public boolean a(EntityHuman entityhuman, World world, BlockPosition blockposition, EnumDirection enumdirection, BlockPosition clicked, ItemStack itemstack) {
2016-02-29 22:32:46 +01:00
+ // CraftBukkit end
if (this.a == Blocks.AIR) {
return false;
} else {
2016-11-17 02:41:03 +01:00
@@ -92,6 +121,15 @@
2016-02-29 22:32:46 +01:00
if (!world.isEmpty(blockposition) && !flag && !flag1) {
return false;
} else {
+ // CraftBukkit start
+ if (entityhuman != null) {
2016-03-06 06:41:13 +01:00
+ PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(entityhuman, clicked.getX(), clicked.getY(), clicked.getZ(), enumdirection, itemstack);
2016-02-29 22:32:46 +01:00
+ if (event.isCancelled()) {
+ // TODO: inventory not updated
+ return false;
+ }
+ }
+ // CraftBukkit end
if (world.worldProvider.l() && this.a == Blocks.FLOWING_WATER) {
int i = blockposition.getX();
int j = blockposition.getY();