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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
--- a/net/minecraft/world/CompoundContainer.java
+++ b/net/minecraft/world/CompoundContainer.java
@@ -3,102 +3,140 @@
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;
- public CompoundContainer(Container container, Container container1) {
- this.container1 = container;
- this.container2 = container1;
+ // 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;
+ }
+
@Override
public int getContainerSize() {
return this.container1.getContainerSize() + this.container2.getContainerSize();
}
@Override
- @Override
public boolean isEmpty() {
return this.container1.isEmpty() && this.container2.isEmpty();
}
- public boolean contains(Container container) {
- return this.container1 == container || this.container2 == container;
+ public boolean contains(Container inventory) {
+ return this.container1 == inventory || this.container2 == inventory;
}
@Override
- @Override
- public ItemStack getItem(int i) {
- return i >= this.container1.getContainerSize() ? this.container2.getItem(i - this.container1.getContainerSize()) : this.container1.getItem(i);
+ public ItemStack getItem(int index) {
+ return index >= this.container1.getContainerSize() ? this.container2.getItem(index - this.container1.getContainerSize()) : this.container1.getItem(index);
}
@Override
- @Override
- public ItemStack removeItem(int i, int j) {
- return i >= this.container1.getContainerSize() ? this.container2.removeItem(i - this.container1.getContainerSize(), j) : this.container1.removeItem(i, j);
+ 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);
}
@Override
- @Override
- public ItemStack removeItemNoUpdate(int i) {
- return i >= this.container1.getContainerSize() ? this.container2.removeItemNoUpdate(i - this.container1.getContainerSize()) : this.container1.removeItemNoUpdate(i);
+ public ItemStack removeItemNoUpdate(int index) {
+ return index >= this.container1.getContainerSize() ? this.container2.removeItemNoUpdate(index - this.container1.getContainerSize()) : this.container1.removeItemNoUpdate(index);
}
@Override
- @Override
- public void setItem(int i, ItemStack itemstack) {
- if (i >= this.container1.getContainerSize()) {
- this.container2.setItem(i - this.container1.getContainerSize(), itemstack);
+ public void setItem(int index, ItemStack stack) {
+ if (index >= this.container1.getContainerSize()) {
+ this.container2.setItem(index - this.container1.getContainerSize(), stack);
} else {
- this.container1.setItem(i, itemstack);
+ this.container1.setItem(index, stack);
}
}
@Override
- @Override
public int getMaxStackSize() {
- return this.container1.getMaxStackSize();
+ return Math.min(this.container1.getMaxStackSize(), this.container2.getMaxStackSize()); // CraftBukkit - check both sides
}
@Override
- @Override
public void setChanged() {
this.container1.setChanged();
this.container2.setChanged();
}
@Override
- @Override
public boolean stillValid(Player player) {
return this.container1.stillValid(player) && this.container2.stillValid(player);
}
@Override
- @Override
public void startOpen(Player player) {
this.container1.startOpen(player);
this.container2.startOpen(player);
}
@Override
- @Override
public void stopOpen(Player player) {
this.container1.stopOpen(player);
this.container2.stopOpen(player);
}
@Override
- @Override
- public boolean canPlaceItem(int i, ItemStack itemstack) {
- return i >= this.container1.getContainerSize() ? this.container2.canPlaceItem(i - this.container1.getContainerSize(), itemstack) : this.container1.canPlaceItem(i, itemstack);
+ 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);
}
@Override
- @Override
public void clearContent() {
this.container1.clearContent();
this.container2.clearContent();
|