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
111
112
113
114
115
116
117
118
119
|
--- a/net/minecraft/world/CompoundContainer.java
+++ b/net/minecraft/world/CompoundContainer.java
@@ -3,10 +3,62 @@
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
+// CraftBukkit start
+import java.util.ArrayList;
+import java.util.List;
+import org.bukkit.Location;
+
+import org.bukkit.craftbukkit.entity.CraftHumanEntity;
+import org.bukkit.entity.HumanEntity;
+// CraftBukkit end
+
public class CompoundContainer implements Container {
- private final Container container1;
- private final Container container2;
+ public final Container container1;
+ public final Container container2;
+
+ // CraftBukkit start - add fields and methods
+ public List<HumanEntity> transaction = new java.util.ArrayList<HumanEntity>();
+
+ public List<ItemStack> getContents() {
+ List<ItemStack> result = new ArrayList<ItemStack>(this.getContainerSize());
+ for (int i = 0; i < this.getContainerSize(); i++) {
+ result.add(this.getItem(i));
+ }
+ return result;
+ }
+
+ public void onOpen(CraftHumanEntity who) {
+ this.container1.onOpen(who);
+ this.container2.onOpen(who);
+ transaction.add(who);
+ }
+
+ public void onClose(CraftHumanEntity who) {
+ this.container1.onClose(who);
+ this.container2.onClose(who);
+ transaction.remove(who);
+ }
+
+ public List<HumanEntity> getViewers() {
+ return transaction;
+ }
+
+ public org.bukkit.inventory.InventoryHolder getOwner() {
+ return null; // This method won't be called since CraftInventoryDoubleChest doesn't defer to here
+ }
+
+ public void setMaxStackSize(int size) {
+ this.container1.setMaxStackSize(size);
+ this.container2.setMaxStackSize(size);
+ }
+
+ @Override
+ public Location getLocation() {
+ return container1.getLocation(); // TODO: right?
+ }
+ // CraftBukkit end
+
public CompoundContainer(Container container1, Container container2) {
this.container1 = container1;
this.container2 = container2;
@@ -28,23 +80,17 @@
@Override
public ItemStack getItem(int index) {
- return index >= this.container1.getContainerSize()
- ? this.container2.getItem(index - this.container1.getContainerSize())
- : this.container1.getItem(index);
+ return index >= this.container1.getContainerSize() ? this.container2.getItem(index - this.container1.getContainerSize()) : this.container1.getItem(index);
}
@Override
public ItemStack removeItem(int index, int count) {
- return index >= this.container1.getContainerSize()
- ? this.container2.removeItem(index - this.container1.getContainerSize(), count)
- : this.container1.removeItem(index, count);
+ return index >= this.container1.getContainerSize() ? this.container2.removeItem(index - this.container1.getContainerSize(), count) : this.container1.removeItem(index, count);
}
@Override
public ItemStack removeItemNoUpdate(int index) {
- return index >= this.container1.getContainerSize()
- ? this.container2.removeItemNoUpdate(index - this.container1.getContainerSize())
- : this.container1.removeItemNoUpdate(index);
+ return index >= this.container1.getContainerSize() ? this.container2.removeItemNoUpdate(index - this.container1.getContainerSize()) : this.container1.removeItemNoUpdate(index);
}
@Override
@@ -54,11 +100,12 @@
} else {
this.container1.setItem(index, stack);
}
+
}
@Override
public int getMaxStackSize() {
- return this.container1.getMaxStackSize();
+ return Math.min(this.container1.getMaxStackSize(), this.container2.getMaxStackSize()); // CraftBukkit - check both sides
}
@Override
@@ -86,9 +133,7 @@
@Override
public boolean canPlaceItem(int index, ItemStack stack) {
- return index >= this.container1.getContainerSize()
- ? this.container2.canPlaceItem(index - this.container1.getContainerSize(), stack)
- : this.container1.canPlaceItem(index, stack);
+ return index >= this.container1.getContainerSize() ? this.container2.canPlaceItem(index - this.container1.getContainerSize(), stack) : this.container1.canPlaceItem(index, stack);
}
@Override
|