diff --git a/src/main/java/org/mvplugins/multiverse/core/commands/GeneratorsCommand.java b/src/main/java/org/mvplugins/multiverse/core/commands/GeneratorsCommand.java new file mode 100644 index 00000000..372fb2c2 --- /dev/null +++ b/src/main/java/org/mvplugins/multiverse/core/commands/GeneratorsCommand.java @@ -0,0 +1,104 @@ +package org.mvplugins.multiverse.core.commands; + +import java.util.List; + +import co.aikar.commands.InvalidCommandArgument; +import co.aikar.commands.MessageType; +import co.aikar.commands.annotation.CommandAlias; +import co.aikar.commands.annotation.CommandCompletion; +import co.aikar.commands.annotation.CommandPermission; +import co.aikar.commands.annotation.Description; +import co.aikar.commands.annotation.Optional; +import co.aikar.commands.annotation.Subcommand; +import co.aikar.commands.annotation.Syntax; +import jakarta.inject.Inject; +import org.bukkit.ChatColor; +import org.jetbrains.annotations.NotNull; +import org.jvnet.hk2.annotations.Service; + +import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer; +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; +import org.mvplugins.multiverse.core.commandtools.MultiverseCommand; +import org.mvplugins.multiverse.core.commandtools.flags.CommandValueFlag; +import org.mvplugins.multiverse.core.commandtools.flags.ParsedCommandFlags; +import org.mvplugins.multiverse.core.display.ContentDisplay; +import org.mvplugins.multiverse.core.display.filters.ContentFilter; +import org.mvplugins.multiverse.core.display.filters.DefaultContentFilter; +import org.mvplugins.multiverse.core.display.filters.RegexContentFilter; +import org.mvplugins.multiverse.core.display.handlers.PagedSendHandler; +import org.mvplugins.multiverse.core.display.parsers.ListContentProvider; +import org.mvplugins.multiverse.core.utils.MVCorei18n; +import org.mvplugins.multiverse.core.world.generators.GeneratorProvider; + +/** + * List all gamerules in your current or specified world. + */ +@Service +@CommandAlias("mv") +class GeneratorsCommand extends MultiverseCommand { + + private final GeneratorProvider generatorProvider; + + private final CommandValueFlag PAGE_FLAG = flag(CommandValueFlag + .builder("--page", Integer.class) + .addAlias("-p") + .context(value -> { + try { + return Integer.parseInt(value); + } catch (NumberFormatException e) { + throw new InvalidCommandArgument("Invalid page number: " + value); + } + }) + .build()); + + private final CommandValueFlag FILTER_FLAG = flag(CommandValueFlag + .builder("--filter", ContentFilter.class) + .addAlias("-f") + .context(value -> { + try { + return RegexContentFilter.fromString(value); + } catch (IllegalArgumentException e) { + throw new InvalidCommandArgument("Invalid filter: " + value); + } + }) + .build()); + + @Inject + GeneratorsCommand(@NotNull MVCommandManager commandManager, @NotNull GeneratorProvider generatorProvider) { + super(commandManager); + this.generatorProvider = generatorProvider; + } + + @Subcommand("generators|gens") + @CommandPermission("multiverse.core.generator") + @CommandCompletion("@flags:groupName=mvgeneratorscommand @flags:groupName=mvgeneratorscommand") + @Syntax("") + @Description("{@@mv-core.generators.description}") + void onGamerulesCommand( + @NotNull MVCommandIssuer issuer, + + @Optional + @Syntax("[--page ] [--filter ]") + @Description("{@@mv-core.generators.description.flags}") + String[] flags) { + ParsedCommandFlags parsedFlags = parseFlags(flags); + + // Get the generators loaded using the command suggestions + List generators = (List) generatorProvider.suggestGeneratorString(""); + + // Tell the user if we cannot find any generator plugins, then abort + if (generators.isEmpty()) { + issuer.sendMessage(commandManager.formatMessage(issuer, MessageType.INFO, MVCorei18n.GENERATORS_EMPTY)); + return; + } + + ContentDisplay.create() + .addContent(ListContentProvider.forContent(generators)) + .withSendHandler(PagedSendHandler.create() + .withHeader("%s====[ Multiverse Generator List ]====", ChatColor.AQUA) + .doPagination(true) + .withTargetPage(parsedFlags.flagValue(PAGE_FLAG, 1)) + .withFilter(parsedFlags.flagValue(FILTER_FLAG, DefaultContentFilter.get()))) + .send(issuer); + } +} diff --git a/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java b/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java index c8a4af49..b92999d3 100644 --- a/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java +++ b/src/main/java/org/mvplugins/multiverse/core/utils/MVCorei18n.java @@ -60,6 +60,11 @@ public enum MVCorei18n implements MessageKeyProvider { GAMERULES_DESCRIPTION_WORLD, GAMERULES_TITLE, + // Generators command + GENERATORS_DESCRIPTION, + GENERATORS_DESCRIPTION_FLAGS, + GENERATORS_EMPTY, + // import command IMPORT_IMPORTING, IMPORT_SUCCESS, diff --git a/src/main/resources/multiverse-core_en.properties b/src/main/resources/multiverse-core_en.properties index 178a6efd..15227afd 100644 --- a/src/main/resources/multiverse-core_en.properties +++ b/src/main/resources/multiverse-core_en.properties @@ -75,6 +75,11 @@ mv-core.gamerules.description.page=The page to view mv-core.gamerules.description.world=The world to list gamerules in mv-core.gamerules.title= --- Gamerules for {world} --- +# /mv generators +mv-core.generators.description=Lists generators known to Multiverse +mv-core.generators.description.flags=Filter - only shows entries matching this. Page - the page to show +mv-core.generators.empty=&cNo Generator Plugins found. + # /mv import mv-core.import.description=Imports an existing world folder. mv-core.import.name.description=Name of the world folder.