Skip to content

Commit

Permalink
Fix misplaced "no version" check #22 (#25)
Browse files Browse the repository at this point in the history
Signed-off-by: Nazar <youtube@superneon4ik.me>
  • Loading branch information
SuperNeon4ik authored Oct 15, 2024
1 parent 9a1414d commit d066f67
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ else if (firstCheck) {
}.runTaskTimerAsynchronously(NoxesiumUtils.getPlugin(), 1, refreshTicks);
}

@SuppressWarnings("deprecation")
public CompletableFuture<VersionStatus> checkForUpdates() {
CompletableFuture<VersionStatus> future = new CompletableFuture<>();
String uri = "https://api.modrinth.com/v2/project/%s/version?game_versions=%%5B%%22%s%%22%%5D"
Expand All @@ -64,17 +65,18 @@ public CompletableFuture<VersionStatus> checkForUpdates() {
Gson gson = new Gson();
var data = response.getBody().getArray().toString();
var availableVersionsArray = gson.fromJson(data, ModrinthVersion[].class);
if (availableVersionsArray.length == 0) {
latestStatus = VersionStatus.NOT_FOUND;
future.complete(VersionStatus.NOT_FOUND);
return;
}

var availableVersions = new ArrayList<>(Arrays.stream(availableVersionsArray)
.filter(v -> v.version_type.equalsIgnoreCase("release")).toList());
availableVersions.sort(ModrinthVersion::compareDatePublishedTo);

if (availableVersions.isEmpty()) {
latestStatus = VersionStatus.NOT_FOUND;
future.complete(VersionStatus.NOT_FOUND);
return;
}

if (availableVersions.get(0).version_number.toLowerCase().endsWith(NoxesiumUtils.getPlugin().getDescription().getVersion().toLowerCase())) {
if (availableVersions.getFirst().version_number.toLowerCase().endsWith(NoxesiumUtils.getPlugin().getDescription().getVersion().toLowerCase())) {
latestStatus = VersionStatus.LATEST;
future.complete(VersionStatus.LATEST);
return;
Expand All @@ -89,7 +91,7 @@ public CompletableFuture<VersionStatus> checkForUpdates() {

future.complete(VersionStatus.OUTDATED);
latestStatus = VersionStatus.OUTDATED;
latestKnownVersion = availableVersions.get(0).version_number;
latestKnownVersion = availableVersions.getFirst().version_number;
}).exceptionally(throwable -> {
latestStatus = VersionStatus.ERROR;
future.complete(VersionStatus.ERROR);
Expand All @@ -104,6 +106,7 @@ public void sendVersionMessage(CommandSender sender) {
sendVersionMessage(sender, latestStatus);
}

@SuppressWarnings("deprecation")
public void sendVersionMessage(CommandSender sender, VersionStatus versionStatus) {
if (latestKnownVersion == null) latestKnownVersion = NoxesiumUtils.getPlugin().getDescription().getVersion();
sender.sendMessage(Component.text("Running NoxesiumUtils v" + NoxesiumUtils.getPlugin().getDescription().getVersion(), NamedTextColor.AQUA));
Expand Down

0 comments on commit d066f67

Please sign in to comment.