-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
704 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
header = "Welcome" | ||
pages = [ | ||
{ | ||
header = "Introduction" | ||
link = "introduction" | ||
default = true | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<center><h1>Introduction</h1></center> | ||
<center><p>Minecraft command framework.</p></center> | ||
|
||
--- | ||
|
||
<center><img src="https://i.imgur.com/RsYXETD.png" alt="header"/></center> | ||
|
||
<center><h1>Triumph CMDs</h1></center> | ||
<center> | ||
<p> | ||
<img src="https://img.shields.io/github/license/TriumphTeam/triumph-cmds?color=blue&style=flat-square" alt="license"/> | ||
<img src="https://img.shields.io/github/v/release/TriumphTeam/triumph-cmds?color=green&style=flat-square" alt="release"> | ||
<a href="https://mattstudios.me/discord"><img src="https://img.shields.io/discord/493380790718038028?label=discord&style=flat-square" alt="discord"/></a> | ||
</p> | ||
</center> | ||
|
||
--- | ||
|
||
!!!! | ||
Attention! This version is still a SNAPSHOT and many things can change. | ||
!!! | ||
|
||
# Features | ||
|
||
# Contributing | ||
|
||
Contributions, issues, and feature requests are welcome! | ||
Feel free to check [issues page](https://github.com/TriumphTeam/triumph-cmds/issues). | ||
|
||
# Show your support | ||
|
||
Give a star on [GitHub](https://github.com/TriumphTeam/triumph-cmds) if this project helped you! | ||
|
||
# License | ||
|
||
Copyright © 2024 [TriumphTeam](https://github.com/TriumphTeam). | ||
This project is [MIT](https://github.com/TriumphTeam/triumph-cmds/blob/master/LICENSE) licensed. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<center><h1>Command Manager</h1></center> | ||
<center><p>The basic entry for everything related to your commands.</p></center> | ||
|
||
--- | ||
|
||
# Creating a command manager | ||
Each platform has its own command manager and each manager has its own sender type. | ||
```java | ||
// Bukkit | ||
BukkitCommandManager<CommandSender> manager = BukkitCommandManager.create(plugin); | ||
|
||
// JDA Prefixed | ||
PrefixedCommandManager<PrefixedSender> manager = PrefixedCommandManager.create(jda); | ||
|
||
// JDA slash | ||
SlashCommandManager<SlashSender> manager = SlashCommandManager.create(jda); | ||
``` | ||
The type parameter for the sender is necessary because you can also specify your own sender type by passing a custom `SenderMapper`. You can read more about it [here](custom-senders). | ||
|
||
# Usage | ||
The command manager is used for doing everything for the commands, registering commands, messages, arguments, etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<center><h1>Commands</h1></center> | ||
<center><p>The basic structure of a command, and its sub commands.</p></center> | ||
|
||
--- | ||
|
||
# Creating a simple command | ||
Every command must extend `BaseCommand`. | ||
You can use the `@Command` annotation to declare the command name and alias. | ||
```java | ||
@Command("foo") | ||
class MyCommand extends BaseCommand {} | ||
``` | ||
A command can also have aliases. | ||
```java | ||
@Command(value = "foo", alias = {"bar", "baz"}) | ||
class MyCommand extends BaseCommand {} | ||
``` | ||
Alternatively you can also declare the command name and alias through the `BaseCommand`'s constructor. | ||
```java | ||
class MyCommand extends BaseCommand { | ||
|
||
public MyCommand() { | ||
super("foo", Arrays.asList("bar", "baz")); | ||
} | ||
} | ||
``` | ||
!!!! | ||
The usage of the keyword `Sender` in the following examples are **not** the correct name, it just represents a sender. | ||
As the real sender name can change based on platform or the provided custom sender. | ||
!!! | ||
|
||
# Sub commands | ||
Each sub commands are declared by methods, currently there is no other way to declare its name and alias other than through annotations. | ||
|
||
## Default | ||
A `@Default` method is a "sub command without a name", implying it is the main executor of a command that has no sub commands. | ||
For example the command `/foo` would be declared in the following way: | ||
```java | ||
@Command("foo") | ||
class MyCommand extends BaseCommand { | ||
|
||
@Default | ||
public void executor(Sender sender) { | ||
// Code to be executed | ||
} | ||
} | ||
``` | ||
|
||
## SubCommand | ||
A `@SubCommand` is a sub command that has a specific name. For example `/foo bar` | ||
```java | ||
@Command("foo") | ||
class MyCommand extends BaseCommand { | ||
|
||
@SubCommand("bar") | ||
public void executor(Sender sender) { | ||
// Code to be executed | ||
} | ||
} | ||
``` | ||
|
||
## Alias | ||
Both annotations also support an alias to be passed: | ||
`@Default(alias = {"bar"})` would be executed as either `/foo` or `/foo bar`. | ||
`@SubCommand(value = "bar", alias = {"baz"})` would be executed as either `/foo bar` or `/foo baz`. | ||
|
||
# Registering | ||
Registering the command is very simple, you simply do: | ||
```java | ||
commandManager.registerCommand(new MyCommand()); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<center><h1>Custom Senders</h1></center> | ||
<center><p>Custom senders creation and registration.</p></center> | ||
|
||
--- | ||
|
||
# Creating a simple sender | ||
```java | ||
public class MySender {} | ||
``` | ||
|
||
# Creating a SenderValidator | ||
Sender Validators are used for pre-command checks. | ||
```java | ||
public class MySenderValidator implements SenderValidator<MySender> { | ||
|
||
// This method is used when registering, it'll check if the sender declared in the command method is valid or not | ||
@Override | ||
public @NotNull Set<Class<? extends MySender>> getAllowedSenders() { | ||
return Collections.singleton(MySender.class); | ||
} | ||
|
||
@Override | ||
public boolean validate(final @NotNull MessageRegistry<MySender> messageRegistry, final @NotNull SubCommand<MySender> subCommand, final @NotNull MySender sender) { | ||
// Do any checks you want here, for example, on Bukkit this is where it checks if the subcommand is console only, or player only, etc. | ||
// Return true if valid, false, if not, use the message registry to send messages to the player if you want | ||
return false; | ||
} | ||
} | ||
``` | ||
Now you can either make a custom SenderMapper or just use lambda. | ||
If you're not using lambda, then make sure you specify the correct senders. If you're using lambda it will be a little easier. | ||
```java | ||
class MyMapper implements SenderMapper<CommandSender, MySender> | ||
``` | ||
Now time to create the command manager. We will be using the BukkitCommandManager for this example. | ||
```java | ||
final BukkitCommandManager<MySender> manager = BukkitCommandManager.create( | ||
plugin, | ||
defaultSender -> new MySender(), // The mapping of the sender, pass a new instance if you don't want lambda | ||
new MySenderValidator() // Validator | ||
); | ||
``` | ||
That is all! You can now register a new command with your custom sender. | ||
```java | ||
@Command("foo") | ||
class MyCommand extends BaseCommand { | ||
|
||
@Default | ||
public void executor(MySender sender) { | ||
// Code to be executed | ||
} | ||
} | ||
``` | ||
You can learn how to create and register commands [here](commands). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
header = "Getting Started" | ||
pages = [ | ||
{ | ||
header = "Setup" | ||
link = "setup" | ||
} | ||
{ | ||
header = "Command Manager" | ||
link = "command-manager" | ||
} | ||
{ | ||
header = "Commands" | ||
link = "commands" | ||
} | ||
{ | ||
header = "Custom Senders" | ||
link = "custom-senders" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<center><h1>Setup</h1></center> | ||
<center><p>This is how you add the lib to your project.</p></center> | ||
|
||
--- | ||
|
||
# Version | ||
|
||
Make sure to replace `{version}` with the version you want to use. | ||
|
||
# Platform | ||
|
||
Make sure to replace `{platform}` with one of the following: | ||
|
||
* `bukkit` - For any Bukkit based plugin, Spigot, Paper, etc. | ||
* `jda-prefixed` - For prefixed commands for JDA, for example `!test`. | ||
* `jda-slash` - For JDA slash commands. | ||
|
||
-+- | ||
+Gradle (Kotlin)+ | ||
You need to add the dependency to your `build.gradle.kts`. | ||
|
||
```kotlin | ||
repositories { | ||
maven("https://repo.triumphteam.dev/snapshots/") | ||
} | ||
|
||
dependencies { | ||
implementation("dev.triumphteam:triumph-cmd-{platform}:{version}") // Replace version here | ||
} | ||
``` | ||
|
||
In order to include the lib in your project, you need to add `shadow` plugin `build.gradle.kts`. | ||
Replace `[YOUR PACKAGE]` with your plugin's package, for example `me.myplugin.plugin`. | ||
|
||
```kotlin | ||
// This goes on the top of the build script. | ||
plugins { | ||
id("io.github.goooler.shadow") version "8.1.8" | ||
} | ||
|
||
// This can go anywhere. | ||
shadowJar { | ||
relocate("dev.triumphteam.cmd", "[YOUR PACKAGE].cmd") | ||
} | ||
``` | ||
|
||
+++ | ||
+Gradle (Groovy)+ | ||
You need to add the dependency to your `build.gradle`. | ||
|
||
```groovy | ||
repositories { | ||
maven { url = "https://repo.triumphteam.dev/snapshots/" } | ||
} | ||
dependencies { | ||
implementation "dev.triumphteam:triumph-cmd-{platform}:{version}" // Replace version here | ||
} | ||
``` | ||
|
||
To include the lib in your project, you need to add `shadow` plugin `build.gradle`. | ||
Replace `[YOUR PACKAGE]` with your plugin's package, for example `me.myplugin.plugin`. | ||
|
||
```groovy | ||
// This goes on the top of the build script. | ||
plugins { | ||
id "io.github.goooler.shadow" version "8.1.8" | ||
} | ||
// This can go anywhere. | ||
shadowJar { | ||
relocate("dev.triumphteam.cmd", "[YOUR PACKAGE].cmd") | ||
} | ||
``` | ||
|
||
+++ | ||
+Maven+ | ||
You need to add the dependency to your `pom.xml`. | ||
|
||
```xml | ||
<repositories> | ||
<repository> | ||
<id>repo</id> | ||
<url>https://repo.triumphteam.dev/snapshots/</url> | ||
</repository> | ||
</repositories> | ||
|
||
<dependency> | ||
<groupId>dev.triumphteam</groupId> | ||
<artifactId>triumph-cmd-{platform}</artifactId> | ||
<version>{version}</version> <!-- replace version here --> | ||
</dependency> | ||
``` | ||
|
||
To include the framework in your project, you need the shade plugin. | ||
Replace `[YOUR PACKAGE]` with your plugin's package, for example `me.myplugin.plugin`. | ||
|
||
```xml | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.6.0</version> | ||
<configuration> | ||
<relocations> | ||
<relocation> | ||
<pattern>dev.triumphteam.cmd</pattern> | ||
<shadedPattern>[YOUR PACKAGE].cmd</shadedPattern> <!-- Replace package here --> | ||
</relocation> | ||
</relocations> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
``` | ||
+++ | ||
-+- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<center><h1>Arguments</h1></center> | ||
<center><p>Command argument declaration and options.</p></center> | ||
|
||
--- | ||
|
||
# Concept | ||
The concept of arguments in the library are based on parameters, each parameter declared in the method will be a command argument. | ||
|
||
# Sender | ||
The first parameter of the command method **must** always be a sender. You can read more about the sender [here](custom-senders). | ||
|
||
# Creating a command with arguments | ||
Let's create the following command `/give item diamond 5`. Where `give` is the command, `item` is the sub command, `diamond` is an argument of type `Material` and `5` is the amount or an `int`. | ||
```java | ||
@Command("give") | ||
class MyClass extends BaseCommand { | ||
|
||
@SubCommand("item") | ||
public void execute(Sender sender, Material material, int amount) { | ||
sender.sendMessage("The selected material was: " + material); // Will send "DIAMOND" | ||
sender.sendMessage("The amount was: " + amount); // Will send "5" | ||
} | ||
} | ||
``` | ||
It is as simple as that to have arguments for your command. | ||
|
||
## Argument Names | ||
By default, argument names will be defined as the name of the parameter. | ||
|
||
The `@ArgName` annotation is used to define the name of the argument should you not want the name of the argument | ||
to be the same as the name of the parameter. If you would like to use the parameter name as the | ||
argument name, you can use the `-parameters` compiler flag when compiling your plugin. | ||
```java | ||
@SubCommand("id") | ||
public void execute(Sender sender, @ArgName("username") Player target) { | ||
sender.sendMessage(target.getName() + " has the id: " + target.getUniqueId()); | ||
} | ||
``` | ||
In this case, the argument will be called `username` instead of the parameter name, `target`. |
Oops, something went wrong.