English | 简体中文
Events documentation
描述
JsPig 通过 GraalVM 提供对 Bukkit API 的完整访问,使开发者能够利用 JavaScript 的灵活性和简洁性高效地构建和管理 Minecraft 插件。
开始使用
在开始之前,请确保已安装相应的 GraalVM Java 环境。在整个开发 JavaScript 插件和部署的过程中,必须使用 GraalVM Java 来启动 Minecraft 服务器。
- 首先,将插件放入
bukkit 系列服务器的 plugins 文件夹中。
- 启动服务器后,你会看到一个与插件同名的插件数据文件夹。在控制台中输入命令
JsPig declare 以生成声明文件 global.d.ts。
- 使用
VSCode 打开该插件数据文件夹(与插件同名),即可开始编写 JavaScript 插件。
高级功能
- 在插件数据文件夹内创建一个新文件夹,按照常规命名约定命名,并在其中创建一个
package.json 文件,填入以下代码:
{
"main": "./block.js",
"modules": [
"registry",
"scripts-manager",
"console",
"timer"
]
}
- 然后在该文件夹中创建一个
block.js 文件,即可开始开发具有高级功能的插件。
block.js 是一个示例文件;你可以使用任何名称。
modules 中可用的选项:
registry 注册事件。
scripts-manager 脚本管理。
console 日志记录。
timer 计时;添加对 setTimeout、setInterval、clearTimeout、clearInterval(精确计时)的支持。
命令
主命令为 /JsPig(别名 /jspig 和 /js);其第一个参数为子命令:
load <path> — 加载脚本文件或包文件夹。
unload [path] — 卸载脚本/包;省略 path 时卸载所有。
reload [path] — 重载脚本/包;省略 path 时重载所有。
list — 列出当前已加载的脚本。
show — 列出插件数据文件夹中注册的脚本,即每个包含 package.json 的文件夹。每项显示为 folder/main.js,绿色 ✓ 标记表示已加载的项。
declare (别名 declaration, d) — 生成 global.d.ts 声明文件。
服务器加载完成后,会自动扫描已注册的脚本,将列表打印到控制台并加载这些脚本。
权限
JsPig.op (默认: op) — 使用 /jspig 所需:
/jspig load <js>
/jspig unload <js>
/jspig reload
/jspig list
/jspig show
/jspig declare
JsPig.JsExtend (默认: default) — 使用 /jse <command>(由 JavaScript 实现的自定义子命令)所需。
自定义命令
每个文件夹中的 package.json 可以定义自定义命令。配置示例:
{
"command": {
"command": "list",
"description": "List all subcommands",
"usage": "Use /<main command> list",
"permission": "JsPig.JsExtend.List",
"permissionMessage": "You do not have permission to use this command."
}
}
// JsExtend.list 对应于 "command": "list";"JsExtend." 是固定前缀且区分大小写。
registry.on("JsExtend.list", (sender, command, args) => {
})
注意!一个 package.json 只能有一个命令。
为了让玩家正确使用命令——例如上面的 list——你需要一个权限管理插件,如 LuckPerms-Bukkit。
然后添加权限节点 JsPig.JsExtend.List(大小写均可),将其值设置为 true,并重载服务器权限,以便玩家可以使用它。
在游戏中,输入:/jsextend list 或 /jse list
如果你的自定义命令有其他选项,请使用 /jse <command> <command options> <options>;它们可以从 args 中获取。
以下是使用自定义命令的完整 package.json 配置:
{
"main": "./block.js",
"modules": [
"registry",
"scripts-manager",
"console",
"timer"
],
"command": {
"command": "list",
"description": "List all subcommands",
"usage": "Use /<main command> list",
"permission": "JsPig.JsExtend.List",
"permissionMessage": "You do not have permission to use this command."
}
}
示例
示例插件:jspig-example
English | 简体中文
Events documentation
Description
JsPig provides complete access to the Bukkit API through GraalVM, enabling developers to build and manage Minecraft plugins efficiently using the flexibility and simplicity of JavaScript.
Start
Before getting started, please ensure that you have installed the corresponding GraalVM Java environment. Throughout the entire process of developing JavaScript plugins and deployment, you must use GraalVM Java to start the Minecraft server.
- First, place the plugin into the
plugins folder of a bukkit-family server.
- After starting the server, you will see a plugin data folder with the same name as the plugin. Enter the command
JsPig declare in the console to generate the declaration file global.d.ts.
- Open the plugin data folder (same name as the plugin) with
VSCode, and you can start writing JavaScript plugins.
Advanced features
- Create a new folder inside the plugin data folder, name it following common naming conventions, create a
package.json file inside it, and fill in the following code:
{
"main": "./block.js",
"modules": [
"registry",
"scripts-manager",
"console",
"timer"
]
}
- Then create a
block.js file in that folder to start developing plugins with advanced features.
block.js is an example file; any name works.
Available options in modules:
registry register events.
scripts-manager script management.
console logging.
timer timing; adds support for setTimeout, setInterval, clearTimeout, clearInterval (precise timing).
Commands
The main command is /JsPig (aliases /jspig and /js); its first argument is the subcommand:
load <path> — load a script file or a package folder.
unload [path] — unload a script/package; unload all when path is omitted.
reload [path] — reload a script/package; reload all when path is omitted.
list — list the currently loaded scripts.
show — list the scripts registered in the plugin data folder, i.e. every folder that contains a package.json. Each entry is displayed as folder/main.js, and a green ✓ marks the ones that are already loaded.
declare (aliases declaration, d) — generate the global.d.ts declaration file.
After the server finishes loading, the registered scripts are scanned automatically, the list is printed to the console, and the scripts are loaded.
Permissions
JsPig.op (default: op) — required to use /jspig:
/jspig load <js>
/jspig unload <js>
/jspig reload
/jspig list
/jspig show
/jspig declare
JsPig.JsExtend (default: default) — required to use /jse <command>, the custom subcommands implemented by JavaScript.
Custom commands
The package.json in each folder can define custom commands. Example configuration:
{
"command": {
"command": "list",
"description": "List all subcommands",
"usage": "Use /<main command> list",
"permission": "JsPig.JsExtend.List",
"permissionMessage": "You do not have permission to use this command."
}
}
// JsExtend.list corresponds to "command": "list"; "JsExtend." is a fixed prefix and is case-sensitive.
registry.on("JsExtend.list", (sender, command, args) => {
})
Note! A package.json can only have one command.
For players to use the command correctly — for example the list above — you need a permission management plugin such as LuckPerms-Bukkit.
Then add a permission node JsPig.JsExtend.List (either case works), set its value to true, and make the server reload permissions so that players can use it.
In-game, enter: /jsextend list or /jse list
If your custom command has additional options, use /jse <command> <command options> <options>; they can be retrieved from args.
Here is the full package.json configuration for using custom commands:
{
"main": "./block.js",
"modules": [
"registry",
"scripts-manager",
"console",
"timer"
],
"command": {
"command": "list",
"description": "List all subcommands",
"usage": "Use /<main command> list",
"permission": "JsPig.JsExtend.List",
"permissionMessage": "You do not have permission to use this command."
}
}
Example
Example plugin: jspig-example
评论 0
登录后参与评分
还没有评论,来抢沙发吧