This repository was archived by the owner on May 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Custom Properties
Xemiru / Marc Tellerva edited this page Nov 2, 2017
·
1 revision
General isn't able to predict everything you might need to do with it. Custom properties allow you to add extra data to commands and context objects to extend the framework in a limited fashion.
The heart of this system is the CustomKey object. Each object is used as a unique identifier for specific kinds of custom data. It is recommended to put them all in one constants class.
import static com.github.xemiru.general.misc.CustomKey.key;
public class CustomKeys {
public static final CustomKey<String> SENDER_NAME = key();
public static final CustomKey<String> SENDER_EMAIL = key();
public static final CustomKey<Integer> SENDER_PERMISSION = key();
public static final CustomKey<Integer> COMMAND_PERMISSION = key();
}You can then use these keys to assign custom values to Command and CommandContext and later retrieve them.
// CommandManager's context factories
import CustomKeys.*;
String userInput = // ...
CommandManager cm = // ...
cm.handleCommand(userInput, ctx -> ctx
.setCustom(SENDER_NAME, "Xemiru")
.setCustom(SENDER_EMAIL, "who@cares.woosh")
.setCustom(SENDER_PERMISSION, 99));// Command's custom properties
import CustomKeys.*;
Command helloWorld = Command.builder()
.name("hello")
.shortDescription("Hello, world!")
.description("Responds with \"Hello, world!\"")
.executor((context, args, dry) -> {
if(dry) return;
context.sendMessage("Hello, world!");
})
.setCustom(COMMAND_PERMISSION, 99) // only the highest can speak : ^ )
.build();