Skip to content

Commit

Permalink
Lower timeout on ping command
Browse files Browse the repository at this point in the history
Fixes #313
  • Loading branch information
rtm516 committed Apr 20, 2024
1 parent 6890230 commit c2a1475
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import java.util.concurrent.TimeUnit;

public class PingCommand extends SlashCommand {
private static final int TIMEOUT = 1250; // in ms, has to stay below 1500 (1.5s for each platform, total of 3s)

public PingCommand() {
this.name = "ping";
Expand Down Expand Up @@ -139,7 +140,7 @@ private MessageEmbed handle(String ip) {
MCPingOptions options = MCPingOptions.builder()
.hostname(hostname)
.port(jePort)
.timeout(1500)
.timeout(TIMEOUT)
.build();

MCPingResponse data = MCPing.getPing(options);
Expand All @@ -159,7 +160,7 @@ private MessageEmbed handle(String ip) {
client.bind().join();

InetSocketAddress addressToPing = new InetSocketAddress(hostname, bePort);
BedrockPong pong = client.ping(addressToPing, 1500, TimeUnit.MILLISECONDS).get();
BedrockPong pong = client.ping(addressToPing, TIMEOUT, TimeUnit.MILLISECONDS).get();

bedrockInfo = "**MOTD:** \n```\n" + BotHelpers.trim(MCPingUtil.stripColors(pong.getMotd()), 100) + (pong.getSubMotd() != null ? "\n" + BotHelpers.trim(MCPingUtil.stripColors(pong.getSubMotd()), 100) : "") + "\n```\n" +
"**Players:** " + pong.getPlayerCount() + "/" + pong.getMaximumPlayerCount() + "\n" +
Expand Down

0 comments on commit c2a1475

Please sign in to comment.