-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an example for CommandBuilders
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
api-examples/src/main/java/net/zffu/hardened/examples/api/BuilderCommandExample.java
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,32 @@ | ||
package net.zffu.hardened.examples.api; | ||
|
||
import net.zffu.hardened.api.args.Argument; | ||
import net.zffu.hardened.api.args.ArgumentTypes; | ||
import net.zffu.hardened.api.commands.builder.CommandBuilder; | ||
import net.zffu.hardened.api.context.CommandContext; | ||
import net.zffu.hardened.api.invoker.InvokerType; | ||
|
||
/** | ||
* An example on how to use the {@link net.zffu.hardened.api.commands.builder.CommandBuilder} | ||
*/ | ||
public class BuilderCommandExample { | ||
|
||
public static void main(String[] args) { | ||
|
||
// Creates the base of the command builder | ||
CommandBuilder builder = new CommandBuilder() { | ||
|
||
// Everything in that function will be ran after validation. | ||
@Override | ||
public void execute(CommandContext commandContext) { | ||
String name = commandContext.get(0, String.class); // Gets the first argument of the command. | ||
System.out.println("Hello " + name); | ||
} | ||
|
||
} | ||
// Adds properties to the CommandBuilder. | ||
.allowed(InvokerType.PLAYER) // Makes sure only players can run this command | ||
.args(new Argument(ArgumentTypes.STRING.get())); // Adds a string argument | ||
} | ||
|
||
} |