diff --git a/src/main/java/de/damcraft/serverseeker/gui/FindNewServersScreen.java b/src/main/java/de/damcraft/serverseeker/gui/FindNewServersScreen.java index cdd7601..7a95e01 100644 --- a/src/main/java/de/damcraft/serverseeker/gui/FindNewServersScreen.java +++ b/src/main/java/de/damcraft/serverseeker/gui/FindNewServersScreen.java @@ -7,6 +7,7 @@ import de.damcraft.serverseeker.country.CountrySetting; import de.damcraft.serverseeker.ssapi.requests.ServersRequest; import de.damcraft.serverseeker.ssapi.responses.ServersResponse; +import de.damcraft.serverseeker.utils.MCVersionUtil; import de.damcraft.serverseeker.utils.MultiplayerScreenUtil; import meteordevelopment.meteorclient.gui.GuiThemes; import meteordevelopment.meteorclient.gui.WindowScreen; @@ -51,15 +52,36 @@ public Boolean toBoolOrNull() { public enum Version { Current, Any, - Custom + Protocol, + VersionString; + + @Override + public String toString() { + return switch (this) { + case Current -> "Current"; + case Any -> "Any"; + case Protocol -> "Protocol"; + case VersionString -> "Version String"; + }; + } } public enum NumRangeType { Any, Equals, - At_Least, - At_Most, - Between + AtLeast, + AtMost, + Between; + @Override + public String toString() { + return switch (this) { + case Any -> "Any"; + case Equals -> "Equal To"; + case AtLeast -> "At Least"; + case AtMost -> "At Most"; + case Between -> "Between"; + }; + } } // Didn't have a better name @@ -81,14 +103,14 @@ public enum GeoSearchType { ); private final Setting onlinePlayersNumTypeSetting = sg.add(new EnumSetting.Builder() - .name("online-players") + .name("online-players-range") .description("The type of number range for the online players") .defaultValue(NumRangeType.Any) .build() ); private final Setting equalsOnlinePlayersSetting = sg.add(new IntSetting.Builder() - .name("online-player-equals") + .name("online-players") .description("The amount of online players the server should have") .defaultValue(2) .min(0) @@ -99,35 +121,35 @@ public enum GeoSearchType { private final Setting atLeastOnlinePlayersSetting = sg.add(new IntSetting.Builder() - .name("online-player-at-least") + .name("minimum-online-players") .description("The minimum amount of online players the server should have") .defaultValue(1) .min(0) - .visible(() -> onlinePlayersNumTypeSetting.get().equals(NumRangeType.At_Least) || onlinePlayersNumTypeSetting.get().equals(NumRangeType.Between)) + .visible(() -> onlinePlayersNumTypeSetting.get().equals(NumRangeType.AtLeast) || onlinePlayersNumTypeSetting.get().equals(NumRangeType.Between)) .noSlider() .build() ); private final Setting atMostOnlinePlayersSetting = sg.add(new IntSetting.Builder() - .name("online-player-at-most") + .name("maximum-online-players") .description("The maximum amount of online players the server should have") .defaultValue(20) .min(0) - .visible(() -> onlinePlayersNumTypeSetting.get().equals(NumRangeType.At_Most) || onlinePlayersNumTypeSetting.get().equals(NumRangeType.Between)) + .visible(() -> onlinePlayersNumTypeSetting.get().equals(NumRangeType.AtMost) || onlinePlayersNumTypeSetting.get().equals(NumRangeType.Between)) .noSlider() .build() ); private final Setting maxPlayersNumTypeSetting = sg.add(new EnumSetting.Builder() - .name("max-players") + .name("max-players-range") .description("The type of number range for the max players") .defaultValue(NumRangeType.Any) .build() ); private final Setting equalsMaxPlayersSetting = sg.add(new IntSetting.Builder() - .name("max-players-equals") + .name("max-players") .description("The amount of max players the server should have") .defaultValue(2) .min(0) @@ -138,35 +160,35 @@ public enum GeoSearchType { private final Setting atLeastMaxPlayersSetting = sg.add(new IntSetting.Builder() - .name("max-players-at-least") + .name("minimum-max-players") .description("The minimum amount of max players the server should have") .defaultValue(1) .min(0) - .visible(() -> maxPlayersNumTypeSetting.get().equals(NumRangeType.At_Least) || maxPlayersNumTypeSetting.get().equals(NumRangeType.Between)) + .visible(() -> maxPlayersNumTypeSetting.get().equals(NumRangeType.AtLeast) || maxPlayersNumTypeSetting.get().equals(NumRangeType.Between)) .noSlider() .build() ); private final Setting atMostMaxPlayersSetting = sg.add(new IntSetting.Builder() - .name("max-players-at-most") + .name("maximum-max-players") .description("The maximum amount of max players the server should have") .defaultValue(20) .min(0) - .visible(() -> maxPlayersNumTypeSetting.get().equals(NumRangeType.At_Most) || maxPlayersNumTypeSetting.get().equals(NumRangeType.Between)) + .visible(() -> maxPlayersNumTypeSetting.get().equals(NumRangeType.AtMost) || maxPlayersNumTypeSetting.get().equals(NumRangeType.Between)) .noSlider() .build() ); private final Setting descriptionSetting = sg.add(new StringSetting.Builder() - .name("description") - .description("The description (aka motd) the servers should have (empty for any)") + .name("MOTD") + .description("What the MOTD of the server should contain (empty for any)") .defaultValue("") .build() ); private final Setting softwareSetting = sg.add(new EnumSetting.Builder() .name("software") - .description("The software the servers should have") + .description("The server software the servers should have") .defaultValue(ServersRequest.Software.Any) .build() ); @@ -178,16 +200,24 @@ public enum GeoSearchType { .build() ); - private final Setting customProtocolSetting = sg.add(new IntSetting.Builder() + private final Setting protocolVersionSetting = sg.add(new IntSetting.Builder() .name("protocol") .description("The protocol version the servers should have") .defaultValue(SharedConstants.getProtocolVersion()) - .visible(() -> versionSetting.get() == Version.Custom) + .visible(() -> versionSetting.get() == Version.Protocol) .min(0) .noSlider() .build() ); + private final Setting versionStringSetting = sg.add(new StringSetting.Builder() + .name("version-string") + .description("The version string (e.g. 1.19.3) of the protocol version the server should have, results may contain different versions that have the same protocol version. Must be at least 1.7.1") + .defaultValue("1.20.2") + .visible(() -> versionSetting.get() == Version.VersionString) + .build() + ); + private final Setting onlineOnlySetting = sg.add(new BoolSetting.Builder() .name("online-only") .description("Whether to only show servers that are online") @@ -238,10 +268,10 @@ public void initWidgets() { switch (onlinePlayersNumTypeSetting.get()) { // [n, "inf"] - case At_Least -> request.setOnlinePlayers(atLeastOnlinePlayersSetting.get(), -1); + case AtLeast -> request.setOnlinePlayers(atLeastOnlinePlayersSetting.get(), -1); // [0, n] - case At_Most -> request.setOnlinePlayers(0, atMostOnlinePlayersSetting.get()); + case AtMost -> request.setOnlinePlayers(0, atMostOnlinePlayersSetting.get()); // [min, max] case Between -> request.setOnlinePlayers(atLeastOnlinePlayersSetting.get(), atMostOnlinePlayersSetting.get()); @@ -252,10 +282,10 @@ public void initWidgets() { switch (maxPlayersNumTypeSetting.get()) { // [n, "inf"] - case At_Least -> request.setMaxPlayers(atLeastMaxPlayersSetting.get(), -1); + case AtLeast -> request.setMaxPlayers(atLeastMaxPlayersSetting.get(), -1); // [0, n] - case At_Most -> request.setMaxPlayers(0, atMostMaxPlayersSetting.get()); + case AtMost -> request.setMaxPlayers(0, atMostMaxPlayersSetting.get()); // [min, max] case Between -> request.setMaxPlayers(atLeastMaxPlayersSetting.get(), atMostMaxPlayersSetting.get()); @@ -278,7 +308,16 @@ public void initWidgets() { request.setSoftware(softwareSetting.get()); switch (versionSetting.get()) { - case Custom -> request.setProtocolVersion(customProtocolSetting.get()); + case Protocol -> request.setProtocolVersion(protocolVersionSetting.get()); + case VersionString -> { + Integer protocol = MCVersionUtil.versionToProtocol(versionStringSetting.get()); + if (protocol == null) { + clear(); + add(theme.label("Unknown version string")); + return; + } + request.setProtocolVersion(protocol); + } case Current -> request.setProtocolVersion(SharedConstants.getProtocolVersion()); } diff --git a/src/main/java/de/damcraft/serverseeker/utils/MCVersionUtil.java b/src/main/java/de/damcraft/serverseeker/utils/MCVersionUtil.java new file mode 100644 index 0000000..7313441 --- /dev/null +++ b/src/main/java/de/damcraft/serverseeker/utils/MCVersionUtil.java @@ -0,0 +1,90 @@ +package de.damcraft.serverseeker.utils; + +import java.util.HashMap; + +public class MCVersionUtil { + private static HashMap versions = new HashMap<>() { + { + put("1.20.2", 764); + put("1.20.1", 763); + put("1.20", 763); + + put("1.19.4", 762); + put("1.19.3", 761); + put("1.19.2", 760); + put("1.19.1", 760); + put("1.19", 759); + + put("1.18.2", 758); + put("1.18.1", 757); + put("1.18", 757); + + put("1.17.1", 756); + put("1.17", 755); + + put("1.16.5", 754); + put("1.16.4", 754); + put("1.16.3", 753); + put("1.16.2", 751); + put("1.16.1", 736); + put("1.16", 735); + + put("1.15.2", 578); + put("1.15.1", 575); + put("1.15", 753); + + put("1.14.4", 498); + put("1.14.3", 490); + put("1.14.2", 485); + put("1.14.1", 480); + put("1.14", 477); + + put("1.13.2", 404); + put("1.13.1", 401); + put("1.13", 393); + + put("1.12.2", 340); + put("1.12.1", 338); + put("1.12", 335); + + put("1.11.2", 316); + put("1.11.1", 316); + put("1.11", 316); + + put("1.10.2", 210); + put("1.10.1", 210); + put("1.10", 210); + + put("1.9.4", 110); + put("1.9.3", 110); + put("1.9.2", 109); + put("1.9.1", 108); + + put("1.9", 107); + put("1.8.9", 47); + put("1.8.8", 47); + put("1.8.7", 47); + put("1.8.6", 47); + put("1.8.5", 47); + put("1.8.4", 47); + put("1.8.3", 47); + put("1.8.2", 47); + put("1.8.1", 47); + put("1.8", 47); + + put("1.7.10", 5); + put("1.7.9", 5); + put("1.7.8", 5); + put("1.7.7", 5); + put("1.7.6", 5); + put("1.7.5", 4); + put("1.7.4", 4); + put("1.7.2", 3); + put("1.7.1", 3); + } + }; + + public static Integer versionToProtocol(String versionString) { + return versions.get(versionString); + } +}