diff --git a/src/main/java/rip/tilly/bedwars/commands/arena/ArenaCommand.java b/src/main/java/rip/tilly/bedwars/commands/arena/ArenaCommand.java index d9b469d..8346a8e 100644 --- a/src/main/java/rip/tilly/bedwars/commands/arena/ArenaCommand.java +++ b/src/main/java/rip/tilly/bedwars/commands/arena/ArenaCommand.java @@ -5,6 +5,7 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.menus.arena.ArenaManagerMenu; import rip.tilly.bedwars.utils.CC; public class ArenaCommand implements CommandExecutor { @@ -40,7 +41,9 @@ public class ArenaCommand implements CommandExecutor { player.sendMessage(CC.translate(" &c/arena buildmax ")); } else { switch (args[0].toLowerCase()) { - + case "manage": + new ArenaManagerMenu().openMenu(player); + break; } } diff --git a/src/main/java/rip/tilly/bedwars/listeners/InteractListener.java b/src/main/java/rip/tilly/bedwars/listeners/InteractListener.java index fff462c..c332db5 100644 --- a/src/main/java/rip/tilly/bedwars/listeners/InteractListener.java +++ b/src/main/java/rip/tilly/bedwars/listeners/InteractListener.java @@ -77,9 +77,10 @@ public class InteractListener implements Listener { case SPAWN: switch (hotbarItem.getActionType()) { case QUEUE_MENU: - for (GameType gameType : GameType.values()) { - new PlayAGameMenu(this.plugin.getPlayerMenuUtil(player), gameType).open(); - } + new QueueMenu().openMenu(player); +// for (GameType gameType : GameType.values()) { +// new PlayAGameMenu(this.plugin.getPlayerMenuUtil(player), gameType).open(); +// } break; case SETTINGS_MENU: diff --git a/src/main/java/rip/tilly/bedwars/menus/arena/ArenaCopyMenu.java b/src/main/java/rip/tilly/bedwars/menus/arena/ArenaCopyMenu.java new file mode 100644 index 0000000..4173c13 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/menus/arena/ArenaCopyMenu.java @@ -0,0 +1,38 @@ +package rip.tilly.bedwars.menus.arena; + +import lombok.AllArgsConstructor; +import org.bukkit.entity.Player; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.game.arena.Arena; +import rip.tilly.bedwars.game.arena.CopiedArena; +import rip.tilly.bedwars.menus.arena.buttons.ArenaCopyButton; +import rip.tilly.bedwars.utils.CC; +import rip.tilly.bedwars.utils.menu.Button; +import rip.tilly.bedwars.utils.menu.Menu; + +import java.util.HashMap; +import java.util.Map; + +@AllArgsConstructor +public class ArenaCopyMenu extends Menu { + + private final Arena arena; + + @Override + public String getTitle(Player player) { + return CC.translate("&eArena Copies"); + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap<>(); + + int i = 0; + for (CopiedArena arenaCopy : BedWars.getInstance().getArenaManager().getArena(arena.getName()).getCopiedArenas()) { + buttons.put(buttons.size(), new ArenaCopyButton(i, arena, arenaCopy)); + i++; + } + + return buttons; + } +} diff --git a/src/main/java/rip/tilly/bedwars/menus/arena/ArenaGenerationMenu.java b/src/main/java/rip/tilly/bedwars/menus/arena/ArenaGenerationMenu.java new file mode 100644 index 0000000..547cb19 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/menus/arena/ArenaGenerationMenu.java @@ -0,0 +1,37 @@ +package rip.tilly.bedwars.menus.arena; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.bukkit.entity.Player; +import rip.tilly.bedwars.game.arena.Arena; +import rip.tilly.bedwars.menus.arena.buttons.ArenaGenerateButton; +import rip.tilly.bedwars.utils.CC; +import rip.tilly.bedwars.utils.menu.Button; +import rip.tilly.bedwars.utils.menu.Menu; + +import java.util.HashMap; +import java.util.Map; + +@AllArgsConstructor +public class ArenaGenerationMenu extends Menu { + + private final Arena arena; + + @Getter private final int[] clonableAmounts = {1, 2, 3, 4, 5, 10, 15}; + + @Override + public String getTitle(Player player) { + return CC.translate("&eArena Copies Generation"); + } + + @Override + public Map getButtons(Player player) { + Map buttons = new HashMap<>(); + + for (int curr : clonableAmounts) { + buttons.put(1 + buttons.size(), new ArenaGenerateButton(arena, curr)); + } + + return buttons; + } +} diff --git a/src/main/java/rip/tilly/bedwars/menus/arena/ArenaManagerMenu.java b/src/main/java/rip/tilly/bedwars/menus/arena/ArenaManagerMenu.java new file mode 100644 index 0000000..92331d2 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/menus/arena/ArenaManagerMenu.java @@ -0,0 +1,53 @@ +package rip.tilly.bedwars.menus.arena; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.menus.arena.buttons.ArenaButton; +import rip.tilly.bedwars.utils.ItemBuilder; +import rip.tilly.bedwars.utils.menu.Button; +import rip.tilly.bedwars.utils.menu.pagination.PageButton; +import rip.tilly.bedwars.utils.menu.pagination.PaginatedMenu; + +import java.util.HashMap; +import java.util.Map; + +public class ArenaManagerMenu extends PaginatedMenu { + + private final BedWars plugin = BedWars.getInstance(); + + @Override + public String getPrePaginatedTitle(Player player) { + return "Arena Management"; + } + + @Override + public Map getAllPagesButtons(Player player) { + Map buttons = new HashMap<>(); + this.plugin.getArenaManager().getArenas().forEach((s, arena) -> buttons.put(buttons.size(), new ArenaButton(arena))); + + return buttons; + } + + @Override + public Map getGlobalButtons(Player player) { + Map buttons = new HashMap<>(); + + buttons.put(0, new PageButton(-1, this)); + buttons.put(8, new PageButton(1, this)); + + bottomTopButtons(false, buttons, new ItemBuilder(Material.STAINED_GLASS_PANE).name(" ").durability(7).build()); + + return buttons; + } + + @Override + public int getSize() { + return 9 * 5; + } + + @Override + public int getMaxItemsPerPage(Player player) { + return 9 * 3; + } +} diff --git a/src/main/java/rip/tilly/bedwars/menus/arena/buttons/ArenaButton.java b/src/main/java/rip/tilly/bedwars/menus/arena/buttons/ArenaButton.java new file mode 100644 index 0000000..1be827a --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/menus/arena/buttons/ArenaButton.java @@ -0,0 +1,66 @@ +package rip.tilly.bedwars.menus.arena.buttons; + +import lombok.AllArgsConstructor; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.game.arena.Arena; +import rip.tilly.bedwars.menus.arena.ArenaCopyMenu; +import rip.tilly.bedwars.menus.arena.ArenaGenerationMenu; +import rip.tilly.bedwars.utils.CC; +import rip.tilly.bedwars.utils.ItemBuilder; +import rip.tilly.bedwars.utils.menu.Button; + +import java.util.Arrays; + +@AllArgsConstructor +public class ArenaButton extends Button { + + private final Arena arena; + + @Override + public ItemStack getButtonItem(Player player) { + return new ItemBuilder(Material.valueOf(arena.getIcon())) + .durability(arena.getIconData()) + .name("&b" + arena.getName()) + .lore(CC.translate( + Arrays.asList( + " ", + "&bArena Information&7:", + " &9&l▸ &fState: " + (arena.isEnabled() ? "&aEnabled" : "&cDisabled"), + " &9&l▸ &fType: &b" + (arena.getAvailableArenas().size() == 0 ? "Shared" : "Standalone"), + " &9&l▸ &fCopies: &b" + (arena.getCopiedArenas().size() == 0 ? "Not Required!" : arena.getCopiedArenas().size()), + " &9&l▸ &fAvailable: &b" + (arena.getAvailableArenas().size() == 0 ? +1 : arena.getAvailableArenas().size()), + " ", + (arena.getCopiedArenas().size() == 0 ? "&4&l&mMIDDLE-CLICK &4&mto see arena copies" : "&6&lMIDDLE-CLICK &6to see arena copies"), + "&a&lLEFT-CLICK &ato teleport to arena", + "&b&lRIGHT CLICK &bto generate standalone arenas") + ) + ) + .hideFlags() + .build(); + } + + @Override + public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) { + playSuccess(player); + switch (clickType) { + case LEFT: + player.teleport(arena.getA().toBukkitLocation()); + break; + case RIGHT: + Bukkit.getScheduler().runTaskLaterAsynchronously(BedWars.getInstance(), () -> new ArenaGenerationMenu(arena).openMenu(player), 1L); + break; + case MIDDLE: + if (arena.getCopiedArenas().size() >= 1) { + Bukkit.getScheduler().runTaskLaterAsynchronously(BedWars.getInstance(), () -> new ArenaCopyMenu(arena).openMenu(player), 1L); + } + break; + } + + player.closeInventory(); + } +} diff --git a/src/main/java/rip/tilly/bedwars/menus/arena/buttons/ArenaCopyButton.java b/src/main/java/rip/tilly/bedwars/menus/arena/buttons/ArenaCopyButton.java new file mode 100644 index 0000000..e414a40 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/menus/arena/buttons/ArenaCopyButton.java @@ -0,0 +1,60 @@ +package rip.tilly.bedwars.menus.arena.buttons; + +import lombok.AllArgsConstructor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import rip.tilly.bedwars.BedWars; +import rip.tilly.bedwars.game.arena.Arena; +import rip.tilly.bedwars.game.arena.CopiedArena; +import rip.tilly.bedwars.runnables.ArenaCopyRemovalRunnable; +import rip.tilly.bedwars.utils.CC; +import rip.tilly.bedwars.utils.ItemBuilder; +import rip.tilly.bedwars.utils.menu.Button; + +import java.util.Arrays; + +@AllArgsConstructor +public class ArenaCopyButton extends Button { + + private final BedWars plugin = BedWars.getInstance(); + + private final int number; + private final Arena arena; + private final CopiedArena arenaCopy; + + @Override + public ItemStack getButtonItem(Player player) { + return new ItemBuilder(Material.PAPER) + .name("&8" + number) + .lore(CC.translate( + Arrays.asList( + "&bCopy Information&7:", + " &9&l▸ &fParent Arena: &b" + arena.getName() + " &7(&f#" + number + "&7)", + " &9&l▸ &f1st Spawn: &b" + Math.round(arenaCopy.getA().getX()) + "&7, &b" + Math.round(arenaCopy.getA().getY()) + "&7, &b" + Math.round(arenaCopy.getA().getZ()), + " &9&l▸ &f2nd Spawn: &b" + Math.round(arenaCopy.getB().getX()) + "&7, &b" + Math.round(arenaCopy.getB().getY()) + "&7, &b" + Math.round(arenaCopy.getB().getZ()), + " &9&l▸ &fMin Location: &b" + Math.round(arenaCopy.getMin().getX()) + "&7, &b" + Math.round(arenaCopy.getMin().getY()) + "&7, &b" + Math.round(arenaCopy.getMin().getZ()), + " &9&l▸ &fMax Location: &b" + Math.round(arenaCopy.getMax().getX()) + "&7, &b" + Math.round(arenaCopy.getMax().getY()) + "&7, &b" + Math.round(arenaCopy.getMax().getZ()), + " ", + "&a&lLEFT-CLICK &ato teleport to this copy!", + "&c&lRIGHT-CLICK &cto delete this copy!" + )) + ) + .build(); + } + + @Override + public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) { + switch (clickType) { + case LEFT: + player.teleport(arenaCopy.getA().toBukkitLocation()); + break; + case RIGHT: + new ArenaCopyRemovalRunnable(number, arena, arenaCopy).runTask(this.plugin); + break; + } + + player.closeInventory(); + } +} diff --git a/src/main/java/rip/tilly/bedwars/menus/arena/buttons/ArenaGenerateButton.java b/src/main/java/rip/tilly/bedwars/menus/arena/buttons/ArenaGenerateButton.java new file mode 100644 index 0000000..e634274 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/menus/arena/buttons/ArenaGenerateButton.java @@ -0,0 +1,53 @@ +package rip.tilly.bedwars.menus.arena.buttons; + +import lombok.AllArgsConstructor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import rip.tilly.bedwars.game.arena.Arena; +import rip.tilly.bedwars.utils.CC; +import rip.tilly.bedwars.utils.ItemBuilder; +import rip.tilly.bedwars.utils.menu.Button; + +import java.util.Arrays; + +@AllArgsConstructor +public class ArenaGenerateButton extends Button { + + private final Arena arena; + private final int currentCopyAmount; + + @Override + public ItemStack getButtonItem(Player player) { + return new ItemBuilder(Material.PAPER) + .name("&aCreate " + currentCopyAmount + " Arena Copies") + .lore(CC.translate( + Arrays.asList( + " ", + "&7Clicking here will generate &b&l" + currentCopyAmount, + "&7arenas for the map &b" + arena.getName() + "&7!", + " ", + "&a&lLEFT-CLICK &ato generate arenas") + )) + .amount(currentCopyAmount) + .build(); + } + + @Override + public void clicked(Player player, int slot, ClickType clickType, int hotbarButton) { + player.performCommand("arena generate " + arena.getName() + " " + currentCopyAmount); + + player.sendMessage(CC.chatBar); + player.sendMessage(CC.translate("&b&lGENERATING ARENAS&b...")); + player.sendMessage(CC.translate(" ")); + player.sendMessage(CC.translate("&fFrost is currently generating copies for:")); + player.sendMessage(CC.translate(" &9&l▸ &fArena: &b" + arena.getName())); + player.sendMessage(CC.translate(" &9&l▸ &fCopies: &b" + currentCopyAmount)); + player.sendMessage(CC.translate(" ")); + player.sendMessage(CC.translate("&7&oYou can check the progress in console.")); + player.sendMessage(CC.chatBar); + + player.closeInventory(); + } +} diff --git a/src/main/java/rip/tilly/bedwars/utils/menu/buttons/BackButton.java b/src/main/java/rip/tilly/bedwars/utils/menu/buttons/BackButton.java new file mode 100644 index 0000000..718a85b --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/utils/menu/buttons/BackButton.java @@ -0,0 +1,35 @@ +package rip.tilly.bedwars.utils.menu.buttons; + +import lombok.AllArgsConstructor; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import rip.tilly.bedwars.utils.menu.Button; +import rip.tilly.bedwars.utils.menu.Menu; + +@AllArgsConstructor +public class BackButton extends Button { + + private Menu back; + + @Override + public ItemStack getButtonItem(Player player) { + ItemStack itemStack = new ItemStack(Material.BED); + ItemMeta itemMeta = itemStack.getItemMeta(); + + itemMeta.setDisplayName(ChatColor.RED + "Go back"); + itemStack.setItemMeta(itemMeta); + + return itemStack; + } + + @Override + public void clicked(Player player, int i, ClickType clickType, int hb) { + Button.playNeutral(player); + + this.back.openMenu(player); + } +} diff --git a/src/main/java/rip/tilly/bedwars/utils/menu/buttons/DisplayButton.java b/src/main/java/rip/tilly/bedwars/utils/menu/buttons/DisplayButton.java new file mode 100644 index 0000000..dcf911e --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/utils/menu/buttons/DisplayButton.java @@ -0,0 +1,31 @@ +package rip.tilly.bedwars.utils.menu.buttons; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import rip.tilly.bedwars.utils.menu.Button; + +@AllArgsConstructor @Getter @Setter +public class DisplayButton extends Button { + + private ItemStack itemStack; + private boolean cancel; + + @Override + public ItemStack getButtonItem(Player player) { + if (this.itemStack == null) { + return new ItemStack(Material.AIR); + } else { + return this.itemStack; + } + } + + @Override + public boolean shouldCancel(Player player, int slot, ClickType clickType) { + return this.cancel; + } +} diff --git a/src/main/java/rip/tilly/bedwars/utils/menu/pagination/JumpToPageButton.java b/src/main/java/rip/tilly/bedwars/utils/menu/pagination/JumpToPageButton.java new file mode 100644 index 0000000..c190327 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/utils/menu/pagination/JumpToPageButton.java @@ -0,0 +1,45 @@ +package rip.tilly.bedwars.utils.menu.pagination; + +import lombok.AllArgsConstructor; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import rip.tilly.bedwars.utils.menu.Button; + +import java.util.Arrays; + +@AllArgsConstructor +public class JumpToPageButton extends Button { + + private int page; + private PaginatedMenu menu; + private boolean current; + + @Override + public ItemStack getButtonItem(Player player) { + ItemStack itemStack = new ItemStack(this.current ? Material.ENCHANTED_BOOK : Material.BOOK, this.page); + ItemMeta itemMeta = itemStack.getItemMeta(); + + itemMeta.setDisplayName(ChatColor.GREEN + "Page " + this.page); + + if (this.current) { + itemMeta.setLore(Arrays.asList( + "", + ChatColor.GREEN + "Current page" + )); + } + + itemStack.setItemMeta(itemMeta); + + return itemStack; + } + + @Override + public void clicked(Player player, int i, ClickType clickType, int hb) { + this.menu.modPage(player, this.page - this.menu.getPage()); + Button.playNeutral(player); + } +} diff --git a/src/main/java/rip/tilly/bedwars/utils/menu/pagination/PageButton.java b/src/main/java/rip/tilly/bedwars/utils/menu/pagination/PageButton.java new file mode 100644 index 0000000..ac23258 --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/utils/menu/pagination/PageButton.java @@ -0,0 +1,61 @@ +package rip.tilly.bedwars.utils.menu.pagination; + +import lombok.AllArgsConstructor; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; +import rip.tilly.bedwars.utils.menu.Button; + +import java.util.Arrays; + +@AllArgsConstructor +public class PageButton extends Button { + + private int mod; + private PaginatedMenu menu; + + @Override + public ItemStack getButtonItem(Player player) { + ItemStack itemStack = new ItemStack(Material.CARPET); + ItemMeta itemMeta = itemStack.getItemMeta(); + + if (this.hasNext(player)) { + itemMeta.setDisplayName(this.mod > 0 ? ChatColor.GREEN + "Next page" : ChatColor.RED + "Previous page"); + } else { + itemMeta.setDisplayName(ChatColor.GRAY + (this.mod > 0 ? "Last page" : "First page")); + } + + itemMeta.setLore(Arrays.asList( + "", + ChatColor.GREEN + "Right click to", + ChatColor.GREEN + "jump to a page" + )); + + itemStack.setItemMeta(itemMeta); + + return itemStack; + } + + @Override + public void clicked(Player player, int i, ClickType clickType, int hb) { + if (clickType == ClickType.RIGHT) { + new ViewAllPagesMenu(this.menu).openMenu(player); + playNeutral(player); + } else { + if (hasNext(player)) { + this.menu.modPage(player, this.mod); + Button.playNeutral(player); + } else { + Button.playFail(player); + } + } + } + + private boolean hasNext(Player player) { + int pg = this.menu.getPage() + this.mod; + return pg > 0 && this.menu.getPages(player) >= pg; + } +} diff --git a/src/main/java/rip/tilly/bedwars/utils/menu/pagination/PaginatedMenu.java b/src/main/java/rip/tilly/bedwars/utils/menu/pagination/PaginatedMenu.java new file mode 100644 index 0000000..631c29e --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/utils/menu/pagination/PaginatedMenu.java @@ -0,0 +1,118 @@ +package rip.tilly.bedwars.utils.menu.pagination; + +import lombok.Getter; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import rip.tilly.bedwars.utils.menu.Button; +import rip.tilly.bedwars.utils.menu.Menu; + +import java.util.HashMap; +import java.util.Map; +import java.util.stream.IntStream; + +public abstract class PaginatedMenu extends Menu { + + @Getter private int page = 1; + + { + setUpdateAfterClick(false); + } + + @Override + public String getTitle(Player player) { + return getPrePaginatedTitle(player) + " - " + page + "/" + getPages(player); + } + + /** + * Changes the page number + * + * @param player player viewing the inventory + * @param mod delta to modify the page number by + */ + public final void modPage(Player player, int mod) { + page += mod; + getButtons().clear(); + openMenu(player); + } + + /** + * @param player player viewing the inventory + */ + public final int getPages(Player player) { + int buttonAmount = getAllPagesButtons(player).size(); + + if (buttonAmount == 0) { + return 1; + } + + return (int) Math.ceil(buttonAmount / (double) getMaxItemsPerPage(player)); + } + + @Override + public final Map getButtons(Player player) { + int minIndex = (int) ((double) (page - 1) * getMaxItemsPerPage(player)); + int maxIndex = (int) ((double) (page) * getMaxItemsPerPage(player)); + + HashMap buttons = new HashMap<>(); + + buttons.put(0, new PageButton(-1, this)); + buttons.put(8, new PageButton(1, this)); + + for (Map.Entry entry : getAllPagesButtons(player).entrySet()) { + int ind = entry.getKey(); + if (ind >= minIndex && ind < maxIndex) { + ind -= (int) ((double) (getMaxItemsPerPage(player)) * (page - 1)) - 9; + buttons.put(ind, entry.getValue()); + } + } + + Map global = getGlobalButtons(player); + if (global != null) { + for (Map.Entry gent : global.entrySet()) { + buttons.put(gent.getKey(), gent.getValue()); + } + } + + return buttons; + } + + public int getMaxItemsPerPage(Player player) { + return 18; + } + + /** + * @param player player viewing the inventory + * + * @return a Map of buttons that returns items which will be present on all pages + */ + public Map getGlobalButtons(Player player) { + return null; + } + + protected void bottomTopButtons(boolean full, Map buttons, ItemStack itemStack) { + IntStream.range(0, getSize()).filter(slot -> buttons.get(slot) == null).forEach(slot -> { + if (slot < 9 || slot > getSize() - 10 || full && (slot % 9 == 0 || (slot + 1) % 9 == 0)) { + buttons.put(slot, new Button() { + @Override + public ItemStack getButtonItem(Player player) { + return itemStack; + } + }); + } + }); + } + + /** + * @param player player viewing the inventory + * + * @return title of the inventory before the page number is added + */ + public abstract String getPrePaginatedTitle(Player player); + + /** + * @param player player viewing the inventory + * + * @return a map of buttons that will be paginated and spread across pages + */ + public abstract Map getAllPagesButtons(Player player); +} diff --git a/src/main/java/rip/tilly/bedwars/utils/menu/pagination/ViewAllPagesMenu.java b/src/main/java/rip/tilly/bedwars/utils/menu/pagination/ViewAllPagesMenu.java new file mode 100644 index 0000000..833afca --- /dev/null +++ b/src/main/java/rip/tilly/bedwars/utils/menu/pagination/ViewAllPagesMenu.java @@ -0,0 +1,47 @@ +package rip.tilly.bedwars.utils.menu.pagination; + +import lombok.Getter; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; +import org.bukkit.entity.Player; +import rip.tilly.bedwars.utils.CC; +import rip.tilly.bedwars.utils.menu.Button; +import rip.tilly.bedwars.utils.menu.Menu; +import rip.tilly.bedwars.utils.menu.buttons.BackButton; + +import java.util.HashMap; +import java.util.Map; + +@RequiredArgsConstructor +public class ViewAllPagesMenu extends Menu { + + @NonNull @Getter PaginatedMenu menu; + + @Override + public String getTitle(Player player) { + return CC.translate("&eJump to page"); + } + + @Override + public Map getButtons(Player player) { + HashMap buttons = new HashMap<>(); + + buttons.put(0, new BackButton(menu)); + + int index = 10; + for (int i = 1; i <= menu.getPages(player); i++) { + buttons.put(index++, new JumpToPageButton(i, menu, menu.getPage() == i)); + + if ((index - 8) % 9 == 0) { + index += 2; + } + } + + return buttons; + } + + @Override + public boolean isAutoUpdate() { + return true; + } +}