SteamWar/BungeeCore
Archiviert
13
2

Adding a first prototype of a new tablist

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2020-04-17 18:54:50 +02:00
Ursprung b3ba571fca
Commit 43ded5e51f
4 geänderte Dateien mit 129 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -62,5 +62,11 @@
<version>1.0</version> <version>1.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>steamwar</groupId>
<artifactId>BungeeTabListPlus</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

Datei anzeigen

@ -96,6 +96,8 @@ public class BungeeCore extends Plugin {
new Broadcaster(); new Broadcaster();
new SessionManager(); new SessionManager();
new Tablist();
getProxy().getScheduler().schedule(this, () -> { getProxy().getScheduler().schedule(this, () -> {
SteamwarUser.clearCache(); SteamwarUser.clearCache();
Team.clearCache(); Team.clearCache();

Datei anzeigen

@ -0,0 +1,120 @@
package de.steamwar.bungeecore.listeners;
import codecrafter47.bungeetablistplus.BungeeTabListPlus;
import codecrafter47.bungeetablistplus.api.bungee.BungeeTabListPlusAPI;
import codecrafter47.bungeetablistplus.api.bungee.CustomTablist;
import codecrafter47.bungeetablistplus.api.bungee.Icon;
import de.steamwar.bungeecore.BungeeCore;
import de.steamwar.bungeecore.Servertype;
import de.steamwar.bungeecore.Subserver;
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.PostLoginEvent;
import net.md_5.bungee.event.EventHandler;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
public class Tablist extends BasicListener {
private final CustomTablist tablist;
private int seconds = 0;
private final Icon darkGray;
private final Icon gray;
public Tablist(){
tablist = BungeeTabListPlusAPI.createCustomTablist();
ProxyServer.getInstance().getScheduler().schedule(BungeeCore.get(), this::updateCustomTablist, 1, 1, TimeUnit.SECONDS);
tablist.setFooter("§8Ping: ${viewer_colored_ping}ms §8Server: §e${viewer server}"); //TODO: Set to tablist per player
//Preload due to bug
BungeeTabListPlus.getInstance().getSkinManager().getIcon("colors/dark_gray.png");
BungeeTabListPlus.getInstance().getSkinManager().getIcon("colors/gray.png");
darkGray = BungeeTabListPlus.getInstance().getSkinManager().getIcon("colors/dark_gray.png");
gray = BungeeTabListPlus.getInstance().getSkinManager().getIcon("colors/gray.png");
//TODO: Fix icons
}
private void setHeader(){
if(seconds % 4 == 0){
int phase = (seconds % 16) / 4;
switch(phase){
case 0:
tablist.setHeader("§8Spieler online: §e" + ProxyServer.getInstance().getPlayers().size());
break;
case 1:
tablist.setHeader("§8Teamspeak: §eSteam§8War.de");
break;
case 2:
tablist.setHeader("§8Discord: §8https://discord.gg/J4NtQmM");
break;
case 3:
tablist.setHeader("§8Website: https://§eSteam§8War.de");
break;
}
}
}
private void updateCustomTablist(){
setHeader();
//Calculate server-player-map
Map<String, List<ProxiedPlayer>> playerMap = new HashMap<>();
for(ProxiedPlayer player : ProxyServer.getInstance().getPlayers()){
ServerInfo server = player.getServer().getInfo();
String serverName = server.getName();
if(serverName.equals("Developer"))
continue;
Subserver subserver = Subserver.getSubserver(server);
List<ProxiedPlayer> players;
if(subserver != null && subserver.getType() == Servertype.BAUSERVER){
players = playerMap.getOrDefault("Bau", new ArrayList<>());
}else{
players = playerMap.getOrDefault(serverName, new ArrayList<>());
}
players.add(player);
playerMap.putIfAbsent(serverName, players);
}
//Set size
int size = -1;
for(Map.Entry<String, List<ProxiedPlayer>> server : playerMap.entrySet())
size += 2 + server.getValue().size();
if(size < 0)
return;
size = size/20+20;
if(size > 80){
size = 80;
//TODO: Handle Oversize
}
tablist.setSize(size);
int i = 0;
//TODO: Set sorting
for(Map.Entry<String, List<ProxiedPlayer>> server : playerMap.entrySet()){
if(i > 0)
tablist.setSlot(i++, 0, darkGray, "", 1000);
tablist.setSlot(i++, 0, gray,"§7§l" + server.getKey(), 1000);
for(ProxiedPlayer player : server.getValue())
tablist.setSlot(i++, 0, BungeeTabListPlusAPI.getIconFromPlayer(player), player.getDisplayName(), 1);
}
while(i < size)
tablist.setSlot(i++, 0, darkGray, "", 1000);
seconds++;
}
@EventHandler
public void onJoin(PostLoginEvent e){
BungeeTabListPlusAPI.setCustomTabList(e.getPlayer(), tablist);
}
}

Datei anzeigen

@ -2,4 +2,4 @@ name: BungeeCore
main: de.steamwar.bungeecore.BungeeCore main: de.steamwar.bungeecore.BungeeCore
version: 1.0 version: 1.0
author: Lixfel author: Lixfel
depends: [PersistentBungeeCore] depends: [PersistentBungeeCore, BungeeTabListPlus]