1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
--- a/net/minecraft/server/ItemBucket.java
+++ b/net/minecraft/server/ItemBucket.java
@@ -1,6 +1,12 @@
package net.minecraft.server;
import javax.annotation.Nullable;
+// 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
public class ItemBucket extends Item {
@@ -34,15 +40,29 @@
Material material = iblockdata.getMaterial();
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);
+
+ if (event.isCancelled()) {
+ return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack);
+ }
+ // CraftBukkit end
world.setTypeAndData(blockposition, Blocks.AIR.getBlockData(), 11);
entityhuman.b(StatisticList.b((Item) this));
entityhuman.a(SoundEffects.S, 1.0F, 1.0F);
- return new InteractionResultWrapper(EnumInteractionResult.SUCCESS, this.a(itemstack, entityhuman, Items.WATER_BUCKET));
+ return new InteractionResultWrapper(EnumInteractionResult.SUCCESS, this.a(itemstack, entityhuman, Items.WATER_BUCKET, event.getItemStack())); // CraftBukkit
} else if (material == Material.LAVA && ((Integer) iblockdata.get(BlockFluids.LEVEL)).intValue() == 0) {
+ // CraftBukkit start
+ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent(entityhuman, blockposition.getX(), blockposition.getY(), blockposition.getZ(), null, itemstack, Items.LAVA_BUCKET);
+
+ if (event.isCancelled()) {
+ return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack);
+ }
+ // CraftBukkit end
entityhuman.a(SoundEffects.T, 1.0F, 1.0F);
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);
}
@@ -53,7 +73,7 @@
if (!entityhuman.a(blockposition1, movingobjectposition.direction, itemstack)) {
return new InteractionResultWrapper(EnumInteractionResult.FAIL, itemstack);
- } else if (this.a(entityhuman, world, blockposition1)) {
+ } else if (this.a(entityhuman, world, blockposition1, movingobjectposition.direction, blockposition, itemstack)) { // CraftBukkit
if (entityhuman instanceof EntityPlayer) {
CriterionTriggers.x.a((EntityPlayer) entityhuman, blockposition1, itemstack);
}
@@ -67,16 +87,19 @@
}
}
- 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 {
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
}
return itemstack;
@@ -84,7 +107,13 @@
}
}
+ // CraftBukkit start
public boolean a(@Nullable EntityHuman entityhuman, World world, BlockPosition blockposition) {
+ return a(entityhuman, world, blockposition, null, blockposition, null);
+ }
+
+ public boolean a(EntityHuman entityhuman, World world, BlockPosition blockposition, EnumDirection enumdirection, BlockPosition clicked, ItemStack itemstack) {
+ // CraftBukkit end
if (this.a == Blocks.AIR) {
return false;
} else {
@@ -96,6 +125,15 @@
if (!world.isEmpty(blockposition) && !flag && !flag1) {
return false;
} else {
+ // CraftBukkit start
+ if (entityhuman != null) {
+ PlayerBucketEmptyEvent event = CraftEventFactory.callPlayerBucketEmptyEvent(entityhuman, clicked.getX(), clicked.getY(), clicked.getZ(), enumdirection, itemstack);
+ 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();
|