Skip to content

Commit

Permalink
Cleanup some ping passthrough stuff (GeyserMC#2726)
Browse files Browse the repository at this point in the history
  • Loading branch information
Konicai authored Dec 23, 2021
1 parent 4c409f9 commit 6cd8b33
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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.chat.TextComponent;
import net.md_5.bungee.api.config.ListenerInfo;
import net.md_5.bungee.api.connection.PendingConnection;
import net.md_5.bungee.api.event.ProxyPingEvent;
Expand All @@ -52,8 +53,11 @@ public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, List
public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
CompletableFuture<ProxyPingEvent> future = new CompletableFuture<>();
proxyServer.getPluginManager().callEvent(new ProxyPingEvent(new GeyserPendingConnection(inetSocketAddress), getPingInfo(), (event, throwable) -> {
if (throwable != null) future.completeExceptionally(throwable);
else future.complete(event);
if (throwable != null) {
future.completeExceptionally(throwable);
} else {
future.complete(event);
}
}));
ProxyPingEvent event = future.join();
ServerPing response = event.getResponse();
Expand All @@ -76,9 +80,12 @@ private static ListenerInfo getDefaultListener() {

private ServerPing getPingInfo() {
return new ServerPing(
new ServerPing.Protocol(proxyServer.getName() + " " + proxyServer.getGameVersion(), ProtocolConstants.SUPPORTED_VERSION_IDS.get(ProtocolConstants.SUPPORTED_VERSION_IDS.size() - 1)),
new ServerPing.Protocol(
proxyServer.getName() + " " + ProtocolConstants.SUPPORTED_VERSIONS.get(0) + "-" + ProtocolConstants.SUPPORTED_VERSIONS.get(ProtocolConstants.SUPPORTED_VERSIONS.size() - 1),
ProtocolConstants.SUPPORTED_VERSION_IDS.get(ProtocolConstants.SUPPORTED_VERSION_IDS.size() - 1)),
new ServerPing.Players(getDefaultListener().getMaxPlayers(), proxyServer.getOnlineCount(), null),
getDefaultListener().getMotd(), proxyServer.getConfig().getFaviconObject()
TextComponent.fromLegacyText(getDefaultListener().getMotd())[0],
proxyServer.getConfig().getFaviconObject()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
Bukkit.getOnlinePlayers().stream().map(Player::getName).forEach(geyserPingInfo.getPlayerList()::add);
return geyserPingInfo;
} catch (Exception e) {
logger.debug("Error while getting Bukkit ping passthrough: " + e.toString());
return new GeyserPingInfo(null, null, null);
logger.debug("Error while getting Bukkit ping passthrough: " + e);
return null;
}
}

Expand All @@ -79,5 +79,4 @@ public Iterator<Player> iterator() throws UnsupportedOperationException {
return Collections.emptyIterator();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

package org.geysermc.geyser.ping;

import javax.annotation.Nullable;
import java.net.Inet4Address;
import java.net.InetSocketAddress;

Expand All @@ -38,6 +39,7 @@ public interface IGeyserPingPassthrough {
*
* @return string of the MOTD
*/
@Nullable
default GeyserPingInfo getPingInformation() {
return this.getPingInformation(new InetSocketAddress(Inet4Address.getLoopbackAddress(), 69));
}
Expand All @@ -48,6 +50,7 @@ default GeyserPingInfo getPingInformation() {
* @param inetSocketAddress the ip address of the client pinging the server
* @return string of the MOTD
*/
@Nullable
GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress);

}

0 comments on commit 6cd8b33

Please sign in to comment.