Package dev.jorel.commandapi
Class CommandAPI
java.lang.Object
dev.jorel.commandapi.CommandAPI
Class to register commands with the 1.13 command UI
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanDetermines whether command registration is permitted via the CommandAPIfailWithMessage(com.mojang.brigadier.Message message) Forces a command to return a success value of 0failWithString(String message) Forces a command to return a success value of 0static InternalConfigReturns the internal configuration used to manage the CommandAPIstatic CommandAPILoggerstatic List<RegisteredCommand>static booleanisLoaded()Returns whether the CommandAPI is currently loaded.static voidLogs an error from the CommandAPI.static voidLogs a message to the console using Logger.info() if the configuration has verbose logging enabledstatic voidLogs a message from the CommandAPI.static voidlogWarning(String message) Logs a warning from the CommandAPI.static voidUnloads the CommandAPI.static voidonEnable()Enables the CommandAPI.static voidonLoad(CommandAPIConfig<?> config) Initializes the CommandAPI for loading.static voidregisterCommand(Class<?> commandClass) Registers a command.static voidReloads all the datapacks that are on the server.static voidsetLogger(CommandAPILogger logger) static voidFlag that commands should no longer be registered.static voidunregister(String command) Unregisters a commandstatic voidunregister(String command, boolean force) Unregisters a command, by force (removes all instances of that command)static <CommandSender,Player extends CommandSender>
voidupdateRequirements(Player player) Updates the requirements required for a given player to execute a command.
-
Method Details
-
isLoaded
public static boolean isLoaded()Returns whether the CommandAPI is currently loaded. This should be true whenonLoad(CommandAPIConfig)is called. If the CommandAPI is loaded, commands are available to register.- Returns:
- whether the CommandAPI has been loaded properly
-
stopCommandRegistration
public static void stopCommandRegistration()Flag that commands should no longer be registered. After running this,canRegister()will return false. -
canRegister
public static boolean canRegister()Determines whether command registration is permitted via the CommandAPI- Returns:
- true if commands can still be registered
-
getConfiguration
Returns the internal configuration used to manage the CommandAPI- Returns:
- the internal configuration used to manage the CommandAPI
-
setLogger
-
getLogger
- Returns:
- the CommandAPI's logger
-
onLoad
Initializes the CommandAPI for loading. This should be placed at the start of youronLoad()method.- Parameters:
config- the configuration to use for the CommandAPI. This should be aCommandAPIConfigsubclass corresponding to the active platform.
-
onEnable
public static void onEnable()Enables the CommandAPI. This should be placed at the start of youronEnable()method. -
onDisable
public static void onDisable()Unloads the CommandAPI. -
logInfo
Logs a message to the console using Logger.info() if the configuration has verbose logging enabled- Parameters:
message- the message to log to the console
-
logNormal
Logs a message from the CommandAPI. If silent logs are enabled, this message is not logged.- Parameters:
message- the message to log
-
logWarning
Logs a warning from the CommandAPI. If silent logs are enabled, this warning is not logged.- Parameters:
message- the message to log as a warning
-
logError
Logs an error from the CommandAPI. This always gets logged, even if silent logs are enabled.- Parameters:
message- the message to log as an error
-
reloadDatapacks
public static void reloadDatapacks()Reloads all the datapacks that are on the server. This should be used if you change a datapack and want to reload a server. Execute this method after running /minecraft:reload, NOT before. -
updateRequirements
public static <CommandSender,Player extends CommandSender> void updateRequirements(Player player) Updates the requirements required for a given player to execute a command.- Parameters:
player- the player whose requirements should be updated
-
failWithString
Forces a command to return a success value of 0- Parameters:
message- Description of the error message- Returns:
- a
WrapperCommandSyntaxExceptionthat wraps Brigadier'sCommandSyntaxException
-
failWithMessage
Forces a command to return a success value of 0- Parameters:
message- Description of the error message, formatted as a brigadier message- Returns:
- a
WrapperCommandSyntaxExceptionthat wraps Brigadier'sCommandSyntaxException
-
unregister
Unregisters a command- Parameters:
command- the name of the command to unregister
-
unregister
Unregisters a command, by force (removes all instances of that command)- Parameters:
command- the name of the command to unregisterforce- if true, attempt to unregister all instances of the command across all plugins as well as minecraft, bukkit and spigot
-
registerCommand
Registers a command. Used with the CommandAPI's Annotation API.- Parameters:
commandClass- the class to register
-
getRegisteredCommands
- Returns:
- A list of all
RegisteredCommandsthat have been registered by the CommandAPI so far. The returned list is immutable.
-