Skip to content

Commit

Permalink
paper: suggest other release channel when build not found (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
itzg authored Jul 18, 2024
1 parent a75327a commit fdf7b5f
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/main/java/me/itzg/helpers/paper/InstallPaperCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import java.io.IOException;
import java.net.URI;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
import java.util.Objects;
import java.util.concurrent.Callable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import lombok.Builder;
import lombok.extern.slf4j.Slf4j;
import me.itzg.helpers.errors.GenericException;
Expand Down Expand Up @@ -250,20 +252,31 @@ private Mono<Result> downloadUsingCoordinates(PaperDownloadsClient client, Strin
String.format("Requested version %s is not available", version))
)
.switchIfEmpty(Mono.error(() -> new InvalidParameterException(
String.format("No build found for version %s with channel %s", version, channel)
String.format("No build found for version %s with channel '%s'. Perhaps try with a different channel: %s",
version, channel, channelsExcept(channel))
)))
.flatMap(resolvedBuild -> download(client, project, version, resolvedBuild));
}
}
else {
return client.getLatestVersionBuild(project, channel)
.switchIfEmpty(
Mono.error(() -> new InvalidParameterException("No build found with channel " + channel))
Mono.error(() -> new InvalidParameterException(
String.format("No build found with channel '%s'. Perhaps try a different channel: %s",
channel, channelsExcept(channel)
)))
)
.flatMap(resolved -> download(client, project, resolved.getVersion(), resolved.getBuild()));
}
}

private String channelsExcept(ReleaseChannel channel) {
return Arrays.stream(ReleaseChannel.values())
.filter(c -> !Objects.equals(c, channel))
.map(ReleaseChannel::toString)
.collect(Collectors.joining(", "));
}

private static boolean isSpecificVersion(String version) {
return version != null && !version.equalsIgnoreCase("latest");
}
Expand Down

0 comments on commit fdf7b5f

Please sign in to comment.