Skip to content

Commit 77b21ed

Browse files
committed
move all old docs to new format
1 parent d1b3cbc commit 77b21ed

28 files changed

+704
-31
lines changed

Diff for: triumph-cmds/2.x.x-S/0-welcome/group.conf

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
header = "Welcome"
2+
pages = [
3+
{
4+
header = "Introduction"
5+
link = "introduction"
6+
default = true
7+
}
8+
]

Diff for: triumph-cmds/2.x.x-S/0-welcome/introduction.md

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<center><h1>Introduction</h1></center>
2+
<center><p>Minecraft command framework.</p></center>
3+
4+
---
5+
6+
<center><img src="https://i.imgur.com/RsYXETD.png" alt="header"/></center>
7+
8+
<center><h1>Triumph CMDs</h1></center>
9+
<center>
10+
<p>
11+
<img src="https://img.shields.io/github/license/TriumphTeam/triumph-cmds?color=blue&style=flat-square" alt="license"/>
12+
<img src="https://img.shields.io/github/v/release/TriumphTeam/triumph-cmds?color=green&style=flat-square" alt="release">
13+
<a href="https://mattstudios.me/discord"><img src="https://img.shields.io/discord/493380790718038028?label=discord&style=flat-square" alt="discord"/></a>
14+
</p>
15+
</center>
16+
17+
---
18+
19+
!!!!
20+
Attention! This version is still a SNAPSHOT and many things can change.
21+
!!!
22+
23+
# Features
24+
25+
# Contributing
26+
27+
Contributions, issues, and feature requests are welcome!
28+
Feel free to check [issues page](https://github.com/TriumphTeam/triumph-cmds/issues).
29+
30+
# Show your support
31+
32+
Give a star on [GitHub](https://github.com/TriumphTeam/triumph-cmds) if this project helped you!
33+
34+
# License
35+
36+
Copyright © 2024 [TriumphTeam](https://github.com/TriumphTeam).
37+
This project is [MIT](https://github.com/TriumphTeam/triumph-cmds/blob/master/LICENSE) licensed.
38+

Diff for: triumph-cmds/2.x.x-S/1-started/command-manager.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<center><h1>Command Manager</h1></center>
2+
<center><p>The basic entry for everything related to your commands.</p></center>
3+
4+
---
5+
6+
# Creating a command manager
7+
Each platform has its own command manager and each manager has its own sender type.
8+
```java
9+
// Bukkit
10+
BukkitCommandManager<CommandSender> manager = BukkitCommandManager.create(plugin);
11+
12+
// JDA Prefixed
13+
PrefixedCommandManager<PrefixedSender> manager = PrefixedCommandManager.create(jda);
14+
15+
// JDA slash
16+
SlashCommandManager<SlashSender> manager = SlashCommandManager.create(jda);
17+
```
18+
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).
19+
20+
# Usage
21+
The command manager is used for doing everything for the commands, registering commands, messages, arguments, etc.

Diff for: triumph-cmds/2.x.x-S/1-started/commands.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<center><h1>Commands</h1></center>
2+
<center><p>The basic structure of a command, and its sub commands.</p></center>
3+
4+
---
5+
6+
# Creating a simple command
7+
Every command must extend `BaseCommand`.
8+
You can use the `@Command` annotation to declare the command name and alias.
9+
```java
10+
@Command("foo")
11+
class MyCommand extends BaseCommand {}
12+
```
13+
A command can also have aliases.
14+
```java
15+
@Command(value = "foo", alias = {"bar", "baz"})
16+
class MyCommand extends BaseCommand {}
17+
```
18+
Alternatively you can also declare the command name and alias through the `BaseCommand`'s constructor.
19+
```java
20+
class MyCommand extends BaseCommand {
21+
22+
public MyCommand() {
23+
super("foo", Arrays.asList("bar", "baz"));
24+
}
25+
}
26+
```
27+
!!!!
28+
The usage of the keyword `Sender` in the following examples are **not** the correct name, it just represents a sender.
29+
As the real sender name can change based on platform or the provided custom sender.
30+
!!!
31+
32+
# Sub commands
33+
Each sub commands are declared by methods, currently there is no other way to declare its name and alias other than through annotations.
34+
35+
## Default
36+
A `@Default` method is a "sub command without a name", implying it is the main executor of a command that has no sub commands.
37+
For example the command `/foo` would be declared in the following way:
38+
```java
39+
@Command("foo")
40+
class MyCommand extends BaseCommand {
41+
42+
@Default
43+
public void executor(Sender sender) {
44+
// Code to be executed
45+
}
46+
}
47+
```
48+
49+
## SubCommand
50+
A `@SubCommand` is a sub command that has a specific name. For example `/foo bar`
51+
```java
52+
@Command("foo")
53+
class MyCommand extends BaseCommand {
54+
55+
@SubCommand("bar")
56+
public void executor(Sender sender) {
57+
// Code to be executed
58+
}
59+
}
60+
```
61+
62+
## Alias
63+
Both annotations also support an alias to be passed:
64+
`@Default(alias = {"bar"})` would be executed as either `/foo` or `/foo bar`.
65+
`@SubCommand(value = "bar", alias = {"baz"})` would be executed as either `/foo bar` or `/foo baz`.
66+
67+
# Registering
68+
Registering the command is very simple, you simply do:
69+
```java
70+
commandManager.registerCommand(new MyCommand());
71+
```

Diff for: triumph-cmds/2.x.x-S/1-started/custom-senders.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<center><h1>Custom Senders</h1></center>
2+
<center><p>Custom senders creation and registration.</p></center>
3+
4+
---
5+
6+
# Creating a simple sender
7+
```java
8+
public class MySender {}
9+
```
10+
11+
# Creating a SenderValidator
12+
Sender Validators are used for pre-command checks.
13+
```java
14+
public class MySenderValidator implements SenderValidator<MySender> {
15+
16+
// This method is used when registering, it'll check if the sender declared in the command method is valid or not
17+
@Override
18+
public @NotNull Set<Class<? extends MySender>> getAllowedSenders() {
19+
return Collections.singleton(MySender.class);
20+
}
21+
22+
@Override
23+
public boolean validate(final @NotNull MessageRegistry<MySender> messageRegistry, final @NotNull SubCommand<MySender> subCommand, final @NotNull MySender sender) {
24+
// 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.
25+
// Return true if valid, false, if not, use the message registry to send messages to the player if you want
26+
return false;
27+
}
28+
}
29+
```
30+
Now you can either make a custom SenderMapper or just use lambda.
31+
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.
32+
```java
33+
class MyMapper implements SenderMapper<CommandSender, MySender>
34+
```
35+
Now time to create the command manager. We will be using the BukkitCommandManager for this example.
36+
```java
37+
final BukkitCommandManager<MySender> manager = BukkitCommandManager.create(
38+
plugin,
39+
defaultSender -> new MySender(), // The mapping of the sender, pass a new instance if you don't want lambda
40+
new MySenderValidator() // Validator
41+
);
42+
```
43+
That is all! You can now register a new command with your custom sender.
44+
```java
45+
@Command("foo")
46+
class MyCommand extends BaseCommand {
47+
48+
@Default
49+
public void executor(MySender sender) {
50+
// Code to be executed
51+
}
52+
}
53+
```
54+
You can learn how to create and register commands [here](commands).

Diff for: triumph-cmds/2.x.x-S/1-started/group.conf

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
header = "Getting Started"
2+
pages = [
3+
{
4+
header = "Setup"
5+
link = "setup"
6+
}
7+
{
8+
header = "Command Manager"
9+
link = "command-manager"
10+
}
11+
{
12+
header = "Commands"
13+
link = "commands"
14+
}
15+
{
16+
header = "Custom Senders"
17+
link = "custom-senders"
18+
}
19+
]

Diff for: triumph-cmds/2.x.x-S/1-started/setup.md

+122
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
<center><h1>Setup</h1></center>
2+
<center><p>This is how you add the lib to your project.</p></center>
3+
4+
---
5+
6+
# Version
7+
8+
Make sure to replace `{version}` with the version you want to use.
9+
10+
# Platform
11+
12+
Make sure to replace `{platform}` with one of the following:
13+
14+
* `bukkit` - For any Bukkit based plugin, Spigot, Paper, etc.
15+
* `jda-prefixed` - For prefixed commands for JDA, for example `!test`.
16+
* `jda-slash` - For JDA slash commands.
17+
18+
-+-
19+
+Gradle (Kotlin)+
20+
You need to add the dependency to your `build.gradle.kts`.
21+
22+
```kotlin
23+
repositories {
24+
maven("https://repo.triumphteam.dev/snapshots/")
25+
}
26+
27+
dependencies {
28+
implementation("dev.triumphteam:triumph-cmd-{platform}:{version}") // Replace version here
29+
}
30+
```
31+
32+
In order to include the lib in your project, you need to add `shadow` plugin `build.gradle.kts`.
33+
Replace `[YOUR PACKAGE]` with your plugin's package, for example `me.myplugin.plugin`.
34+
35+
```kotlin
36+
// This goes on the top of the build script.
37+
plugins {
38+
id("io.github.goooler.shadow") version "8.1.8"
39+
}
40+
41+
// This can go anywhere.
42+
shadowJar {
43+
relocate("dev.triumphteam.cmd", "[YOUR PACKAGE].cmd")
44+
}
45+
```
46+
47+
+++
48+
+Gradle (Groovy)+
49+
You need to add the dependency to your `build.gradle`.
50+
51+
```groovy
52+
repositories {
53+
maven { url = "https://repo.triumphteam.dev/snapshots/" }
54+
}
55+
56+
dependencies {
57+
implementation "dev.triumphteam:triumph-cmd-{platform}:{version}" // Replace version here
58+
}
59+
```
60+
61+
To include the lib in your project, you need to add `shadow` plugin `build.gradle`.
62+
Replace `[YOUR PACKAGE]` with your plugin's package, for example `me.myplugin.plugin`.
63+
64+
```groovy
65+
// This goes on the top of the build script.
66+
plugins {
67+
id "io.github.goooler.shadow" version "8.1.8"
68+
}
69+
70+
// This can go anywhere.
71+
shadowJar {
72+
relocate("dev.triumphteam.cmd", "[YOUR PACKAGE].cmd")
73+
}
74+
```
75+
76+
+++
77+
+Maven+
78+
You need to add the dependency to your `pom.xml`.
79+
80+
```xml
81+
<repositories>
82+
<repository>
83+
<id>repo</id>
84+
<url>https://repo.triumphteam.dev/snapshots/</url>
85+
</repository>
86+
</repositories>
87+
88+
<dependency>
89+
<groupId>dev.triumphteam</groupId>
90+
<artifactId>triumph-cmd-{platform}</artifactId>
91+
<version>{version}</version> <!-- replace version here -->
92+
</dependency>
93+
```
94+
95+
To include the framework in your project, you need the shade plugin.
96+
Replace `[YOUR PACKAGE]` with your plugin's package, for example `me.myplugin.plugin`.
97+
98+
```xml
99+
<plugin>
100+
<groupId>org.apache.maven.plugins</groupId>
101+
<artifactId>maven-shade-plugin</artifactId>
102+
<version>3.6.0</version>
103+
<configuration>
104+
<relocations>
105+
<relocation>
106+
<pattern>dev.triumphteam.cmd</pattern>
107+
<shadedPattern>[YOUR PACKAGE].cmd</shadedPattern> <!-- Replace package here -->
108+
</relocation>
109+
</relocations>
110+
</configuration>
111+
<executions>
112+
<execution>
113+
<phase>package</phase>
114+
<goals>
115+
<goal>shade</goal>
116+
</goals>
117+
</execution>
118+
</executions>
119+
</plugin>
120+
```
121+
+++
122+
-+-

Diff for: triumph-cmds/2.x.x-S/2-arguments/arguments.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<center><h1>Arguments</h1></center>
2+
<center><p>Command argument declaration and options.</p></center>
3+
4+
---
5+
6+
# Concept
7+
The concept of arguments in the library are based on parameters, each parameter declared in the method will be a command argument.
8+
9+
# Sender
10+
The first parameter of the command method **must** always be a sender. You can read more about the sender [here](custom-senders).
11+
12+
# Creating a command with arguments
13+
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`.
14+
```java
15+
@Command("give")
16+
class MyClass extends BaseCommand {
17+
18+
@SubCommand("item")
19+
public void execute(Sender sender, Material material, int amount) {
20+
sender.sendMessage("The selected material was: " + material); // Will send "DIAMOND"
21+
sender.sendMessage("The amount was: " + amount); // Will send "5"
22+
}
23+
}
24+
```
25+
It is as simple as that to have arguments for your command.
26+
27+
## Argument Names
28+
By default, argument names will be defined as the name of the parameter.
29+
30+
The `@ArgName` annotation is used to define the name of the argument should you not want the name of the argument
31+
to be the same as the name of the parameter. If you would like to use the parameter name as the
32+
argument name, you can use the `-parameters` compiler flag when compiling your plugin.
33+
```java
34+
@SubCommand("id")
35+
public void execute(Sender sender, @ArgName("username") Player target) {
36+
sender.sendMessage(target.getName() + " has the id: " + target.getUniqueId());
37+
}
38+
```
39+
In this case, the argument will be called `username` instead of the parameter name, `target`.

0 commit comments

Comments
 (0)