From 39c72549639d1592f9c3714e4f8b929214323061 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 22 Dec 2021 17:09:16 +0100 Subject: [PATCH] Simplify code Signed-off-by: Lixfel --- .../bungeecore/listeners/TablistManager.java | 30 ++++++------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/TablistManager.java b/src/de/steamwar/bungeecore/listeners/TablistManager.java index 4cda03a3..6b5cb345 100644 --- a/src/de/steamwar/bungeecore/listeners/TablistManager.java +++ b/src/de/steamwar/bungeecore/listeners/TablistManager.java @@ -103,7 +103,7 @@ public class TablistManager extends BasicListener { if(bau.size() > 0) tablist.addSubTablist(bau); - size = (int) Math.ceil(tablist.size() / 20.0); + size = (int) Math.ceil((tablist.size() - 1) / 20.0); tablists.values().forEach(Tablist::refresh); seconds++; } @@ -197,23 +197,11 @@ public class TablistManager extends BasicListener { @Override public int slimSize(ProxiedPlayer viewer) { - int size = 0; - for (int i = 0; i < subTablists.size(); i++) { - TablistPart tablistPart = subTablists.get(i); - boolean removeFooter = i == subTablists.size() - 1; - if (viewer == null) { - size += tablistPart.size(); - } else { - int slimSize = tablistPart.slimSize(viewer); - size += slimSize; - if (slimSize == 0) removeFooter = true; - } - if (withHeaders) { - size += 2; // The 2 is for the header and footer - if (removeFooter) size--; // The last one has no footer - } - } - return size; + return subTablists.stream().mapToInt(tPart -> viewer == null ? tPart.size() : tPart.slimSize(viewer)).map(size -> { + size += withHeaders ? 1 : 0; // Space for header + size += withHeaders && size > 1 ? 1 : 0; // Space for footer + return size; + }).sum(); } @Override @@ -225,7 +213,7 @@ public class TablistManager extends BasicListener { public void print(Tablist viewer, boolean slim) { for (int i = 0; i < subTablists.size(); i++) { TablistPart tPart = subTablists.get(i); - boolean removeFooter = i == subTablists.size() - 1; + boolean withoutFooter = i == subTablists.size() - 1; if (withHeaders) { if (slim) { int slimSize = tPart.slimSize(viewer.player); @@ -234,7 +222,7 @@ public class TablistManager extends BasicListener { viewer.setSlot(gray, "§7§l" + tPart.name(), 1000); } else if (slimSize == 0) { viewer.setSlot(gray, "§7§l" + tPart.name() + " §8(§7" + size + "§8)", 1000); - removeFooter = true; + withoutFooter = true; } else { viewer.setSlot(gray, "§7§l" + tPart.name() + " §8(§7+" + (size - slimSize) + "§8)", 1000); } @@ -243,7 +231,7 @@ public class TablistManager extends BasicListener { } } tPart.print(viewer, slim); - if (withHeaders && !removeFooter) { + if (withHeaders && !withoutFooter) { viewer.setSlot(darkGray, "", 1000); } }