You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First, lets make a brand new class and have it implement a Caramel Command. For this tutorial, I'll be using the class name "MyCommand" and main file "MyPlugin".
36
36
```java
37
37
publicclassMyCommandimplementsCaramelCommand {
@@ -63,7 +63,7 @@ public CaramelCommandDetail getDetails() {
63
63
}
64
64
```
65
65
66
-
# Registering
66
+
###Registering
67
67
1. Make sure your command is added to your `plugin.yml` file under `commands`. It should have the basic layout of `commands > my-command-name > description+usage`.
68
68
2. Add a new variable in your main class to store your command:
69
69
```java
@@ -84,3 +84,51 @@ public class MyPlugin extends JavaPlugin {
84
84
}
85
85
```
86
86
4. All set! Your command is now registered.
87
+
88
+
<br/><br/><br/>
89
+
90
+
## The garnish on top
91
+
### (OPTIONAL) Tab Completion
92
+
Step 1 - Dead simple - Add this code to your command file:
93
+
```java
94
+
@Override
95
+
publicList<String> complete(String[] args) {
96
+
...
97
+
}
98
+
```
99
+
100
+
#### Tab completion (the boring way)
101
+
Simply `return` a List<> of your choices.
102
+
```java
103
+
returnArrays.asList("my", "choices");
104
+
```
105
+
106
+
#### With a little spice
107
+
Caramel comes bundled with a tab completion handler for some no-hassle satisfying tab completion.
108
+
```java
109
+
// Both of these example only work for one argument, as we only use "args[0]". See below for more.
This will shorten the tab completion options based on how much you have already typed (like autocomplete). To further the complexity (aka if you have multiple args) you can handle it based on what argument you are on. Example:
118
+
119
+
Lets say you have a command with the usage /command <pet> <name> <player>.
120
+
Your args would be ["pet", "name", "player"] (0,1,2). Lets try this:
121
+
122
+
```java
123
+
if(args.length ==1) { // first argument - pet
124
+
String arg = args[0]; // [0] is the first argument in an array.
0 commit comments