-
Notifications
You must be signed in to change notification settings - Fork 298
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement remove and import command (#2839)
* feat: Implement remove and import command * chore: Improve some description strings
- Loading branch information
1 parent
8bdb45a
commit 9d18c4a
Showing
4 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/onarandombox/MultiverseCore/commands/RemoveCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters