| 1 |  |  | package de.pewpewproject.lasertag.command.suggestions; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | import com.mojang.brigadier.arguments.StringArgumentType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | import com.mojang.brigadier.context.CommandContext; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | import com.mojang.brigadier.exceptions.CommandSyntaxException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | import com.mojang.brigadier.suggestion.SuggestionProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | import com.mojang.brigadier.suggestion.Suggestions; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | import com.mojang.brigadier.suggestion.SuggestionsBuilder; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | import de.pewpewproject.lasertag.worldgen.chunkgen.type.ArenaType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | import de.pewpewproject.lasertag.worldgen.chunkgen.type.ProceduralArenaType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | import net.minecraft.server.command.ServerCommandSource; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | import java.util.concurrent.CompletableFuture; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * Suggestion provider for the arenas | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @author Étienne Muser | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | public class MapSuggestionProvider implements SuggestionProvider<ServerCommandSource> { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     private static MapSuggestionProvider instance = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     private MapSuggestionProvider() {} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     public static MapSuggestionProvider getInstance() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         if (instance == null) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             instance = new MapSuggestionProvider(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         return instance; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     @Override | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |     public CompletableFuture<Suggestions> getSuggestions(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) throws CommandSyntaxException { | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |         boolean inputEmpty = false; | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |         // Try to get current input | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |         String input = null; | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |         try { | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |             input = StringArgumentType.getString(context, "map"); | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         } catch (IllegalArgumentException ex) { | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |             inputEmpty = true; | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |         for (var map : ArenaType.values()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |             if (map == ArenaType.PROCEDURAL) { | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |                 for (var proceduralMap : ProceduralArenaType.values()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |                     if (inputEmpty || proceduralMap.translatableName.toLowerCase().contains(input.toLowerCase())) { | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |                         builder.suggest(proceduralMap.translatableName); | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |                     } | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |             } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |                 if (inputEmpty || map.translatableName.toLowerCase().contains(input.toLowerCase())) { | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |                     builder.suggest(map.translatableName); | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |         return builder.buildFuture(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 60 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |  |