Class ScriptEnginPlugin

java.lang.Object
com.mclds.plugins.customplugin.CustomPlugin
com.mclds.plugins.scriptengin.ScriptEnginPlugin

public class ScriptEnginPlugin extends CustomPlugin
  • Field Details

  • 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

      public void onEnable() throws IOException
      Overrides:
      onEnable in class CustomPlugin
      Throws:
      IOException
    • onDisable

      public void onDisable()
      Overrides:
      onDisable in class CustomPlugin
    • applyScripts

      public void applyScripts(File scriptFolder) throws IOException
      Throws:
      IOException
    • loadScript

      public ScriptEnginPlugin.Script loadScript(Path scriptPath)
    • 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

      public void closeOneScript(Path path)
    • 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