Add ping() method to GeyserConnection in api

This commit is contained in:
onebeastchris 2023-10-01 16:29:45 +02:00
parent 7c194a0b74
commit 21f596b52e
3 changed files with 14 additions and 4 deletions

View File

@ -95,4 +95,9 @@ public interface GeyserConnection extends Connection, CommandSource {
*/
@NonNull
Set<String> fogEffects();
/**
* Returns the current ping of the connection.
*/
int ping();
}

View File

@ -25,8 +25,6 @@
package org.geysermc.geyser.command.defaults;
import org.cloudburstmc.netty.channel.raknet.RakChildChannel;
import org.cloudburstmc.netty.handler.codec.raknet.common.RakSessionCodec;
import org.geysermc.geyser.command.GeyserCommand;
import org.geysermc.geyser.command.GeyserCommandSource;
import org.geysermc.geyser.session.GeyserSession;
@ -40,8 +38,7 @@ public class PingCommand extends GeyserCommand {
@Override
public void execute(GeyserSession session, GeyserCommandSource sender, String[] args) {
if (session == null) return;
RakSessionCodec rakSessionCodec = ((RakChildChannel) session.getUpstream().getSession().getPeer().getChannel()).rakPipeline().get(RakSessionCodec.class);
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.ping.message", sender.locale(), (int) Math.floor(rakSessionCodec.getPing())));
sender.sendMessage(GeyserLocale.getPlayerLocaleString("geyser.commands.ping.message", sender.locale(), session.ping()));
}
@Override

View File

@ -85,6 +85,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.common.value.qual.IntRange;
import org.cloudburstmc.math.vector.*;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.netty.channel.raknet.RakChildChannel;
import org.cloudburstmc.netty.handler.codec.raknet.common.RakSessionCodec;
import org.cloudburstmc.protocol.bedrock.BedrockDisconnectReasons;
import org.cloudburstmc.protocol.bedrock.BedrockServerSession;
import org.cloudburstmc.protocol.bedrock.data.*;
@ -2032,6 +2034,12 @@ public class GeyserSession implements GeyserConnection, GeyserCommandSource {
return Set.copyOf(this.appliedFog);
}
@Override
public int ping() {
RakSessionCodec rakSessionCodec = ((RakChildChannel) getUpstream().getSession().getPeer().getChannel()).rakPipeline().get(RakSessionCodec.class);
return (int) Math.floor(rakSessionCodec.getPing());
}
public void addCommandEnum(String name, String enums) {
softEnumPacket(name, SoftEnumUpdateType.ADD, enums);
}