Merge pull request #535 from zkitefly/version-id

正确解析包含 hash 的版本号
This commit is contained in:
ShirosakiMio 2024-08-23 11:58:54 +08:00 committed by GitHub
commit 1f86ab5fa7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 3 deletions

View File

@ -17,7 +17,6 @@
*/
package com.tungsten.fclcore.game;
import static com.tungsten.fclcore.util.Lang.tryCast;
import static com.tungsten.fclcore.util.Logging.LOG;
import com.google.gson.JsonParseException;
@ -47,8 +46,11 @@ public final class GameVersion {
private static Optional<String> getVersionFromJson(InputStream versionJson) {
try {
Map<?, ?> version = JsonUtils.fromNonNullJsonFully(versionJson, Map.class);
return tryCast(version.get("id"), String.class);
} catch (IOException | JsonParseException e) {
String id = (String) version.get("id");
if (id != null && id.contains(" / "))
id = id.substring(0, id.indexOf(" / "));
return Optional.ofNullable(id);
} catch (IOException | JsonParseException | ClassCastException e) {
LOG.log(Level.WARNING, "Failed to parse version.json", e);
return Optional.empty();
}