Skip to content

Commit

Permalink
feat: Implement remove and import command (#2839)
Browse files Browse the repository at this point in the history
* feat: Implement remove and import command

* chore: Improve some description strings
  • Loading branch information
benwoo1110 authored Feb 17, 2023
1 parent 8bdb45a commit 9d18c4a
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
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;
Expand Down Expand Up @@ -203,10 +205,12 @@ private void registerCommands() {
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));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ private List<String> getMVWorldNames(BukkitCommandCompletionContext context) {
case "unloaded":
worlds.addAll(worldManager.getUnloadedWorlds());
break;
case "potential":
worlds.addAll(worldManager.getPotentialWorlds());
break;
}
return worlds;
}
Expand Down

0 comments on commit 9d18c4a

Please sign in to comment.