diff --git a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java index 4b0b74bd..880e8d20 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MultiverseCore.java @@ -32,10 +32,12 @@ import com.onarandombox.MultiverseCore.commands.ConfirmCommand; import com.onarandombox.MultiverseCore.commands.CreateCommand; import com.onarandombox.MultiverseCore.commands.DebugCommand; import com.onarandombox.MultiverseCore.commands.DeleteCommand; +import com.onarandombox.MultiverseCore.commands.ImportCommand; import com.onarandombox.MultiverseCore.commands.GameruleCommand; import com.onarandombox.MultiverseCore.commands.LoadCommand; import com.onarandombox.MultiverseCore.commands.RegenCommand; import com.onarandombox.MultiverseCore.commands.ReloadCommand; +import com.onarandombox.MultiverseCore.commands.RemoveCommand; import com.onarandombox.MultiverseCore.commands.TeleportCommand; import com.onarandombox.MultiverseCore.commands.UnloadCommand; import com.onarandombox.MultiverseCore.commandtools.MVCommandManager; @@ -203,10 +205,12 @@ public class MultiverseCore extends JavaPlugin implements MVCore { this.commandManager.registerCommand(new CreateCommand(this)); this.commandManager.registerCommand(new DebugCommand(this)); this.commandManager.registerCommand(new DeleteCommand(this)); + this.commandManager.registerCommand(new ImportCommand(this)); this.commandManager.registerCommand(new GameruleCommand(this)); this.commandManager.registerCommand(new LoadCommand(this)); this.commandManager.registerCommand(new RegenCommand(this)); this.commandManager.registerCommand(new ReloadCommand(this)); + this.commandManager.registerCommand(new RemoveCommand(this)); this.commandManager.registerCommand(new TeleportCommand(this)); this.commandManager.registerCommand(new UnloadCommand(this)); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java new file mode 100644 index 00000000..2cc80ef6 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java @@ -0,0 +1,88 @@ +package com.onarandombox.MultiverseCore.commands; + +import java.util.Arrays; +import java.util.stream.Collectors; + +import co.aikar.commands.BukkitCommandIssuer; +import co.aikar.commands.annotation.CommandAlias; +import co.aikar.commands.annotation.CommandCompletion; +import co.aikar.commands.annotation.CommandPermission; +import co.aikar.commands.annotation.Conditions; +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 com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.commandtools.flags.CommandFlag; +import com.onarandombox.MultiverseCore.commandtools.flags.CommandFlagGroup; +import com.onarandombox.MultiverseCore.commandtools.flags.CommandValueFlag; +import com.onarandombox.MultiverseCore.commandtools.flags.ParsedCommandFlags; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.World; +import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; + +@CommandAlias("mv") +public class ImportCommand extends MultiverseCoreCommand { + public ImportCommand(@NotNull MultiverseCore plugin) { + super(plugin); + + registerFlagGroup(CommandFlagGroup.builder("mvimport") + .add(CommandValueFlag.builder("--generator", String.class) + .addAlias("-g") + .completion(() -> Arrays.stream(Bukkit.getServer().getPluginManager().getPlugins()) + .filter(Plugin::isEnabled) + .filter(genplugin -> this.plugin.getUnsafeCallWrapper().wrap( + () -> genplugin.getDefaultWorldGenerator("world", ""), + genplugin.getName(), + "Get generator" + ) != null) + .map(genplugin -> genplugin.getDescription().getName()) + .collect(Collectors.toList())) + .build()) + .add(CommandFlag.builder("--adjust-spawn") + .addAlias("-a") + .build()) + .build()); + } + + @Subcommand("import") + @CommandPermission("multiverse.core.import") + @CommandCompletion("@mvworlds:scope=potential @flags:groupName=mvimport") + @Syntax(" --generator [generator[:id]] --adjust-spawn") + @Description("Imports a existing world folder.") + public void onImportCommand(BukkitCommandIssuer issuer, + + @Conditions("validWorldName:scope=new") + @Syntax("") + @Description("Name of the world folder.") + String worldName, + + @Syntax("") + @Description("The world's environment. See: /mv env") + World.Environment environment, + + @Optional + @Syntax("--generator [generator[:id]] --adjust-spawn") + @Description("Other world settings. See: https://gg.gg/nn8c2") + String[] flags) { + + ParsedCommandFlags parsedFlags = parseFlags(flags); + + issuer.sendMessage(String.format("Starting import of world '%s'...", worldName)); + + if (!this.worldManager.addWorld( + worldName, environment, + null, + null, + null, + parsedFlags.flagValue("--generator", String.class), + parsedFlags.hasFlag("--adjust-spawn")) + ) { + issuer.sendMessage(String.format("%sFailed! See console for more details.", ChatColor.RED)); + return; + } + issuer.sendMessage(String.format("%sComplete!", ChatColor.GREEN)); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/RemoveCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/RemoveCommand.java new file mode 100644 index 00000000..e011a2ca --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/RemoveCommand.java @@ -0,0 +1,41 @@ +package com.onarandombox.MultiverseCore.commands; + +import co.aikar.commands.BukkitCommandIssuer; +import co.aikar.commands.annotation.CommandAlias; +import co.aikar.commands.annotation.CommandCompletion; +import co.aikar.commands.annotation.CommandPermission; +import co.aikar.commands.annotation.Conditions; +import co.aikar.commands.annotation.Description; +import co.aikar.commands.annotation.Single; +import co.aikar.commands.annotation.Subcommand; +import co.aikar.commands.annotation.Syntax; +import com.onarandombox.MultiverseCore.MultiverseCore; +import org.bukkit.ChatColor; +import org.jetbrains.annotations.NotNull; + +@CommandAlias("mv") +public class RemoveCommand extends MultiverseCoreCommand { + public RemoveCommand(@NotNull MultiverseCore plugin) { + super(plugin); + } + + @Subcommand("remove") + @CommandPermission("multiverse.core.remove") + @CommandCompletion("@mvworlds:scope=both") + @Syntax("") + @Description("Unloads a world from Multiverse and removes it from worlds.yml, this does NOT DELETE the world folder.") + public void onRemoveCommand(BukkitCommandIssuer issuer, + + @Single + @Conditions("mvworlds:scope=both") + @Syntax("") + @Description("World you want to remove from mv's knowledge.") + String worldName + ) { + if (!this.plugin.getMVWorldManager().removeWorldFromConfig(worldName)) { + issuer.sendMessage(String.format("%sError trying to remove world from config!", ChatColor.RED)); + return; + } + issuer.sendMessage(String.format("World '%s' is removed from config!", worldName)); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java index b55f5cc2..044dac90 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandtools/MVCommandCompletions.java @@ -93,6 +93,9 @@ public class MVCommandCompletions extends PaperCommandCompletions { case "unloaded": worlds.addAll(worldManager.getUnloadedWorlds()); break; + case "potential": + worlds.addAll(worldManager.getPotentialWorlds()); + break; } return worlds; }