|
26 | 26 | import java.util.Arrays; |
27 | 27 | import java.util.Comparator; |
28 | 28 | import java.util.Date; |
| 29 | +import java.util.HashMap; |
29 | 30 | import java.util.Objects; |
30 | 31 | import java.util.Optional; |
31 | 32 | import java.util.UUID; |
@@ -66,6 +67,8 @@ public final class POS { |
66 | 67 | */ |
67 | 68 | public final @NotNull Date created; |
68 | 69 |
|
| 70 | + public final static @NotNull HashMap<@NotNull Inventory, @NotNull POS> activePosChestGuis = new HashMap<>(); |
| 71 | + |
69 | 72 | /** |
70 | 73 | * Create new POS instance |
71 | 74 | * |
@@ -118,6 +121,15 @@ public POS(final @NotNull ResultSet rs) throws @NotNull SQLException, @NotNull I |
118 | 121 | return getLocation().getBlock(); |
119 | 122 | } |
120 | 123 |
|
| 124 | + /** |
| 125 | + * Get POS chest |
| 126 | + */ |
| 127 | + public @Nullable Chest getChest() { |
| 128 | + if (getBlock().getState() instanceof final @NotNull Chest chest) return chest; |
| 129 | + delete(); |
| 130 | + return null; |
| 131 | + } |
| 132 | + |
121 | 133 | /** |
122 | 134 | * Create POS id |
123 | 135 | */ |
@@ -259,10 +271,11 @@ public void delete() { |
259 | 271 | * @param pos The POS |
260 | 272 | */ |
261 | 273 | public static void openOwnerGui(final @NotNull Player player, final @NotNull Chest chest, final @NotNull POS pos) { |
262 | | - final @NotNull ItemStack @NotNull [] items = Arrays.stream(chest.getInventory().getStorageContents()).filter(Objects::nonNull).toArray(ItemStack[]::new); |
| 274 | + final @NotNull ItemStack @NotNull [] items = Arrays.stream(chest.getInventory().getStorageContents()).filter(Objects::nonNull).map(ItemStack::clone).toArray(ItemStack[]::new); |
263 | 275 | final int extraRows = 1; |
264 | 276 | final int size = extraRows * 9 + items.length + 9 - items.length % 9; |
265 | 277 | final @NotNull Inventory gui = BankAccounts.getInstance().getServer().createInventory(null, size, BankAccounts.getInstance().config().posTitle(pos)); |
| 278 | + POS.activePosChestGuis.put(gui, pos); |
266 | 279 | gui.addItem(items); |
267 | 280 |
|
268 | 281 | final @NotNull ItemStack overview = new ItemStack(BankAccounts.getInstance().config().posInfoMaterial(), 1); |
@@ -304,10 +317,11 @@ public static void openOwnerGui(final @NotNull Player player, final @NotNull Che |
304 | 317 | * @param pos The POS |
305 | 318 | */ |
306 | 319 | public static void openBuyGui(final @NotNull Player player, final @NotNull Chest chest, final @NotNull POS pos, final @NotNull Account account) { |
307 | | - final @NotNull ItemStack @NotNull [] items = Arrays.stream(chest.getInventory().getStorageContents()).filter(Objects::nonNull).toArray(ItemStack[]::new); |
| 320 | + final @NotNull ItemStack @NotNull [] items = Arrays.stream(chest.getInventory().getStorageContents()).filter(Objects::nonNull).map(ItemStack::clone).toArray(ItemStack[]::new); |
308 | 321 | final int extraRows = 1; |
309 | 322 | final int size = extraRows * 9 + items.length + 9 - items.length % 9; |
310 | 323 | final @NotNull Inventory gui = BankAccounts.getInstance().getServer().createInventory(null, size, BankAccounts.getInstance().config().posTitle(pos)); |
| 324 | + POS.activePosChestGuis.put(gui, pos); |
311 | 325 | gui.addItem(items); |
312 | 326 |
|
313 | 327 | final @NotNull ItemStack overview = new ItemStack(BankAccounts.getInstance().config().posInfoMaterial(), 1); |
|
0 commit comments