Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Add Version String option and rename some stuff #22

Merged
merged 2 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -81,14 +103,14 @@ public enum GeoSearchType {
);

private final Setting<NumRangeType> onlinePlayersNumTypeSetting = sg.add(new EnumSetting.Builder<NumRangeType>()
.name("online-players")
.name("online-players-range")
.description("The type of number range for the online players")
.defaultValue(NumRangeType.Any)
.build()
);

private final Setting<Integer> 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)
Expand All @@ -99,35 +121,35 @@ public enum GeoSearchType {


private final Setting<Integer> 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<Integer> 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<NumRangeType> maxPlayersNumTypeSetting = sg.add(new EnumSetting.Builder<NumRangeType>()
.name("max-players")
.name("max-players-range")
.description("The type of number range for the max players")
.defaultValue(NumRangeType.Any)
.build()
);

private final Setting<Integer> 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)
Expand All @@ -138,35 +160,35 @@ public enum GeoSearchType {


private final Setting<Integer> 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<Integer> 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<String> 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<ServersRequest.Software> softwareSetting = sg.add(new EnumSetting.Builder<ServersRequest.Software>()
.name("software")
.description("The software the servers should have")
.description("The server software the servers should have")
.defaultValue(ServersRequest.Software.Any)
.build()
);
Expand All @@ -178,16 +200,24 @@ public enum GeoSearchType {
.build()
);

private final Setting<Integer> customProtocolSetting = sg.add(new IntSetting.Builder()
private final Setting<Integer> 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<String> 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<Boolean> onlineOnlySetting = sg.add(new BoolSetting.Builder()
.name("online-only")
.description("Whether to only show servers that are online")
Expand Down Expand Up @@ -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());
Expand All @@ -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());
Expand All @@ -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());
}

Expand Down
90 changes: 90 additions & 0 deletions src/main/java/de/damcraft/serverseeker/utils/MCVersionUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package de.damcraft.serverseeker.utils;

import java.util.HashMap;

public class MCVersionUtil {
private static HashMap<String, Integer> 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);
}
}