Mineplex2018-withcommit/Plugins/Mineplex.Bungee.Mineplexer/src/mineplex/bungee/playerCount/PlayerCount.java
Jonathan Williams fc45b80e2b Added rank pulling on bungee login and the ability to put a cap on network player count.
Removed log message for converted server group.
2015-01-03 23:37:04 -06:00

56 lines
1.7 KiB
Java

package mineplex.bungee.playerCount;
import java.util.concurrent.TimeUnit;
import net.md_5.bungee.api.ServerPing.Players;
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
{
private Plugin _plugin;
private PlayerCountRepository _repository;
private int _totalPlayers = -1;
private int _totalMaxPlayers;
public PlayerCount(Plugin plugin)
{
_plugin = plugin;
_plugin.getProxy().getScheduler().schedule(_plugin, this, 3L, 3L, TimeUnit.SECONDS);
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
ListenerInfo listenerInfo = _plugin.getProxy().getConfigurationAdapter().getListeners().iterator().next();
_repository = new PlayerCountRepository(listenerInfo.getHost().getAddress().getHostAddress() + ":" + listenerInfo.getHost().getPort(), listenerInfo.getMaxPlayers());
_repository.initialize();
}
public void run()
{
_repository.updatePlayerCountInDatabase(_plugin.getProxy().getOnlineCount());
PlayerTotalData playerTotalData = _repository.retrievePlayerCount();
_totalPlayers = playerTotalData.CurrentPlayers;
_totalMaxPlayers = playerTotalData.MaxPlayers;
}
@EventHandler
public void ServerPing(ProxyPingEvent event)
{
net.md_5.bungee.api.ServerPing serverPing = event.getResponse();
event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), new Players(_totalPlayers + 1, _totalPlayers, null), serverPing.getDescription(), serverPing.getFaviconObject()));
}
public int getTotalPlayers()
{
return _totalPlayers;
}
}