SteamWar/BungeeCore
Archiviert
13
2

New working Tablist!

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2020-04-20 11:57:19 +02:00
Ursprung a75906a5e6
Commit 995fa97c26

Datei anzeigen

@ -1,8 +1,8 @@
package de.steamwar.bungeecore.listeners; package de.steamwar.bungeecore.listeners;
import codecrafter47.bungeetablistplus.api.bungee.BungeeTabListPlusAPI; import codecrafter47.bungeetablistplus.api.bungee.BungeeTabListPlusAPI;
import codecrafter47.bungeetablistplus.api.bungee.CustomTablist;
import codecrafter47.bungeetablistplus.api.bungee.Icon; import codecrafter47.bungeetablistplus.api.bungee.Icon;
import codecrafter47.bungeetablistplus.tablist.DefaultCustomTablist;
import de.steamwar.bungeecore.BungeeCore; import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Servertype;
import de.steamwar.bungeecore.Subserver; import de.steamwar.bungeecore.Subserver;
@ -41,7 +41,7 @@ public class TablistManager extends BasicListener {
} }
} }
private void setHeader(){ private void calcHeader(){
if(seconds % 4 == 0){ if(seconds % 4 == 0){
int phase = (seconds % 16) / 4; int phase = (seconds % 16) / 4;
switch(phase){ switch(phase){
@ -66,16 +66,15 @@ public class TablistManager extends BasicListener {
size = -1; size = -1;
for(Map.Entry<String, List<ProxiedPlayer>> server : playerMap.entrySet()) for(Map.Entry<String, List<ProxiedPlayer>> server : playerMap.entrySet())
size += 2 + server.getValue().size(); 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(){ private synchronized void updateCustomTablist(){
setHeader(); calcHeader();
//Calculate server-player-map //Calculate server-player-map
playerMap.clear(); playerMap.clear();
@ -89,19 +88,18 @@ public class TablistManager extends BasicListener {
List<ProxiedPlayer> players; List<ProxiedPlayer> players;
if(subserver != null && subserver.getType() == Servertype.BAUSERVER){ if(subserver != null && subserver.getType() == Servertype.BAUSERVER){
players = playerMap.getOrDefault("Bau", new ArrayList<>()); players = playerMap.getOrDefault("Bau", new ArrayList<>());
players.add(player);
playerMap.putIfAbsent("Bau", players);
}else{ }else{
players = playerMap.getOrDefault(serverName, new ArrayList<>()); 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()))); playerMap.forEach((server, players) -> players.sort((proxiedPlayer, t1) -> proxiedPlayer.getName().compareToIgnoreCase(t1.getName())));
//Set size //Set size
calculateSize(); calculateSize();
if(size > 80)
size = 80;
for(Tablist tablist : tablists.values()) for(Tablist tablist : tablists.values())
tablist.refresh(); tablist.refresh();
@ -119,14 +117,12 @@ public class TablistManager extends BasicListener {
tablists.remove(e.getPlayer()); tablists.remove(e.getPlayer());
} }
private class Tablist{ private class Tablist extends DefaultCustomTablist {
private final CustomTablist customTablist;
private final ProxiedPlayer player; private final ProxiedPlayer player;
private Tablist(ProxiedPlayer player){ private Tablist(ProxiedPlayer player){
this.player = player; this.player = player;
this.customTablist = BungeeTabListPlusAPI.createCustomTablist(); BungeeTabListPlusAPI.setCustomTabList(player, this);
BungeeTabListPlusAPI.setCustomTabList(player, customTablist);
} }
private String getPing(){ private String getPing(){
@ -141,22 +137,33 @@ public class TablistManager extends BasicListener {
} }
private void refresh(){ private void refresh(){
customTablist.setHeader(header); ServerInfo currentServer = player.getServer().getInfo();
customTablist.setFooter("§e" + player.getServer().getInfo().getName() + " " + getPing() + "§8ms"); setHeader(header);
customTablist.setSize(size); setFooter("§e" + currentServer.getName() + " " + getPing() + "§8ms");
setSize(size, 20);
try { try {
int i = 0; int i = 0;
for (String server : playerMap.navigableKeySet()) { for (String server : playerMap.navigableKeySet()) {
if (i > 0) if (i > 0){
customTablist.setSlot(i++, 0, darkGray, "", 1000); setSlot(i%20, i/20, darkGray, "", 1000);
customTablist.setSlot(i++, 0, gray, "§7§l" + server, 1000); i++;
for (ProxiedPlayer p : playerMap.get(server)) }
customTablist.setSlot(i++, 0, BungeeTabListPlusAPI.getIconFromPlayer(p), p.getDisplayName(), 1); 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) while (i < size*20){
customTablist.setSlot(i++, 0, darkGray, "", 1000); setSlot(i%20, i/20, darkGray, "", 1000);
i++;
}
}catch(IndexOutOfBoundsException e){ }catch(IndexOutOfBoundsException e){
//Ignore //Ignore
} }