Files
2009scape/Server/src/main/core/api/Commands.kt
T
Ceikry c99dfe7031 Interface Developer Tools
Implemented fully functioning interface decoders referenced from the client
Added ::iftriggers command that gives visibility of all the varp/varc triggers on an interface
Added ::listifmodels command that gives visibility of all the models present on an interface
Added ::listiftext command that gives visibility of all the text present on an interface
2023-09-14 08:43:22 +00:00

53 lines
2.2 KiB
Kotlin

package core.api
import core.game.node.entity.player.Player
import core.game.system.command.Command
import core.game.system.command.CommandMapping
import core.game.system.command.Privilege
import core.tools.Log
import core.tools.colorize
/**
* An interface for writing content that allows the class to define commands.
*
* Includes methods [reject] and [notify] for notifying the player of a command rejection or some output text respectively.
*
* Includes the method [define] to define individual commands
*
* Commands should ideally be defined in the required [defineCommands] method.
*/
interface Commands : ContentInterface {
/**
* Glorified player.sendMessage with red text coloring. Please use this
* rather than just player.sendMessage for anything that involves informing the player
* of proper usage or invalid syntax. Throws an IllegalStateException and ends command execution immediately.
*/
fun reject(player: Player, vararg message: String){
for(msg in message) {
player.sendMessage(colorize("-->%R$msg"))
}
throw IllegalStateException()
}
/**
* Glorified player.sendMessage with black text coloring and an arrow. Use this when you need to
* notify/inform a player of some information from within the command without ending execution.
*/
fun notify(player: Player, message: String, logToConsole: Boolean = false){
if (logToConsole)
log (this::class.java, Log.DEBUG, message)
player.sendMessage(colorize("-->$message"))
}
/**
* Used to define commands. define("name",(optional) privilege override){ handle }
* @param name the name of the command. Example: ::example would be just "example"
* @param privilege the rights level needed to execute the command. Options are [Privilege.STANDARD], [Privilege.MODERATOR], [Privilege.ADMIN]. Defaults to [Privilege.STANDARD]
*/
fun define(name: String, privilege: Privilege = Privilege.ADMIN, usage: String = "", description: String = "", handle: (Player, Array<String>) -> Unit){
CommandMapping.register(Command(name, privilege, usage, description, handle))
}
fun defineCommands()
}