Nacre
Nacre脚本文件放置于 plugins\CraneCore\script 文件夹下,命名为 文件名.nc 即可
CraneCore 1.1.0 新增
示例文件
HelloWorld.nc
nacre
package cranecore
import org.bukkit.Bukkit
import org.bukkit.command.CommandSender
fun enable() {
Bukkit.getConsoleSender().sendMessage("HelloWorld.nc enable!")
}
fun disable() {
Bukkit.getConsoleSender().sendMessage("HelloWorld.nc disable!")
}
fun run(user: CommandSender): Boolean {
user.sendMessage("Hello World")
return true
}
fun run2(user: CommandSender, msg: String, msg1: String, msg2: String): Boolean {
user.sendMessage(msg)
user.sendMessage(msg1)
user.sendMessage(msg2)
return true
}
fun test(user: CommandSender) {
val a = 1
val b = 2
val c = 1 + 2
}使用
使用命令 /cranecore script <player> <file> <function> 可运行脚本
比如使用 /cranecore script MonsterChum HelloWorld.nc run 可以为玩家 MonsterChum 运行 HelloWorld.nc 中的 run 函数
使用 /cranecore script MonsterChum HelloWorld.nc run2 1 2 3 可以为玩家 MonsterChum 运行 HelloWorld.nc 中的 run2 函数,1 2 3 作为 3 个参数,它们都是字符串
当玩家为 ~ 时,可以为控制台运行,比如 /cranecore script ~ HelloWorld.nc run
生命周期
当脚本加载和卸载时,会自动运行所有脚本中的 enable() 和 disable() 函数,若没有编写对应函数则不会运行
Nacre 是什么
nacre(nc)是一门跑在 JVM 上的轻量脚本语言:一个 .nc 文件就是一个程序, 不需要任何类和样板。写起来像 Kotlin,跑起来是原生速度。
