mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2025-02-16 20:41:59 +01:00
Add docs and minor cleanup.
This commit is contained in:
parent
04802f2fda
commit
808c4ce704
@ -35,6 +35,9 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Generate tab-complete suggestion.
|
||||
*/
|
||||
public class MVCommandCompletions extends PaperCommandCompletions {
|
||||
|
||||
private final MultiverseCore plugin;
|
||||
|
@ -24,6 +24,9 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Args input validation.
|
||||
*/
|
||||
public class MVCommandConditions {
|
||||
|
||||
private final MultiverseCore plugin;
|
||||
|
@ -37,6 +37,9 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Parse args into objects.
|
||||
*/
|
||||
public class MVCommandContexts extends PaperCommandContexts {
|
||||
|
||||
private final MultiverseCore plugin;
|
||||
@ -55,7 +58,6 @@ public class MVCommandContexts extends PaperCommandContexts {
|
||||
registerContext(World.Environment.class, this::deriveEnvironment);
|
||||
registerIssuerAwareContext(GameRuleProperty.class, this::deriveGameRuleProperty);
|
||||
registerIssuerAwareContext(MVDestination.class, this::deriveMVDestination);
|
||||
registerIssuerAwareContext(Location.class, this::deriveLocation);
|
||||
registerIssuerAwareContext(PasteServiceType.class, this::derivePasteServiceType);
|
||||
registerOptionalContext(String.class, this::deriveString);
|
||||
registerIssuerAwareContext(ContentFilter.class, this::deriveContentFilter);
|
||||
@ -185,11 +187,19 @@ public class MVCommandContexts extends PaperCommandContexts {
|
||||
private Player getPlayerFromSelf(@NotNull BukkitCommandExecutionContext context, String errorReason) {
|
||||
Player self = context.getPlayer();
|
||||
if (self == null && !context.isOptional()) {
|
||||
throw new InvalidCommandArgument(errorReason, false);
|
||||
throw new InvalidCommandArgument(errorReason);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Player from string.
|
||||
* Supports player name, UUID and selectors.
|
||||
*
|
||||
* @param sender Sender use to parse vanilla selectors.
|
||||
* @param playerIdentifier Text to parse into a Player object.
|
||||
* @return A Player object if found, null otherwise.
|
||||
*/
|
||||
@Nullable
|
||||
public Player getPlayerFromValue(@NotNull CommandSender sender,
|
||||
@Nullable String playerIdentifier) {
|
||||
@ -352,55 +362,6 @@ public class MVCommandContexts extends PaperCommandContexts {
|
||||
return worldName.replaceAll("^[./\\\\]+", "");
|
||||
}
|
||||
|
||||
private Location deriveLocation(BukkitCommandExecutionContext context) {
|
||||
if (context.getArgs().isEmpty()) {
|
||||
Player player = context.getPlayer();
|
||||
if (player != null) {
|
||||
return player.getLocation();
|
||||
}
|
||||
throw new InvalidCommandArgument("You need to specify world and coordinates from the console!");
|
||||
}
|
||||
|
||||
MultiverseWorld world;
|
||||
try {
|
||||
world = deriveMultiverseWorld(context);
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
e.printStackTrace();
|
||||
throw new InvalidCommandArgument("There was an error getting Target location world!");
|
||||
}
|
||||
|
||||
List<String> locationArgs = context.getArgs();
|
||||
if (locationArgs.size() != 3 && locationArgs.size() != 5) {
|
||||
context.getSender().sendMessage(ChatColor.RED + "Invalid location arguments.");
|
||||
context.getSender().sendMessage("Use no arguments for your current location, or world/x/y/z, or world/x/y/z/yaw/pitch!");
|
||||
throw new InvalidCommandArgument(true);
|
||||
}
|
||||
|
||||
double x = parsePos(locationArgs.get(0), "x");
|
||||
double y = parsePos(locationArgs.get(1), "y");
|
||||
double z = parsePos(locationArgs.get(2), "z");
|
||||
|
||||
double yaw = 0.0;
|
||||
double pitch = 0.0;
|
||||
|
||||
if (locationArgs.size() == 5) {
|
||||
yaw = parsePos(locationArgs.get(3), "yaw");
|
||||
pitch = parsePos(locationArgs.get(4), "pitch");
|
||||
}
|
||||
|
||||
return new Location(world.getCBWorld(), x, y, z, (float) yaw, (float) pitch);
|
||||
}
|
||||
|
||||
private double parsePos(String value, String posType) {
|
||||
try {
|
||||
return Double.parseDouble(value);
|
||||
}
|
||||
catch (NumberFormatException e) {
|
||||
throw new InvalidCommandArgument("'" + value + "' for "+ posType + " coordinate is not a number.", false);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private PasteServiceType derivePasteServiceType(BukkitCommandExecutionContext context) {
|
||||
String pasteType = context.popFirstArg();
|
||||
|
@ -52,6 +52,7 @@ import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -60,6 +61,9 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Heart of Multiverse Command Handler.
|
||||
*/
|
||||
public class MVCommandManager extends PaperCommandManager {
|
||||
|
||||
private final MultiverseCore plugin;
|
||||
@ -68,7 +72,7 @@ public class MVCommandManager extends PaperCommandManager {
|
||||
|
||||
private static final Pattern PERMISSION_SPLIT = Pattern.compile(",");
|
||||
|
||||
public MVCommandManager(MultiverseCore plugin) {
|
||||
public MVCommandManager(@NotNull MultiverseCore plugin) {
|
||||
super(plugin);
|
||||
this.plugin = plugin;
|
||||
this.commandQueueManager = new CommandQueueManager(plugin);
|
||||
@ -116,12 +120,28 @@ public class MVCommandManager extends PaperCommandManager {
|
||||
addAvailableSubModule("mvinv", new SubModulesCommand.Inventories());
|
||||
}
|
||||
|
||||
private void addAvailableSubModule(String moduleName, BaseCommand cmd) {
|
||||
/**
|
||||
* Use for download link suggestion for sub-module
|
||||
*
|
||||
* @param moduleName A sub-module for Multiverse.
|
||||
* @param cmd Command to register.
|
||||
*/
|
||||
private void addAvailableSubModule(@NotNull String moduleName,
|
||||
@NotNull BaseCommand cmd) {
|
||||
|
||||
subModuleRootCommands.put(moduleName, cmd);
|
||||
registerCommand(cmd);
|
||||
}
|
||||
|
||||
public void registerSubModule(String moduleName, BaseCommand cmd) {
|
||||
/**
|
||||
* Replace suggest download with actual command from sub-module.
|
||||
*
|
||||
* @param moduleName A sub-module for Multiverse.
|
||||
* @param cmd Command to register.
|
||||
*/
|
||||
public void registerSubModule(@NotNull String moduleName,
|
||||
@NotNull BaseCommand cmd) {
|
||||
|
||||
unregisterCommand(subModuleRootCommands.remove(moduleName));
|
||||
registerCommand(cmd);
|
||||
}
|
||||
@ -146,7 +166,9 @@ public class MVCommandManager extends PaperCommandManager {
|
||||
* Change default implementation to be able to choose from OR / AND
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPermission(CommandIssuer issuer, Set<String> permissions) {
|
||||
public boolean hasPermission(@NotNull CommandIssuer issuer,
|
||||
@Nullable Set<String> permissions) {
|
||||
|
||||
if (permissions == null || permissions.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
@ -156,40 +178,56 @@ public class MVCommandManager extends PaperCommandManager {
|
||||
: orPermissionCheck(issuer, permissions);
|
||||
}
|
||||
|
||||
private boolean orPermissionCheck(CommandIssuer issuer, Set<String> permissions) {
|
||||
private boolean orPermissionCheck(@NotNull CommandIssuer issuer,
|
||||
@NotNull Set<String> permissions) {
|
||||
|
||||
return permissions.stream()
|
||||
.unordered()
|
||||
.anyMatch(permission -> hasPermission(issuer, permission));
|
||||
}
|
||||
|
||||
private boolean andPermissionCheck(CommandIssuer issuer, Set<String> permissions) {
|
||||
private boolean andPermissionCheck(@NotNull CommandIssuer issuer,
|
||||
@NotNull Set<String> permissions) {
|
||||
|
||||
return permissions.stream()
|
||||
.unordered()
|
||||
.allMatch(permission -> hasPermission(issuer, permission));
|
||||
}
|
||||
|
||||
/**
|
||||
* Change default implementation to OR instead of AND
|
||||
* Change default implementation to be able to choose from OR / AND
|
||||
*/
|
||||
@Override
|
||||
public boolean hasPermission(CommandIssuer issuer, String permission) {
|
||||
public boolean hasPermission(@NotNull CommandIssuer issuer,
|
||||
@Nullable String permission) {
|
||||
|
||||
if (permission == null || permission.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (permission.startsWith("AND:")) {
|
||||
return Arrays.stream(PERMISSION_SPLIT.split(permission.substring(4)))
|
||||
.unordered()
|
||||
.allMatch(issuer::hasPermission);
|
||||
}
|
||||
|
||||
return Arrays.stream(PERMISSION_SPLIT.split(permission))
|
||||
.unordered()
|
||||
.anyMatch(issuer::hasPermission);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets {@link CommandQueueManager}.
|
||||
*
|
||||
* @return {@link CommandQueueManager}.
|
||||
*/
|
||||
public CommandQueueManager getQueueManager() {
|
||||
return commandQueueManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Standardise usage command formatting for all mv modules.
|
||||
*
|
||||
* @param help The target {@link CommandHelp}.
|
||||
*/
|
||||
public void showUsage(@NotNull CommandHelp help) {
|
||||
List<HelpEntry> entries = help.getHelpEntries();
|
||||
|
||||
@ -201,6 +239,14 @@ public class MVCommandManager extends PaperCommandManager {
|
||||
help.showHelp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Standardise root command for all mv modules.
|
||||
*
|
||||
* @param sender Sender to send the info to.
|
||||
* @param description mv-module's description and info.
|
||||
* @param colour Special colour for each mv-module.
|
||||
* @param baseCommand mv-module's root command name.
|
||||
*/
|
||||
public void showPluginInfo(@NotNull CommandSender sender,
|
||||
@NotNull PluginDescriptionFile description,
|
||||
@NotNull ColourAlternator colour,
|
||||
|
Loading…
Reference in New Issue
Block a user