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
|
--- a/net/minecraft/world/inventory/DispenserMenu.java
+++ b/net/minecraft/world/inventory/DispenserMenu.java
@@ -6,6 +6,11 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
+// CraftBukkit start
+import org.bukkit.craftbukkit.inventory.CraftInventory;
+import org.bukkit.craftbukkit.inventory.CraftInventoryView;
+// CraftBukkit end
+
public class DispenserMenu extends AbstractContainerMenu {
private static final int SLOT_COUNT = 9;
@@ -13,17 +18,25 @@
private static final int INV_SLOT_END = 36;
private static final int USE_ROW_SLOT_START = 36;
private static final int USE_ROW_SLOT_END = 45;
- private final Container dispenser;
+ public final Container dispenser;
+ // CraftBukkit start
+ private CraftInventoryView bukkitEntity = null;
+ private Inventory player;
+ // CraftBukkit end
- public DispenserMenu(int i, Inventory inventory) {
- this(i, inventory, new SimpleContainer(9));
+ public DispenserMenu(int containerId, Inventory playerInventory) {
+ this(containerId, playerInventory, new SimpleContainer(9));
}
- public DispenserMenu(int i, Inventory inventory, Container container) {
- super(MenuType.GENERIC_3x3, i);
+ public DispenserMenu(int containerId, Inventory playerInventory, Container container) {
+ super(MenuType.GENERIC_3x3, containerId);
+ // CraftBukkit start - Save player
+ this.player = playerInventory;
+ // CraftBukkit end
+
checkContainerSize(container, 9);
this.dispenser = container;
- container.startOpen(inventory.player);
+ container.startOpen(playerInventory.player);
int j;
int k;
@@ -36,33 +49,32 @@
for (j = 0; j < 3; ++j) {
for (k = 0; k < 9; ++k) {
- this.addSlot(new Slot(inventory, k + j * 9 + 9, 8 + k * 18, 84 + j * 18));
+ this.addSlot(new Slot(playerInventory, k + j * 9 + 9, 8 + k * 18, 84 + j * 18));
}
}
for (j = 0; j < 9; ++j) {
- this.addSlot(new Slot(inventory, j, 8 + j * 18, 142));
+ this.addSlot(new Slot(playerInventory, j, 8 + j * 18, 142));
}
}
@Override
- @Override
public boolean stillValid(Player player) {
+ if (!this.checkReachable) return true; // CraftBukkit
return this.dispenser.stillValid(player);
}
@Override
- @Override
- public ItemStack quickMoveStack(Player player, int i) {
+ public ItemStack quickMoveStack(Player player, int index) {
ItemStack itemstack = ItemStack.EMPTY;
- Slot slot = (Slot) this.slots.get(i);
+ Slot slot = (Slot) this.slots.get(index);
if (slot != null && slot.hasItem()) {
ItemStack itemstack1 = slot.getItem();
itemstack = itemstack1.copy();
- if (i < 9) {
+ if (index < 9) {
if (!this.moveItemStackTo(itemstack1, 9, 45, true)) {
return ItemStack.EMPTY;
}
@@ -87,9 +99,21 @@
}
@Override
- @Override
public void removed(Player player) {
super.removed(player);
this.dispenser.stopOpen(player);
}
+
+ // CraftBukkit start
+ @Override
+ public CraftInventoryView getBukkitView() {
+ if (bukkitEntity != null) {
+ return bukkitEntity;
+ }
+
+ CraftInventory inventory = new CraftInventory(this.dispenser);
+ bukkitEntity = new CraftInventoryView(this.player.player.getBukkitEntity(), inventory, this);
+ return bukkitEntity;
+ }
+ // CraftBukkit end
}
|