diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandCompletions.java b/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandCompletions.java index 9c1cbfa6..830e33c4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandCompletions.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandCompletions.java @@ -91,9 +91,6 @@ public class MVCommandCompletions extends PaperCommandCompletions { String[] args = context.getContextValue(String[].class); CommandFlag flag = (args.length <= 1) ? null : flagGroup.getByKey(args[args.length - 2]); - Logging.info(Arrays.toString(args)); - Logging.info(String.valueOf(flag)); - if (flag == null || flag.getValueRequirement() == ValueRequirement.NONE) { // suggest new flags. return getRemainingFlagIdentifiers(flagGroup, args); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandTools/flags/MVFlags.java b/src/main/java/com/onarandombox/MultiverseCore/commandTools/flags/MVFlags.java index f038da1a..bba12a50 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandTools/flags/MVFlags.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandTools/flags/MVFlags.java @@ -1,14 +1,18 @@ package com.onarandombox.MultiverseCore.commandtools.flags; +import co.aikar.commands.InvalidCommandArgument; import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.utils.webpaste.PasteServiceType; import org.bukkit.WorldType; import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Random; +import java.util.stream.Collectors; public class MVFlags { @@ -18,7 +22,8 @@ public class MVFlags { multiverse = plugin; } - public static final CommandFlag SEED = new RequiredCommandFlag("Seed", "-s", String.class) { + public static final CommandFlag SEED = new RequiredCommandFlag + ("Seed", "-s", String.class) { @Override public Collection suggestValue() { return Arrays.asList("seed", String.valueOf(new Random().nextLong())); @@ -30,7 +35,8 @@ public class MVFlags { } }; - public static final CommandFlag RANDOM_SEED = new OptionalCommandFlag("Seed", "-s", String.class) { + public static final CommandFlag RANDOM_SEED = new OptionalCommandFlag + ("Seed", "-s", String.class) { @Override public Collection suggestValue() { return Arrays.asList("seed", String.valueOf(new Random().nextLong())); @@ -42,7 +48,8 @@ public class MVFlags { } }; - public static final CommandFlag WORLD_TYPE = new RequiredCommandFlag("WorldType", "-t", WorldType.class) { + public static final CommandFlag WORLD_TYPE = new RequiredCommandFlag + ("WorldType", "-t", WorldType.class) { private final Map typeAlias = new HashMap(4){{ put("normal", WorldType.NORMAL); @@ -76,7 +83,8 @@ public class MVFlags { } }; - public static final CommandFlag GENERATOR = new RequiredCommandFlag("Generator", "-g", String.class) { + public static final CommandFlag GENERATOR = new RequiredCommandFlag + ("Generator", "-g", String.class) { @Override public Collection suggestValue() { return multiverse.getMVWorldManager().getAvailableWorldGenerators(); @@ -98,7 +106,8 @@ public class MVFlags { } }; - public static final CommandFlag GENERATE_STRUCTURES = new RequiredCommandFlag("GenerateStructures", "-a", Boolean.class) { + public static final CommandFlag GENERATE_STRUCTURES = new RequiredCommandFlag + ("GenerateStructures", "-a", Boolean.class) { @Override public Collection suggestValue() { return Arrays.asList("true", "false"); @@ -115,7 +124,8 @@ public class MVFlags { } }; - public static final CommandFlag SPAWN_ADJUST = new NoValueCommandFlag("AdjustSpawn", "-n", Boolean.class) { + public static final CommandFlag SPAWN_ADJUST = new NoValueCommandFlag + ("AdjustSpawn", "-n", Boolean.class) { @Override public Boolean getValue() throws FlagParseFailedException { return false; @@ -127,5 +137,50 @@ public class MVFlags { } }; + public static final CommandFlag PASTE_SERVICE_TYPE = new OptionalCommandFlag + ("PasteServiceType", "--paste", PasteServiceType.class) { + private final List pasteTypes = Arrays.stream(PasteServiceType.values()) + .filter(pt -> pt != PasteServiceType.NONE) + .map(p -> p.toString().toLowerCase()) + .collect(Collectors.toList()); + + @Override + public Collection suggestValue() { + return pasteTypes; + } + + @Override + public PasteServiceType getValue(@NotNull String input) throws FlagParseFailedException { + try { + return PasteServiceType.valueOf(input.toUpperCase()); + } + catch (IllegalArgumentException e) { + throw new InvalidCommandArgument(String.format("Invalid paste service type '%s'.", input)); + } + } + + @Override + public PasteServiceType getValue() throws FlagParseFailedException { + return PasteServiceType.PASTEGG; + } + + @Override + public PasteServiceType getDefaultValue() { + return PasteServiceType.NONE; + } + }.addAlias("-p"); + + public static final CommandFlag INCLUDE_PLUGIN_LIST = new NoValueCommandFlag + ("IncludePlugins", "--include-plugin-list", Boolean.class) { + @Override + public Boolean getValue() throws FlagParseFailedException { + return true; + } + + @Override + public Boolean getDefaultValue() { + return true; + } + }.addAlias("-pl"); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java index 848d1947..d4a63808 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/VersionCommand.java @@ -14,6 +14,9 @@ import co.aikar.commands.annotation.Description; import co.aikar.commands.annotation.Subcommand; import co.aikar.commands.annotation.Syntax; import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.commandtools.flags.FlagGroup; +import com.onarandombox.MultiverseCore.commandtools.flags.FlagResult; +import com.onarandombox.MultiverseCore.commandtools.flags.MVFlags; import com.onarandombox.MultiverseCore.event.MVVersionEvent; import com.onarandombox.MultiverseCore.utils.webpaste.PasteFailedException; import com.onarandombox.MultiverseCore.utils.webpaste.PasteService; @@ -25,6 +28,7 @@ import com.onarandombox.MultiverseCore.utils.webpaste.URLShortenerType; import org.apache.commons.lang.StringUtils; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; import org.bukkit.scheduler.BukkitRunnable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -40,30 +44,31 @@ public class VersionCommand extends MultiverseCoreCommand { public VersionCommand(MultiverseCore plugin) { super(plugin); + this.setFlagGroup(FlagGroup.of( + MVFlags.PASTE_SERVICE_TYPE, + MVFlags.INCLUDE_PLUGIN_LIST + )); } @Subcommand("version") @CommandPermission("multiverse.core.version") - @Syntax("[pastebin|hastebin|pastegg] [--include-plugin-list]") - @CommandCompletion("@pasteTypes --include-plugin-list") + @Syntax("--paste [pastebin|hastebin|pastegg] [--include-plugin-list]") + @CommandCompletion("@flags") @Description("Dumps version info to the console, optionally to pastal service.") public void onVersionCommand(@NotNull CommandSender sender, @NotNull @Syntax("[paste-service]") @Description("Website to upload your version info to.") - PasteServiceType pasteType, + String[] flagsArray) { - @Nullable - @Syntax("[--include-plugin-list]") - @Description("Whether you want to have plugins list in version info.") - String includePlugin) { + FlagResult flags = FlagResult.parse(flagsArray, this.getFlagGroup()); MVVersionEvent versionEvent = new MVVersionEvent(); this.addVersionInfoToEvent(versionEvent); this.plugin.getServer().getPluginManager().callEvent(versionEvent); - if (includePlugin != null && (includePlugin.equalsIgnoreCase("--include-plugin-list") || includePlugin.equalsIgnoreCase("-pl"))) { + if (flags.getValue(MVFlags.INCLUDE_PLUGIN_LIST)) { versionEvent.appendVersionInfo('\n' + "Plugins: " + getPluginList()); versionEvent.putDetailedVersionInfo("plugins.txt", "Plugins: " + getPluginList()); } @@ -75,7 +80,8 @@ public class VersionCommand extends MultiverseCoreCommand { logToConsole(versionInfo); - if (pasteType == PasteServiceType.NONE) { + PasteServiceType pasteType = flags.getValue(MVFlags.PASTE_SERVICE_TYPE); + if (pasteType == PasteServiceType.NONE && !(sender instanceof ConsoleCommandSender)) { sender.sendMessage("Version info dumped to console! Please check your server logs."); return; }