|
24 | 24 | import java.util.ArrayList; |
25 | 25 | import java.util.Collections; |
26 | 26 | import java.util.List; |
| 27 | +import java.util.Objects; |
27 | 28 |
|
28 | 29 | public class UnlinkCommandHandler { |
29 | 30 | public static Response handleModrinthUnlink(SlashCommandInteraction interaction) { |
@@ -132,27 +133,25 @@ public static List<Command.Choice> getMinecraftChoices(String focusedOption, Use |
132 | 133 | try { |
133 | 134 | var userResult = ModGardenAPIClient.get("user/" + user.getId() + "?service=discord", HttpResponse.BodyHandlers.ofInputStream()); |
134 | 135 | if (userResult.statusCode() == 200) { |
135 | | - List<Command.Choice> choices = new ArrayList<>(); |
136 | 136 | try (InputStreamReader userReader = new InputStreamReader(userResult.body())) { |
137 | 137 | JsonElement userJson = JsonParser.parseReader(userReader); |
138 | 138 | if (userJson.isJsonObject()) { |
139 | 139 | JsonArray minecraftAccounts = userJson.getAsJsonObject().getAsJsonArray("minecraft_accounts"); |
140 | 140 | if (minecraftAccounts != null) { |
141 | | - for (JsonElement accountJson : minecraftAccounts.getAsJsonArray()) { |
| 141 | + return minecraftAccounts.getAsJsonArray().asList().parallelStream().map(accountJson -> { |
142 | 142 | if (!accountJson.isJsonPrimitive() || !accountJson.getAsJsonPrimitive().isString()) |
143 | | - continue; |
| 143 | + return null; |
144 | 144 | String uuid = accountJson.getAsString(); |
145 | 145 | String username = MinecraftAccountUtil.getMinecraftUsernameFromUuid(uuid); |
146 | 146 | if (username != null) { |
147 | | - choices.add(new Command.Choice(username, username)); |
148 | | - } else { |
149 | | - choices.add(new Command.Choice(uuid, uuid)); |
| 147 | + return new Command.Choice(username, username); |
150 | 148 | } |
151 | | - } |
| 149 | + return new Command.Choice(uuid, uuid); |
| 150 | + }).filter(Objects::nonNull).toList(); |
152 | 151 | } |
153 | 152 | } |
154 | 153 | } |
155 | | - return choices; |
| 154 | + return Collections.emptyList(); |
156 | 155 | } |
157 | 156 | } catch (IOException | InterruptedException ex) { |
158 | 157 | GardenBot.LOG.error("Could not get Minecraft accounts from user.", ex); |
|
0 commit comments