This repository has been archived by the owner on Dec 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleCommand.java
67 lines (54 loc) · 3.25 KB
/
ExampleCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.github.derrop.simplecommand;
import com.github.derrop.simplecommand.annotation.Argument;
import com.github.derrop.simplecommand.annotation.Command;
import com.github.derrop.simplecommand.annotation.Handler;
import com.github.derrop.simplecommand.annotation.SubCommand;
import com.github.derrop.simplecommand.argument.ArgumentRequirement;
import com.github.derrop.simplecommand.argument.ArgumentType;
import com.github.derrop.simplecommand.argument.CommandArgumentWrapper;
import com.github.derrop.simplecommand.sender.CommandSender;
import java.util.Map;
import static com.github.derrop.simplecommand.argument.DefaultArgumentTypes.*;
@Command(
aliases = "example",
permission = "command.example",
description = "Description for this command",
prefix = "command-prefix",
consoleOnly = false
)
public class ExampleCommand {
@Argument
public final ArgumentType<?> set = anyStringIgnoreCase("set", "modify");
@Argument
public final ArgumentType<?> value = anyStringIgnoreCase("value", "val");
@Argument
public final ArgumentType<?> newValue = positiveInteger("newValue");
@Handler
public void preHandle(CommandSender sender, CommandArgumentWrapper args, String commandLine, CommandProperties properties, Map<String, Object> internalProperties) {
// you don't have to provide any of those parameters, you can choose whatever you want. You can also use 0 parameters
sender.sendMessage("This method is being called first!");
}
@Handler
public void postHandle(CommandSender sender, CommandArgumentWrapper args, String commandLine, CommandProperties properties, Map<String, Object> internalProperties) {
// you don't have to provide any of those parameters, you can choose whatever you want. You can also use 0 parameters
sender.sendMessage("This method is being called last!");
}
@SubCommand(
args = {"set", "value", "newValue"}, // the keys of the arguments from above
preHandlers = "preHandle", // the names of the methods from above
postHandlers = "postHandle", // the names of the methods from above
consoleOnly = false,
description = "Set the new value",
permission = "command.example.set.value",
requirement = ArgumentRequirement.EXACT, // does the command need an exact amount of arguments or can the user provide infinity arguments?
maxArgs = -1, // ignored if the "requirement" is set to EXACT
showMinArgsIndicator = true, // this will show a "..." at the end of the usage if the "requirement is set to "MINIMUM"
async = false, // whether the command should be called async from the dispatchCommand method
enableProperties = false, // if false, the "properties" in the parameters will be null
extendedUsage = " | this will be appended to the usage of this command"
)
public void setValueCommand(CommandSender sender, CommandArgumentWrapper args, String commandLine, CommandProperties properties, Map<String, Object> internalProperties) {
// you don't have to provide any of those parameters, you can choose whatever you want. You can also use 0 parameters
int newValue = (int) args.argument("newValue");
}
}