mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-01-08 09:17:38 +01:00
feat: Implement remove and import command (#2839)
* feat: Implement remove and import command * chore: Improve some description strings
This commit is contained in:
parent
d8fff0ae15
commit
20ba6f130a
@ -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));
|
||||
}
|
||||
|
@ -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("<name> <env> --generator [generator[:id]] --adjust-spawn")
|
||||
@Description("Imports a existing world folder.")
|
||||
public void onImportCommand(BukkitCommandIssuer issuer,
|
||||
|
||||
@Conditions("validWorldName:scope=new")
|
||||
@Syntax("<name>")
|
||||
@Description("Name of the world folder.")
|
||||
String worldName,
|
||||
|
||||
@Syntax("<env>")
|
||||
@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));
|
||||
}
|
||||
}
|
@ -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("<world>")
|
||||
@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("<world>")
|
||||
@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));
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user