mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Cleanup some ping passthrough stuff (#2726)
This commit is contained in:
parent
4c409f98f3
commit
6cd8b3387c
3 changed files with 16 additions and 7 deletions
|
@ -29,6 +29,7 @@ import lombok.AllArgsConstructor;
|
||||||
import net.md_5.bungee.api.ProxyServer;
|
import net.md_5.bungee.api.ProxyServer;
|
||||||
import net.md_5.bungee.api.ServerPing;
|
import net.md_5.bungee.api.ServerPing;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
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.config.ListenerInfo;
|
||||||
import net.md_5.bungee.api.connection.PendingConnection;
|
import net.md_5.bungee.api.connection.PendingConnection;
|
||||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||||
|
@ -52,8 +53,11 @@ public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, List
|
||||||
public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
|
public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
|
||||||
CompletableFuture<ProxyPingEvent> future = new CompletableFuture<>();
|
CompletableFuture<ProxyPingEvent> future = new CompletableFuture<>();
|
||||||
proxyServer.getPluginManager().callEvent(new ProxyPingEvent(new GeyserPendingConnection(inetSocketAddress), getPingInfo(), (event, throwable) -> {
|
proxyServer.getPluginManager().callEvent(new ProxyPingEvent(new GeyserPendingConnection(inetSocketAddress), getPingInfo(), (event, throwable) -> {
|
||||||
if (throwable != null) future.completeExceptionally(throwable);
|
if (throwable != null) {
|
||||||
else future.complete(event);
|
future.completeExceptionally(throwable);
|
||||||
|
} else {
|
||||||
|
future.complete(event);
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
ProxyPingEvent event = future.join();
|
ProxyPingEvent event = future.join();
|
||||||
ServerPing response = event.getResponse();
|
ServerPing response = event.getResponse();
|
||||||
|
@ -76,9 +80,12 @@ public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, List
|
||||||
|
|
||||||
private ServerPing getPingInfo() {
|
private ServerPing getPingInfo() {
|
||||||
return new ServerPing(
|
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),
|
new ServerPing.Players(getDefaultListener().getMaxPlayers(), proxyServer.getOnlineCount(), null),
|
||||||
getDefaultListener().getMotd(), proxyServer.getConfig().getFaviconObject()
|
TextComponent.fromLegacyText(getDefaultListener().getMotd())[0],
|
||||||
|
proxyServer.getConfig().getFaviconObject()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,8 @@ public class GeyserSpigotPingPassthrough implements IGeyserPingPassthrough {
|
||||||
Bukkit.getOnlinePlayers().stream().map(Player::getName).forEach(geyserPingInfo.getPlayerList()::add);
|
Bukkit.getOnlinePlayers().stream().map(Player::getName).forEach(geyserPingInfo.getPlayerList()::add);
|
||||||
return geyserPingInfo;
|
return geyserPingInfo;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.debug("Error while getting Bukkit ping passthrough: " + e.toString());
|
logger.debug("Error while getting Bukkit ping passthrough: " + e);
|
||||||
return new GeyserPingInfo(null, null, null);
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,5 +79,4 @@ public class GeyserSpigotPingPassthrough implements IGeyserPingPassthrough {
|
||||||
return Collections.emptyIterator();
|
return Collections.emptyIterator();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
package org.geysermc.geyser.ping;
|
package org.geysermc.geyser.ping;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.net.Inet4Address;
|
import java.net.Inet4Address;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
|
@ -38,6 +39,7 @@ public interface IGeyserPingPassthrough {
|
||||||
*
|
*
|
||||||
* @return string of the MOTD
|
* @return string of the MOTD
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
default GeyserPingInfo getPingInformation() {
|
default GeyserPingInfo getPingInformation() {
|
||||||
return this.getPingInformation(new InetSocketAddress(Inet4Address.getLoopbackAddress(), 69));
|
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
|
* @param inetSocketAddress the ip address of the client pinging the server
|
||||||
* @return string of the MOTD
|
* @return string of the MOTD
|
||||||
*/
|
*/
|
||||||
|
@Nullable
|
||||||
GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress);
|
GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue