From 254a8daf5921b304293232356ddb981324e02186 Mon Sep 17 00:00:00 2001
From: Hempfest <64885225+Hempfest@users.noreply.github.com>
Date: Wed, 5 Jul 2023 12:53:23 -0700
Subject: [PATCH] * Updated panther dependency * Started creation of new gui
utility basalt * Updated version in pom
---
labyrinth-common/pom.xml | 6 +-
labyrinth-gui/pom.xml | 2 +-
.../gui/basalt/InventoryContainer.java | 63 +++++++++++++++
.../labyrinth/gui/basalt/InventoryFormat.java | 9 +++
.../labyrinth/gui/basalt/InventoryPane.java | 53 +++++++++++++
.../gui/basalt/InventoryProperties.java | 26 ++++++
.../labyrinth/gui/basalt/InventorySize.java | 54 +++++++++++++
.../gui/basalt/InventorySnapshot.java | 79 +++++++++++++++++++
.../sanctum/labyrinth/gui/basalt/Menu.java | 20 +++++
labyrinth-loci/pom.xml | 2 +-
labyrinth-perms/pom.xml | 2 +-
labyrinth-plugin/pom.xml | 2 +-
labyrinth-regions/pom.xml | 2 +-
labyrinth-skulls/pom.xml | 2 +-
pom.xml | 4 +-
15 files changed, 313 insertions(+), 13 deletions(-)
create mode 100644 labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventoryContainer.java
create mode 100644 labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventoryFormat.java
create mode 100644 labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventoryPane.java
create mode 100644 labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventoryProperties.java
create mode 100644 labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventorySize.java
create mode 100644 labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventorySnapshot.java
create mode 100644 labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/Menu.java
diff --git a/labyrinth-common/pom.xml b/labyrinth-common/pom.xml
index 5e389a2d..29d9ca48 100644
--- a/labyrinth-common/pom.xml
+++ b/labyrinth-common/pom.xml
@@ -5,7 +5,7 @@
labyrinth
com.github.the-h-team
- 1.9.2
+ 1.9.3
4.0.0
@@ -43,10 +43,6 @@
VaultAPI
provided
-
- com.github.the-h-team.Panther
- panther-common
-
\ No newline at end of file
diff --git a/labyrinth-gui/pom.xml b/labyrinth-gui/pom.xml
index ff2bb315..95fdfc69 100644
--- a/labyrinth-gui/pom.xml
+++ b/labyrinth-gui/pom.xml
@@ -5,7 +5,7 @@
labyrinth
com.github.the-h-team
- 1.9.2
+ 1.9.3
4.0.0
diff --git a/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventoryContainer.java b/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventoryContainer.java
new file mode 100644
index 00000000..121b45af
--- /dev/null
+++ b/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventoryContainer.java
@@ -0,0 +1,63 @@
+package com.github.sanctum.labyrinth.gui.basalt;
+
+import com.github.sanctum.labyrinth.data.service.AnvilMechanics;
+import com.github.sanctum.panther.container.PantherEntryMap;
+import com.github.sanctum.panther.container.PantherMap;
+import java.util.UUID;
+import org.bukkit.Bukkit;
+import org.bukkit.entity.Player;
+import org.bukkit.inventory.Inventory;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+public abstract class InventoryContainer {
+
+ private final Inventory inventory;
+ private final InventoryProperties properties;
+ private final PantherMap inventoryMap = new PantherEntryMap<>();
+
+ public InventoryContainer(Inventory inventory, InventoryProperties properties) {
+ this.inventory = inventory;
+ this.properties = properties;
+ }
+
+ public @Nullable Inventory getInventory() {
+ return inventory;
+ }
+
+ public @Nullable Inventory getInventory(@NotNull Player player) {
+ return inventoryMap.get(player.getUniqueId());
+ }
+
+ public @Nullable InventorySnapshot newSnapshot() {
+ if (inventory == null) return null;
+ return new InventorySnapshot(inventory);
+ }
+
+ public @Nullable InventorySnapshot newSnapshot(@NotNull Player player) {
+ if (inventory == null) return null;
+ return new InventorySnapshot(inventoryMap.computeIfAbsent(player.getUniqueId(), () -> {
+ // use properties to create copy of menu.
+ switch (properties.getFormat()) {
+ case ANVIL:
+ AnvilMechanics mechanics = AnvilMechanics.getInstance();
+ final Object container = mechanics.newContainerAnvil(player, properties.getTitle());
+ Inventory ne = mechanics.toBukkitInventory(container);
+ for (int i = 0; i < this.inventory.getSize() + 1; i++) {
+ ne.setItem(i, this.inventory.getItem(i));
+ }
+ return ne;
+ case NORMAL:
+ case PAGINATED:
+ Inventory inv = Bukkit.createInventory(null, 54, properties.getTitle());
+ for (int i = 0; i < this.inventory.getSize() + 1; i++) {
+ inv.setItem(i, this.inventory.getItem(i));
+ }
+ return inv;
+ }
+ // this should never happen.
+ return null;
+ }));
+ }
+
+}
diff --git a/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventoryFormat.java b/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventoryFormat.java
new file mode 100644
index 00000000..e66845e3
--- /dev/null
+++ b/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventoryFormat.java
@@ -0,0 +1,9 @@
+package com.github.sanctum.labyrinth.gui.basalt;
+
+public enum InventoryFormat {
+
+ ANVIL,
+ NORMAL,
+ PAGINATED,
+
+}
diff --git a/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventoryPane.java b/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventoryPane.java
new file mode 100644
index 00000000..93b57419
--- /dev/null
+++ b/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventoryPane.java
@@ -0,0 +1,53 @@
+package com.github.sanctum.labyrinth.gui.basalt;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.IntStream;
+
+public enum InventoryPane {
+
+ /**
+ * The top bar of slots within the inventory.
+ */
+ TOP(i -> IntStream.range(0, 9).toArray()),
+
+ /**
+ * The bottom bar of slots within the inventory.
+ */
+ BOTTOM(i -> IntStream.range(i - 9, i).toArray()),
+
+ /**
+ * The middle space of the inventory.
+ */
+ MIDDLE(i -> {
+ if (i <= 18) {
+ return IntStream.range(0, 9).toArray();
+ }
+ return IntStream.range(10, i).filter(n -> n < i - 9 && n % 9 != 0 && n % 9 != 8).toArray();
+ }),
+
+ /**
+ * The left bar of slots within the inventory.
+ */
+ LEFT(i -> IntStream.iterate(0, n -> n + 9).limit(i / 9).toArray()),
+
+ /**
+ * The right bar of slots within the inventory.
+ */
+ RIGHT(i -> IntStream.iterate(8, n -> n + 9).limit(i / 9).toArray());
+
+ private final Function generatorFunction;
+ private final Map cache = new HashMap<>();
+
+ InventoryPane(final Function generatorFunction) {
+ this.generatorFunction = generatorFunction;
+ }
+
+ public int[] get(int slots) {
+ int[] result = cache.computeIfAbsent(slots, generatorFunction);
+ return Arrays.copyOf(result, result.length);
+ }
+
+}
diff --git a/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventoryProperties.java b/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventoryProperties.java
new file mode 100644
index 00000000..80fb4d51
--- /dev/null
+++ b/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventoryProperties.java
@@ -0,0 +1,26 @@
+package com.github.sanctum.labyrinth.gui.basalt;
+
+public class InventoryProperties {
+
+ private int size;
+ private String title;
+ private InventoryFormat type;
+
+ public InventoryProperties(InventoryFormat format, String title) {
+ this.title = title;
+ this.type = format;
+ this.size = 4;// decide size with new enum
+ }
+
+ public InventoryFormat getFormat() {
+ return type;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public int getSize() {
+ return size;
+ }
+}
diff --git a/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventorySize.java b/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventorySize.java
new file mode 100644
index 00000000..9cdaf0d6
--- /dev/null
+++ b/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventorySize.java
@@ -0,0 +1,54 @@
+package com.github.sanctum.labyrinth.gui.basalt;
+
+import com.github.sanctum.labyrinth.gui.unity.construct.Menu;
+
+public enum InventorySize {
+
+ /**
+ * Slots: 9
+ */
+ ONE(9),
+
+ /**
+ * Slots: 18
+ */
+ TWO(18),
+
+ /**
+ * Slots: 27
+ */
+ THREE(27),
+
+ /**
+ * Slots: 36
+ */
+ FOUR(36),
+
+ /**
+ * Slots: 45
+ */
+ FIVE(45),
+
+ /**
+ * Slots: 54
+ */
+ SIX(54);
+
+ private final int slots;
+
+ InventorySize(int slots) {
+ this.slots = slots;
+ }
+
+ /**
+ * @return The size of the inventory.
+ */
+ public int getSize() {
+ return slots;
+ }
+
+ public int[] getSlots(InventoryPane layout) {
+ return layout.get(getSize());
+ }
+
+}
diff --git a/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventorySnapshot.java b/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventorySnapshot.java
new file mode 100644
index 00000000..26c6c146
--- /dev/null
+++ b/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/InventorySnapshot.java
@@ -0,0 +1,79 @@
+package com.github.sanctum.labyrinth.gui.basalt;
+
+import com.github.sanctum.labyrinth.task.TaskScheduler;
+import java.util.concurrent.CompletableFuture;
+import org.bukkit.inventory.Inventory;
+import org.bukkit.inventory.ItemStack;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+public final class InventorySnapshot {
+
+ private final ItemStack[] contents;
+ private Inventory parent;
+ private ItemStack[] modifiedContents;
+
+ public InventorySnapshot(Inventory inventory) {
+ this(inventory.getContents());
+ this.parent = inventory;
+ }
+
+ public InventorySnapshot(ItemStack[] inventory) {
+ this.contents = inventory;
+ this.modifiedContents = new ItemStack[inventory.length];
+ for (int i = 0; i < inventory.length + 1; i++) {
+ modifiedContents[i] = new ItemStack(inventory[i]);
+ }
+ }
+
+ public void set(int index, @Nullable ItemStack itemStack) {
+ modifiedContents[index] = itemStack;
+ }
+
+ public void set(@Nullable ItemStack[] items) {
+ if (items == null) {
+ this.modifiedContents = new ItemStack[this.contents.length];
+ } else {
+ this.modifiedContents = items;
+ }
+ }
+
+ public @Nullable ItemStack get(int index) {
+ return modifiedContents[index];
+ }
+
+ public CompletableFuture reset() {
+ return CompletableFuture.supplyAsync(() -> {
+ TaskScheduler.of(() -> {
+ this.modifiedContents = new ItemStack[this.contents.length];
+ for (int i = 0; i < this.contents.length + 1; i++) {
+ modifiedContents[i] = new ItemStack(this.contents[i]);
+ }
+ }).schedule();
+ return null;
+ });
+ }
+
+ public CompletableFuture update() {
+ return CompletableFuture.supplyAsync(() -> {
+ TaskScheduler.of(() -> {
+ for (int i = 0; i < this.modifiedContents.length + 1; i++) {
+ this.parent.setItem(i, this.modifiedContents[i]);
+ }
+ }).schedule();
+ return null;
+ });
+ }
+
+ public CompletableFuture update(@NotNull Inventory inventory) {
+ return CompletableFuture.supplyAsync(() -> {
+ TaskScheduler.of(() -> {
+ for (int i = 0; i < this.modifiedContents.length + 1; i++) {
+ inventory.setItem(i, this.modifiedContents[i]);
+ }
+ }).schedule();
+ return null;
+ });
+ }
+
+}
diff --git a/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/Menu.java b/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/Menu.java
new file mode 100644
index 00000000..53142cc8
--- /dev/null
+++ b/labyrinth-gui/src/main/java/com/github/sanctum/labyrinth/gui/basalt/Menu.java
@@ -0,0 +1,20 @@
+package com.github.sanctum.labyrinth.gui.basalt;
+
+public class Menu {
+
+ private final boolean isSharable;
+ private final InventoryProperties properties;
+
+ public Menu(String title, InventoryFormat format, boolean sharable) {
+ this.isSharable = sharable;
+ this.properties = new InventoryProperties(format, title);
+ }
+
+ public InventoryContainer getContainer() {
+ if (isSharable) {
+ // new instance
+ }
+ return null; // cached instance
+ }
+
+}
diff --git a/labyrinth-loci/pom.xml b/labyrinth-loci/pom.xml
index 5a2b1bd9..8b04349c 100644
--- a/labyrinth-loci/pom.xml
+++ b/labyrinth-loci/pom.xml
@@ -5,7 +5,7 @@
labyrinth
com.github.the-h-team
- 1.9.2
+ 1.9.3
4.0.0
diff --git a/labyrinth-perms/pom.xml b/labyrinth-perms/pom.xml
index 95b945b4..fcfd0c6f 100644
--- a/labyrinth-perms/pom.xml
+++ b/labyrinth-perms/pom.xml
@@ -5,7 +5,7 @@
labyrinth
com.github.the-h-team
- 1.9.2
+ 1.9.3
4.0.0
diff --git a/labyrinth-plugin/pom.xml b/labyrinth-plugin/pom.xml
index 43858385..16b4de23 100644
--- a/labyrinth-plugin/pom.xml
+++ b/labyrinth-plugin/pom.xml
@@ -5,7 +5,7 @@
labyrinth
com.github.the-h-team
- 1.9.2
+ 1.9.3
4.0.0
diff --git a/labyrinth-regions/pom.xml b/labyrinth-regions/pom.xml
index cc5d28f7..d0fac84f 100644
--- a/labyrinth-regions/pom.xml
+++ b/labyrinth-regions/pom.xml
@@ -5,7 +5,7 @@
labyrinth
com.github.the-h-team
- 1.9.2
+ 1.9.3
4.0.0
diff --git a/labyrinth-skulls/pom.xml b/labyrinth-skulls/pom.xml
index ea745c4e..d240a26a 100644
--- a/labyrinth-skulls/pom.xml
+++ b/labyrinth-skulls/pom.xml
@@ -5,7 +5,7 @@
labyrinth
com.github.the-h-team
- 1.9.2
+ 1.9.3
4.0.0
diff --git a/pom.xml b/pom.xml
index 09e4c5ed..11b2a6e3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.github.the-h-team
labyrinth
- 1.9.2
+ 1.9.3
labyrinth-common
labyrinth-gui
@@ -28,7 +28,7 @@
UTF-8
1.16.2-R0.1-SNAPSHOT
1.1.0
- 1.0.2
+ 1.0.3