From 55cf19b1d8bd5ea4f1947e9c3b42b4b3153685e0 Mon Sep 17 00:00:00 2001 From: benwoo1110 <30431861+benwoo1110@users.noreply.github.com> Date: Fri, 5 Mar 2021 12:15:34 +0800 Subject: [PATCH] Generate improvements througout. --- .../onarandombox/MultiverseCore/MVWorld.java | 2 - .../MultiverseCore/api/MultiverseWorld.java | 1 - .../commandTools/MVCommandCompletions.java | 5 +- .../commandTools/MVCommandContexts.java | 52 ++++---- .../commandTools/contexts/RequiredPlayer.java | 16 +++ .../queue/CommandQueueManager.java | 109 ++-------------- .../commandTools/queue/QueuedCommand.java | 118 ++++++++++++++---- .../commands/AnchorCommand.java | 10 +- .../MultiverseCore/commands/BedCommand.java | 30 ++++- .../MultiverseCore/commands/CheckCommand.java | 17 +-- .../MultiverseCore/commands/CloneCommand.java | 6 +- .../commands/ConfigCommand.java | 6 +- .../MultiverseCore/commands/CoordCommand.java | 45 ++++--- .../commands/CreateCommand.java | 16 ++- .../MultiverseCore/commands/DebugCommand.java | 9 +- .../commands/DeleteCommand.java | 16 +-- .../commands/EnvironmentCommand.java | 2 +- .../commands/GameRuleCommand.java | 3 +- .../commands/ImportCommand.java | 10 +- .../MultiverseCore/commands/InfoCommand.java | 5 +- .../MultiverseCore/commands/ListCommand.java | 12 +- .../MultiverseCore/commands/LoadCommand.java | 4 +- .../commands/ModifyCommand.java | 41 ++++-- .../MultiverseCore/commands/PurgeCommand.java | 9 +- .../MultiverseCore/commands/RegenCommand.java | 18 +-- .../commands/RemoveCommand.java | 8 +- .../commands/ScriptCommand.java | 15 +-- .../commands/SetSpawnCommand.java | 13 +- .../MultiverseCore/commands/SpawnCommand.java | 69 ++++------ .../commands/TeleportCommand.java | 21 ++-- .../commands/UnloadCommand.java | 3 +- .../MultiverseCore/commands/UsageCommand.java | 5 +- .../commands/VersionCommand.java | 7 +- .../MultiverseCore/commands/WhoCommand.java | 8 +- .../listeners/MVAsyncPlayerChatListener.java | 2 - .../listeners/MVEntityListener.java | 2 - .../listeners/MVPlayerChatListener.java | 2 - .../listeners/MVPlayerListener.java | 1 - .../listeners/MVPortalListener.java | 2 - .../MultiverseCore/utils/AnchorManager.java | 1 - .../utils/BukkitTravelAgent.java | 2 - .../MultiverseCore/utils/FileUtils.java | 3 - .../MultiverseCore/utils/PermissionTools.java | 2 - .../MultiverseCore/utils/PurgeWorlds.java | 1 - .../utils/SimpleLocationManipulation.java | 1 - .../utils/SimpleSafeTTeleporter.java | 2 - .../MultiverseCore/TestWorldProperties.java | 2 - .../MultiverseCore/utils/FileUtilsTest.java | 1 - 48 files changed, 392 insertions(+), 343 deletions(-) create mode 100644 src/main/java/com/onarandombox/MultiverseCore/commandTools/contexts/RequiredPlayer.java diff --git a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java index a1c5bf19..4db92942 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/MVWorld.java @@ -28,7 +28,6 @@ import org.bukkit.Material; import org.bukkit.World; import org.bukkit.World.Environment; import org.bukkit.WorldType; -import org.bukkit.command.CommandSender; import org.bukkit.configuration.serialization.SerializableAs; import org.bukkit.entity.Player; import org.bukkit.permissions.Permission; @@ -42,7 +41,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.UUID; -import java.util.logging.Level; /** * The implementation of a Multiverse handled world. diff --git a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java index 515b80e5..fa82e5c0 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java +++ b/src/main/java/com/onarandombox/MultiverseCore/api/MultiverseWorld.java @@ -16,7 +16,6 @@ import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; import org.bukkit.WorldType; -import org.bukkit.command.CommandSender; import org.bukkit.permissions.Permission; import org.jetbrains.annotations.Nullable; diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandCompletions.java b/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandCompletions.java index 6b6d36f2..9c1cbfa6 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandCompletions.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandCompletions.java @@ -89,7 +89,10 @@ public class MVCommandCompletions extends PaperCommandCompletions { FlagGroup flagGroup = command.getFlagGroup(); String[] args = context.getContextValue(String[].class); - CommandFlag flag = flagGroup.getByKey(args[args.length - 1]); + CommandFlag flag = (args.length <= 1) ? null : flagGroup.getByKey(args[args.length - 2]); + + Logging.info(Arrays.toString(args)); + Logging.info(String.valueOf(flag)); if (flag == null || flag.getValueRequirement() == ValueRequirement.NONE) { // suggest new flags. diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandContexts.java b/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandContexts.java index 94ab2969..25c749da 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandContexts.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandTools/MVCommandContexts.java @@ -15,6 +15,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore; import com.onarandombox.MultiverseCore.api.MVDestination; import com.onarandombox.MultiverseCore.api.MVWorldManager; import com.onarandombox.MultiverseCore.api.MultiverseWorld; +import com.onarandombox.MultiverseCore.commandtools.contexts.RequiredPlayer; import com.onarandombox.MultiverseCore.commandtools.contexts.GameRuleProperty; import com.onarandombox.MultiverseCore.commandtools.contexts.PageFilter; import com.onarandombox.MultiverseCore.commandtools.contexts.PlayerWorld; @@ -56,9 +57,11 @@ public class MVCommandContexts extends PaperCommandContexts { this.plugin = plugin; this.worldManager = plugin.getMVWorldManager(); + registerContext(RequiredPlayer.class, this::deriveRequiredPlayer); + registerIssuerOnlyContext(Player.class, this::derivePlayer); + registerIssuerAwareContext(PlayerWorld.class, this::derivePlayerWorld); registerIssuerAwareContext(MultiverseWorld.class, this::deriveMultiverseWorld); - registerIssuerAwareContext(Player.class, this::derivePlayer); registerContext(World.Environment.class, this::deriveEnvironment); registerIssuerAwareContext(GameRuleProperty.class, this::deriveGameRuleProperty); registerIssuerAwareContext(MVDestination.class, this::deriveMVDestination); @@ -68,7 +71,26 @@ public class MVCommandContexts extends PaperCommandContexts { registerOptionalContext(PageFilter.class, this::derivePageFilter); } - @Nullable + @NotNull + private Player derivePlayer(@NotNull BukkitCommandExecutionContext context) { + Player player = context.getPlayer(); + if (player == null) { + throw new InvalidCommandArgument("You must be a player to run this command."); + } + return player; + } + + @NotNull + private RequiredPlayer deriveRequiredPlayer(BukkitCommandExecutionContext context) { + String playerIdentifier = context.getFirstArg(); + Player player = getPlayerFromValue(context.getSender(), playerIdentifier); + if (player == null) { + throw new InvalidCommandArgument("Invalid player name '" + playerIdentifier + "'!"); + } + return new RequiredPlayer(player); + } + + @NotNull private PlayerWorld derivePlayerWorld(@NotNull BukkitCommandExecutionContext context) { Player player = derivePlayer(context); if (player == null) { @@ -182,32 +204,6 @@ public class MVCommandContexts extends PaperCommandContexts { return targetWorld; } - @Nullable - private Player derivePlayer(@NotNull BukkitCommandExecutionContext context) { - if (!context.hasFlag("other")) { - return getPlayerFromSelf(context, "You must be a player to run this command."); - } - - String playerIdentifier = context.getFirstArg(); - if (playerIdentifier == null) { - if (context.hasFlag("defaultself")) { - return getPlayerFromSelf(context, "You need to specify a player from console."); - } - throw new InvalidCommandArgument("You need to specify a player."); - } - - Player player = getPlayerFromValue(context.getSender(), playerIdentifier); - if (player == null) { - if (context.hasFlag("fallbackself")) { - return getPlayerFromSelf(context, String.format("Player '%s' not found.", playerIdentifier)); - } - throw new InvalidCommandArgument(String.format("Player '%s' not found.", playerIdentifier)); - } - - context.popFirstArg(); - return player; - } - @Nullable private Player getPlayerFromSelf(@NotNull BukkitCommandExecutionContext context, String errorReason) { Player self = context.getPlayer(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandTools/contexts/RequiredPlayer.java b/src/main/java/com/onarandombox/MultiverseCore/commandTools/contexts/RequiredPlayer.java new file mode 100644 index 00000000..a90498b7 --- /dev/null +++ b/src/main/java/com/onarandombox/MultiverseCore/commandTools/contexts/RequiredPlayer.java @@ -0,0 +1,16 @@ +package com.onarandombox.MultiverseCore.commandtools.contexts; + +import org.bukkit.entity.Player; + +public class RequiredPlayer { + + private final Player player; + + public RequiredPlayer(Player player) { + this.player = player; + } + + public Player get() { + return player; + } +} diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandTools/queue/CommandQueueManager.java b/src/main/java/com/onarandombox/MultiverseCore/commandTools/queue/CommandQueueManager.java index 0ab72fae..cb9debff 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandTools/queue/CommandQueueManager.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandTools/queue/CommandQueueManager.java @@ -11,14 +11,12 @@ import com.dumptruckman.minecraft.util.Logging; import com.onarandombox.MultiverseCore.MultiverseCore; import org.bukkit.Bukkit; import org.bukkit.ChatColor; -import org.bukkit.block.data.type.CommandBlock; -import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.NotNull; -import java.util.HashMap; import java.util.Map; +import java.util.WeakHashMap; /** * Queue dangerous commands, with the need to use '/mv confirm' before executing. @@ -28,77 +26,19 @@ public class CommandQueueManager { private final MultiverseCore plugin; private final Map queuedCommandMap; - private static final DummyCommandBlockSender COMMAND_BLOCK = new DummyCommandBlockSender(); - private static final String DEFAULT_PROMPT_MESSAGE = "The command you are trying to run is deemed dangerous."; - private static final int DEFAULT_VALID_TIME = 200; // In ticks, 20 ticks = 1s - public CommandQueueManager(@NotNull MultiverseCore plugin) { this.plugin = plugin; - this.queuedCommandMap = new HashMap<>(); + this.queuedCommandMap = new WeakHashMap<>(); } - /** - * Add a command to queue. - * - * @param sender {@link CommandSender} that executed the command. - * @param runnable Action to do when the command is ran. - */ - public void addToQueue(@NotNull CommandSender sender, - @NotNull Runnable runnable) { + public void addToQueue(QueuedCommand queuedCommand) { + CommandSender sender = queuedCommand.getSender(); + this.cancelPreviousInQueue(sender); + this.queuedCommandMap.put(sender, queuedCommand); - addToQueue(sender, runnable, DEFAULT_PROMPT_MESSAGE, DEFAULT_VALID_TIME); - } + queuedCommand.setExpireTask(runExpireLater(queuedCommand)); - /** - * Add a command to queue. - * - * @param sender {@link CommandSender} that executed the command. - * @param runnable Action to do when the command is ran. - * @param prompt Reason for needing to confirm the action before running. - */ - public void addToQueue(@NotNull CommandSender sender, - @NotNull Runnable runnable, - @NotNull String prompt) { - - addToQueue(sender, runnable, prompt, DEFAULT_VALID_TIME); - } - - /** - * Add a command to queue. - * - * @param sender {@link CommandSender} that executed the command. - * @param runnable Action to do when the command is ran. - * @param validPeriod How long before the command expires and is removed from queue without running. - */ - public void addToQueue(@NotNull CommandSender sender, - @NotNull Runnable runnable, - int validPeriod) { - - addToQueue(sender, runnable, DEFAULT_PROMPT_MESSAGE, validPeriod); - } - - /** - * Add a command to queue. - * - * @param sender {@link CommandSender} that executed the command. - * @param runnable Action to do when the command is ran. - * @param prompt Reason for needing to confirm the action before running. - * @param validPeriod How long before the command expires and is removed from queue without running. - */ - public void addToQueue(@NotNull CommandSender sender, - @NotNull Runnable runnable, - @NotNull String prompt, - int validPeriod) { - - CommandSender targetSender = parseSender(sender); - cancelPreviousInQueue(targetSender); - - Logging.finer("Adding command to queue for %s.", sender.getName()); - QueuedCommand queuedCommand = new QueuedCommand(targetSender, runnable); - queuedCommand.setExpireTask(runExpireLater(queuedCommand, validPeriod)); - this.queuedCommandMap.put(targetSender, queuedCommand); - - sender.sendMessage(prompt); + sender.sendMessage(queuedCommand.getPrompt()); sender.sendMessage(String.format("Run %s/mv confirm %sto continue.", ChatColor.GREEN, ChatColor.WHITE)); } @@ -112,7 +52,6 @@ public class CommandQueueManager { if (previousCommand == null) { return; } - previousCommand.getExpireTask().cancel(); this.queuedCommandMap.remove(sender); } @@ -121,15 +60,14 @@ public class CommandQueueManager { * Expire task that remove {@link QueuedCommand} from queue after expiry. * * @param queuedCommand Command to run the expire task on. - * @param validPeriod How long before the command expires and is removed from queue without running. * @return The expire {@link BukkitTask}. */ @NotNull - private BukkitTask runExpireLater(@NotNull QueuedCommand queuedCommand, int validPeriod) { + private BukkitTask runExpireLater(@NotNull QueuedCommand queuedCommand) { return Bukkit.getScheduler().runTaskLater( this.plugin, expireRunnable(queuedCommand), - validPeriod + queuedCommand.getValidDuration() ); } @@ -141,7 +79,6 @@ public class CommandQueueManager { Logging.finer("This is an old command already."); return; } - Logging.finer("Command has expired, removing..."); this.queuedCommandMap.remove(queuedCommand.getSender()); }; @@ -154,7 +91,7 @@ public class CommandQueueManager { * @return True of queued command ran successfully, false otherwise. */ public boolean runQueuedCommand(@NotNull CommandSender sender) { - CommandSender targetSender = parseSender(sender); + CommandSender targetSender = QueuedCommand.parseSender(sender); QueuedCommand queuedCommand = this.queuedCommandMap.get(targetSender); if (queuedCommand == null) { sender.sendMessage("You do not have any commands in queue."); @@ -162,31 +99,9 @@ public class CommandQueueManager { } Logging.finer("Running queued command..."); - queuedCommand.runAction(); + queuedCommand.getAction().run(); queuedCommand.getExpireTask().cancel(); this.queuedCommandMap.remove(targetSender); return true; } - - /** - * To allow all CommandBlocks to be a common sender with use of {@link DummyCommandBlockSender}. - * So confirm command can be used for a queue command on another command block. - */ - @NotNull - private CommandSender parseSender(@NotNull CommandSender sender) { - Logging.fine(sender.getClass().getName()); - if (isCommandBlock(sender)) { - Logging.finer("Is command block."); - return COMMAND_BLOCK; - } - return sender; - } - - /** - * Check if sender is a command block. - */ - private boolean isCommandBlock(@NotNull CommandSender sender) { - return sender instanceof BlockCommandSender - && ((BlockCommandSender) sender).getBlock().getBlockData() instanceof CommandBlock; - } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commandTools/queue/QueuedCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commandTools/queue/QueuedCommand.java index 92e2842b..7b9af6d9 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commandTools/queue/QueuedCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commandTools/queue/QueuedCommand.java @@ -7,6 +7,9 @@ package com.onarandombox.MultiverseCore.commandtools.queue; +import com.dumptruckman.minecraft.util.Logging; +import org.bukkit.block.data.type.CommandBlock; +import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; import org.bukkit.scheduler.BukkitTask; import org.jetbrains.annotations.NotNull; @@ -14,41 +17,106 @@ import org.jetbrains.annotations.NotNull; /** * Represents a single command in {@link CommandQueueManager}. */ -class QueuedCommand { - private final CommandSender sender; - private final Runnable runnable; +public class QueuedCommand { + + private static final DummyCommandBlockSender COMMAND_BLOCK = new DummyCommandBlockSender(); + private static final String DEFAULT_PROMPT_MESSAGE = "The command you are trying to run is deemed dangerous."; + private static final int DEFAULT_VALID_TIME = 200; // In ticks, 20 ticks = 1s + + /** + * To allow all CommandBlocks to be a common sender with use of {@link DummyCommandBlockSender}. + * So confirm command can be used for a queue command on another command block. + */ + @NotNull + static CommandSender parseSender(@NotNull CommandSender sender) { + Logging.fine(sender.getClass().getName()); + if (isCommandBlock(sender)) { + Logging.finer("Is command block."); + return COMMAND_BLOCK; + } + return sender; + } + + /** + * Check if sender is a command block. + */ + static boolean isCommandBlock(@NotNull CommandSender sender) { + return sender instanceof BlockCommandSender + && ((BlockCommandSender) sender).getBlock().getBlockData() instanceof CommandBlock; + } + + private CommandSender sender; + private String prompt = DEFAULT_PROMPT_MESSAGE; + private int validDuration = DEFAULT_VALID_TIME; + private Runnable action; private BukkitTask expireTask; - /** - * - * @param sender {@link CommandSender} that executed the command. - * @param runnable Action to do when the command is ran. - */ - public QueuedCommand(@NotNull CommandSender sender, - @NotNull Runnable runnable) { - - this.sender = sender; - this.runnable = runnable; - } - - /** - * Do the command actions. - */ - public void runAction() { - runnable.run(); - } - - public void setExpireTask(@NotNull BukkitTask expireTask) { - this.expireTask = expireTask; - } + private QueuedCommand() { } @NotNull public CommandSender getSender() { return sender; } + @NotNull + public String getPrompt() { + return prompt; + } + + public int getValidDuration() { + return validDuration; + } + + @NotNull + public Runnable getAction() { + return action; + } + @NotNull public BukkitTask getExpireTask() { return expireTask; } + + public void setExpireTask(@NotNull BukkitTask expireTask) { + this.expireTask = expireTask; + } + + public static class Builder { + + private final QueuedCommand command; + + @NotNull + public Builder() { + this.command = new QueuedCommand(); + } + + @NotNull + public Builder sender(@NotNull CommandSender sender) { + this.command.sender = sender; + return this; + } + + @NotNull + public Builder action(@NotNull Runnable action) { + this.command.action = action; + return this; + } + + @NotNull + public Builder prompt(@NotNull String prompt, Object...replacements) { + this.command.prompt = String.format(prompt, replacements); + return this; + } + + @NotNull + public Builder validDuration(int validDuration) { + this.command.validDuration = validDuration; + return this; + } + + @NotNull + public QueuedCommand build() { + return this.command; + } + } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/AnchorCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/AnchorCommand.java index d93d9054..1ed404c4 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/AnchorCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/AnchorCommand.java @@ -50,9 +50,11 @@ public class AnchorCommand extends MultiverseCoreCommand { @Description("Create a new anchor point.") public void onCreateAnchorCommand(@NotNull Player player, + @NotNull @Syntax("") @Description("Name of your new anchor.") - @NotNull @Single @Flags("type=anchor name") String anchorName) { + @Flags("type=anchor name") + @Single String anchorName) { player.sendMessage((this.plugin.getAnchorManager().saveAnchorLocation(anchorName, player.getLocation())) @@ -71,9 +73,11 @@ public class AnchorCommand extends MultiverseCoreCommand { @Description("Delete an existing anchor point.") public void onDeleteAnchorCommand(@NotNull CommandSender sender, + @NotNull @Syntax("") @Description("Name of anchor you want to delete.") - @NotNull @Single @Flags("type=anchor name") String anchorName) { + @Flags("type=anchor name") + @Single String anchorName) { sender.sendMessage((this.plugin.getAnchorManager().deleteAnchor(anchorName)) @@ -87,7 +91,7 @@ public class AnchorCommand extends MultiverseCoreCommand { @Subcommand("list") @CommandPermission("multiverse.core.anchor.list") @Syntax("[filter] [page]") - @Description("Delete an existing anchor point.") + @Description("View a list of current anchors.") public void onListAnchorCommand(@NotNull CommandSender sender, @NotNull PageFilter pageFilter) { diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/BedCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/BedCommand.java index 4d462bcb..16f4a1d8 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/BedCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/BedCommand.java @@ -8,12 +8,16 @@ package com.onarandombox.MultiverseCore.commands; 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.Subcommand; +import co.aikar.commands.annotation.Syntax; import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.commandtools.contexts.RequiredPlayer; import org.bukkit.ChatColor; import org.bukkit.Location; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -25,15 +29,35 @@ public class BedCommand extends MultiverseCoreCommand { } @Subcommand("bed") - @CommandPermission("multiverse.core.bed") + @CommandPermission("multiverse.core.bed.self") @Description("Takes your current respawn point.") public void onBedCommand(@NotNull Player player) { + doBedRespawn(player, player); + } + + @Subcommand("bed") + @CommandPermission("multiverse.core.bed.other") + @Syntax("[player]") + @CommandCompletion("@players") + @Description("Takes another player to their respawn location.") + public void onOtherBedCommand(@NotNull CommandSender sender, + + @Syntax("[player]") + @Description("Target player to teleport to respawn location.") + @NotNull RequiredPlayer player) { + + doBedRespawn(sender, player.get()); + } + + private void doBedRespawn(@NotNull CommandSender sender, + @NotNull Player player) { + Location bedLocation = player.getBedSpawnLocation(); if (bedLocation == null) { - player.sendMessage(String.format("%sYou do not have a respawn point set!", ChatColor.RED)); + sender.sendMessage(String.format("%sYou do not have a respawn point set!", ChatColor.RED)); return; } - player.sendMessage((player.teleport(bedLocation)) + sender.sendMessage((player.teleport(bedLocation)) ? "You have been teleported to your respawn point!" : String.format("%sThere was an error teleporting you to your respawn point.", ChatColor.RED)); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java index 6b18a059..61d2bf9c 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CheckCommand.java @@ -11,13 +11,12 @@ 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.MVDestination; +import com.onarandombox.MultiverseCore.commandtools.contexts.RequiredPlayer; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @CommandAlias("mv") @@ -29,19 +28,21 @@ public class CheckCommand extends MultiverseCoreCommand { @Subcommand("check") @CommandPermission("multiverse.core.debug") - @Syntax("[player] ") + @Syntax(" ") @CommandCompletion("@players @destinations|@MVWorlds") @Description("Checks to see if a player can go to a destination. Prints debug if false.") public void onCheckCommand(@NotNull CommandSender sender, - @Syntax("[player]") + @NotNull + @Syntax("") @Description("Player to check destination on.") - @NotNull @Flags("other,defaultself,fallbackself") Player player, + RequiredPlayer player, + @NotNull @Syntax("") - @Description("Location, can be a world name.") - @NotNull MVDestination destination) { + @Description("A destination location, e.g. a world name.") + MVDestination destination) { - this.plugin.getMVPerms().tellMeWhyICantDoThis(sender, player, destination); + this.plugin.getMVPerms().tellMeWhyICantDoThis(sender, player.get(), destination); } } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CloneCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CloneCommand.java index fbeb7ba7..01cd5c52 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CloneCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CloneCommand.java @@ -35,13 +35,15 @@ public class CloneCommand extends MultiverseCoreCommand { @Description("Clones a world.") public void onCloneCommand(@NotNull CommandSender sender, + @NotNull @Syntax("") @Description("Current multiverse world.") - @NotNull @Conditions("isWorldInConfig") String worldName, + @Conditions("isWorldInConfig") String worldName, + @NotNull @Syntax("") @Description("New cloned world name.") - @NotNull @Single @Flags("trim") @Conditions("creatableWorldName") String newWorldName) { + @Single @Flags("trim") @Conditions("creatableWorldName") String newWorldName) { sender.sendMessage((this.plugin.getMVWorldManager().cloneWorld(worldName, newWorldName)) ? String.format("%sWorld cloned!", ChatColor.GREEN) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java index 1536f536..277e7849 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ConfigCommand.java @@ -60,13 +60,15 @@ public class ConfigCommand extends MultiverseCoreCommand { @Description("Set Global MV Variables.") public void onSetCommand(@NotNull CommandSender sender, + @NotNull @Syntax("") @Description("Config option.") - @NotNull @Values("@MVConfigs") String property, + @Values("@MVConfigs") String property, + @NotNull @Syntax("") @Description("New value for the given config option.") - @NotNull @Single String value) { + @Single String value) { property = property.toLowerCase(); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CoordCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CoordCommand.java index 7eae0ed7..73d3c94f 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CoordCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CoordCommand.java @@ -7,17 +7,16 @@ package com.onarandombox.MultiverseCore.commands; +import co.aikar.commands.InvalidCommandArgument; 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.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.commandtools.contexts.PlayerWorld; +import com.onarandombox.MultiverseCore.commandtools.contexts.RequiredPlayer; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -31,26 +30,40 @@ public class CoordCommand extends MultiverseCoreCommand { } @Subcommand("coord|coordinate") - @CommandPermission("multiverse.core.coord.self,multiverse.core.coord.other") + @CommandPermission("multiverse.core.coord.self") + @Description("Detailed information on your own where abouts.") + public void onCoordCommand(@NotNull Player player) { + showCoordInfo(player, player); + } + + @Subcommand("coord|coordinate") + @CommandPermission("multiverse.core.coord.other") @Syntax("[player]") @CommandCompletion("@players") @Description("Detailed information on the player's where abouts.") - public void onCoorCommand(@NotNull CommandSender sender, + public void onOtherCoordCommand(@NotNull CommandSender sender, - @Syntax("[player]") - @Description("Player you want coordinate info of.") - @NotNull - @Flags("other,defaultself") - @Conditions("selfOtherPerm:multiverse.core.coord") PlayerWorld targetPlayer) { + @NotNull + @Syntax("[player]") + @Description("Player you want coordinate info of.") + RequiredPlayer player) { - Player player = targetPlayer.getPlayer(); - MultiverseWorld world = targetPlayer.getWorld(); + showCoordInfo(sender, player.get()); + } - sender.sendMessage(String.format("%s--- Location Information %s---", ChatColor.AQUA, - (targetPlayer.isSender(sender)) - ? "" - : String.format("for %s%s%s",ChatColor.YELLOW, player.getName(), ChatColor.AQUA))); + private void showCoordInfo(@NotNull CommandSender sender, + @NotNull Player player) { + MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(player.getWorld()); + if (world == null) { + throw new InvalidCommandArgument("Player is not in a multiverse world."); + } + + String name = player.equals(sender) + ? "" + : String.format("for %s%s%s",ChatColor.YELLOW, player.getName(), ChatColor.AQUA); + + sender.sendMessage(String.format("%s--- Location Information %s---", ChatColor.AQUA, name)); sender.sendMessage(String.format("%sWorld: %s%s", ChatColor.AQUA, ChatColor.WHITE, world.getName())); sender.sendMessage(String.format("%sAlias: %s%s", ChatColor.AQUA, ChatColor.WHITE, world.getColoredWorldString())); sender.sendMessage(String.format("%sWorld Scale: %s%s", ChatColor.AQUA, ChatColor.WHITE, world.getScaling())); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java index 649193ae..a35400ce 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/CreateCommand.java @@ -13,7 +13,6 @@ import co.aikar.commands.annotation.CommandPermission; import co.aikar.commands.annotation.Conditions; import co.aikar.commands.annotation.Description; import co.aikar.commands.annotation.Flags; -import co.aikar.commands.annotation.Optional; import co.aikar.commands.annotation.Subcommand; import co.aikar.commands.annotation.Syntax; import com.dumptruckman.minecraft.util.Logging; @@ -22,12 +21,13 @@ import com.onarandombox.MultiverseCore.commandtools.flags.FlagGroup; import com.onarandombox.MultiverseCore.commandtools.flags.FlagResult; import com.onarandombox.MultiverseCore.commandtools.flags.MVFlags; import org.bukkit.ChatColor; -import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import static org.bukkit.World.*; + @CommandAlias("mv") public class CreateCommand extends MultiverseCoreCommand { @@ -45,21 +45,25 @@ public class CreateCommand extends MultiverseCoreCommand { @Subcommand("create") @CommandPermission("multiverse.core.create") @Syntax(" -s [seed] -g [generator[:id]] -t [worldtype] [-n] -a [true|false]") - @CommandCompletion("@empty @environments @worldFlags:-s/-g/-t/-n/-a") + @CommandCompletion("@empty @environments @flags") @Description("Creates a new world and loads it.") public void onCreateCommand(@NotNull CommandSender sender, + @NotNull @Syntax("") @Description("New world name.") - @NotNull @Flags("trim") @Conditions("creatableWorldName") String worldName, + @Flags("trim") + @Conditions("creatableWorldName") String worldName, + @NotNull @Syntax("") @Description("The world's environment. See: /mv env") - @NotNull World.Environment environment, + Environment environment, + @Nullable @Syntax("[world-flags]") @Description("Other world settings. See: http://gg.gg/nn8bl") - @Nullable @Optional String[] flagsArray) { + String[] flagsArray) { FlagResult flags = FlagResult.parse(flagsArray, this.getFlagGroup()); Logging.info(String.valueOf(flags)); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java index 34fd9245..c6a2f81e 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/DebugCommand.java @@ -30,20 +30,23 @@ public class DebugCommand extends MultiverseCoreCommand { } @Subcommand("debug") + @CommandPermission("multiverse.core.debug") @Description("Show the current debug level.") public void onShowDebugCommand(@NotNull CommandSender sender) { displayDebugMode(sender); } @Subcommand("debug") - @CommandCompletion("@toggles|@range:3") + @CommandPermission("multiverse.core.debug") @Syntax("") + @CommandCompletion("@toggles|@range:3") @Description("Change debug level.") public void onChangeDebugCommand(@NotNull CommandSender sender, + @NotNull @Syntax("") @Description("Set debug mode level, 0 to 3.") - @NotNull @Single String debugLevel) { + @Single String debugLevel) { int parsedLevel = parseDebugLevel(debugLevel); if (parsedLevel == -1) { @@ -76,7 +79,7 @@ public class DebugCommand extends MultiverseCoreCommand { } private void displayDebugMode(@NotNull CommandSender sender) { - final int debugLevel = this.plugin.getMVConfig().getGlobalDebug(); + int debugLevel = this.plugin.getMVConfig().getGlobalDebug(); if (debugLevel == 0) { sender.sendMessage(String.format("Multiverse Debug mode is %soff", ChatColor.RED)); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/DeleteCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/DeleteCommand.java index b1d6c227..22208fdd 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/DeleteCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/DeleteCommand.java @@ -17,6 +17,7 @@ import co.aikar.commands.annotation.Single; import co.aikar.commands.annotation.Subcommand; import co.aikar.commands.annotation.Syntax; import com.onarandombox.MultiverseCore.MultiverseCore; +import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -35,17 +36,18 @@ public class DeleteCommand extends MultiverseCoreCommand { @Description("Deletes a world on your server PERMANENTLY.") public void onDeleteCommand(@NotNull CommandSender sender, + @NotNull @Syntax("") @Description("Multiverse world you want to delete.") - @NotNull - @Single @Flags("trim") - @Conditions("isWorldInConfig|validWorldFolder") String worldName) { + @Conditions("isWorldInConfig|validWorldFolder") + @Single String worldName) { - this.plugin.getMVCommandManager().getQueueManager().addToQueue( - sender, - deleteRunnable(sender, worldName), - String.format("Are you sure you want to delete world '%s'?", worldName) + this.plugin.getMVCommandManager().getQueueManager().addToQueue(new QueuedCommand.Builder() + .sender(sender) + .action(deleteRunnable(sender, worldName)) + .prompt("Are you sure you want to delete world '%s'?", worldName) + .build() ); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java index f24cd86c..e30c87d3 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/EnvironmentCommand.java @@ -24,7 +24,7 @@ public class EnvironmentCommand extends MultiverseCoreCommand { @Subcommand("env|environments") @CommandPermission("multiverse.core.list.environments") - @Description("Lists valid known environments/world types.") + @Description("Lists valid known environments and world types.") public void onEnvironmentCommand(CommandSender sender) { showEnvironments(sender); sender.sendMessage(""); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/GameRuleCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/GameRuleCommand.java index 93365266..5a27fe66 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/GameRuleCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/GameRuleCommand.java @@ -46,9 +46,10 @@ public class GameRuleCommand extends MultiverseCoreCommand { @Description("See the list gamerules values for a given world.") public void onGameRulesCommand(@NotNull CommandSender sender, + @NotNull @Syntax("[world]") @Description("World you want to see game rule info.") - @NotNull @Flags("other,defaultself, fallbackself") MultiverseWorld world, + @Flags("other,defaultself, fallbackself") MultiverseWorld world, @NotNull ContentFilter filter) { diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java index f753e4b1..a28ecc77 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ImportCommand.java @@ -12,7 +12,6 @@ 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; @@ -20,12 +19,13 @@ import com.onarandombox.MultiverseCore.commandtools.flags.FlagGroup; import com.onarandombox.MultiverseCore.commandtools.flags.FlagResult; import com.onarandombox.MultiverseCore.commandtools.flags.MVFlags; import org.bukkit.ChatColor; -import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import static org.bukkit.World.*; + @CommandAlias("mv") public class ImportCommand extends MultiverseCoreCommand { @@ -45,13 +45,15 @@ public class ImportCommand extends MultiverseCoreCommand { @Description("Folder name of the world.") @NotNull @co.aikar.commands.annotation.Flags("trim") @Conditions("importableWorldName") String worldName, + @NotNull @Syntax("") @Description("The world's environment. See: /mv env") - @NotNull World.Environment environment, + Environment environment, + @Nullable @Syntax("-g [generator[:id]] [-n]") @Description("Other world settings. See: http://gg.gg/nn8c2") - @Nullable @Optional String[] flagsArray) { + String[] flagsArray) { FlagResult flags = FlagResult.parse(flagsArray, this.getFlagGroup()); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java index de20d032..91eb9b7b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/InfoCommand.java @@ -40,12 +40,13 @@ public class InfoCommand extends MultiverseCoreCommand { @CommandPermission("multiverse.core.info") @Syntax("[world] [page]") @CommandCompletion("@MVWorlds @range:1-5") - @Description("") + @Description("Display detailed information of the world.") public void onInfoCommand(@NotNull CommandSender sender, + @NotNull @Syntax("[world]") @Description("World you want to see info.") - @NotNull @Flags("other,defaultself,fallbackself") MultiverseWorld world, + @Flags("other,defaultself,fallbackself") MultiverseWorld world, @Syntax("[page]") @Description("Info page to display.") diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java index 4ed9106b..a1908782 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ListCommand.java @@ -10,7 +10,6 @@ package com.onarandombox.MultiverseCore.commands; import co.aikar.commands.annotation.CommandAlias; import co.aikar.commands.annotation.CommandPermission; 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; @@ -23,7 +22,6 @@ import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -40,20 +38,22 @@ public class ListCommand extends MultiverseCoreCommand { @Syntax("[filter] [page]") @Description("Displays a listing of all worlds that you can enter.") public void onListCommand(@NotNull CommandSender sender, - @Nullable @Optional Player player, + @NotNull PageFilter pageFilter) { new PageDisplay().withSender(sender) .withHeader(String.format("%s====[ Multiverse World List ]====", ChatColor.GOLD)) - .withCreator(getListContents(sender, player)) + .withCreator(getListContents(sender)) .withPageFilter(pageFilter) .build() .runTaskAsynchronously(this.plugin); } - private ContentCreator> getListContents(@NotNull CommandSender sender, - @Nullable @Optional Player player) { + private ContentCreator> getListContents(@NotNull CommandSender sender) { return () -> { + Player player = (sender instanceof Player) + ? (Player) sender + : null; List worldList = new ArrayList<>(); plugin.getMVWorldManager().getMVWorlds().stream() .filter(world -> player == null || plugin.getMVPerms().canEnterWorld(player, world)) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/LoadCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/LoadCommand.java index f25d1162..2a40e24d 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/LoadCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/LoadCommand.java @@ -34,9 +34,11 @@ public class LoadCommand extends MultiverseCoreCommand { @Description("Loads a world. World must be already in worlds.yml, else please use /mv import.") public void onLoadCommand(@NotNull CommandSender sender, + @NotNull @Syntax("") @Description("Name of world you want to load.") - @NotNull @Flags("type=world name") @Conditions("isUnloadedWorld") String worldName) { + @Flags("type=world name") + @Conditions("isUnloadedWorld") String worldName) { if (!this.plugin.getMVWorldManager().loadWorld(worldName)) { sender.sendMessage(String.format("Error trying to load world '%s'!", worldName)); diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java index 7269b60e..e2aa1c73 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ModifyCommand.java @@ -47,17 +47,21 @@ public class ModifyCommand extends MultiverseCoreCommand { @Description("Modify various aspects of worlds by setting a property. For more info; https://tinyurl.com/nehhzp6") public void onModifySetCommand(@NotNull CommandSender sender, + @NotNull @Syntax("") @Description("Property option key.") - @NotNull @Flags("type=property") @Conditions("validAddProperty:set") String property, + @Flags("type=property") + @Conditions("validAddProperty:set") String property, + @NotNull @Syntax("") @Description("New property value.") - @NotNull @Flags("type=property value") String value, + @Flags("type=property value") String value, + @NotNull @Syntax("[world]") @Description("World that you want property change to apply.") - @NotNull @Flags("other,defaultself") MultiverseWorld world) { + @Flags("other,defaultself") MultiverseWorld world) { if ((property.equalsIgnoreCase("aliascolor") || property.equalsIgnoreCase("color")) @@ -92,17 +96,21 @@ public class ModifyCommand extends MultiverseCoreCommand { @Description("Modify various aspects of worlds by adding a property. For more info: https://tinyurl.com/nehhzp6") public void onModifyAddCommand(@NotNull CommandSender sender, + @NotNull @Syntax("") @Description("Property option key.") - @NotNull @Flags("type=property") @Conditions("validAddProperty:add") String property, + @Flags("type=property") + @Conditions("validAddProperty:add") String property, + @NotNull @Syntax("") @Description("Property value to add.") - @NotNull @Flags("type=property value") String value, + @Flags("type=property value") String value, + @NotNull @Syntax("[world]") @Description("World that you want property change to apply.") - @NotNull @Flags("other,defaultself") MultiverseWorld world) { + @Flags("other,defaultself") MultiverseWorld world) { if (!world.addToVariable(property, value)) { sender.sendMessage(String.format("%s %scould not be added to %s%s%s.", @@ -123,17 +131,21 @@ public class ModifyCommand extends MultiverseCoreCommand { @Description("Modify various aspects of worlds by removing a property. For more info: https://tinyurl.com/nehhzp6") public void onModifyRemoveCommand(@NotNull CommandSender sender, + @NotNull @Syntax("") @Description("Property option key.") - @NotNull @Flags("type=property") @Conditions("validAddProperty:remove") String property, + @Flags("type=property") + @Conditions("validAddProperty:remove") String property, + @NotNull @Syntax("") @Description("Property value to remove.") - @NotNull @Flags("type=property value") String value, + @Flags("type=property value") String value, + @NotNull @Syntax("[world]") @Description("World that you want property change to apply.") - @NotNull @Flags("other,defaultself") MultiverseWorld world) { + @Flags("other,defaultself") MultiverseWorld world) { if (!world.removeFromVariable(property, value)) { sender.sendMessage(String.format("%sThere was an error removing %s%s%s from %s%s%s!", @@ -154,13 +166,15 @@ public class ModifyCommand extends MultiverseCoreCommand { @Description("Modify various aspects of worlds by clearing a property. For more info: https://tinyurl.com/nehhzp6") public void onModifyClearCommand(@NotNull CommandSender sender, + @NotNull @Syntax("") @Description("Property option key.") - @NotNull @Flags("type=property") @Conditions("validAddProperty:clear") String property, + @Flags("type=property") @Conditions("validAddProperty:clear") String property, + @NotNull @Syntax("[world]") @Description("World that you want property be cleared.") - @NotNull @Flags("other,defaultself") MultiverseWorld world) { + @Flags("other,defaultself") MultiverseWorld world) { if (!world.clearList(property)) { sender.sendMessage(String.format("%sThere was an error clearing %s%s%s.", @@ -178,11 +192,12 @@ public class ModifyCommand extends MultiverseCoreCommand { @Syntax("[world] [filter]") @CommandCompletion("@MVWorlds") @Description("Show properties available to set.") - public void onModifyClearCommand(@NotNull CommandSender sender, + public void onModifyListCommand(@NotNull CommandSender sender, + @NotNull @Syntax("[world]") @Description("World that you want to see current property values set.") - @NotNull @Flags("other,defaultself,fallbackself") MultiverseWorld world, + @Flags("other,defaultself,fallbackself") MultiverseWorld world, @NotNull ContentFilter filter) { diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/PurgeCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/PurgeCommand.java index b3183620..571edf0a 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/PurgeCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/PurgeCommand.java @@ -40,9 +40,10 @@ public class PurgeCommand extends MultiverseCoreCommand { @Description("Removed the specified type of mob from all worlds.") public void onPurgeAllCommand(@NotNull CommandSender sender, + @NotNull @Syntax("") @Description("Entity types that you want to remove from all worlds.") - @NotNull @Split(",") String[] targetEntities) { + @Split(",") String[] targetEntities) { doPurge(sender, this.plugin.getMVWorldManager().getMVWorlds(), targetEntities); } @@ -54,13 +55,15 @@ public class PurgeCommand extends MultiverseCoreCommand { @Description("Removed the specified type of mob from the specified world.") public void onPurgeCommand(@NotNull CommandSender sender, + @NotNull @Syntax("[world]") @Description("World that you want to remove entities.") - @NotNull @Flags("other,defaultself,fallbackself") MultiverseWorld world, + @Flags("other,defaultself,fallbackself") MultiverseWorld world, + @NotNull @Syntax("") @Description("Entity types that you want to remove from a world.") - @NotNull @Split(",") String[] targetEntities) { + @Split(",") String[] targetEntities) { doPurge(sender, Collections.singleton(world), targetEntities); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/RegenCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/RegenCommand.java index f0cda7c6..83cc79fd 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/RegenCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/RegenCommand.java @@ -11,7 +11,7 @@ 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.Optional; +import co.aikar.commands.annotation.Flags; import co.aikar.commands.annotation.Subcommand; import co.aikar.commands.annotation.Syntax; import com.onarandombox.MultiverseCore.MultiverseCore; @@ -19,6 +19,7 @@ import com.onarandombox.MultiverseCore.api.MultiverseWorld; import com.onarandombox.MultiverseCore.commandtools.flags.FlagGroup; import com.onarandombox.MultiverseCore.commandtools.flags.FlagResult; import com.onarandombox.MultiverseCore.commandtools.flags.MVFlags; +import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -39,20 +40,23 @@ public class RegenCommand extends MultiverseCoreCommand { @Description("Regenerates a world on your server. The previous state will be lost PERMANENTLY.") public void onRegenCommand(@NotNull CommandSender sender, + @NotNull @Syntax("") @Description("World that you want to regen.") - @NotNull @co.aikar.commands.annotation.Flags("other") MultiverseWorld world, + @Flags("other") MultiverseWorld world, + @Nullable @Syntax("[-s [seed]]") @Description("Other world settings. See: http://gg.gg/nn8lk") - @Nullable @Optional String[] flagsArray) { + String[] flagsArray) { FlagResult flags = FlagResult.parse(flagsArray, this.getFlagGroup()); - this.plugin.getMVCommandManager().getQueueManager().addToQueue( - sender, - regenRunnable(sender, world, flags), - String.format("Are you sure you want to regen world '%s'?", world.getColoredWorldString()) + this.plugin.getMVCommandManager().getQueueManager().addToQueue(new QueuedCommand.Builder() + .sender(sender) + .action(regenRunnable(sender, world, flags)) + .prompt("Are you sure you want to regen world '%s'?", world.getColoredWorldString()) + .build() ); } diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/RemoveCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/RemoveCommand.java index 9b2f10ca..1019930b 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/RemoveCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/RemoveCommand.java @@ -29,18 +29,18 @@ public class RemoveCommand extends MultiverseCoreCommand { } @Subcommand("remove") - @CommandPermission("multiverse.core.spawn.other") + @CommandPermission("multiverse.core.remove") @CommandCompletion("@MVWorlds|@unloadedWorlds") @Syntax("") @Description("Unloads a world from Multiverse and removes it from worlds.yml, this does NOT DELETE the world folder.") public void onRemoveCommand(@NotNull CommandSender sender, + @NotNull @Syntax("") @Description("World you want to remove from mv's knowledge.") - @NotNull - @Single @Flags("type=world name") - @Conditions("isWorldInConfig") String worldName) { + @Conditions("isWorldInConfig") + @Single String worldName) { sender.sendMessage((this.plugin.getMVWorldManager().removeWorldFromConfig(worldName)) ? String.format("World '%s' is removed from config!", worldName) diff --git a/src/main/java/com/onarandombox/MultiverseCore/commands/ScriptCommand.java b/src/main/java/com/onarandombox/MultiverseCore/commands/ScriptCommand.java index 36fdabdb..bf672f65 100644 --- a/src/main/java/com/onarandombox/MultiverseCore/commands/ScriptCommand.java +++ b/src/main/java/com/onarandombox/MultiverseCore/commands/ScriptCommand.java @@ -13,13 +13,12 @@ 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.commandtools.contexts.RequiredPlayer; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -33,18 +32,20 @@ public class ScriptCommand extends MultiverseCoreCommand { @Subcommand("script") @CommandPermission("multiverse.core.script") - @Syntax("