feat(core): support root command deletion & standardize capabilities (#369)
This commit is contained in:
parent
08a97b2c4f
commit
28ff5d3003
14 changed files with 416 additions and 16 deletions
|
|
@ -23,6 +23,7 @@
|
|||
//
|
||||
package cloud.commandframework.bukkit;
|
||||
|
||||
import cloud.commandframework.CloudCapability;
|
||||
import cloud.commandframework.CommandManager;
|
||||
import cloud.commandframework.CommandTree;
|
||||
import cloud.commandframework.brigadier.BrigadierManagerHolder;
|
||||
|
|
@ -55,6 +56,7 @@ import java.lang.reflect.Method;
|
|||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
import org.apiguardian.api.API;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
|
@ -126,6 +128,9 @@ public class BukkitCommandManager<C> extends CommandManager<C> implements Brigad
|
|||
final BukkitSynchronizer bukkitSynchronizer = new BukkitSynchronizer(owningPlugin);
|
||||
this.taskFactory = new TaskFactory(bukkitSynchronizer);
|
||||
|
||||
/* Register capabilities */
|
||||
CloudBukkitCapabilities.CAPABLE.forEach(this::registerCapability);
|
||||
|
||||
/* Register Bukkit Preprocessor */
|
||||
this.registerCommandPreProcessor(new BukkitCommandPreprocessor<>(this));
|
||||
|
||||
|
|
@ -157,7 +162,7 @@ public class BukkitCommandManager<C> extends CommandManager<C> implements Brigad
|
|||
new MultiplePlayerSelectorArgument.MultiplePlayerSelectorParser<>());
|
||||
|
||||
/* Register MC 1.13+ parsers */
|
||||
if (this.queryCapability(CloudBukkitCapabilities.BRIGADIER)) {
|
||||
if (this.hasCapability(CloudBukkitCapabilities.BRIGADIER)) {
|
||||
this.registerParserSupplierFor(ItemStackPredicateArgument.class);
|
||||
this.registerParserSupplierFor(BlockPredicateArgument.class);
|
||||
}
|
||||
|
|
@ -256,7 +261,7 @@ public class BukkitCommandManager<C> extends CommandManager<C> implements Brigad
|
|||
* will contain the reason for this.
|
||||
*/
|
||||
protected final void checkBrigadierCompatibility() throws BrigadierFailureException {
|
||||
if (!this.queryCapability(CloudBukkitCapabilities.BRIGADIER)) {
|
||||
if (!this.hasCapability(CloudBukkitCapabilities.BRIGADIER)) {
|
||||
throw new BrigadierFailureException(
|
||||
BrigadierFailureReason.VERSION_TOO_LOW,
|
||||
new IllegalArgumentException(
|
||||
|
|
@ -271,7 +276,10 @@ public class BukkitCommandManager<C> extends CommandManager<C> implements Brigad
|
|||
*
|
||||
* @param capability Capability
|
||||
* @return {@code true} if the manager has the given capability, else {@code false}
|
||||
* @deprecated for removal since 1.7.0. Use the new standard {@link #hasCapability(CloudCapability)} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@API(status = API.Status.DEPRECATED, since = "1.7.0")
|
||||
public final boolean queryCapability(final @NonNull CloudBukkitCapabilities capability) {
|
||||
return capability.capable();
|
||||
}
|
||||
|
|
@ -371,7 +379,7 @@ public class BukkitCommandManager<C> extends CommandManager<C> implements Brigad
|
|||
}
|
||||
|
||||
final void lockIfBrigadierCapable() {
|
||||
if (this.queryCapability(CloudBukkitCapabilities.BRIGADIER)) {
|
||||
if (this.hasCapability(CloudBukkitCapabilities.BRIGADIER)) {
|
||||
this.lockRegistration();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import cloud.commandframework.brigadier.argument.WrappedBrigadierParser;
|
|||
import cloud.commandframework.bukkit.internal.BukkitBackwardsBrigadierSenderMapper;
|
||||
import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext;
|
||||
import cloud.commandframework.execution.preprocessor.CommandPreprocessor;
|
||||
import java.util.Set;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
|
|
@ -40,7 +39,6 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||
final class BukkitCommandPreprocessor<C> implements CommandPreprocessor<C> {
|
||||
|
||||
private final BukkitCommandManager<C> commandManager;
|
||||
private final Set<CloudBukkitCapabilities> bukkitCapabilities;
|
||||
private final @Nullable BukkitBackwardsBrigadierSenderMapper<C, ?> mapper;
|
||||
|
||||
/**
|
||||
|
|
@ -50,8 +48,8 @@ final class BukkitCommandPreprocessor<C> implements CommandPreprocessor<C> {
|
|||
*/
|
||||
BukkitCommandPreprocessor(final @NonNull BukkitCommandManager<C> commandManager) {
|
||||
this.commandManager = commandManager;
|
||||
this.bukkitCapabilities = commandManager.queryCapabilities();
|
||||
if (this.bukkitCapabilities.contains(CloudBukkitCapabilities.BRIGADIER)) {
|
||||
|
||||
if (this.commandManager.hasCapability(CloudBukkitCapabilities.BRIGADIER)) {
|
||||
this.mapper = new BukkitBackwardsBrigadierSenderMapper<>(this.commandManager);
|
||||
} else {
|
||||
this.mapper = null;
|
||||
|
|
@ -76,7 +74,7 @@ final class BukkitCommandPreprocessor<C> implements CommandPreprocessor<C> {
|
|||
);
|
||||
context.getCommandContext().store(
|
||||
BukkitCommandContextKeys.CLOUD_BUKKIT_CAPABILITIES,
|
||||
this.bukkitCapabilities
|
||||
this.commandManager.queryCapabilities()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,15 +23,17 @@
|
|||
//
|
||||
package cloud.commandframework.bukkit;
|
||||
|
||||
import cloud.commandframework.CloudCapability;
|
||||
import cloud.commandframework.bukkit.internal.CraftBukkitReflection;
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* Capabilities for the Bukkit module
|
||||
*/
|
||||
public enum CloudBukkitCapabilities {
|
||||
public enum CloudBukkitCapabilities implements CloudCapability {
|
||||
BRIGADIER(CraftBukkitReflection.classExists("com.mojang.brigadier.tree.CommandNode")
|
||||
&& CraftBukkitReflection.findOBCClass("command.BukkitCommandWrapper") != null),
|
||||
|
||||
|
|
@ -56,4 +58,9 @@ public enum CloudBukkitCapabilities {
|
|||
boolean capable() {
|
||||
return this.capable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String toString() {
|
||||
return name();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
//
|
||||
package cloud.commandframework.paper;
|
||||
|
||||
import cloud.commandframework.CloudCapability;
|
||||
import cloud.commandframework.CommandTree;
|
||||
import cloud.commandframework.brigadier.CloudBrigadierManager;
|
||||
import cloud.commandframework.bukkit.BukkitCommandManager;
|
||||
|
|
@ -120,7 +121,7 @@ public class PaperCommandManager<C> extends BukkitCommandManager<C> {
|
|||
public void registerBrigadier() throws BrigadierFailureException {
|
||||
this.requireState(RegistrationState.BEFORE_REGISTRATION);
|
||||
this.checkBrigadierCompatibility();
|
||||
if (!this.queryCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) {
|
||||
if (!this.hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) {
|
||||
super.registerBrigadier();
|
||||
} else {
|
||||
try {
|
||||
|
|
@ -153,11 +154,11 @@ public class PaperCommandManager<C> extends BukkitCommandManager<C> {
|
|||
* is up to the caller to guarantee that such is the case
|
||||
*
|
||||
* @throws IllegalStateException when the server does not support asynchronous completions.
|
||||
* @see #queryCapability(CloudBukkitCapabilities) Check if the capability is present
|
||||
* @see #hasCapability(CloudCapability) Check if the capability is present
|
||||
*/
|
||||
public void registerAsynchronousCompletions() throws IllegalStateException {
|
||||
this.requireState(RegistrationState.BEFORE_REGISTRATION);
|
||||
if (!this.queryCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) {
|
||||
if (!this.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) {
|
||||
throw new IllegalStateException("Failed to register asynchronous command completion listener.");
|
||||
}
|
||||
Bukkit.getServer().getPluginManager().registerEvents(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue