File tree Expand file tree Collapse file tree
src/main/java/org/mvplugins/multiverse/core/world/generators Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,7 +17,10 @@ public interface GeneratorPlugin {
1717 * <p>Suggest possible generator ids. To be used in command tab-completion.</p>
1818 *
1919 * <p>These suggestions can be static without relying on currentIdInput, or dynamically changed based
20- * on the currentIdInput.</p>
20+ * on the currentIdInput. Add an entry of empty string "" if your plugin supports generator string without an id.</p>
21+ *
22+ * <p>These suggestions should be quick lookups, that gets from your cached or loaded data as tab-complete handler
23+ * may be called multiple times a second.</p>
2124 *
2225 * @param currentIdInput The current state user input. This may be null or empty if user has not started
2326 * any input for generator id.
Original file line number Diff line number Diff line change 11package org .mvplugins .multiverse .core .world .generators ;
22
33import java .io .File ;
4- import java .util .ArrayList ;
54import java .util .Arrays ;
65import java .util .Collection ;
76import java .util .HashMap ;
8- import java .util .List ;
97import java .util .Map ;
108import java .util .Set ;
9+ import java .util .stream .Stream ;
1110
1211import com .dumptruckman .minecraft .util .Logging ;
1312import com .google .common .base .Strings ;
@@ -176,16 +175,19 @@ public boolean isGeneratorPluginRegistered(@NotNull String pluginName) {
176175 */
177176 public Collection <String > suggestGeneratorString (@ Nullable String currentInput ) {
178177 String [] genSpilt = currentInput == null ? new String [0 ] : REPatterns .COLON .split (currentInput , 2 );
179- List <String > suggestions = new ArrayList <>(generatorPlugins .keySet ());
180- if (genSpilt .length < 2 ) {
181- return suggestions ;
182- }
183- GeneratorPlugin generatorPlugin = generatorPlugins .get (genSpilt [0 ]);
184- if (generatorPlugin == null ) {
185- return suggestions ;
186- }
187- suggestions .addAll (generatorPlugin .suggestIds (genSpilt [1 ]).stream ().map (id -> genSpilt [0 ] + ":" + id ).toList ());
188- return suggestions ;
178+ String generatorName = genSpilt [0 ];
179+ String generatorId = genSpilt .length > 1 ? genSpilt [1 ] : "" ;
180+ return generatorPlugins .entrySet ().stream ()
181+ .flatMap (entry -> {
182+ var ids = entry .getValue ().suggestIds (entry .getKey ().equals (generatorName ) ? generatorId : "" );
183+ if (ids .isEmpty ()) {
184+ return Stream .of (entry .getKey ());
185+ }
186+ return ids .stream ().map (id -> Strings .isNullOrEmpty (id )
187+ ? entry .getKey ()
188+ : entry .getKey () + ":" + id );
189+ })
190+ .toList ();
189191 }
190192
191193 /**
You can’t perform that action at this time.
0 commit comments