From 59a66d7bc431b84d645e50b45e25174fe952acb5 Mon Sep 17 00:00:00 2001 From: William278 Date: Fri, 16 Apr 2021 15:12:10 +0100 Subject: [PATCH] Fix incorrect numbers in warp list --- .../huskhomes2/teleport/ListHandler.java | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/william278/huskhomes2/teleport/ListHandler.java b/src/main/java/me/william278/huskhomes2/teleport/ListHandler.java index b737168a1..a3f95495a 100644 --- a/src/main/java/me/william278/huskhomes2/teleport/ListHandler.java +++ b/src/main/java/me/william278/huskhomes2/teleport/ListHandler.java @@ -167,6 +167,21 @@ public static void displayPublicHomeList(Player player, int pageNumber) { displayPageButtons(player, pageNumber, homes.size(), homeUpperBound, "/huskhomes:publichomelist", itemsPerPage); } + // Returns the number of warps the Player can access + private static int getAccessibleWarpCount(Player player, List warps) { + if (HuskHomes.getSettings().doPermissionRestrictedWarps() && HuskHomes.getSettings().doHideRestrictedWarps()) { + int count = 0; + for (Warp warp : warps) { + if (Warp.getWarpCanUse(player, warp.getName())) { + count++; + } + } + return count; + } else { + return warps.size(); + } + } + public static void displayWarpList(Player player, int pageNumber) { ComponentBuilder warpList = new ComponentBuilder(); List warps = DataManager.getWarps(); @@ -177,12 +192,12 @@ public static void displayWarpList(Player player, int pageNumber) { int itemsPerPage = HuskHomes.getSettings().getWarpsPerPage(); int warpsLowerBound = (pageNumber - 1) * itemsPerPage; int warpsUpperBound = pageNumber * itemsPerPage; - if (warpsUpperBound > warps.size()) { - warpsUpperBound = warps.size(); + if (warpsUpperBound > getAccessibleWarpCount(player, warps)) { + warpsUpperBound = getAccessibleWarpCount(player, warps); } player.sendMessage(""); - MessageManager.sendMessage(player, "warp_list_page_top", Integer.toString(warpsLowerBound + 1), Integer.toString(warpsUpperBound), Integer.toString(warps.size())); + MessageManager.sendMessage(player, "warp_list_page_top", Integer.toString(warpsLowerBound + 1), Integer.toString(warpsUpperBound), Integer.toString(getAccessibleWarpCount(player, warps))); int itemsOnPage = 0; for (int i = warpsLowerBound; i < warpsUpperBound; i++) { @@ -192,7 +207,7 @@ public static void displayWarpList(Player player, int pageNumber) { if (!Warp.getWarpCanUse(player, warp.getName())) { continue; } } if (i != warpsLowerBound) { - warpList.append(divider(), ComponentBuilder.FormatRetention.NONE); + if (!warpList.toString().equals("")) { warpList.append(divider(), ComponentBuilder.FormatRetention.NONE); } } warpList.append(clickableWarp(warp), ComponentBuilder.FormatRetention.NONE); itemsOnPage = itemsOnPage + 1; @@ -211,7 +226,7 @@ public static void displayWarpList(Player player, int pageNumber) { } // Display page buttons - displayPageButtons(player, pageNumber, warps.size(), warpsUpperBound, "/huskhomes:warplist", itemsPerPage); + displayPageButtons(player, pageNumber, getAccessibleWarpCount(player, warps), warpsUpperBound, "/huskhomes:warplist", itemsPerPage); } } \ No newline at end of file