diff --git a/src/main/java/net/knarcraft/bookswithoutborders/gui/AuthorBookIndex.java b/src/main/java/net/knarcraft/bookswithoutborders/gui/AuthorBookIndex.java index 1daac01..8fa76cd 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/gui/AuthorBookIndex.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/gui/AuthorBookIndex.java @@ -1,6 +1,7 @@ package net.knarcraft.bookswithoutborders.gui; import net.knarcraft.bookswithoutborders.BooksWithoutBorders; +import net.knarcraft.bookswithoutborders.config.BooksWithoutBordersConfig; import net.knarcraft.bookswithoutborders.utility.BookFormatter; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.ClickEvent; @@ -27,7 +28,8 @@ public class AuthorBookIndex extends BookIndex { public static void printBooks(@NotNull CommandSender sender, boolean listPublic, @NotNull String command, int page, @NotNull String authorName) { List availableBooks = BooksWithoutBorders.getAvailableBooks(sender, listPublic); - availableBooks.removeIf((bookPath) -> !BookFormatter.stripColor(bookPath.substring(0, bookPath.length() - 4).split(",")[1]).equalsIgnoreCase(authorName)); + availableBooks.removeIf((bookPath) -> !BookFormatter.stripColor(bookPath.substring(0, bookPath.length() - 4).split( + BooksWithoutBordersConfig.getTitleAuthorSeparator())[1]).equalsIgnoreCase(authorName)); int totalPages = (int) Math.ceil((double) availableBooks.size() / booksPerPage); if (page > totalPages) { @@ -50,17 +52,23 @@ public class AuthorBookIndex extends BookIndex { private static void showAuthorBooks(@NotNull CommandSender sender, @NotNull String command, int page, int totalPages, @NotNull List availableBooks, @NotNull String authorName) { ComponentBuilder componentBuilder = new ComponentBuilder(); + String navigationCommand = command + " author" + authorName; + + componentBuilder.append("--- "); + if (command.toLowerCase().contains("public")) { + componentBuilder.append("Publicly saved books by: ").color(ChatColor.GREEN).append(authorName).color(ChatColor.AQUA); + } else { + componentBuilder.append("Your saved books by: ").color(ChatColor.GREEN).append(authorName).color(ChatColor.AQUA); + } + componentBuilder.append(" ---", ComponentBuilder.FormatRetention.NONE).append("\n"); + - // Display the list of books, with the next and previous buttons - displayPreviousButton(componentBuilder, command + " author" + authorName, page); - componentBuilder.append("\n"); displayBookList(componentBuilder, command, page, availableBooks); - displayNextButton(componentBuilder, command + " author" + authorName, page, totalPages); - - // Display total pages and the manual change page command suggestion - componentBuilder.append(" ", ComponentBuilder.FormatRetention.NONE); - displayTotalPages(componentBuilder, page, totalPages); - componentBuilder.append(" ", ComponentBuilder.FormatRetention.NONE); + displayPreviousButton(componentBuilder, navigationCommand, page); + componentBuilder.append(" | ", ComponentBuilder.FormatRetention.NONE); + displayTotalPages(componentBuilder, navigationCommand, page, totalPages); + componentBuilder.append(" | ", ComponentBuilder.FormatRetention.NONE); + displayNextButton(componentBuilder, navigationCommand, page, totalPages); sender.spigot().sendMessage(componentBuilder.create()); } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/gui/BookIndex.java b/src/main/java/net/knarcraft/bookswithoutborders/gui/BookIndex.java index 1e5cce6..d7d00f7 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/gui/BookIndex.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/gui/BookIndex.java @@ -52,28 +52,18 @@ public abstract class BookIndex { } /** - * Displays the suggestion for manually going to any page + * Displays the current page and total amount of pages * * @param componentBuilder

The component builder to append to

* @param command

The command used for switching pages

* @param page

The current page

- */ - protected static void displayPageCommand(@NotNull ComponentBuilder componentBuilder, @NotNull String command, int page) { - componentBuilder.append("[Page Command]", ComponentBuilder.FormatRetention.NONE).color(interactColor).event(new HoverEvent( - HoverEvent.Action.SHOW_TEXT, new Text("/" + command + " page" + page))).event( - new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/" + command + " page" + page)); - } - - /** - * Displays the current page and total amount of pages - * - * @param componentBuilder

The component builder to append to

- * @param page

The current page

* @param totalPages

The total amount of pages

*/ - protected static void displayTotalPages(@NotNull ComponentBuilder componentBuilder, int page, int totalPages) { + protected static void displayTotalPages(@NotNull ComponentBuilder componentBuilder, @NotNull String command, int page, int totalPages) { componentBuilder.append("Page " + page + " of " + totalPages, - ComponentBuilder.FormatRetention.NONE).color(inactiveColor); + ComponentBuilder.FormatRetention.NONE).color(interactColor).event(new HoverEvent( + HoverEvent.Action.SHOW_TEXT, new Text("/" + command + " page" + page))).event( + new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, "/" + command + " page" + page)); } /** @@ -114,10 +104,10 @@ public abstract class BookIndex { String fullCommand = "/" + command + " page" + (page - 1); HoverEvent prevPagePreview = new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("To page " + (page - 1))); ClickEvent prevPageClick = new ClickEvent(ClickEvent.Action.RUN_COMMAND, fullCommand); - componentBuilder.append("Previous [<]", ComponentBuilder.FormatRetention.NONE).color(interactColor) + componentBuilder.append("[<] Previous", ComponentBuilder.FormatRetention.NONE).color(interactColor) .event(prevPagePreview).event(prevPageClick); } else { - componentBuilder.append("Previous [<]", ComponentBuilder.FormatRetention.NONE).color(inactiveColor); + componentBuilder.append("[<] Previous", ComponentBuilder.FormatRetention.NONE).color(inactiveColor); } } diff --git a/src/main/java/net/knarcraft/bookswithoutborders/gui/PagedBookIndex.java b/src/main/java/net/knarcraft/bookswithoutborders/gui/PagedBookIndex.java index 65001a4..16e2fbf 100644 --- a/src/main/java/net/knarcraft/bookswithoutborders/gui/PagedBookIndex.java +++ b/src/main/java/net/knarcraft/bookswithoutborders/gui/PagedBookIndex.java @@ -63,20 +63,21 @@ public class PagedBookIndex extends BookIndex { @NotNull Map firstInstances) { ComponentBuilder componentBuilder = new ComponentBuilder(); - // Display the list of books, with the next and previous buttons - displayPreviousButton(componentBuilder, command, page); - componentBuilder.append("\n"); + componentBuilder.append("--- "); + if (command.toLowerCase().contains("public")) { + componentBuilder.append("Publicly saved books").color(ChatColor.GREEN); + } else { + componentBuilder.append("Your saved books").color(ChatColor.GREEN); + } + componentBuilder.append(" ---", ComponentBuilder.FormatRetention.NONE).append("\n"); + displayBookList(componentBuilder, command, page, availableBooks); + displayPreviousButton(componentBuilder, command, page); + componentBuilder.append(" | ", ComponentBuilder.FormatRetention.NONE); + displayTotalPages(componentBuilder, command, page, totalPages); + componentBuilder.append(" | ", ComponentBuilder.FormatRetention.NONE); displayNextButton(componentBuilder, command, page, totalPages); - - // Display total pages and the manual change page command suggestion - componentBuilder.append(" ", ComponentBuilder.FormatRetention.NONE); - displayTotalPages(componentBuilder, page, totalPages); - componentBuilder.append(" ", ComponentBuilder.FormatRetention.NONE); - displayPageCommand(componentBuilder, command, page); componentBuilder.append("\n"); - - // Display the alphabet index as the header displayAlphabetIndex(componentBuilder, command, firstInstances); sender.spigot().sendMessage(componentBuilder.create()); }