Package com.mclds.plugins.scriptengin
Class ScriptEnginPlugin
java.lang.Object
com.mclds.plugins.customplugin.CustomPlugin
com.mclds.plugins.scriptengin.ScriptEnginPlugin
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic classstatic classstatic classScriptEnginPlugin.ScriptListener<E extends org.bukkit.event.Event>static classstatic interface三参数函数式接口(java.util.function 只提供到 BiFunction)。 -
Field Summary
FieldsFields inherited from class com.mclds.plugins.customplugin.CustomPlugin
plugins -
Constructor Summary
ConstructorsConstructorDescriptionScriptEnginPlugin(org.bukkit.plugin.java.JavaPlugin javaPlugin, CommandRegistry.CommandTester tester, @Nullable BiConsumer<ScriptEnginPlugin, org.graalvm.polyglot.Context> extraJsContextConsumer) ScriptEnginPlugin(org.bukkit.plugin.java.JavaPlugin javaPlugin, @Nullable BiConsumer<ScriptEnginPlugin, org.graalvm.polyglot.Context> extraJsContextConsumer) -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyScripts(File scriptFolder) voidvoidcloseOneScript(Path path) getScriptDb(String name, org.graalvm.polyglot.Context context, String baseScriptName) 按 name 获取/创建 SQLite DB 实例(按 (context, 文件) 缓存,跨脚本/跨 reload 复用)。booleanisContextClosed(org.graalvm.polyglot.Context context) loadScript(Path scriptPath) voidvoidonEnable()parseCommand(org.graalvm.polyglot.Context context, Map<?, ?> map) @Nullable ScriptEnginPlugin.ScriptListenerparseListener(org.graalvm.polyglot.Context context, Map<?, ?> map) registerScriptCommanders(org.graalvm.polyglot.Context context, Path filename, List commanders) 注册命令行registerScriptListeners(org.graalvm.polyglot.Context context, Path filename, List listeners) 注册监听器@Nullable PathresolveRequirePath(Path baseScript, String require_path) Node.js 风格 require 路径解析。Methods inherited from class com.mclds.plugins.customplugin.CustomPlugin
config, defineConfig, disable, disable, disable, enable, enable, enableManagerCommand, get, get, getCommandRegistry, getDataFolder, getJavaPlugin, getListenerRegistry, getName, logger, onLoad, reloadConfig, saveConfig
-
Field Details
-
status
-
-
Constructor Details
-
ScriptEnginPlugin
public ScriptEnginPlugin(org.bukkit.plugin.java.JavaPlugin javaPlugin, CommandRegistry.CommandTester tester, @Nullable @Nullable BiConsumer<ScriptEnginPlugin, org.graalvm.polyglot.Context> extraJsContextConsumer) -
ScriptEnginPlugin
public ScriptEnginPlugin(org.bukkit.plugin.java.JavaPlugin javaPlugin, @Nullable @Nullable BiConsumer<ScriptEnginPlugin, org.graalvm.polyglot.Context> extraJsContextConsumer)
-
-
Method Details
-
onEnable
- Overrides:
onEnablein classCustomPlugin- Throws:
IOException
-
onDisable
public void onDisable()- Overrides:
onDisablein classCustomPlugin
-
applyScripts
- Throws:
IOException
-
loadScript
-
registerScriptCommanders
public List<ScriptEnginPlugin.ScriptCommand> registerScriptCommanders(org.graalvm.polyglot.Context context, Path filename, List commanders) 注册命令行 -
registerScriptListeners
public List<ScriptEnginPlugin.ScriptListener> registerScriptListeners(org.graalvm.polyglot.Context context, Path filename, List listeners) throws IOException 注册监听器- Throws:
IOException
-
closeOneScript
-
closeAllScripts
public void closeAllScripts() -
isContextClosed
public boolean isContextClosed(org.graalvm.polyglot.Context context) -
getScriptDb
public ScriptSqliteDB getScriptDb(String name, org.graalvm.polyglot.Context context, String baseScriptName) 按 name 获取/创建 SQLite DB 实例(按 (context, 文件) 缓存,跨脚本/跨 reload 复用)。路径解析(与
mclds().io.storage的绝对路径约定一致):name为绝对路径(Unix 以/开头,Windows 含盘符如C:\...)→ 按该绝对路径打开/创建,路径原样使用、不补.db扩展名, 便于多个子服指向同一共享文件;SQLite WAL 模式原生支持多进程并发读 + 单写, 不会像 MapDB 排他锁那样阻塞其他子服;- 否则按裸名解析到
dbFolder/<name>.db(原行为不变)。
缓存 key 用规范化后的绝对路径(而非裸 name),保证同一文件经不同入参 (裸名 / 绝对路径 / 不同写法)只开一个实例(同 Context 内)。
按 (context, 文件) 分桶而非全局共享:get() 用 Context 的 JSON.parse 返回 JS 原生值, 跨 Context 共享实例会在异步回调里触发 GraalJS 多线程报错(与 ScriptLocalStorage 同理)。 不同 Context 各自一份 Connection 指向同一文件,并发由 SQLite WAL 协调。
-
parseListener
@Nullable public @Nullable ScriptEnginPlugin.ScriptListener parseListener(org.graalvm.polyglot.Context context, Map<?, ?> map) -
parseCommand
public ScriptEnginPlugin.ScriptCommand parseCommand(org.graalvm.polyglot.Context context, Map<?, ?> map) -
resolveRequirePath
@Nullable public @Nullable Path resolveRequirePath(Path baseScript, String require_path) throws IOException Node.js 风格 require 路径解析。 支持:相对路径、.js/.json 扩展名补全、目录 index.js/index.json、package.json main、node_modules 向上查找。- Parameters:
baseScript- 当前调用 require 的脚本路径(用于解析相对路径基准与 node_modules 起始向上查找)require_path- require 参数- Returns:
- 规范化后的目标文件 Path,找不到返回 null
- Throws:
IOException
-