Improve docs around Brigadier on bukkit/paper

This commit is contained in:
Jason Penilla 2023-04-02 12:53:06 -07:00 committed by Jason
parent c8f07033e6
commit 5bd2b90d02
5 changed files with 35 additions and 7 deletions

View file

@ -331,7 +331,10 @@ public class BukkitCommandManager<C> extends CommandManager<C> implements Brigad
}
/**
* Attempt to register the Brigadier mapper, and return it.
* Attempts to enable Brigadier command registration through Commodore.
*
* <p>Callers should check for {@link CloudBukkitCapabilities#COMMODORE_BRIGADIER} first
* to avoid exceptions.</p>
*
* @throws BrigadierFailureException If Brigadier isn't
* supported by the platform

View file

@ -34,16 +34,36 @@ import org.checkerframework.checker.nullness.qual.NonNull;
* Capabilities for the Bukkit module
*/
public enum CloudBukkitCapabilities implements CloudCapability {
/**
* Whether Brigadier is present in the current environment. Certain parser types require this, and are able to work
* even if a capability for Brigadier command registration is not present (as long as this capability is present).
*/
BRIGADIER(CraftBukkitReflection.classExists("com.mojang.brigadier.tree.CommandNode")
&& CraftBukkitReflection.findOBCClass("command.BukkitCommandWrapper") != null),
/**
* Whether support for native Brigadier command registration is available
* through the Paper API ({@code PaperCommandManager#registerBrigadier} from {@code cloud-paper}).
*/
NATIVE_BRIGADIER(CraftBukkitReflection.classExists(
"com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent")),
/**
* Whether support for Brigadier command registration is available through Commodore
* ({@link BukkitCommandManager#registerBrigadier}).
*
* <p><b>Note:</b> As of 1.19.2, Commodore simply delegates to the same Paper API as cloud is capable of using directly,
* doing nothing on non-Paper Bukkit implementations. As such, this capability will not be present in 1.19.2+ environments.
* Users should prefer using {@code PaperCommandManager} from {@code cloud-paper} and checking for
* {@link #NATIVE_BRIGADIER}.</p>
*/
COMMODORE_BRIGADIER(BRIGADIER.capable()
&& !NATIVE_BRIGADIER.capable()
&& !CraftBukkitReflection.classExists("org.bukkit.entity.Warden")),
/**
* Whether asynchronous command completions are supported through the Paper API.
*/
ASYNCHRONOUS_COMPLETION(CraftBukkitReflection.classExists(
"com.destroystokyo.paper.event.server.AsyncTabCompleteEvent"));

View file

@ -113,7 +113,16 @@ public class PaperCommandManager<C> extends BukkitCommandManager<C> {
}
/**
* Register Brigadier mappings using the native paper events
* Attempts to enable Brigadier command registration through the Paper API, falling
* back to {@link BukkitCommandManager#registerBrigadier()} if that fails.
*
* <p>Callers should check for {@link CloudBukkitCapabilities#NATIVE_BRIGADIER} first
* to avoid exceptions.</p>
*
* <p>A check for {@link CloudBukkitCapabilities#NATIVE_BRIGADIER} {@code ||} {@link CloudBukkitCapabilities#COMMODORE_BRIGADIER}
* may also be appropriate for some use cases (because of the fallback behavior), but not most, as Commodore does not offer
* any functionality on modern
* versions (see the documentation for {@link CloudBukkitCapabilities#COMMODORE_BRIGADIER}).</p>
*
* @throws BrigadierFailureException Exception thrown if the mappings cannot be registered
*/