From 0cc93f433ee36aac43873c12c0749be4d5810da6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 22 Dec 2021 10:17:28 +0100 Subject: [PATCH 1/4] Fix TablistManager --- .../bungeecore/listeners/TablistManager.java | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/TablistManager.java b/src/de/steamwar/bungeecore/listeners/TablistManager.java index 066facb..797471d 100644 --- a/src/de/steamwar/bungeecore/listeners/TablistManager.java +++ b/src/de/steamwar/bungeecore/listeners/TablistManager.java @@ -197,9 +197,25 @@ public class TablistManager extends BasicListener { @Override public int slimSize(ProxiedPlayer viewer) { - int size = subTablists.stream().mapToInt(tPart -> viewer == null ? tPart.size() : tPart.slimSize(viewer)).sum(); - if(withHeaders) - size += subTablists.size() * 2; + 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(); + if (withHeaders) size += 2; // The 2 is for the header and footer + if (removeFooter) size--; // The last one has no footer + } else { + int slimSize = tablistPart.slimSize(viewer); + if (slimSize == 0) { + if (withHeaders) size++; // This increment is just for the header + } else { + size += slimSize; + if (withHeaders) size += 2; // The 2 is for the header and footer + if (removeFooter) size--; // The last one has no footer + } + } + } return size; } @@ -210,8 +226,10 @@ public class TablistManager extends BasicListener { @Override public void print(Tablist viewer, boolean slim) { - subTablists.forEach(tPart -> { - if(withHeaders) + for (int i = 0; i < subTablists.size(); i++) { + TablistPart tPart = subTablists.get(i); + boolean removeFooter = i == subTablists.size() - 1; + if (withHeaders) { if (slim) { int slimSize = tPart.slimSize(viewer.player); int size = tPart.size(); @@ -219,16 +237,19 @@ 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; } else { viewer.setSlot(gray, "§7§l" + tPart.name() + " §8(§7+" + (size - slimSize) + "§8)", 1000); } } else { viewer.setSlot(gray, "§7§l" + tPart.name(), 1000); } + } tPart.print(viewer, slim); - if(withHeaders) + if (withHeaders && !removeFooter) { viewer.setSlot(darkGray, "", 1000); - }); + } + } } } -- 2.39.5 From 02883f2beae6a0b75ad2ad4ef86e55d6f0451569 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 22 Dec 2021 11:29:43 +0100 Subject: [PATCH 2/4] Update TablistManager --- .../bungeecore/listeners/TablistManager.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/TablistManager.java b/src/de/steamwar/bungeecore/listeners/TablistManager.java index 797471d..4ef84d7 100644 --- a/src/de/steamwar/bungeecore/listeners/TablistManager.java +++ b/src/de/steamwar/bungeecore/listeners/TablistManager.java @@ -203,18 +203,13 @@ public class TablistManager extends BasicListener { boolean removeFooter = i == subTablists.size() - 1; if (viewer == null) { size += tablistPart.size(); - if (withHeaders) size += 2; // The 2 is for the header and footer - if (removeFooter) size--; // The last one has no footer } else { int slimSize = tablistPart.slimSize(viewer); - if (slimSize == 0) { - if (withHeaders) size++; // This increment is just for the header - } else { - size += slimSize; - if (withHeaders) size += 2; // The 2 is for the header and footer - if (removeFooter) size--; // The last one has no footer - } + 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; } -- 2.39.5 From 6e6cf764790aebce1db9ec16811db3b68bc44ac3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 22 Dec 2021 11:38:00 +0100 Subject: [PATCH 3/4] Update TablistManager --- src/de/steamwar/bungeecore/listeners/TablistManager.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/TablistManager.java b/src/de/steamwar/bungeecore/listeners/TablistManager.java index 4ef84d7..4cda03a 100644 --- a/src/de/steamwar/bungeecore/listeners/TablistManager.java +++ b/src/de/steamwar/bungeecore/listeners/TablistManager.java @@ -208,8 +208,10 @@ public class TablistManager extends BasicListener { 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 + if (withHeaders) { + size += 2; // The 2 is for the header and footer + if (removeFooter) size--; // The last one has no footer + } } return size; } -- 2.39.5 From 39c72549639d1592f9c3714e4f8b929214323061 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Wed, 22 Dec 2021 17:09:16 +0100 Subject: [PATCH 4/4] 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 4cda03a..6b5cb34 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); } } -- 2.39.5