Appearance
脚本插件(JavaScript)已移除
这个页面是历史遗留
自 1.6.2 起,Bngeuit 不再支持 JavaScript 脚本插件。
ScriptPlugin / ScriptBridge 与 js-language / truffle-runtime 依赖已全部删除,plugins/ 目录下的 .js 文件不会被加载。插件体系现在只有两种形态:JAR 插件 与 nc 脚本插件。
现在怎么写脚本插件
用 nc(自研 nacre 语言):把 .nc 文件放进 plugins/ 即自动加载,加载时内存编译为 JVM 字节码直接执行,性能接近原生 Java 插件。
nc
package bngeuit.examples.hello
import cn.org.bukkit.bngeuit.Bngeuit
import cn.org.bukkit.bngeuit.event.receive.GroupAtMessageEvent
import cn.org.bukkit.bngeuit.script.NcBridge
val pluginName = "Hello"
val b = NcBridge.of("bngeuit.examples.hello")
fun onEnable() {
b.on(GroupAtMessageEvent.class) { e ->
if ("你好".equals(e.getContent())) {
Bngeuit.replyGroupText(e.getGroupOpenid(), e.getId(), 1, "你好,这是 nc 脚本插件的回复")
}
}
b.info("Hello 已启用")
}
fun onDisable() {
}完整语法、生命周期、桥接对象 API 见 脚本插件(nc)。
从 JS 迁移到 nc
| JS 写法 | nc 写法 |
|---|---|
plugin = { name: 'x', version: '1.0' } | 顶层 val pluginName = "x" / val pluginVersion = "1.0" |
bngeuit.on('GroupAtMessageEvent', (e) => {...}) | b.on(GroupAtMessageEvent.class) { e -> ... } |
bngeuit.registerCommand('x', fn) | b.registerCommand("x") { sender, args -> ... } |
bngeuit.runAsync(fn) / runAsyncTimer(fn, d, p) | b.runAsync { ... } / b.runAsyncTimer(fn, d, p) |
bngeuit.info / warn / error(msg) | b.info / warn / error(msg) |
bngeuit.getDataFolder() | b.getDataFolder() |
Java 类用 Java.type('...') | 直接 import 全限定类名 |
文件名 xxx.js | 文件名 xxx.nc,且必须写唯一的 package |
生命周期函数名基本不变:onLoad / onEnable / onActive / onDisable 在 nc 里都存在。
