From 25283705f63e7d2335927ad4ba6ce6c5b1d556c0 Mon Sep 17 00:00:00 2001 From: Silent Date: Thu, 19 Nov 2020 22:11:06 +0100 Subject: [PATCH] Redesigned the GUI & added main menu to categories --- src/main/java/tsp/headdb/api/LocalHead.java | 4 +- .../tsp/headdb/inventory/InventoryUtils.java | 46 ++++++++++--------- .../java/tsp/headdb/inventory/PagedPane.java | 18 +++++--- 3 files changed, 39 insertions(+), 29 deletions(-) diff --git a/src/main/java/tsp/headdb/api/LocalHead.java b/src/main/java/tsp/headdb/api/LocalHead.java index 020a896..eda807b 100644 --- a/src/main/java/tsp/headdb/api/LocalHead.java +++ b/src/main/java/tsp/headdb/api/LocalHead.java @@ -22,9 +22,9 @@ public class LocalHead { ItemStack item = new ItemStack(Material.PLAYER_HEAD); SkullMeta meta = (SkullMeta) item.getItemMeta(); meta.setOwningPlayer(Bukkit.getOfflinePlayer(uuid)); - meta.setDisplayName(Utils.colorize("&8" + name)); + meta.setDisplayName(Utils.colorize("&e" + name)); List lore = new ArrayList<>(); - lore.add(Utils.colorize("&aUUID: " + uuid.toString())); + lore.add(Utils.colorize("&7UUID: " + uuid.toString())); meta.setLore(lore); item.setItemMeta(meta); diff --git a/src/main/java/tsp/headdb/inventory/InventoryUtils.java b/src/main/java/tsp/headdb/inventory/InventoryUtils.java index 3a8d0bb..6d500b4 100644 --- a/src/main/java/tsp/headdb/inventory/InventoryUtils.java +++ b/src/main/java/tsp/headdb/inventory/InventoryUtils.java @@ -1,6 +1,7 @@ package tsp.headdb.inventory; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.Inventory; @@ -62,7 +63,7 @@ public class InventoryUtils { if (e.getClick() == ClickType.RIGHT) { HeadAPI.removeFavoriteHead(player.getUniqueId(), head.getId()); openFavoritesMenu(player); - Utils.sendMessage(player, "Removed &e" + head.getName() + " &8from favorites."); + Utils.sendMessage(player, "Removed &e" + head.getName() + " &7from favorites."); } })); } @@ -87,7 +88,7 @@ public class InventoryUtils { } if (e.getClick() == ClickType.RIGHT) { HeadAPI.addFavoriteHead(player.getUniqueId(), head.getId()); - Utils.sendMessage(player, "Added &e" + head.getName() + " &8to favorites."); + Utils.sendMessage(player, "Added &e" + head.getName() + " &7to favorites."); } })); } @@ -123,7 +124,7 @@ public class InventoryUtils { public static void openDatabase(Player player) { Inventory inventory = Bukkit.createInventory(null, 54, Utils.colorize("&c&lHeadDB &8(" + HeadAPI.getHeads().size() + ")")); - fillBorder(inventory, XMaterial.BLACK_STAINED_GLASS_PANE.parseItem()); + fill(inventory, XMaterial.BLACK_STAINED_GLASS_PANE.parseItem()); for (Category category : Category.getCategories()) { ItemStack item = category.getItem(); ItemMeta meta = item.getItemMeta(); @@ -135,14 +136,14 @@ public class InventoryUtils { inventory.addItem(item); } - inventory.setItem(37, buildButton( + inventory.setItem(39, buildButton( XMaterial.BOOK.parseItem(), "&eFavorites", "", "&8Click to view your favorites") ); - inventory.setItem(43, buildButton( + inventory.setItem(41, buildButton( XMaterial.COMPASS.parseItem(), "&aLocal", "", @@ -152,26 +153,29 @@ public class InventoryUtils { player.openInventory(inventory); } - public static void fillBorder(Inventory inv, ItemStack item) { + public static void fill(Inventory inv, ItemStack item) { int size = inv.getSize(); - int rows = (size + 1) / 9; + int[] ignored = new int[]{20, 21, 22, 23, 24, 29, 30, 31, 32, 33, 39, 41}; - // Fill top - for (int i = 0; i < 9; i++) { - inv.setItem(i, item); + // Fill + for (int i = 0; i < size; i++) { + if (!contains(i, ignored)) { + ItemStack slotItem = inv.getItem(i); + if (slotItem == null || slotItem.getType() == Material.AIR) { + inv.setItem(i, item); + } + } + } + } + + private static boolean contains(int n, int... array) { + for (int i : array) { + if (i == n) { + return true; + } } - // Fill bottom - for (int i = size - 9; i < size; i++) { - inv.setItem(i, item); - } - - // Fill sides - for (int i = 2; i <= rows - 1; i++) { - int[] slots = new int[]{i * 9 - 1, (i - 1) * 9}; - inv.setItem(slots[0], item); - inv.setItem(slots[1], item); - } + return false; } private static ItemStack buildButton(ItemStack item, String name, String... lore) { diff --git a/src/main/java/tsp/headdb/inventory/PagedPane.java b/src/main/java/tsp/headdb/inventory/PagedPane.java index 33954cd..e67ba6b 100644 --- a/src/main/java/tsp/headdb/inventory/PagedPane.java +++ b/src/main/java/tsp/headdb/inventory/PagedPane.java @@ -33,6 +33,8 @@ public class PagedPane implements InventoryHolder { protected Button controlBack; @SuppressWarnings("WeakerAccess") protected Button controlNext; + @SuppressWarnings("WeakerAccess") + protected Button controlMain; /** * @param pageSize The page size. inventory rows - 2 @@ -145,6 +147,7 @@ public class PagedPane implements InventoryHolder { controlBack = null; controlNext = null; + controlMain = null; createControls(inventory); } @@ -169,6 +172,12 @@ public class PagedPane implements InventoryHolder { } return; } + else if (event.getSlot() == inventory.getSize()- 5) { + if (controlMain != null){ + controlMain.onClick(event); + } + return; + } pages.get(currentIndex).handleClick(event); @@ -236,12 +245,9 @@ public class PagedPane implements InventoryHolder { "&3&lPage &a&l%d &7/ &c&l%d", getCurrentPage(), getPageAmount() ); - String lore = String.format( - Locale.ROOT, - "&7Current: &a%d", - getCurrentPage() - ); + String lore = "&7Click to go to the &cMain Menu"; ItemStack itemStack = setMeta(HeadAPI.getHeadByValue("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvY2Q5MWY1MTI2NmVkZGM2MjA3ZjEyYWU4ZDdhNDljNWRiMDQxNWFkYTA0ZGFiOTJiYjc2ODZhZmRiMTdmNGQ0ZSJ9fX0=").getItemStack(), name, lore); + controlMain = new Button(itemStack, event -> InventoryUtils.openDatabase((Player) event.getWhoClicked())); inventory.setItem(inventory.getSize() - 5, itemStack); } } @@ -250,7 +256,7 @@ public class PagedPane implements InventoryHolder { int yMod = rowIndex * 9; for (int i = 0; i < 9; i++) { int slot = yMod + i; - inventory.setItem(slot, itemStack); + inventory.setItem(slot, setMeta(itemStack, "")); } }