Skip to content

Commit

Permalink
Sort ServerStatusInfo fields in the way they appear in the packet
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed May 23, 2024
1 parent 4624099 commit 0fefe04
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public static void main(String[] args) {
server.setGlobalFlag(MinecraftConstants.VERIFY_USERS_KEY, VERIFY_USERS);
server.setGlobalFlag(MinecraftConstants.SERVER_INFO_BUILDER_KEY, session ->
new ServerStatusInfo(
new VersionInfo(MinecraftCodec.CODEC.getMinecraftVersion(), MinecraftCodec.CODEC.getProtocolVersion()),
new PlayerInfo(100, 0, new ArrayList<>()),
Component.text("Hello world!"),
new PlayerInfo(100, 0, new ArrayList<>()),
new VersionInfo(MinecraftCodec.CODEC.getMinecraftVersion(), MinecraftCodec.CODEC.getProtocolVersion()),
null,
false
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ public void packetReceived(Session session, Packet packet) {
ServerInfoBuilder builder = session.getFlag(MinecraftConstants.SERVER_INFO_BUILDER_KEY);
if (builder == null) {
builder = $ -> new ServerStatusInfo(
new VersionInfo(protocol.getCodec().getMinecraftVersion(), protocol.getCodec().getProtocolVersion()),
new PlayerInfo(0, 20, new ArrayList<>()),
Component.text("A Minecraft Server"),
new PlayerInfo(0, 20, new ArrayList<>()),
new VersionInfo(protocol.getCodec().getMinecraftVersion(), protocol.getCodec().getProtocolVersion()),
null,
false
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
@Setter(AccessLevel.NONE)
@AllArgsConstructor
public class ServerStatusInfo {
private @Nullable VersionInfo versionInfo;
private @Nullable PlayerInfo playerInfo;
private @NonNull Component description;
private @Nullable PlayerInfo playerInfo;
private @Nullable VersionInfo versionInfo;
private byte[] iconPng;
private boolean enforcesSecureChat;
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public ServerStatusInfo parseInfo() {
enforcesSecureChat = data.get("enforcesSecureChat").getAsBoolean();
}

return new ServerStatusInfo(version, players, description, icon, enforcesSecureChat);
return new ServerStatusInfo(description, players, version, icon, enforcesSecureChat);
}

public ClientboundStatusResponsePacket withInfo(@NonNull ServerStatusInfo info) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public class MinecraftProtocolTest {
private static final int PORT = 25562;

private static final ServerStatusInfo SERVER_INFO = new ServerStatusInfo(
new VersionInfo(MinecraftCodec.CODEC.getMinecraftVersion(), MinecraftCodec.CODEC.getProtocolVersion()),
new PlayerInfo(100, 0, new ArrayList<>()),
Component.text("Hello world!"),
new PlayerInfo(100, 0, new ArrayList<>()),
new VersionInfo(MinecraftCodec.CODEC.getMinecraftVersion(), MinecraftCodec.CODEC.getProtocolVersion()),
null,
false
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ public class ClientboundStatusResponsePacketTest extends PacketTest {
public void setup() {
this.setPackets(new ClientboundStatusResponsePacket(
new ServerStatusInfo(
new VersionInfo(MinecraftCodec.CODEC.getMinecraftVersion(), MinecraftCodec.CODEC.getProtocolVersion()),
Component.text("Description"),
new PlayerInfo(100, 10, new ArrayList<>(
Collections.singleton(new GameProfile(UUID.randomUUID(), "Username"))
Collections.singleton(new GameProfile(UUID.randomUUID(), "Username"))
)),
Component.text("Description"),
new VersionInfo(MinecraftCodec.CODEC.getMinecraftVersion(), MinecraftCodec.CODEC.getProtocolVersion()),
null,
false
)
Expand Down

0 comments on commit 0fefe04

Please sign in to comment.