Skip to content

Instantly share code, notes, and snippets.

@ITZVGcGPmO
Last active January 10, 2020 14:44
Show Gist options
  • Save ITZVGcGPmO/ee54205e01ee936333fe14b7920151ec to your computer and use it in GitHub Desktop.
Save ITZVGcGPmO/ee54205e01ee936333fe14b7920151ec to your computer and use it in GitHub Desktop.
non async bungeecord ping passthrough (forced host) implementation
import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.event.ProxyPingEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import net.md_5.bungee.event.EventPriority;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
public class ListenerClass implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onPing(ProxyPingEvent e) throws ExecutionException, InterruptedException {
String hostName = e.getConnection().getVirtualHost().getHostName();
String srvnm = Main.findSrvByHost(hostName); // custom mapping implementation for hostname -> servername
System.out.println("someone's pinging "+hostName+" srvnm:"+srvnm);
if (srvnm!=null) {
CountDownLatch pingLatch = new CountDownLatch(1);
ProxyServer.getInstance().getServers().get(srvnm).ping((resp, status) -> {
if (resp!=null) { e.setResponse(resp); }
pingLatch.countDown();
});
pingLatch.await();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment