Introduction
Imperat is a powerful command dispatching framework, it allows you to create
commands and converts them into the form of multiple data-condensed objects like Command
, CommandUsage
and CommandParameter
These objects are registered/injected into the class Imperat
which handles all information about each command and then dispatches/executes the command requested.
Initiazling your Imperat
Frequently asked question: What's a command dispatcher/Imperat ??
Answer: It's the Ultimate class handling all data needed when processing and registering
commands objects (Command
).
You have to create new instance of the imperat.
on the start of your platform by calling YourPlatformImperat#create
(the method is static) to create
and initialize a new instance of Imperat
type.
Creation of an instance of your PlatformImperat
depends mainly on which platform
you are using. For more details, Check out Supported-Platforms
Customizing Imperat
If you wanted to register a Context Resolver or a Parameter Type , or even set a Suggestion Resolver for tab-completion in commands, You would have to call some methods using your platform's dispatcher instance/ For a complete detailed guide on this, please check out Dispatcher API
It must be done BEFORE registering any command.
If you ever wanted to create your own implementation of Imperat
interface,
you will not receive any support and your issue will be instantly ignored/discarded
Creation of Commands
There's mainly 2 ways of creating commands
Classic
The main original (OG) way of creating a command is by using our built-in Command.create(commandName)
method for creation
It returns a built-in builder for the command
Here's a quick example :
var command = Command.<YourPlatformSource>createCommand("example").usage(...).othermethods(...)
By using the builder from Command#createCommand
, you should use the methods in it to build and establish your command.
For more details about what type of Source
you should use, please check out Supported platforms
You may modify the command
object however you would like by checking out Classic Command API which explains every possible way to modify any command object you create.
Quick example:
command.usage(
CommandUsage.<YourPlatformSource>builder()
.parameters(
CommandParameter.requiredInt("firstArg")
)
.execute((source, context) -> {
Integer firstArg = context.getArgument("firstArg");
source.reply("Entered required number= " + firstArg);
});
);
Annotated Commands
Creating commands with annotations is easy with 2 steps only:
- Create a class that will represent your command class
- Add unique annotations to it that allows the dispatcher to identify it as a command class
Quick example (Same results as the one above, but with annotations):
@Command("example")
public final class ExampleCommand {
@Usage
public void defaultUsage(YourPlatformSource source) {
source.reply("This is just an example with no arguments entered");
}
@Usage
public void exampleOneArg(
YourPlatformSource source,
@Named("firstArg") int firstArg
) {
source.reply("Entered required number= " + firstArg);
}
}
Register your commands
Finally after constructing and modifying your command
object, it's now easy
to register it by calling the method Imperat#registerCommand(command)
Note: the method is called from the Imperat
instance that you should have created
Here's a quick example below if you're using the Command.create
built-in way:
myCommandDispatcher.registerCommand(command);
Another example below with Annotations Command API :
myCommandDispatcher.registerCommand(new ExampleCommand())
Tutorials
Check out all the Imperat tutorials here!
📄️ Dispatcher API
The platform-dependant api managing and controling commands and sources
🗃️ Command API
2 items
📄️ Throwable Handlers
~
📄️ Parameter Type
It's an interface that aims to define how the raw argument entered by the command-source/sender
📄️ Context Resolver
Unlike the Value Resolver, the context resolver resolves a value that is NOT DIRECTLY from the input, however the value is created from the context by a certain logic you specify.
📄️ Suggestion Resolver
Imperat has it's own AutoCompleter algorithm that works pretty good.
📄️ Command Help
A command help is an object that is responsible for showing all the help usages of a command you make, it's easy to customize how will your help-menu will be displayed.
📄️ Processors
We have already talked about the life cycle of Context object during the command's execution
📄️ Source Resolver
In Imperat, SourceResolver is an interface designed to handle the resolution of platform-specific command sources (S) into custom types (R). This allows for the flexibility of customizing the command source based on the platform, enabling developers to transform platform-specific command senders into their own command source representations.
📄️ Platforms
Imperat is a generic command dispatching framework, It can work almost on every platform possible if implemented properly.