Fix Bedrock server edition parsing
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0) (push) Successful in 1m1s

This commit is contained in:
Braydon 2024-04-09 00:36:01 -04:00
parent 936a1c47eb
commit 32c93b5e58
4 changed files with 16 additions and 6 deletions

@ -67,7 +67,7 @@ public final class BedrockPacketUnconnectedPong implements MinecraftBedrockPacke
ByteBuffer buffer = ByteBuffer.wrap(receivePacket.getData()).order(ByteOrder.LITTLE_ENDIAN);
byte id = buffer.get(); // The received packet id
if (id == ID) {
response = new String(buffer.array(), StandardCharsets.UTF_8).substring(35).trim();
response = new String(buffer.array(), StandardCharsets.UTF_8).substring(34).trim();
}
}
}

@ -75,11 +75,21 @@ public final class BedrockMinecraftServer extends MinecraftServer {
@NonNull
public static BedrockMinecraftServer create(@NonNull String hostname, String ip, int port, @NonNull String token) {
String[] split = token.split(";"); // Split the token
Edition edition;
try {
edition = Edition.valueOf(split[0]);
} catch (IllegalArgumentException ex) {
// Funky fix, but sometimes the edition can contain an extra
// portion of the length of the edition, so we need to remove it
edition = Edition.valueOf(split[0].substring(1));
}
Version version = new Version(Integer.parseInt(split[2]), split[3]);
Players players = new Players(Integer.parseInt(split[4]), Integer.parseInt(split[5]), null);
MOTD motd = MOTD.create(split[1] + "\n" + split[7]);
GameMode gameMode = new GameMode(split[8], Integer.parseInt(split[9]));
return new BedrockMinecraftServer(split[6], hostname, ip, port, Edition.valueOf(split[0]), version, players, motd, gameMode);
return new BedrockMinecraftServer(split[6], hostname, ip, port, edition, version, players, motd, gameMode);
}
/**

@ -37,8 +37,8 @@ import java.io.IOException;
import java.net.*;
/**
* The {@link MinecraftServerPinger} for
* pinging {@link BedrockMinecraftServer}'s.
* The {@link MinecraftServerPinger} for pinging
* {@link BedrockMinecraftServer} over UDP.
*
* @author Braydon
*/

@ -41,8 +41,8 @@ import java.io.IOException;
import java.net.*;
/**
* The {@link MinecraftServerPinger} for
* pinging {@link JavaMinecraftServer}'s.
* The {@link MinecraftServerPinger} for pinging
* {@link JavaMinecraftServer}'s over TCP.
*
* @author Braydon
*/