feat: support Nukkit and async init engine
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
9bcd4cd748
commit
367b732f7c
4
pom.xml
4
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>pw.yumc</groupId>
|
||||
<artifactId>MiaoScript</artifactId>
|
||||
<version>0.2.0</version>
|
||||
<version>0.3.0</version>
|
||||
<developers>
|
||||
<developer>
|
||||
<id>502647092</id>
|
||||
@ -54,6 +54,8 @@
|
||||
<properties>
|
||||
<env.GIT_COMMIT>DEV</env.GIT_COMMIT>
|
||||
<update.changes>
|
||||
§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 支持;
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -1,10 +0,0 @@
|
||||
#MySQL数据库配置
|
||||
DataBase:
|
||||
#默认数据库
|
||||
def:
|
||||
#数据库需要自行建立
|
||||
database: minecraft
|
||||
username: root
|
||||
password: root
|
||||
ip: 127.0.0.1
|
||||
port: 3306
|
@ -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')
|
||||
}
|
||||
|
6
src/main/resources/nukkit.yml
Normal file
6
src/main/resources/nukkit.yml
Normal file
@ -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
|
@ -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:
|
||||
|
@ -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]
|
Loading…
Reference in New Issue
Block a user