Skip to content

Commit

Permalink
* Updated panther dependency
Browse files Browse the repository at this point in the history
* Started creation of new gui utility basalt
* Updated version in pom
  • Loading branch information
Hempfest committed Jul 5, 2023
1 parent aeec6cc commit 254a8da
Show file tree
Hide file tree
Showing 15 changed files with 313 additions and 13 deletions.
6 changes: 1 addition & 5 deletions labyrinth-common/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>labyrinth</artifactId>
<groupId>com.github.the-h-team</groupId>
<version>1.9.2</version>
<version>1.9.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -43,10 +43,6 @@
<artifactId>VaultAPI</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.the-h-team.Panther</groupId>
<artifactId>panther-common</artifactId>
</dependency>
</dependencies>

</project>
2 changes: 1 addition & 1 deletion labyrinth-gui/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>labyrinth</artifactId>
<groupId>com.github.the-h-team</groupId>
<version>1.9.2</version>
<version>1.9.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
@@ -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<UUID, Inventory> 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;
}));
}

}
@@ -0,0 +1,9 @@
package com.github.sanctum.labyrinth.gui.basalt;

public enum InventoryFormat {

ANVIL,
NORMAL,
PAGINATED,

}
@@ -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<Integer, int[]> generatorFunction;
private final Map<Integer, int[]> cache = new HashMap<>();

InventoryPane(final Function<Integer, int[]> generatorFunction) {
this.generatorFunction = generatorFunction;
}

public int[] get(int slots) {
int[] result = cache.computeIfAbsent(slots, generatorFunction);
return Arrays.copyOf(result, result.length);
}

}
@@ -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;
}
}
@@ -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());
}

}
@@ -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<Void> 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<Void> 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<Void> 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;
});
}

}
@@ -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
}

}
2 changes: 1 addition & 1 deletion labyrinth-loci/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>labyrinth</artifactId>
<groupId>com.github.the-h-team</groupId>
<version>1.9.2</version>
<version>1.9.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion labyrinth-perms/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>labyrinth</artifactId>
<groupId>com.github.the-h-team</groupId>
<version>1.9.2</version>
<version>1.9.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion labyrinth-plugin/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>labyrinth</artifactId>
<groupId>com.github.the-h-team</groupId>
<version>1.9.2</version>
<version>1.9.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion labyrinth-regions/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>labyrinth</artifactId>
<groupId>com.github.the-h-team</groupId>
<version>1.9.2</version>
<version>1.9.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion labyrinth-skulls/pom.xml
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>labyrinth</artifactId>
<groupId>com.github.the-h-team</groupId>
<version>1.9.2</version>
<version>1.9.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down

0 comments on commit 254a8da

Please sign in to comment.