From 367b732f7c488d94028f515f93729f781a3432e6 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Sat, 29 Feb 2020 17:32:53 +0800 Subject: [PATCH] feat: support Nukkit and async init engine Signed-off-by: MiaoWoo --- pom.xml | 4 +- .../pw/yumc/MiaoScript/MiaoScriptNukkit.java | 1 + src/main/resources/bios.js | 11 +- src/main/resources/config.yml | 10 -- src/main/resources/core/ployfill.js | 1 + src/main/resources/nukkit.yml | 6 + src/main/resources/plugin.yml | 4 +- src/main/resources/script.yml | 114 ------------------ 8 files changed, 19 insertions(+), 132 deletions(-) delete mode 100644 src/main/resources/config.yml create mode 100644 src/main/resources/nukkit.yml delete mode 100644 src/main/resources/script.yml diff --git a/pom.xml b/pom.xml index 148921c..d86f662 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 pw.yumc MiaoScript - 0.2.0 + 0.3.0 502647092 @@ -54,6 +54,8 @@ DEV + §620-02-27 §afeat: 异步加载脚本引擎; + §620-02-25 §afeat: 新增 Nukkit 的支持; §620-02-16 §afeat: 新增 Source Map 支持; §620-02-02 §afeat: 迁移 ployfill 到 @ms/ployfill; §620-01-14 §afeat: 新增 Bungee 支持; diff --git a/src/main/java/pw/yumc/MiaoScript/MiaoScriptNukkit.java b/src/main/java/pw/yumc/MiaoScript/MiaoScriptNukkit.java index f2fe3bc..6ab3dbb 100644 --- a/src/main/java/pw/yumc/MiaoScript/MiaoScriptNukkit.java +++ b/src/main/java/pw/yumc/MiaoScript/MiaoScriptNukkit.java @@ -12,6 +12,7 @@ public class MiaoScriptNukkit extends PluginBase { @Override @SneakyThrows public void onEnable() { + Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); engine = new ScriptEngine(getDataFolder().getCanonicalPath(), getLogger(), this); engine.enableEngine(); } diff --git a/src/main/resources/bios.js b/src/main/resources/bios.js index fb9a77c..e433a11 100644 --- a/src/main/resources/bios.js +++ b/src/main/resources/bios.js @@ -27,11 +27,12 @@ var global = this; // Check Class Loader, Sometimes Server will can't find plugin.yml file loader = checkClassLoader(); // Force decompression core|node_modules to folder when not debug mode - release(root, '(core|node_modules)+/.*', !global.debug); - // Plugin file decompression to folder when file not exist - release(root, '(plugins)+/.*', false); - load(root + '/core/ployfill.js')(root, logger); - engineDisable = require('@ms/core').default; + release(root, '(core)+/.*', !global.debug); + // Async Loading MiaoScript Engine + new java.lang.Thread(function() { + load(root + '/core/ployfill.js')(root, logger); + engineDisable = require('@ms/core').default; + }, "MiaoScript thread").start() }; var pluginYml; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml deleted file mode 100644 index e6d9c5b..0000000 --- a/src/main/resources/config.yml +++ /dev/null @@ -1,10 +0,0 @@ -#MySQL数据库配置 -DataBase: - #默认数据库 - def: - #数据库需要自行建立 - database: minecraft - username: root - password: root - ip: 127.0.0.1 - port: 3306 diff --git a/src/main/resources/core/ployfill.js b/src/main/resources/core/ployfill.js index 527f4f9..0bccdb4 100644 --- a/src/main/resources/core/ployfill.js +++ b/src/main/resources/core/ployfill.js @@ -14,6 +14,7 @@ global.setGlobal = function(key, value) { global[key] = value; }; // Init console and require global.console = engineLoad(global.root + '/core/console.js')(logger); + console.log("Loading Engine at Thread", java.lang.Thread.currentThread().name) global.require = engineLoad(global.root + '/core/require.js')(root); require('@ms/ployfill') } diff --git a/src/main/resources/nukkit.yml b/src/main/resources/nukkit.yml new file mode 100644 index 0000000..f596479 --- /dev/null +++ b/src/main/resources/nukkit.yml @@ -0,0 +1,6 @@ +name: ${project.artifactId} +description: ${project.description} +main: ${project.groupId}.${project.artifactId}.${project.artifactId}Nukkit +version: ${project.version} +api: "1.0.0" +author: MiaoWoo diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 110a56e..1cbd1fa 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,8 +1,8 @@ name: ${project.artifactId} description: ${project.description} main: ${project.groupId}.${project.artifactId}.${project.artifactId} -version: ${project.version}-git-${env.GIT_COMMIT} -author: 喵♂呜 +version: ${project.version} +author: MiaoWoo website: ${ciManagement.url} load: STARTUP softdepend: diff --git a/src/main/resources/script.yml b/src/main/resources/script.yml deleted file mode 100644 index 26e66fc..0000000 --- a/src/main/resources/script.yml +++ /dev/null @@ -1,114 +0,0 @@ -#脚本名称 -#xxxxx: -# 脚本表达式 -# expression: | [这里写"|"则下方缩进均为一行 请看案例] -# if( x = y ) { -# 省略代码 -# } -# expression: "Player.getDisplayName()" -# PS: JS表达式 支持调用Bukkit的内部方法 -# 当前支持Bukkit(Server),Player,Event -# Bukkit(或Server): 调用的是服务器数据 -# - getOnlinePlayer().size(): 在线玩家数量 -# - broadcastMessage('xxx'): 公告xxx -# - getConsoleSender(): 获得控制台 -# - dispatchCommand(Bukkit.getConsoleSender(),"xxx"): 控制台执行xxx命令 -# - dispatchCommand(Player,"xxx"): 玩家执行xxx命令 -# 更多的方法请查询: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Bukkit.html -# -# Player: 调用玩家对象 常用方法有: -# - getName(): 玩家名称 -# - getDisplayName(): 玩家显示名称 -# - hasPermission("xxx"): 判断玩家是否有xxx权限 -# - sendMessage("xxx"): 向玩家发送xxx消息 -# - isOp():是否为OP -# - setFlying(true 或 false): 设置飞行 -# - setHealth(20): 设置玩家血量 -# 更多的方法请查询: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/Player.html -# -# Event: 调用事件 不同事件有不同的参数 常用方法如下: -# - setCancelled(true): 用于取消事件 -# 更多的方法请查询: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerEvent.html -# -# Data: 数据库支持 -# - get("def") 获得默认数据库配置 详见config.yml -# 例: -# var db = Data.get("def"); -# == 创建表 ====================================== -# var sql = 'CREATE TABLE IF NOT EXISTS `MiaoScript` ( `id` INTEGER PRIMARY KEY AUTO_INCREMENT, `name` VARCHAR(30), `script` VARCHAR(600)) ENGINE = InnoDB DEFAULT CHARSET=UTF8"'; -# db.execute(sql); - #增删改 返回值为数据库改动条数 -# == 插入数据 ==================================== -# var sql = 'INSERT INTO `MiaoScript` (`name`, `script`) VALUES ("setOp", "Player.setOp(false)")'; -# var result = db.update(sql); -# if ( result >1 ){ -# Log.info("数据添加成功!"); -# } -# == 更新数据 ==================================== -# var sql = 'UPDATE `MiaoScript` SET `script` = "Player.setOp(true)" WHERE name = "setOp"'; -# var result = db.update(sql); -# == 删除数据 ==================================== -# var sql = 'DELETE FROM `MiaoScript` WHERE name = "setOp"'; -# var result = db.update(sql); -# =============================================== - -# [Config, PlayerConfig(玩家数据)]: 调用数据存储 若崩服数据可能丢失 -# - set("key","value"): 保存一条键为key值为value的数据 -# - get("key"): 获得键为key的值 -# - getStringList("dirChat"): 获得键为dirChat的字符串列表 -# - save(): 保存数据到硬盘 -# 更多的方法请查询: https://hub.spigotmc.org/javadocs/spigot/org/bukkit/configuration/ConfigurationSection.html -# -# Log: 调用插件日志系统 -# - info("xxx"): 输出信息xxx到日志 -# - warning("xxx"): 输出警告xxx -# 更多的方法请查询: http://docs.oracle.com/javase/7/docs/api/java/util/logging/Logger.html -# -# type: "boolean" 或 "string" 不写 默认为string -# #下面两个参数 当type为boolean时才有效 -# trueResult: '&c管理员' [脚本返回True时的返回值] -# falseResult: '&a玩家' [脚本返回False时的返回值] -# -#脚本名称 -welcome: - #脚本表达式 - expression: 'file: welcome.js' - -#物品丢弃检测 -checkDrop: - expression: | - function handle(Event){ - if( Event.getItemDrop().getItemStack().getType().name().contains("DIAMOND") ){ - Player.sendMessage("&6[&b警告&6] &c您可能丢弃了一件贵重物品!"); - } - } - -#获得玩家前缀 -getPrefix: - expression: Player.isOp() - #脚本返回值 - type: boolean - #脚本返回True时的返回值 - trueResult: '&c管理员' - #脚本返回False时的返回值 - falseResult: '&a玩家' - -#获取玩家的显示名称 -getDisplayName: - expression: Player.getDisplayName() - type: string - -#开启玩家飞行模式 -flyon: - expression: 'Player.setAllowFlight(true);Player.sendMessage("&6[&bMiaoScript&6] &a已为您开启飞行模式!")' -#关闭玩家飞行模式 -flyoff: - expression: | - Player.setAllowFlight(false); - Player.sendMessage("&6[&bMiaoScript&6] &a已为您关闭飞行模式!"); - -#top命令 -top: - expression: | - Player.teleport(Player.getWorld().getHighestBlockAt(Player.getLocation()).getLocation()); - commands: [top] \ No newline at end of file