SkJvm
SkJvm 允许你在 Skript 脚本中直接编写并执行 Java 代码。
将游戏逻辑保留在 Skript 中,并在需要更多灵活性、可复用代码或访问 Bukkit/Paper API 时使用 Java。
该项目曾名为 SkBee++。这是一个独立项目,与 ShaneBee 的 SkBee 无关。
功能特性
- Skript 中的 Java: 在
execute java: 下方直接编写 Java 代码。
- 可复用的
.jv 模块: 将较大的 Java 代码段保存在单独的文件中,并从你的脚本中运行它们。
- 现代 Java 语法: 使用 Lambda 表达式、方法引用、
var 以及其他 Java 语言特性。
- 变量桥接: 在 Java 和 Skript 之间交换值、List(列表)、数组和嵌套 Map(映射)。
- Skript 回调: 通过
Runnable 和 Consumer 从 Java 调用 Skript 部分。
- 事件上下文: 访问触发事件、命令发送者以及相关的事件值。
- 后台编译: 异步编译 Java 代码,并在脚本重载时重用未更改的代码。
- Maven 依赖: 使用经过明确批准的外部库,并附带 SHA-256 校验验证。
- 可读的错误信息: 通过指向原始脚本或模块行的消息来查找问题。
- 调试工具: 使用
/jvdebug 检查事件绑定和记录的变量写入操作。
在 Skript 中直接使用 Java
command /javahello:
trigger:
execute java:
var words = List.of("Hello", "from", "SkJvm!");
sender.sendMessage(String.join(" ", words));
Java 代码块可以访问 event、sender 和 context,以及用于读写 Skript 变量的辅助函数。
可复用的 Java 模块
从脚本中调用模块:
on join:
run jv "modules/welcome.jv"
在 plugins/Skript/scripts/modules/welcome.jv 中编写其 Java 代码:
Player player = (Player) sender;
player.sendMessage("Welcome back, " + player.getName());
与 Skript 共享数据
setVar("_items::*", List.of("sword", "shield"));
List<?> items = getList("_items");
setVar("profile::*", Map.of(
"name", "Alex",
"stats", Map.of("wins", 12)
));
使用以 _ 开头的名称作为事件局部变量,无前缀的名称作为全局变量。
要求
- Paper — 当前构建目标为 Minecraft 26.1.2。
- Skript 2.15.4 — 当前的 API 目标版本及最低预期版本。
- 完整的 JDK 25,包括 Java 编译器模块。
- 仅限服务器端: 玩家无需安装任何内容。
不支持 Bukkit/Spigot 和 Folia。其他 Minecraft 版本和 Paper 分支需要进行兼容性测试。
编译与重载
Java 代码会在后台编译,且未更改的已编译代码会在 /sk reload 期间保留在缓存中。
请留意控制台中的编译错误和就绪消息。如果某个 Java 代码块仍在编译或已失败,当前的触发器执行将在该代码块处停止。这也适用于 on load。
安全性
SkJvm 会检查生成的字节码并限制类加载。默认情况下,通过 allow-system-io: false 限制直接的文件系统/网络访问,同时限制反射、进程执行和 JVM 关闭操作。
SkJvm 旨在用于受信任的脚本,而非不受信任的代码。 这些限制并非完整的沙箱机制:Bukkit/Paper API 和已批准的库仍保留服务器权限,无限循环或内存耗尽也不会被隔离。
仅应允许受信任的管理员编辑启用 Java 的脚本并批准外部依赖项。
SkJvm
SkJvm lets you write and execute Java directly inside your Skript scripts.
Keep your gameplay logic in Skript and use Java whenever you need more flexibility, reusable code, or access to the Bukkit/Paper API.
Formerly known as SkBee++. This project is independent and is not affiliated with ShaneBee's SkBee.
Features
- Java inside Skript: Write Java code directly under
execute java:.
- Reusable
.jv modules: Keep larger pieces of Java in separate files and run them from your scripts.
- Modern Java syntax: Use lambdas, method references,
var, and other Java language features.
- Variable Bridge: Exchange values, Lists, arrays, and nested Maps between Java and Skript.
- Skript callbacks: Call Skript sections from Java through
Runnable and Consumer.
- Event context: Access the triggering event, command sender, and relevant event values.
- Background compilation: Compile Java asynchronously and reuse unchanged code across script reloads.
- Maven dependencies: Use explicitly approved external libraries with SHA-256 verification.
- Readable errors: Find problems through messages pointing to the original script or module line.
- Debugging tools: Inspect event bindings and recorded variable writes with
/jvdebug.
Java directly inside Skript
command /javahello:
trigger:
execute java:
var words = List.of("Hello", "from", "SkJvm!");
sender.sendMessage(String.join(" ", words));
Java blocks can access event, sender, and context, along with helpers for reading and writing Skript variables.
Reusable Java modules
Call a module from your script:
on join:
run jv "modules/welcome.jv"
Write its Java code in plugins/Skript/scripts/modules/welcome.jv:
Player player = (Player) sender;
player.sendMessage("Welcome back, " + player.getName());
Share data with Skript
setVar("_items::*", List.of("sword", "shield"));
List<?> items = getList("_items");
setVar("profile::*", Map.of(
"name", "Alex",
"stats", Map.of("wins", 12)
));
Use _-prefixed names for event-local variables and unprefixed names for global variables.
Requirements
- Paper — the current build targets Minecraft 26.1.2.
- Skript 2.15.4 — the current API target and minimum intended version.
- Full JDK 25, including the Java compiler module.
- Server-side only: players do not need to install anything.
Bukkit/Spigot and Folia are not supported. Other Minecraft versions and Paper forks require compatibility testing.
Compilation and reloading
Java compiles in the background, and unchanged compiled code remains cached across /sk reload.
Watch the console for compilation errors and readiness messages. If a Java block is still compiling or has failed, the current trigger invocation stops at that block. This also applies to on load.
Security
SkJvm checks generated bytecode and restricts class loading. Direct filesystem/network access is restricted by default through allow-system-io: false, alongside restrictions on reflection, process execution, and JVM shutdown.
SkJvm is intended for trusted scripts, not untrusted code. These restrictions are not a complete sandbox: Bukkit/Paper APIs and approved libraries retain server privileges, and infinite loops or memory exhaustion are not isolated.
Only trusted administrators should be allowed to edit Java-enabled scripts and approve external dependencies.
评论 0
登录后参与评分
还没有评论,来抢沙发吧