From 995fa97c26efdbfb1956ec3a5748a82ee56ef1a7 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Mon, 20 Apr 2020 11:57:19 +0200 Subject: [PATCH] New working Tablist! Signed-off-by: Lixfel --- .../bungeecore/listeners/TablistManager.java | 61 +++++++++++-------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/src/de/steamwar/bungeecore/listeners/TablistManager.java b/src/de/steamwar/bungeecore/listeners/TablistManager.java index 5a44330..5243e5e 100644 --- a/src/de/steamwar/bungeecore/listeners/TablistManager.java +++ b/src/de/steamwar/bungeecore/listeners/TablistManager.java @@ -1,8 +1,8 @@ package de.steamwar.bungeecore.listeners; import codecrafter47.bungeetablistplus.api.bungee.BungeeTabListPlusAPI; -import codecrafter47.bungeetablistplus.api.bungee.CustomTablist; import codecrafter47.bungeetablistplus.api.bungee.Icon; +import codecrafter47.bungeetablistplus.tablist.DefaultCustomTablist; import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; @@ -41,7 +41,7 @@ public class TablistManager extends BasicListener { } } - private void setHeader(){ + private void calcHeader(){ if(seconds % 4 == 0){ int phase = (seconds % 16) / 4; switch(phase){ @@ -66,16 +66,15 @@ public class TablistManager extends BasicListener { size = -1; for(Map.Entry> server : playerMap.entrySet()) size += 2 + server.getValue().size(); - if(size < 0){ - size = 0; - return; - } - size = size/20+20; + size = (size+19)/20; + + if(size > 4) + size = 4; } private synchronized void updateCustomTablist(){ - setHeader(); + calcHeader(); //Calculate server-player-map playerMap.clear(); @@ -89,19 +88,18 @@ public class TablistManager extends BasicListener { List players; if(subserver != null && subserver.getType() == Servertype.BAUSERVER){ players = playerMap.getOrDefault("Bau", new ArrayList<>()); + players.add(player); + playerMap.putIfAbsent("Bau", players); }else{ players = playerMap.getOrDefault(serverName, new ArrayList<>()); + players.add(player); + playerMap.putIfAbsent(serverName, players); } - - players.add(player); - playerMap.putIfAbsent(serverName, players); } playerMap.forEach((server, players) -> players.sort((proxiedPlayer, t1) -> proxiedPlayer.getName().compareToIgnoreCase(t1.getName()))); //Set size calculateSize(); - if(size > 80) - size = 80; for(Tablist tablist : tablists.values()) tablist.refresh(); @@ -119,14 +117,12 @@ public class TablistManager extends BasicListener { tablists.remove(e.getPlayer()); } - private class Tablist{ - private final CustomTablist customTablist; + private class Tablist extends DefaultCustomTablist { private final ProxiedPlayer player; private Tablist(ProxiedPlayer player){ this.player = player; - this.customTablist = BungeeTabListPlusAPI.createCustomTablist(); - BungeeTabListPlusAPI.setCustomTabList(player, customTablist); + BungeeTabListPlusAPI.setCustomTabList(player, this); } private String getPing(){ @@ -141,22 +137,33 @@ public class TablistManager extends BasicListener { } private void refresh(){ - customTablist.setHeader(header); - customTablist.setFooter("§e" + player.getServer().getInfo().getName() + " " + getPing() + "§8ms"); - customTablist.setSize(size); + ServerInfo currentServer = player.getServer().getInfo(); + setHeader(header); + setFooter("§e" + currentServer.getName() + " " + getPing() + "§8ms"); + setSize(size, 20); try { int i = 0; for (String server : playerMap.navigableKeySet()) { - if (i > 0) - customTablist.setSlot(i++, 0, darkGray, "", 1000); - customTablist.setSlot(i++, 0, gray, "§7§l" + server, 1000); - for (ProxiedPlayer p : playerMap.get(server)) - customTablist.setSlot(i++, 0, BungeeTabListPlusAPI.getIconFromPlayer(p), p.getDisplayName(), 1); + if (i > 0){ + setSlot(i%20, i/20, darkGray, "", 1000); + i++; + } + setSlot(i%20, i/20, gray, "§7§l" + server, 1000); + i++; + for (ProxiedPlayer p : playerMap.get(server)){ + if(currentServer == p.getServer().getInfo()) + setSlot(i%20, i/20, BungeeTabListPlusAPI.getIconFromPlayer(p), p.getDisplayName(), 1); + else + setSlot(i%20, i/20, BungeeTabListPlusAPI.getIconFromPlayer(p), "§7" + p.getDisplayName(), 500); + i++; + } } - while (i < size) - customTablist.setSlot(i++, 0, darkGray, "", 1000); + while (i < size*20){ + setSlot(i%20, i/20, darkGray, "", 1000); + i++; + } }catch(IndexOutOfBoundsException e){ //Ignore }