mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 10:36:06 +01:00
Make use of getAvailableWorldGenerators to reduce duplicate code.
This commit is contained in:
parent
e2bf1a2bbe
commit
4a4a2505e7
@ -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<String> suggestions = flag.suggestValue();
|
||||
Collection<String> suggestions = flag.suggestValue(this.plugin);
|
||||
flagsKeys.removeAll(args);
|
||||
flagsKeys.addAll(suggestions);
|
||||
return flagsKeys;
|
||||
|
@ -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<T> {
|
||||
|
||||
@ -28,13 +25,9 @@ public abstract class Flag<T> {
|
||||
|
||||
public static final Flag<String> GENERATOR = new Flag<String>("-g", String.class) {
|
||||
@Override
|
||||
public @NotNull Collection<String> suggestValue() {
|
||||
public @NotNull Collection<String> 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<T> {
|
||||
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<T> {
|
||||
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<T> {
|
||||
}};
|
||||
|
||||
@Override
|
||||
public @NotNull Collection<String> suggestValue() {
|
||||
public @NotNull Collection<String> suggestValue(@NotNull MultiverseCore plugin) {
|
||||
return typeAlias.keySet();
|
||||
}
|
||||
|
||||
@ -120,7 +113,7 @@ public abstract class Flag<T> {
|
||||
|
||||
public static final Flag<String> SEED = new Flag<String>("-s", String.class, FlagValue.OPTIONAL) {
|
||||
@Override
|
||||
public @NotNull Collection<String> suggestValue() {
|
||||
public @NotNull Collection<String> suggestValue(@NotNull MultiverseCore plugin) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@ -140,7 +133,7 @@ public abstract class Flag<T> {
|
||||
|
||||
public static final Flag<Boolean> GENERATE_STRUCTURES = new Flag<Boolean>("-a", Boolean.class) {
|
||||
@Override
|
||||
public @NotNull Collection<String> suggestValue() {
|
||||
public @NotNull Collection<String> suggestValue(@NotNull MultiverseCore plugin) {
|
||||
return Arrays.asList("true", "false");
|
||||
}
|
||||
|
||||
@ -166,7 +159,7 @@ public abstract class Flag<T> {
|
||||
|
||||
public static final Flag<Boolean> SPAWN_ADJUST = new Flag<Boolean>("-n", Boolean.class, FlagValue.NONE) {
|
||||
@Override
|
||||
public @NotNull Collection<String> suggestValue() {
|
||||
public @NotNull Collection<String> suggestValue(@NotNull MultiverseCore plugin) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@ -221,7 +214,7 @@ public abstract class Flag<T> {
|
||||
flagMap.put(this.key, this);
|
||||
}
|
||||
|
||||
public abstract @NotNull Collection<String> suggestValue();
|
||||
public abstract @NotNull Collection<String> suggestValue(@NotNull MultiverseCore plugin);
|
||||
|
||||
public abstract T parseValue(@Nullable String value,
|
||||
@NotNull MultiverseCore plugin,
|
||||
|
@ -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<List<String>> 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<List<String>> getGeneratorContent(@NotNull MultiverseCore plugin) {
|
||||
return () -> plugin.getMVWorldManager().getAvailableWorldGenerators();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user