3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-19 14:30:17 +01:00

Cleanup some ping passthrough stuff (#2726)

Dieser Commit ist enthalten in:
Konicai 2021-12-22 23:05:56 -05:00 committet von GitHub
Ursprung 4c409f98f3
Commit 6cd8b3387c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 16 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -29,6 +29,7 @@ import lombok.AllArgsConstructor;
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;
@ -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();
@ -76,9 +80,12 @@ public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, List
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()
);
}

Datei anzeigen

@ -57,8 +57,8 @@ public class GeyserSpigotPingPassthrough implements IGeyserPingPassthrough {
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;
}
}
@ -79,5 +79,4 @@ public class GeyserSpigotPingPassthrough implements IGeyserPingPassthrough {
return Collections.emptyIterator();
}
}
}

Datei anzeigen

@ -25,6 +25,7 @@
package org.geysermc.geyser.ping;
import javax.annotation.Nullable;
import java.net.Inet4Address;
import java.net.InetSocketAddress;
@ -38,6 +39,7 @@ public interface IGeyserPingPassthrough {
*
* @return string of the MOTD
*/
@Nullable
default GeyserPingInfo getPingInformation() {
return this.getPingInformation(new InetSocketAddress(Inet4Address.getLoopbackAddress(), 69));
}
@ -48,6 +50,7 @@ public interface IGeyserPingPassthrough {
* @param inetSocketAddress the ip address of the client pinging the server
* @return string of the MOTD
*/
@Nullable
GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress);
}