Skip to content

Commit

Permalink
Added an example for CommandBuilders
Browse files Browse the repository at this point in the history
  • Loading branch information
Zffu committed Jul 16, 2024
1 parent c8d5e2a commit 82bb67a
Showing 1 changed file with 32 additions and 0 deletions.
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
}

}

0 comments on commit 82bb67a

Please sign in to comment.