Mineplex2018-withcommit/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerCount/PlayerCount.java

65 lines
2.1 KiB
Java
Raw Normal View History

package mineplex.bungee.playerCount;
2013-09-05 11:12:12 +02:00
import java.io.File;
2013-09-05 11:12:12 +02:00
import java.util.concurrent.TimeUnit;
import mineplex.serverdata.Region;
import mineplex.serverdata.ServerManager;
import mineplex.serverdata.ServerRepository;
import mineplex.serverdata.data.BungeeServer;
import net.md_5.bungee.api.ServerPing.Players;
2013-09-05 11:12:12 +02:00
import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.event.ProxyPingEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
import net.md_5.bungee.event.EventHandler;
public class PlayerCount implements Listener, Runnable
2013-09-05 11:12:12 +02:00
{
private Plugin _plugin;
private ServerRepository _repository;
private ListenerInfo _listenerInfo;
private int _totalPlayers = -1;
public PlayerCount(Plugin plugin)
2013-09-05 11:12:12 +02:00
{
_plugin = plugin;
2013-09-05 11:12:12 +02:00
_plugin.getProxy().getScheduler().schedule(_plugin, this, 500L, 500L, TimeUnit.MILLISECONDS);
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
_listenerInfo = _plugin.getProxy().getConfigurationAdapter().getListeners().iterator().next();
Region region = !new File("eu.dat").exists() ? Region.US : Region.EU;
_repository = ServerManager.getServerRepository(region);
2013-09-05 11:12:12 +02:00
}
public void run()
{
_repository.updateBungeeStatus(new BungeeServer(_listenerInfo.getHost().getAddress().getHostAddress(), _listenerInfo.getHost().getAddress().getHostAddress(), _listenerInfo.getHost().getPort(), _plugin.getProxy().getOnlineCount(), 1250, (int) ((Runtime.getRuntime().maxMemory() - Runtime.getRuntime().freeMemory()) / 1048576), (int) (Runtime.getRuntime().maxMemory() / 1048576)), 15);
2015-03-14 02:10:35 +01:00
int totalPlayers = 0;
2013-09-05 11:12:12 +02:00
for (BungeeServer server : _repository.getGlobalBungeeStatuses())
{
2015-03-14 02:10:35 +01:00
totalPlayers += server.getPlayerCount();
}
2015-03-14 02:10:35 +01:00
_totalPlayers = totalPlayers;
2013-09-05 11:12:12 +02:00
}
@EventHandler
public void ServerPing(ProxyPingEvent event)
{
net.md_5.bungee.api.ServerPing serverPing = event.getResponse();
2014-12-12 11:21:23 +01:00
event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), new Players(_totalPlayers + 1, _totalPlayers, null), serverPing.getDescription(), serverPing.getFaviconObject()));
2013-09-05 11:12:12 +02:00
}
public int getTotalPlayers()
{
return _totalPlayers;
}
2013-09-05 11:12:12 +02:00
}