Closed jupiter1390 closed 4 years ago
Please review this new module function.
Function description:
// ScriptModule class
/**
* Register custom command.
*
* If [label] were test, '/test abc 123' could be recognized as input for this command.
* [Handler][BiConsumer] is consequently executed, supplied with executor(player) and string array(abc 123) to handle its operation.
*
* Note: Tab completion is not supported.
*
* @param label Name of command to register.
* @param handler Operation of this command which accepts [Player] and [String] array as input.
* @return Whether it is successfully registered or not.
*/
fun registerCommand(label: String, handler: BiConsumer<Player, Array<String>>): Boolean
/**
* Un-register a command that is previously registered by [registerCommand].
*
* @param label Name of command to unregister.
* @return Whether it is successfully un-registered or not.
*/
fun unregisterCommand(label: String): Boolean
Example in script:
ScriptModule.registerCommand("ping") { player, args ->
if (args.isEmpty()) {
player.sendMessage("Pong!")
} else {
for (int i = 0; i < args.size(); i++) {
player.sendMessage("Pong!")
}
}
}
Review halt! Refactor is undergoing to support the following features in custom commands:
Notable change:
I reviewed the change myself.
script module that lets adding custom command per game - commands can execute script actions