Created
August 9, 2015 02:38
-
-
Save vemacs/52732193aec0406a5f8c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import net.md_5.bungee.api.Callback; | |
| import net.md_5.bungee.api.ProxyServer; | |
| import net.md_5.bungee.api.ServerPing; | |
| import net.md_5.bungee.api.chat.BaseComponent; | |
| import net.md_5.bungee.api.config.ListenerInfo; | |
| import net.md_5.bungee.api.event.ProxyPingEvent; | |
| import java.net.InetSocketAddress; | |
| import java.util.UUID; | |
| public class ServerInfoProvider { | |
| protected ProxyServer bungeeCord = ProxyServer.getInstance(); | |
| private SCConnection scConnection = new SCConnection(); | |
| private ListenerInfo listener = (ListenerInfo) bungeeCord.getConfig().getListeners().iterator().next(); | |
| private Callback<ProxyPingEvent> callback; | |
| private int lastCount; | |
| public ServerInfoProvider() { | |
| callback = new Callback<ProxyPingEvent>() { | |
| @Override | |
| public void done(ProxyPingEvent event, Throwable throwable) { | |
| lastCount = event.getResponse().getPlayers().getOnline(); | |
| } | |
| }; | |
| bungeeCord.getScheduler().schedule(TabHFBungee.getInstance(), new Runnable() { | |
| @Override | |
| public void run() { | |
| ServerPing ping = new ServerPing(new net.md_5.bungee.api.ServerPing.Protocol( | |
| bungeeCord.getGameVersion(), bungeeCord.getProtocolVersion()), | |
| new ServerPing.Players(listener.getMaxPlayers(), bungeeCord.getOnlineCount(), null), | |
| listener.getMotd(), bungeeCord.getConfig().getFaviconObject()); | |
| bungeeCord.getPluginManager().callEvent(new ProxyPingEvent(scConnection, ping, | |
| callback)); | |
| } | |
| }, 0L, 1L, java.util.concurrent.TimeUnit.SECONDS); | |
| } | |
| public int getTotalPlayerCount() { | |
| return lastCount; | |
| } | |
| private class SCConnection implements net.md_5.bungee.api.connection.PendingConnection { | |
| private String name = "SCConnection"; | |
| private UUID uuid = UUID.nameUUIDFromBytes(name.getBytes()); | |
| InetSocketAddress addr = new InetSocketAddress("127.0.0.1", 55555); | |
| private SCConnection() { | |
| } | |
| public String getName() { | |
| return name; | |
| } | |
| public int getVersion() { | |
| return bungeeCord.getProtocolVersion(); | |
| } | |
| public InetSocketAddress getVirtualHost() { | |
| return addr; | |
| } | |
| public ListenerInfo getListener() { | |
| return listener; | |
| } | |
| public String getUUID() { | |
| return uuid.toString(); | |
| } | |
| public UUID getUniqueId() { | |
| return uuid; | |
| } | |
| @Override | |
| public void setUniqueId(UUID uuid) { | |
| } | |
| public boolean isOnlineMode() { | |
| return bungeeCord.getConfig().isOnlineMode(); | |
| } | |
| public void setOnlineMode(boolean b) { | |
| } | |
| @Override | |
| public boolean isLegacy() { | |
| return false; | |
| } | |
| public InetSocketAddress getAddress() { | |
| return addr; | |
| } | |
| public void disconnect(String s) { | |
| } | |
| public void disconnect(BaseComponent... baseComponents) { | |
| } | |
| public void disconnect(BaseComponent baseComponent) { | |
| } | |
| public net.md_5.bungee.api.connection.Connection.Unsafe unsafe() { | |
| return null; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment