LazoYoung / CraftGames

Minecraft Paper plugin that enables you to make custom minigame scripts.
MIT License
2 stars 1 forks source link

Custom command per game #75

Closed jupiter1390 closed 4 years ago

jupiter1390 commented 4 years ago

script module that lets adding custom command per game - commands can execute script actions

LazoYoung commented 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!")
        }
    }
}
LazoYoung commented 4 years ago

Review halt! Refactor is undergoing to support the following features in custom commands:

Notable change:

LazoYoung commented 4 years ago

I reviewed the change myself.