diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands_acf/DeleteCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands_acf/DeleteCommand.java index c1983ce3..2db2cb60 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands_acf/DeleteCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands_acf/DeleteCommand.java @@ -25,7 +25,7 @@ public class DeleteCommand extends MultiverseCommand { @CommandPermission("multiverse.core.delete") @Syntax("") @CommandCompletion("@MVWorlds|@unloadedWorlds") - @Description("") + @Description("Deletes a world on your server PERMANENTLY.") public void onDeleteCommand(@NotNull CommandSender sender, @NotNull @Single @Flags("trim") @Conditions("isWorldInConfig|validWorldFolder") String worldName) { @@ -37,11 +37,9 @@ public class DeleteCommand extends MultiverseCommand { return () -> { //TODO: deleteWorld method should take world object directly - String resultMessage = (this.plugin.getMVWorldManager().deleteWorld(worldName)) + sender.sendMessage((this.plugin.getMVWorldManager().deleteWorld(worldName)) ? ChatColor.GREEN + "World '" + worldName + "' is deleted!" - : ChatColor.RED + "World '" + worldName + "' could not be deleted!"; - - sender.sendMessage(resultMessage); + : ChatColor.RED + "World '" + worldName + "' could not be deleted!"); }; } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands_acf/EnvironmentCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands_acf/EnvironmentCommand.java new file mode 100644 index 00000000..40f204c3 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commands_acf/EnvironmentCommand.java @@ -0,0 +1,47 @@ +package com.onarandombox.MultiverseCore.commands_acf; + +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.onarandombox.MultiverseCore.MultiverseCore; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; + +@CommandAlias("mv") +public class EnvironmentCommand extends MultiverseCommand { + + public EnvironmentCommand(MultiverseCore plugin) { + super(plugin); + } + + @Subcommand("env|environments") + @CommandPermission("multiverse.core.list.environments") + @Description("Lists valid known environments/world types.") + public void onEnvironmentCommand(CommandSender sender) { + showEnvironments(sender); + showWorldTypes(sender); + } + + /** + * Shows all valid known environments to a {@link CommandSender}. + * + * @param sender The {@link CommandSender}. + */ + private void showEnvironments(CommandSender sender) { + sender.sendMessage(ChatColor.YELLOW + "Valid Environments are:"); + sender.sendMessage(ChatColor.GREEN + "NORMAL"); + sender.sendMessage(ChatColor.RED + "NETHER"); + sender.sendMessage(ChatColor.AQUA + "END"); + } + /** + * Shows all valid known world types to a {@link CommandSender}. + * + * @param sender The {@link CommandSender}. + */ + private void showWorldTypes(CommandSender sender) { + sender.sendMessage(ChatColor.YELLOW + "Valid World Types are:"); + sender.sendMessage(String.format("%sNORMAL%s, %sFLAT, %sLARGEBIOMES %sor %sAMPLIFIED", + ChatColor.GREEN, ChatColor.WHITE, ChatColor.AQUA, ChatColor.RED, ChatColor.WHITE, ChatColor.GOLD)); + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands_acf/RegenCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands_acf/RegenCommand.java new file mode 100644 index 00000000..c080893b --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commands_acf/RegenCommand.java @@ -0,0 +1,54 @@ +package com.onarandombox.MultiverseCore.commands_acf; + +import co.aikar.commands.annotation.CommandAlias; +import co.aikar.commands.annotation.CommandCompletion; +import co.aikar.commands.annotation.CommandPermission; +import co.aikar.commands.annotation.Description; +import co.aikar.commands.annotation.Flags; +import co.aikar.commands.annotation.Subcommand; +import co.aikar.commands.annotation.Syntax; +import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import com.onarandombox.MultiverseCore.commands_helper.WorldFlags; +import org.bukkit.ChatColor; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +@CommandAlias("mv") +public class RegenCommand extends MultiverseCommand { + + public RegenCommand(MultiverseCore plugin) { + super(plugin); + } + + @Subcommand("regen") + @CommandPermission("multiverse.core.regen") + @Syntax("") + @CommandCompletion("@MVWorlds") + @Description("Regenerates a world on your server. The previous state will be lost PERMANENTLY.") + public void onRegenCommand(@NotNull CommandSender sender, + //TODO: Allow regen of unloaded worlds. + @NotNull @Flags("other") MultiverseWorld world, + @NotNull WorldFlags flags) { + + this.plugin.getMVCommandManager().getQueueManager().addToQueue(sender, regenRunnable(sender, world, flags)); + } + + private Runnable regenRunnable(@NotNull CommandSender sender, + @NotNull MultiverseWorld world, + @NotNull WorldFlags flags) { + + return () -> { + //TODO: regenWorld method should take world object directly + //TODO: Shouldn't need randomSeed, just check if seed parameter is null. + sender.sendMessage((this.plugin.getMVWorldManager().regenWorld( + world.getName(), + flags.hasFlag("-s"), + flags.getSeed() == null, + flags.getSeed()) + ) + ? ChatColor.GREEN + "World Regenerated!" + : ChatColor.RED + "World could NOT be regenerated!"); + }; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands_helper/MVCommandContexts.java b/src/main/java/com/onarandombox/MultiverseCore/commands_helper/MVCommandContexts.java index 2bd4573d..bb44ba1f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands_helper/MVCommandContexts.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands_helper/MVCommandContexts.java @@ -262,6 +262,7 @@ public class MVCommandContexts extends PaperCommandContexts { private WorldFlags deriveWorldFlags(@NotNull BukkitCommandExecutionContext context) { Map flags = parseFlags(context.getArgs()); return new WorldFlags( + flags.keySet(), flags.get("-s"), validateGenerator(flags.get("-g")), getWorldType(flags.get("-t")), diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands_helper/MVCommandManager.java b/src/main/java/com/onarandombox/MultiverseCore/commands_helper/MVCommandManager.java index 734692fc..7a7741c4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands_helper/MVCommandManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands_helper/MVCommandManager.java @@ -18,12 +18,14 @@ import com.onarandombox.MultiverseCore.commands_acf.CoordCommand; import com.onarandombox.MultiverseCore.commands_acf.CreateCommand; import com.onarandombox.MultiverseCore.commands_acf.DebugCommand; import com.onarandombox.MultiverseCore.commands_acf.DeleteCommand; +import com.onarandombox.MultiverseCore.commands_acf.EnvironmentCommand; import com.onarandombox.MultiverseCore.commands_acf.GameRuleCommand; import com.onarandombox.MultiverseCore.commands_acf.GeneratorCommand; import com.onarandombox.MultiverseCore.commands_acf.ImportCommand; import com.onarandombox.MultiverseCore.commands_acf.InfoCommand; import com.onarandombox.MultiverseCore.commands_acf.ListCommand; import com.onarandombox.MultiverseCore.commands_acf.LoadCommand; +import com.onarandombox.MultiverseCore.commands_acf.RegenCommand; import com.onarandombox.MultiverseCore.commands_acf.ReloadCommand; import com.onarandombox.MultiverseCore.commands_acf.RemoveCommand; import com.onarandombox.MultiverseCore.commands_acf.ScriptCommand; @@ -82,6 +84,8 @@ public class MVCommandManager extends PaperCommandManager { registerCommand(new ImportCommand(plugin)); registerCommand(new CheckCommand(plugin)); registerCommand(new GameRuleCommand(plugin)); + registerCommand(new EnvironmentCommand(plugin)); + registerCommand(new RegenCommand(plugin)); } @Override diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands_helper/WorldFlags.java b/src/main/java/com/onarandombox/MultiverseCore/commands_helper/WorldFlags.java index 48c4d743..ef9baaba 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands_helper/WorldFlags.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands_helper/WorldFlags.java @@ -2,14 +2,23 @@ package com.onarandombox.MultiverseCore.commands_helper; import org.bukkit.WorldType; +import java.util.Set; + public class WorldFlags { + private final Set flagsUsed; private final String seed; private final String generator; private final WorldType worldType; private final boolean spawnAdjust; private final boolean generateStructures; - public WorldFlags(String seed, String generator, WorldType worldType, boolean spawnAdjust, boolean generateStructures) { + public WorldFlags(Set flagsUsed, + String seed, String generator, + WorldType worldType, + boolean spawnAdjust, + boolean generateStructures) { + + this.flagsUsed = flagsUsed; this.seed = seed; this.generator = generator; this.worldType = worldType; @@ -17,6 +26,10 @@ public class WorldFlags { this.generateStructures = generateStructures; } + public boolean hasFlag(String flag) { + return flagsUsed.contains(flag); + } + public String getSeed() { return seed; }