| Total Complexity | 8 |
| Total Lines | 34 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | package de.pewpewproject.lasertag.command.suggestions; |
||
| 18 | public class LasertagGameModeSuggestionProvider implements SuggestionProvider<ServerCommandSource> { |
||
| 19 | |||
| 20 | private static LasertagGameModeSuggestionProvider instance = null; |
||
| 21 | |||
| 22 | private LasertagGameModeSuggestionProvider() { |
||
| 23 | } |
||
| 24 | |||
| 25 | public static LasertagGameModeSuggestionProvider getInstance() { |
||
| 26 | if (instance == null) { |
||
| 27 | instance = new LasertagGameModeSuggestionProvider(); |
||
| 28 | } |
||
| 29 | |||
| 30 | return instance; |
||
| 31 | } |
||
| 32 | |||
| 33 | @Override |
||
| 34 | public CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) { |
||
| 35 | boolean inputEmpty = false; |
||
| 36 | // Try to get current input |
||
| 37 | String input = null; |
||
| 38 | try { |
||
| 39 | input = StringArgumentType.getString(context, "gamemode"); |
||
| 40 | } catch (IllegalArgumentException ex) { |
||
| 41 | inputEmpty = true; |
||
| 42 | } |
||
| 43 | |||
| 44 | for (var gameModeTranslatableName : GameModes.GAME_MODES.keySet()) { |
||
| 45 | |||
| 46 | if (inputEmpty || gameModeTranslatableName.toLowerCase().contains(input.toLowerCase())) { |
||
| 47 | builder.suggest(gameModeTranslatableName); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | return builder.buildFuture(); |
||
| 52 | } |
||
| 54 |