diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandCompletions.java b/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandCompletions.java index 81807bc5..4b66c028 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandCompletions.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandCompletions.java @@ -101,9 +101,9 @@ public class MVCommandCompletions extends PaperCommandCompletions { } switch (flag.getValueRequirement()) { case REQUIRED: - return flag.suggestValue(); + return flag.suggestValue(this.plugin); case OPTIONAL: - Collection suggestions = flag.suggestValue(); + Collection suggestions = flag.suggestValue(this.plugin); flagsKeys.removeAll(args); flagsKeys.addAll(suggestions); return flagsKeys; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandTools/contexts/Flag.java b/src/main/java/com/onarandombox/MultiverseCore/commandTools/contexts/Flag.java index a0b37012..8fbd3be4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandTools/contexts/Flag.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandTools/contexts/Flag.java @@ -6,11 +6,9 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.commands.EnvironmentCommand; import com.onarandombox.MultiverseCore.commands.GeneratorCommand; import com.onarandombox.MultiverseCore.enums.FlagValue; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.WorldType; import org.bukkit.command.CommandSender; -import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -20,7 +18,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; -import java.util.stream.Collectors; public abstract class Flag { @@ -28,13 +25,9 @@ public abstract class Flag { public static final Flag GENERATOR = new Flag("-g", String.class) { @Override - public @NotNull Collection suggestValue() { + public @NotNull Collection suggestValue(@NotNull MultiverseCore plugin) { //TODO ACF: Put in WorldManager. - return Arrays.stream(Bukkit.getServer().getPluginManager().getPlugins()) - .filter(Plugin::isEnabled) - .filter(plugin -> plugin.getDefaultWorldGenerator("world", "") != null) - .map(plugin -> plugin.getDescription().getName()) - .collect(Collectors.toList()); + return plugin.getMVWorldManager().getAvailableWorldGenerators(); } @Override @@ -45,7 +38,7 @@ public abstract class Flag { if (genString == null) { sender.sendMessage(String.format("%sYou need to specify a generator for flag '%s'.", ChatColor.RED, this.getKey())); - GeneratorCommand.showAvailableGenerator(sender); + GeneratorCommand.showAvailableGenerator(plugin, sender); throw new InvalidCommandArgument(false); } @@ -55,7 +48,7 @@ public abstract class Flag { try { if (plugin.getMVWorldManager().getChunkGenerator(generator, generatorId, "test") == null) { sender.sendMessage(String.format("%sInvalid generator string '%s'.", ChatColor.RED, genString)); - GeneratorCommand.showAvailableGenerator(sender); + GeneratorCommand.showAvailableGenerator(plugin, sender); throw new InvalidCommandArgument(); } } @@ -85,7 +78,7 @@ public abstract class Flag { }}; @Override - public @NotNull Collection suggestValue() { + public @NotNull Collection suggestValue(@NotNull MultiverseCore plugin) { return typeAlias.keySet(); } @@ -120,7 +113,7 @@ public abstract class Flag { public static final Flag SEED = new Flag("-s", String.class, FlagValue.OPTIONAL) { @Override - public @NotNull Collection suggestValue() { + public @NotNull Collection suggestValue(@NotNull MultiverseCore plugin) { return Collections.emptyList(); } @@ -140,7 +133,7 @@ public abstract class Flag { public static final Flag GENERATE_STRUCTURES = new Flag("-a", Boolean.class) { @Override - public @NotNull Collection suggestValue() { + public @NotNull Collection suggestValue(@NotNull MultiverseCore plugin) { return Arrays.asList("true", "false"); } @@ -166,7 +159,7 @@ public abstract class Flag { public static final Flag SPAWN_ADJUST = new Flag("-n", Boolean.class, FlagValue.NONE) { @Override - public @NotNull Collection suggestValue() { + public @NotNull Collection suggestValue(@NotNull MultiverseCore plugin) { return Collections.emptyList(); } @@ -221,7 +214,7 @@ public abstract class Flag { flagMap.put(this.key, this); } - public abstract @NotNull Collection suggestValue(); + public abstract @NotNull Collection suggestValue(@NotNull MultiverseCore plugin); public abstract T parseValue(@Nullable String value, @NotNull MultiverseCore plugin, diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/GeneratorCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/GeneratorCommand.java index 9b070b55..fb618805 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/GeneratorCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/GeneratorCommand.java @@ -11,21 +11,15 @@ import co.aikar.commands.annotation.CommandAlias; import co.aikar.commands.annotation.CommandPermission; import co.aikar.commands.annotation.Description; import co.aikar.commands.annotation.Subcommand; -import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.commandTools.display.ColorAlternator; import com.onarandombox.MultiverseCore.commandTools.display.ContentCreator; import com.onarandombox.MultiverseCore.commandTools.display.inline.ListDisplay; -import net.milkbowl.vault.chat.Chat; -import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import org.bukkit.plugin.Plugin; import org.jetbrains.annotations.NotNull; -import java.util.Arrays; import java.util.List; -import java.util.stream.Collectors; @CommandAlias("mv") public class GeneratorCommand extends MultiverseCommand { @@ -38,24 +32,22 @@ public class GeneratorCommand extends MultiverseCommand { @CommandPermission("multiverse.core.generator") @Description("Shows a list of Loaded Generator Plugins.") public void onGeneratorCommand(@NotNull CommandSender sender) { - showAvailableGenerator(sender); + showAvailableGenerator(this.plugin, sender); } - public static void showAvailableGenerator(@NotNull CommandSender sender) { + public static void showAvailableGenerator(@NotNull MultiverseCore plugin, + @NotNull CommandSender sender) { + new ListDisplay().withSender(sender) .withHeader(String.format("%s--- Available Generator Plugins ---", ChatColor.GOLD)) - .withCreator(getGeneratorContent()) + .withCreator(getGeneratorContent(plugin)) .withColors(new ColorAlternator(ChatColor.AQUA, ChatColor.WHITE)) .withEmptyMessage(String.format("%sYou do not have any generator plugins installed.", ChatColor.RED)) .build() .run(); } - private static ContentCreator> getGeneratorContent() { - return () -> Arrays.stream(Bukkit.getServer().getPluginManager().getPlugins()) - .filter(Plugin::isEnabled) - .filter(plugin -> plugin.getDefaultWorldGenerator("world", "") != null) - .map(plugin -> plugin.getDescription().getName()) - .collect(Collectors.toList()); + private static ContentCreator> getGeneratorContent(@NotNull MultiverseCore plugin) { + return () -> plugin.getMVWorldManager().getAvailableWorldGenerators(); } }