Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.mvplugins.multiverse.core.command;

import co.aikar.commands.CommandCompletionContext;
import co.aikar.commands.CommandCompletionFilter;
import co.aikar.commands.apachecommonslang.ApacheCommonsLangUtil;
import org.jetbrains.annotations.ApiStatus;

import java.util.Locale;

Check warning on line 8 in src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletionFilters.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Wrong order for 'java.util.Locale' import. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletionFilters.java:8:1: warning: Wrong order for 'java.util.Locale' import. (com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck)

/**
* Utility filters for command completion matching.
*
* @since 5.7
*/
@ApiStatus.AvailableSince("5.7")
public final class MVCommandCompletionFilters {

/**
* Matches namespaced keys (for example, {@code minecraft:stone}) using namespace-aware checks.
* <p>

Check warning on line 20 in src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletionFilters.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 <p> tag should be preceded with an empty line. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletionFilters.java:20:0: warning: <p> tag should be preceded with an empty line. (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocParagraphCheck)

Check warning on line 20 in src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletionFilters.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 <p> tag should be placed immediately before the first word, with no space after. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletionFilters.java:20:0: warning: <p> tag should be placed immediately before the first word, with no space after. (com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocParagraphCheck)
* This filter accepts completions that:
* <ul>
* <li>start with the current input,</li>
* <li>have a namespace starting with the input, or</li>
* <li>have a key value containing the input.</li>
* </ul>
*
* @since 5.7
*/
@ApiStatus.AvailableSince("5.7")
public static final CommandCompletionFilter NAMESPACED_KEY = (context, completion) -> {
String[] split = completion.split(":", 2);
if (split.length < 2) {
return ApacheCommonsLangUtil.startsWithIgnoreCase(completion, context.getInput());
}
String lowerCase = context.getInput().toLowerCase(Locale.ROOT);
return ApacheCommonsLangUtil.startsWithIgnoreCase(completion, context.getInput())
|| split[0].toLowerCase(Locale.ROOT).startsWith(lowerCase)
|| split[1].toLowerCase(Locale.ROOT).contains(lowerCase);
};

/**
* Gets the namespaced-key completion filter with a generic type-safe signature.
* Use this method instead of {@link MVCommandCompletionFilters#NAMESPACED_KEY}
* to avoid raw type unchecked warnings.
*
* @param <C> completion context type
* @return the namespaced key filter
*
* @since 5.7
*/
@ApiStatus.AvailableSince("5.7")
public static <C extends CommandCompletionContext> CommandCompletionFilter<C> namespacedKey() {
return NAMESPACED_KEY;
}

private MVCommandCompletionFilters() {
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.stream.Collectors;

import co.aikar.commands.BukkitCommandCompletionContext;
import co.aikar.commands.CommandCompletionFilter;
import co.aikar.commands.CommandIssuer;
import co.aikar.commands.PaperCommandCompletions;
import co.aikar.commands.RegisteredCommand;
Expand Down Expand Up @@ -89,27 +90,27 @@
this.generatorProvider = generatorProvider;
this.potentialWorldFinder = potentialWorldFinder;

registerAsyncCompletion("anchornames", this::suggestAnchorNames);
registerAsyncCompletion("anchornames", this::suggestAnchorNames, CommandCompletionFilter.contains());
registerAsyncCompletion("commands", this::suggestCommands);
registerAsyncCompletion("destinations", this::suggestDestinations);
registerStaticCompletion("difficulties", suggestEnums(Difficulty.class));
registerStaticCompletion("environments", List.of("normal", "nether", "the_end")); // Don't tab complete the "custom" environment
registerAsyncCompletion("flags", this::suggestFlags);
registerStaticCompletion("gamemodes", suggestEnums(GameMode.class));
registerStaticCompletion("gamerules", this::suggestGamerules);
registerStaticCompletion("gamerules", this::suggestGamerules, MVCommandCompletionFilters.namespacedKey());

Check warning on line 100 in src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletions.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 The String "gamerules" appears 2 times in the file. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletions.java:100:34: warning: The String "gamerules" appears 2 times in the file. (com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck)
registerAsyncCompletion("gamerulesvalues", this::suggestGamerulesValues);
registerAsyncCompletion("generatorplugins", this::suggestGeneratorPlugins);
registerStaticCompletion("materials", suggestEnums(Material.class));
registerStaticCompletion("mvconfigs", config.getStringPropertyHandle().getAllPropertyNames());
registerAsyncCompletion("generatorplugins", this::suggestGeneratorPlugins, CommandCompletionFilter.contains());
registerStaticCompletion("materials", suggestEnums(Material.class), CommandCompletionFilter.contains());
registerStaticCompletion("mvconfigs", config.getStringPropertyHandle().getAllPropertyNames(), CommandCompletionFilter.contains());

Check warning on line 104 in src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletions.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Line is longer than 120 characters (found 138). Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletions.java:104:0: warning: Line is longer than 120 characters (found 138). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
registerAsyncCompletion("mvconfigvalues", this::suggestMVConfigValues);
registerAsyncCompletion("mvworlds", this::suggestMVWorlds);
registerAsyncCompletion("mvworldmetakey", this::suggestMVWorldMetaKey);
registerAsyncCompletion("mvworldpropsname", this::suggestMVWorldPropsName);
registerAsyncCompletion("mvworlds", this::suggestMVWorlds, MVCommandCompletionFilters.namespacedKey());

Check warning on line 106 in src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletions.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 The String "mvworlds" appears 2 times in the file. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletions.java:106:33: warning: The String "mvworlds" appears 2 times in the file. (com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck)
registerAsyncCompletion("mvworldmetakey", this::suggestMVWorldMetaKey, CommandCompletionFilter.contains());
registerAsyncCompletion("mvworldpropsname", this::suggestMVWorldPropsName, CommandCompletionFilter.contains());
registerAsyncCompletion("mvworldpropsvalue", this::suggestMVWorldPropsValue);
registerCompletion("playersarray", this::suggestPlayersArray); // getting online players cannot be async
registerCompletion("playersarray", this::suggestPlayersArray, CommandCompletionFilter.contains()); // getting online players cannot be async

Check warning on line 110 in src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletions.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Don't use trailing comments. Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletions.java:110:108: warning: Don't use trailing comments. (com.puppycrawl.tools.checkstyle.checks.TrailingCommentCheck)

Check warning on line 110 in src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletions.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Line is longer than 120 characters (found 148). Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletions.java:110:0: warning: Line is longer than 120 characters (found 148). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
registerStaticCompletion("propsmodifyaction", suggestEnums(PropertyModifyAction.class));
registerStaticCompletion("spawncategories", suggestEnums(SpawnCategory.class));
registerAsyncCompletion("spawncategorypropsname", this::suggestSpawnCategoryPropsName);
registerAsyncCompletion("spawncategorypropsname", this::suggestSpawnCategoryPropsName, CommandCompletionFilter.contains());

Check warning on line 113 in src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletions.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Line is longer than 120 characters (found 131). Raw Output: /github/workspace/src/main/java/org/mvplugins/multiverse/core/command/MVCommandCompletions.java:113:0: warning: Line is longer than 120 characters (found 131). (com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck)
registerAsyncCompletion("spawncategorypropsvalue", this::suggestSpawnCategoryPropsValue);

setDefaultCompletion("destinations", DestinationInstance.class);
Expand Down
Loading