Generate improvements througout.

This commit is contained in:
benwoo1110 2021-03-05 12:15:34 +08:00
parent 2fc6f3dc26
commit 55cf19b1d8
48 changed files with 392 additions and 343 deletions

View File

@ -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.

View File

@ -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;

View File

@ -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.

View File

@ -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();

View File

@ -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;
}
}

View File

@ -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<CommandSender, QueuedCommand> 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;
}
}

View File

@ -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;
}
}
}

View File

@ -50,9 +50,11 @@ public class AnchorCommand extends MultiverseCoreCommand {
@Description("Create a new anchor point.")
public void onCreateAnchorCommand(@NotNull Player player,
@NotNull
@Syntax("<name>")
@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("<name>")
@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) {

View File

@ -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));
}

View File

@ -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] <destination>")
@Syntax("<player> <destination>")
@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("<player>")
@Description("Player to check destination on.")
@NotNull @Flags("other,defaultself,fallbackself") Player player,
RequiredPlayer player,
@NotNull
@Syntax("<destination>")
@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);
}
}

View File

@ -35,13 +35,15 @@ public class CloneCommand extends MultiverseCoreCommand {
@Description("Clones a world.")
public void onCloneCommand(@NotNull CommandSender sender,
@NotNull
@Syntax("<world>")
@Description("Current multiverse world.")
@NotNull @Conditions("isWorldInConfig") String worldName,
@Conditions("isWorldInConfig") String worldName,
@NotNull
@Syntax("<name>")
@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)

View File

@ -60,13 +60,15 @@ public class ConfigCommand extends MultiverseCoreCommand {
@Description("Set Global MV Variables.")
public void onSetCommand(@NotNull CommandSender sender,
@NotNull
@Syntax("<property>")
@Description("Config option.")
@NotNull @Values("@MVConfigs") String property,
@Values("@MVConfigs") String property,
@NotNull
@Syntax("<value>")
@Description("New value for the given config option.")
@NotNull @Single String value) {
@Single String value) {
property = property.toLowerCase();

View File

@ -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,
@NotNull
@Syntax("[player]")
@Description("Player you want coordinate info of.")
@NotNull
@Flags("other,defaultself")
@Conditions("selfOtherPerm:multiverse.core.coord") PlayerWorld targetPlayer) {
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))
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)));
: 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()));

View File

@ -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("<name> <env> -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("<name>")
@Description("New world name.")
@NotNull @Flags("trim") @Conditions("creatableWorldName") String worldName,
@Flags("trim")
@Conditions("creatableWorldName") String worldName,
@NotNull
@Syntax("<env>")
@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));

View File

@ -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("<level>")
@CommandCompletion("@toggles|@range:3")
@Description("Change debug level.")
public void onChangeDebugCommand(@NotNull CommandSender sender,
@NotNull
@Syntax("<level>")
@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));
}

View File

@ -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("<world>")
@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()
);
}

View File

@ -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("");

View File

@ -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) {

View File

@ -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("<env>")
@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());

View File

@ -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.")

View File

@ -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<List<String>> getListContents(@NotNull CommandSender sender,
@Nullable @Optional Player player) {
private ContentCreator<List<String>> getListContents(@NotNull CommandSender sender) {
return () -> {
Player player = (sender instanceof Player)
? (Player) sender
: null;
List<String> worldList = new ArrayList<>();
plugin.getMVWorldManager().getMVWorlds().stream()
.filter(world -> player == null || plugin.getMVPerms().canEnterWorld(player, world))

View File

@ -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("<world>")
@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));

View File

@ -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("<property>")
@Description("Property option key.")
@NotNull @Flags("type=property") @Conditions("validAddProperty:set") String property,
@Flags("type=property")
@Conditions("validAddProperty:set") String property,
@NotNull
@Syntax("<value>")
@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("<property>")
@Description("Property option key.")
@NotNull @Flags("type=property") @Conditions("validAddProperty:add") String property,
@Flags("type=property")
@Conditions("validAddProperty:add") String property,
@NotNull
@Syntax("<value>")
@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("<property>")
@Description("Property option key.")
@NotNull @Flags("type=property") @Conditions("validAddProperty:remove") String property,
@Flags("type=property")
@Conditions("validAddProperty:remove") String property,
@NotNull
@Syntax("<value>")
@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("<property>")
@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) {

View File

@ -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("<entities>")
@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("<entities>")
@Description("Entity types that you want to remove from a world.")
@NotNull @Split(",") String[] targetEntities) {
@Split(",") String[] targetEntities) {
doPurge(sender, Collections.singleton(world), targetEntities);
}

View File

@ -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("<world>")
@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()
);
}

View File

@ -29,18 +29,18 @@ public class RemoveCommand extends MultiverseCoreCommand {
}
@Subcommand("remove")
@CommandPermission("multiverse.core.spawn.other")
@CommandPermission("multiverse.core.remove")
@CommandCompletion("@MVWorlds|@unloadedWorlds")
@Syntax("<world>")
@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("<world>")
@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)

View File

@ -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("<script> [player]")
@Syntax("<script> <player>")
@CommandCompletion("@scripts @players")
@Description("Runs a script.")
public void onScriptCommand(@NotNull CommandSender sender,
@NotNull
@Syntax("<script>")
@Description("Script name that you want to run.")
@NotNull String targetScript,
String targetScript,
@Syntax("[player]")
@NotNull
@Syntax("<player>")
@Description("Player that you want to execute the script on.")
@NotNull @Flags("other,defaultself") Player player) {
RequiredPlayer player) {
Buscript scriptAPI = this.plugin.getScriptAPI();
if (scriptAPI == null) {
@ -56,7 +57,7 @@ public class ScriptCommand extends MultiverseCoreCommand {
throw new InvalidCommandArgument("That script file does not exist in the Multiverse-Core scripts directory!");
}
scriptAPI.executeScript(file, targetScript, player);
scriptAPI.executeScript(file, targetScript, player.get());
sender.sendMessage(String.format("Script '%s%s%s' finished!", ChatColor.GOLD, file.getName(), ChatColor.WHITE));
}
}

View File

@ -45,9 +45,11 @@ public class SetSpawnCommand extends MultiverseCoreCommand {
public void onSetSpawnCommand(@NotNull CommandSender sender,
@Nullable @Optional Player player,
@NotNull
@Syntax("[world x y z [yaw pitch]]")
@Description("New location of spawn.")
@NotNull @Flags("other,defaultself") MultiverseWorld world,
@Flags("other,defaultself") MultiverseWorld world,
@Nullable @Optional Double x,
@Nullable @Optional Double y,
@Nullable @Optional Double z,
@ -65,9 +67,11 @@ public class SetSpawnCommand extends MultiverseCoreCommand {
public void onModifySetSpawnCommand(@NotNull CommandSender sender,
@Nullable @Optional Player player,
@NotNull
@Syntax("[world x y z [yaw pitch]]")
@Description("New location of spawn.")
@NotNull @Flags("other,defaultself") MultiverseWorld world,
@Flags("other,defaultself") MultiverseWorld world,
@Nullable @Optional Double x,
@Nullable @Optional Double y,
@Nullable @Optional Double z,
@ -89,15 +93,16 @@ public class SetSpawnCommand extends MultiverseCoreCommand {
public void onAliasSetSpawnCommand(@NotNull CommandSender sender,
@Nullable @Optional Player player,
@NotNull
@Syntax("[world x y z [yaw pitch]]")
@Description("New location of spawn.")
@NotNull @Flags("other,defaultself") MultiverseWorld world,
@Flags("other,defaultself") MultiverseWorld world,
@Nullable @Optional Double x,
@Nullable @Optional Double y,
@Nullable @Optional Double z,
@Nullable @Optional Float yaw,
@Nullable @Optional Float pitch) {
doSpawnSet(sender, world, parseLocation(player, world, x, y, z, yaw, pitch));
}
}

View File

@ -7,73 +7,58 @@
package com.onarandombox.MultiverseCore.commands;
import co.aikar.commands.BaseCommand;
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.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
@CommandAlias("mv")
public class SpawnCommand extends MultiverseCoreCommand {
public SpawnCommand(MultiverseCore plugin) {
super(plugin);
}
@CommandAlias("mv")
public class Spawn extends BaseCommand {
@Subcommand("spawn")
@CommandPermission("multiverse.core.spawn.self,multiverse.core.spawn.other")
@CommandPermission("multiverse.core.spawn.self")
@Description("Teleport yourself to the spawn of the world.")
public void onSpawnCommand(@NotNull Player player) {
doSpawn(player, player);
}
@CommandAlias("spawn")
@CommandPermission("multiverse.core.spawn.other")
@Syntax("[player]")
@CommandCompletion("@players")
@Description("Teleport another player to the spawn of the world they are in.")
public void onSpawnCommand(@NotNull CommandSender sender,
@NotNull
@Syntax("[player]")
@Description("Target player to teleport to spawn.")
@NotNull
@Flags("other|defaultself")
@Conditions("selfOtherPerm:multiverse.core.spawn") PlayerWorld targetPlayer) {
RequiredPlayer player) {
doSpawn(sender, targetPlayer.getPlayer(), targetPlayer.getWorld());
}
}
public class AliasSpawn extends BaseCommand {
@CommandAlias("mvspawn")
@CommandPermission("multiverse.core.spawn.self,multiverse.core.spawn.other")
@Syntax("[player]")
@CommandCompletion("@players")
@Description("Teleport another player to the spawn of the world they are in.")
public void onSpawnCommand(@NotNull CommandSender sender,
@Syntax("[player]")
@Description("Target player to teleport to spawn.")
@NotNull
@Flags("other|defaultself")
@Conditions("selfOtherPerm:multiverse.core.spawn") PlayerWorld targetPlayer) {
doSpawn(sender, targetPlayer.getPlayer(), targetPlayer.getWorld());
}
doSpawn(sender, player.get());
}
private void doSpawn(@NotNull CommandSender sender,
@NotNull Player player,
@NotNull MultiverseWorld world) {
@NotNull Player player) {
this.plugin.getSafeTTeleporter().safelyTeleport(player, player, world.getSpawnLocation(), false);
MultiverseWorld world = this.plugin.getMVWorldManager().getMVWorld(player.getWorld());
Location spawnLocation = (world == null) ? player.getWorld().getSpawnLocation() : world.getSpawnLocation();
this.plugin.getSafeTTeleporter().safelyTeleport(player, player, spawnLocation, false);
if (sender.equals(player)) {
player.sendMessage("Teleported to this world's spawn.");
@ -81,9 +66,9 @@ public class SpawnCommand extends MultiverseCoreCommand {
}
String senderName = (sender instanceof ConsoleCommandSender)
? String.format("%sconsole", ChatColor.LIGHT_PURPLE)
: String.format("%s%s", ChatColor.YELLOW, sender.getName());
? String.format("%sconsole%s", ChatColor.LIGHT_PURPLE, ChatColor.RESET)
: String.format("%s%s%s", ChatColor.YELLOW, sender.getName(), ChatColor.RESET);
player.sendMessage("You were teleported by " + senderName);
player.sendMessage("You were teleported by " + senderName + "to spawn.");
}
}

View File

@ -19,6 +19,7 @@ import com.onarandombox.MultiverseCore.MultiverseCore;
import com.onarandombox.MultiverseCore.api.MVDestination;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.api.Teleporter;
import com.onarandombox.MultiverseCore.commandtools.queue.QueuedCommand;
import com.onarandombox.MultiverseCore.destination.CustomTeleporterDestination;
import com.onarandombox.MultiverseCore.destination.InvalidDestination;
import com.onarandombox.MultiverseCore.destination.WorldDestination;
@ -155,12 +156,16 @@ public class TeleportCommand extends MultiverseCoreCommand {
TeleportResult result = teleportObject.teleport(teleporter, teleportee, destination);
if (result == TeleportResult.FAIL_UNSAFE) {
Logging.fine("Could not teleport " + teleportee.getName() + " to " + this.plugin.getLocationManipulation().strCoordsRaw(destination.getLocation(teleportee)));
this.plugin.getMVCommandManager().getQueueManager().addToQueue(
teleporter,
unsafeTeleportRunnable(teleporter, teleportee, destination.getLocation(teleportee)),
"The location you are trying to teleport to is deemed unsafe, do you still want to try?",
UNSAFE_TELEPORT_EXPIRE_DELAY);
Logging.fine("Could not teleport %s to %s.",
teleportee.getName(), this.plugin.getLocationManipulation().strCoordsRaw(destination.getLocation(teleportee)));
this.plugin.getMVCommandManager().getQueueManager().addToQueue(new QueuedCommand.Builder()
.sender(teleporter)
.action(unsafeTeleportRunnable(teleporter, teleportee, destination.getLocation(teleportee)))
.prompt("The location you are trying to teleport to is deemed unsafe, do you still want to try?")
.validDuration(UNSAFE_TELEPORT_EXPIRE_DELAY)
.build()
);
}
// else: Player was teleported successfully (or the tp event was fired I should say)
@ -211,8 +216,6 @@ public class TeleportCommand extends MultiverseCoreCommand {
@NotNull Player teleportee,
@NotNull Location location) {
return () -> {
this.plugin.getSafeTTeleporter().safelyTeleport(teleporter, teleportee, location, false);
};
return () -> this.plugin.getSafeTTeleporter().safelyTeleport(teleporter, teleportee, location, false);
}
}

View File

@ -34,9 +34,10 @@ public class UnloadCommand extends MultiverseCoreCommand {
@Description("Unloads a world from Multiverse. This does NOT remove the world folder. This does NOT remove it from the config file.")
public void onUnloadCommand(@NotNull CommandSender sender,
@NotNull
@Syntax("<world>")
@Description("Name of world you want to unload.")
@NotNull @Flags("other") MultiverseWorld world) {
@Flags("other") MultiverseWorld world) {
//TODO API: Should be able to use MVWorld object directly
if (!this.plugin.getMVWorldManager().unloadWorld(world.getName())) {

View File

@ -16,7 +16,6 @@ import co.aikar.commands.annotation.HelpCommand;
import co.aikar.commands.annotation.Subcommand;
import co.aikar.commands.annotation.Syntax;
import com.onarandombox.MultiverseCore.MultiverseCore;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
@CommandAlias("mv")
@ -32,9 +31,7 @@ public class UsageCommand extends MultiverseCoreCommand {
@Syntax("[filter] [page]")
@CommandCompletion("@subCommands:mv")
@Description("Show Multiverse-Core Command usage.")
public void onUsageCommand(@NotNull CommandSender sender,
@NotNull CommandHelp help) {
public void onUsageCommand(@NotNull CommandHelp help) {
this.plugin.getMVCommandManager().showUsage(help);
}
}

View File

@ -11,7 +11,6 @@ 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.Subcommand;
import co.aikar.commands.annotation.Syntax;
import com.onarandombox.MultiverseCore.MultiverseCore;
@ -50,13 +49,15 @@ public class VersionCommand extends MultiverseCoreCommand {
@Description("Dumps version info to the console, optionally to pastal service.")
public void onVersionCommand(@NotNull CommandSender sender,
@NotNull
@Syntax("[paste-service]")
@Description("Website to upload your version info to.")
@NotNull PasteServiceType pasteType,
PasteServiceType pasteType,
@Nullable
@Syntax("[--include-plugin-list]")
@Description("Whether you want to have plugins list in version info.")
@Nullable @Optional String includePlugin) {
String includePlugin) {
MVVersionEvent versionEvent = new MVVersionEvent();
this.addVersionInfoToEvent(versionEvent);

View File

@ -44,9 +44,10 @@ public class WhoCommand extends MultiverseCoreCommand {
public void onWhoAllCommand(@NotNull CommandSender sender,
@Nullable @Optional Player player,
@NotNull
@Syntax("[filter]")
@Description("Filter the player names.")
@NotNull ContentFilter filter) {
ContentFilter filter) {
Set<Player> visiblePlayers = getVisiblePlayers(player);
@ -84,15 +85,16 @@ public class WhoCommand extends MultiverseCoreCommand {
public void onWhoCommand(@NotNull CommandSender sender,
@Nullable @Optional Player player,
@NotNull
@Syntax("[world]")
@Description("World to show player list.")
@NotNull
@Flags("other,defaultself,fallbackself")
@Conditions("hasWorldAccess") MultiverseWorld world,
@NotNull
@Syntax("[filter]")
@Description("Filter the player names.")
@NotNull ContentFilter filter) {
ContentFilter filter) {
Set<Player> visiblePlayers = getVisiblePlayers(player);

View File

@ -7,8 +7,6 @@
package com.onarandombox.MultiverseCore.listeners;
import java.util.logging.Level;
import com.dumptruckman.minecraft.util.Logging;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.AsyncPlayerChatEvent;

View File

@ -22,8 +22,6 @@ import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import java.util.logging.Level;
/**
* Multiverse's Entity {@link Listener}.
*/

View File

@ -7,8 +7,6 @@
package com.onarandombox.MultiverseCore.listeners;
import java.util.logging.Level;
import com.dumptruckman.minecraft.util.Logging;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerChatEvent;

View File

@ -9,7 +9,6 @@ package com.onarandombox.MultiverseCore.listeners;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.MultiverseCore;

View File

@ -19,8 +19,6 @@ import org.bukkit.event.entity.EntityCreatePortalEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.world.PortalCreateEvent;
import java.util.logging.Level;
/**
* A custom listener for portal related events.
*/

View File

@ -22,7 +22,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
/**
* Manages anchors.

View File

@ -1,7 +1,5 @@
package com.onarandombox.MultiverseCore.utils;
import java.util.logging.Level;
import com.dumptruckman.minecraft.util.Logging;
import com.onarandombox.MultiverseCore.api.SafeTTeleporter;
import com.onarandombox.MultiverseCore.destination.CannonDestination;

View File

@ -16,11 +16,8 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream;
import com.dumptruckman.minecraft.util.Logging;

View File

@ -16,8 +16,6 @@ import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permission;
import java.util.logging.Level;
/**
* Utility-class for permissions.
*/

View File

@ -23,7 +23,6 @@ import org.bukkit.entity.Squid;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
/**
* Utility class that removes animals from worlds that don't belong there.

View File

@ -15,7 +15,6 @@ import org.bukkit.entity.Vehicle;
import org.bukkit.util.Vector;
import com.onarandombox.MultiverseCore.api.LocationManipulation;
import org.jetbrains.annotations.NotNull;
import java.text.DecimalFormat;
import java.util.Collections;

View File

@ -25,8 +25,6 @@ import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;
import org.bukkit.util.Vector;
import java.util.logging.Level;
/**
* The default-implementation of {@link SafeTTeleporter}.
*/

View File

@ -52,8 +52,6 @@ import org.powermock.modules.junit4.PowerMockRunner;
import java.io.File;
import static org.junit.Assert.*;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.*;
@RunWith(PowerMockRunner.class)

View File

@ -10,7 +10,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.dumptruckman.minecraft.util.Logging;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;