|
| 1 | +# Make your first Addon |
| 2 | + |
| 3 | +## Requirements |
| 4 | + |
| 5 | +Developing with the Ree6 Addon API requires Java 17.\ |
| 6 | +We recommend using Maven or Gradle to import Ree6 as a Library file into your project. |
| 7 | + |
| 8 | +Example for Maven: |
| 9 | + |
| 10 | +```xml |
| 11 | +... |
| 12 | +<repository> |
| 13 | + <id>jitpack.io</id> |
| 14 | + <url>https://jitpack.io</url> |
| 15 | +</repository> |
| 16 | + |
| 17 | +... |
| 18 | + |
| 19 | +<dependency> |
| 20 | + <groupId>de.ree6</groupId> |
| 21 | + <artifactId>Ree6</artifactId> |
| 22 | + <version>VERSION</version> |
| 23 | +</dependency> |
| 24 | +... |
| 25 | +``` |
| 26 | + |
| 27 | +## Lets get started! |
| 28 | + |
| 29 | +When working with the Ree6 Addon API you need to create a Main class of your Addon which implements our `AddonInterface` class! |
| 30 | + |
| 31 | +In this example we call the class AddonMain: |
| 32 | + |
| 33 | +```java |
| 34 | +public class AddonMain implements AddonInterface { |
| 35 | +} |
| 36 | +``` |
| 37 | + |
| 38 | +After implementing the AddonInterface you should start with the onEnable and onDisable Methods! |
| 39 | + |
| 40 | +```java |
| 41 | + @Override |
| 42 | + public void onEnable() { |
| 43 | + System.out.println("Start!"); |
| 44 | + } |
| 45 | + |
| 46 | + @Override |
| 47 | + public void onDisable() { |
| 48 | + System.out.println("Goodybye!"); |
| 49 | + } |
| 50 | +``` |
| 51 | + |
| 52 | +## Creating a command! |
| 53 | + |
| 54 | +To create a command we need to first understand the concept behind the Ree6 Command System.\ |
| 55 | +We have a `CommandManager` which is handling all the internal works like command parameter parsing and more!\ |
| 56 | +For a command we need to create a class implements the `ICommand` class and having the `Command` Annonciation. |
| 57 | + |
| 58 | +Lets make a command together called `PongCommand`: |
| 59 | + |
| 60 | +```java |
| 61 | +@Command(name = "ping", description = "Answer with Pong!", category = Category.FUN) |
| 62 | +public class PongCommand extends ICommand { |
| 63 | + |
| 64 | + @Override |
| 65 | + public void onPerform(CommandEvent commandEvent) { |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public CommandData getCommandData() { |
| 70 | + return null; |
| 71 | + } |
| 72 | + |
| 73 | + @Override |
| 74 | + public String[] getAlias() { |
| 75 | + return new String[0]; |
| 76 | + } |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +When creating the commands you will need to implement these 3 methods to work with them.\ |
| 81 | +The `onPerform` method is where you are going to do most of the stuff.\ |
| 82 | +I will give you a `CommandEvent` as parameter which will contain informations like:\ |
| 83 | + |
| 84 | + |
| 85 | +* Has this Command been executed as SlashCommand? |
| 86 | +* Who executed this Command? |
| 87 | +* In which Guild has this Command been executed? |
| 88 | + |
| 89 | +Now, lets continue with our work!\ |
| 90 | +Since we want the Bot to respond with `Pong!` when someone writes `/ping` or `ree!ping`\ |
| 91 | +We need to go into the `onPerform` method and respond to it!\ |
| 92 | +For this we can use the internal reply method.\ |
| 93 | +Just like this: |
| 94 | + |
| 95 | +```java |
| 96 | +@Override |
| 97 | +public void onPerform(CommandEvent commandEvent) { |
| 98 | + commandEvent.reply("Pong!"); |
| 99 | +} |
| 100 | +``` |
| 101 | + |
| 102 | +## Register the command. |
| 103 | + |
| 104 | +Well now that we finished our great `PongCommand` we will need to register it!\ |
| 105 | + |
| 106 | + |
| 107 | +How do we do that?\ |
| 108 | +Simple, we go into our Main class into the `onEnable` method and tell the `CommandManager` to add it into the system! |
| 109 | + |
| 110 | +It would look like this: |
| 111 | + |
| 112 | +```java |
| 113 | +@Override |
| 114 | +public void onEnable() { |
| 115 | + System.out.println("Start!"); |
| 116 | + Main.getInstance().getCommandManager().addCommand(new PongCommand()); |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +But we shouldn't forget to also remove the Command once the Addon shutsdown!\ |
| 121 | +You can do this like this: |
| 122 | + |
| 123 | +```java |
| 124 | +@Override |
| 125 | +public void onDisable() { |
| 126 | + System.out.println("Goodybye!"); |
| 127 | + Main.getInstance().getCommandManager().removeCommand(new PongCommand()); |
| 128 | +} |
| 129 | +``` |
| 130 | + |
| 131 | +## The missing Addon.yml |
| 132 | + |
| 133 | +To let Ree6 now where to look you will need to create a `Addon.yml`!\ |
| 134 | +In this you will need to add the name of the Addon, the Author name, the path to the main class, the version of the addon, the version of Ree6 it has been made for!\ |
| 135 | +For example addon it would looks like this: |
| 136 | + |
| 137 | +```yaml |
| 138 | +name: Pong Command |
| 139 | +version: 1.0 |
| 140 | +api-version: 2.4.11 |
| 141 | +author: Presti |
| 142 | +main: de.presti.pongcommand.AddonMain |
| 143 | +``` |
| 144 | +
|
| 145 | +## Finishing up! |
| 146 | +
|
| 147 | +You should be ready to go with your Addon!\ |
| 148 | +Now you will need to export it either via Maven, Gradle or any desired way you have! |
| 149 | +
|
| 150 | +After exporting it you just need to put it into the `addons` folder of Ree6!\ |
| 151 | +You can either restart Ree6 to load the addon or use the `/addon load NAME` to load it! |
0 commit comments