Compare commits
170 Commits
v0.23.0-al
...
v0.4.0
| Author | SHA1 | Date | |
|---|---|---|---|
| d9a2ea9c78 | |||
| c505cda10b | |||
| 100ccbcde3 | |||
| c6575ed481 | |||
| 83359d8cb9 | |||
| cca4979f16 | |||
| 251c9366f5 | |||
| 8f01dcc8e8 | |||
| c25a616dba | |||
| aa9169b043 | |||
| d87e152f3b | |||
| 2fcadeda4e | |||
| b7927830ae | |||
| 2dbd2182c2 | |||
| 01df79eaf1 | |||
| 16fe9ba9bd | |||
| 950ce69b83 | |||
| fa8e44d838 | |||
| b7af785273 | |||
| 6c9f7bbcf6 | |||
| c4c4c7f301 | |||
| 6538c4b7bb | |||
| a4e6d1660d | |||
| 511b042eba | |||
| 6f0b5a5572 | |||
| e9ac46487c | |||
| 9371823d30 | |||
| c86f0d9ec1 | |||
| c2d94ef104 | |||
| 6ada3e41d0 | |||
| 8c12319dc9 | |||
| 395d2d8816 | |||
| 6f628a3d7e | |||
| 2232e82c36 | |||
| 291b5010e7 | |||
| 3595294444 | |||
| e38358ef98 | |||
| 4c418c33c0 | |||
| 65d112be09 | |||
| 15a75dffe2 | |||
| 7b8e693a03 | |||
| 5426023adb | |||
| 73b91c417e | |||
| 2693a22bf0 | |||
| 2322de1e40 | |||
| 2320736a92 | |||
| e8d5d10d44 | |||
| a9996ba297 | |||
| 68380ddbba | |||
| 0baf8f3cab | |||
| a2bce715f3 | |||
| 3c55df03d8 | |||
| f6526e79fc | |||
| f4c2294c06 | |||
| cf9508ba31 | |||
| e0f4c5e77d | |||
| e4a87095ce | |||
| 950575edbc | |||
| c2a71b9a7a | |||
| 068ac7b76e | |||
| 05cbd85828 | |||
| ea28d20aa1 | |||
| d3f33f50e0 | |||
| d004ba17e6 | |||
| 7a25dd8b3b | |||
| dedc8393da | |||
| 8d344492d9 | |||
| 81a76af7be | |||
| b458da7a6e | |||
| 45cb6fa667 | |||
| 9c4543df30 | |||
| 512bdb22c5 | |||
| f6e39c131c | |||
| 73d4dad7f6 | |||
| de4a22362f | |||
| 5fde2e5554 | |||
| 6a6765e5c3 | |||
| 4a1f25ee6a | |||
| 5999567ee3 | |||
| fad4e27a7f | |||
| b477938e4f | |||
| 7cbd91826a | |||
| 6797761a2f | |||
| be114e6d1b | |||
| 3e40934339 | |||
| 3e6c7b2d8c | |||
| 6c0bb75561 | |||
| a47896a97f | |||
| 1d97bbc9ce | |||
| b1f1f9837e | |||
| 99dee28fd4 | |||
| c7f66d8252 | |||
| 8c4f266356 | |||
| 39e899211b | |||
| da72a0dac6 | |||
| 9984787202 | |||
| 4493d35786 | |||
| e1aad59eeb | |||
| 849393492f | |||
| 1ff33702d8 | |||
| e68005fd6f | |||
| 17269b50f4 | |||
| 363d0c164a | |||
| 13a0b62103 | |||
| cb4e152800 | |||
| fb83acfcc8 | |||
| 7263fbb437 | |||
| 23868a58b9 | |||
| effa7f70ec | |||
| eef0baa740 | |||
| 4d0c0122c7 | |||
| aa581afbe5 | |||
| 1425c473fd | |||
| 53e4f6c658 | |||
| 73db4a9169 | |||
| a2efd878db | |||
| 4e6cda0545 | |||
| 859a3a9171 | |||
| 96481032c5 | |||
| f950c3dae8 | |||
| 9248294cb3 | |||
| 53873d7b63 | |||
| be59ae480b | |||
| 9fa3ed704a | |||
| a76858d626 | |||
| 55a6b33110 | |||
| b87b94aade | |||
| 4110ed2c20 | |||
| 3cbc101eff | |||
| 221b821085 | |||
| 7331cfaa55 | |||
| 40d020ef67 | |||
| eea2a225e8 | |||
| 48f7f0fdbb | |||
| 99ed76f9bb | |||
| 7f21fa67ee | |||
| 8584709828 | |||
| d1f58e7482 | |||
| 1bd35aef6d | |||
| fdf1088564 | |||
| 7bb4d1f6a3 | |||
| b8c3d0d19d | |||
| a616a07553 | |||
| 781524f83e | |||
| c7a812c003 | |||
| 325f2c8cf9 | |||
| 562e2d0017 | |||
| b7871e8d33 | |||
| 060cffd8e7 | |||
| 4b1fb07cc9 | |||
| 0931d69188 | |||
| 7d33368ebd | |||
| c95fc5fcff | |||
| a7479f60c8 | |||
| ac75356778 | |||
| 7f32382dbc | |||
| b3c2def36d | |||
| 1ea93dfb9f | |||
| e5ffa70ed9 | |||
| 2a60b36e23 | |||
| c4c2c0ab0f | |||
| bf5628a646 | |||
| 13e9f0a5af | |||
| cdd5f2d250 | |||
| dfd7182008 | |||
| 533859808f | |||
| 15cea1dfc8 | |||
| dfa43d58f0 | |||
| 2bf239d8ea | |||
| cbe87cc378 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,8 @@
|
||||
.vscode
|
||||
.theia
|
||||
node_modules
|
||||
dist
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
packages/nashorn/docs
|
||||
!packages/types/dist
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
src
|
||||
test
|
||||
typings
|
||||
bundled
|
||||
@@ -19,4 +18,5 @@ wallaby.js
|
||||
.travis.yml
|
||||
.gitignore
|
||||
.vscode
|
||||
type_definitions
|
||||
.theia
|
||||
type_definitions
|
||||
34
README.MD
Normal file
34
README.MD
Normal file
@@ -0,0 +1,34 @@
|
||||
# MiaoScript implement
|
||||
|
||||
## MiaoScript JS 实现
|
||||
|
||||
项目 由 TypeScript 进行编写 然后编译至 `es5` 用于兼容 Java8 的 `Nashorn`
|
||||
|
||||
### Project Path
|
||||
|
||||
```txt
|
||||
└─packages
|
||||
├─api 全平台兼容的接口
|
||||
├─core 核心代码 用于引导加载
|
||||
├─common 公共类库代码 例如 http reflect 模块
|
||||
├─client NodeJS的Minecraft客户端 用于调试插件
|
||||
├─container IOC容器 用于注入具体实现
|
||||
├─ployfill Nashorn 的一些自定义增强
|
||||
├─nashorn Nashorn 的类型定义
|
||||
├─bungee BungeeCordAPI内部实现
|
||||
├─bukkit BukkitAPI内部实现
|
||||
├─sponge SpongeAPI内部实现
|
||||
├─nukkit NukkitAPI内部实现
|
||||
├─plugin 插件管理器
|
||||
├─websocket Netty的WebSocket注入
|
||||
├─type Java的类型定义
|
||||
| ├─bungee BungeeCord类型定义
|
||||
| ├─bukkit Bukkit类型定义
|
||||
| ├─sponge Sponge类型定义
|
||||
| └─nukkit Nukkit类型定义
|
||||
└─plugins 这里当然是插件啦
|
||||
├─bungee 只兼容BungeeCord的插件
|
||||
├─bukkit 只兼容Bukkit的插件
|
||||
├─sponge 只兼容Sponge的插件
|
||||
└─nukkit 只兼容Nukkit的插件
|
||||
```
|
||||
478
doc/MCBBS.MD
Normal file
478
doc/MCBBS.MD
Normal file
@@ -0,0 +1,478 @@
|
||||
- 构建状态 [](https://ci.yumc.pw/job/Minecraft/job/MiaoScript/)
|
||||
- 当前版本 
|
||||
- 下载地址 [](http://w.yumc.pw/free.html#MiaoScript-download)
|
||||
- 为了方便阅读 我对帖子进行了分页 请点击目录阅读!
|
||||
|
||||
### 更新日志
|
||||
|
||||
- 2020-03-03
|
||||
- 发布 `v0.3.1` 版本
|
||||
- 2020-03-02
|
||||
- 杂项 更新文档以及示例插件
|
||||
- 2020-03-01
|
||||
- 修复 多个包之间的循环依赖问题
|
||||
- 优化 `@ms/types` 的引用逻辑
|
||||
- 2020-02-29
|
||||
- 更新 `TypeScript` 版本为 `3.8.3`
|
||||
- 新增 `@ms/common` 的 `http` 下载功能
|
||||
- 2020-02-27
|
||||
- 发布 `v0.3.0` 版本
|
||||
- 新增 `@ms/i18n` 国际化包的支持
|
||||
- 修复 `@ms/plugin` 对 `servers` 相关处理异常
|
||||
- 优化 `@ms/api` 的 `Channel` 处理增加 扩展原始数据
|
||||
- 2020-02-26
|
||||
- 优化 `@ms/container` 使用 `autoProvide` 自动注入依赖
|
||||
- 2020-02-25
|
||||
- 修复 `@ms/api` 对 `evnet` 的类型处理异常
|
||||
- 2020-02-24
|
||||
- 发布 `v0.2.1` 版本
|
||||
- 完善 对 `Nukkit` 端的支持
|
||||
- 新增 `@ms/api` 通道相关的支持
|
||||
- 2020-02-23
|
||||
- 新增 `@ms/nukkit` 包 对 `Nukkit` 端的支持
|
||||
- 新增 `@ms/type` 的 `nukkit` 类型自动补全
|
||||
- 2020-02-22
|
||||
- 发布 `v0.2.0` 版本
|
||||
- 新增 `@ms/plugin` 的 `@config` 注解 目前支持 `json` `yml` 格式的配置
|
||||
- 2020-02-15
|
||||
- 新增 `SourceMap` 的支持 用于跟踪源代码行数
|
||||
- 2020-02-09
|
||||
- 新增 `core-js` 用于支持大部分新ES语法
|
||||
- 2020-01-31
|
||||
- 优化 `@ms/ployfill` 全局处理
|
||||
- 2020-01-15
|
||||
- 新增 `@ms/bungee` 包 对 `BungeeCord` 端的支持
|
||||
- 2020-01-14
|
||||
- 新增 `@ms/type` 的 `bungee` 类型自动补全
|
||||
- 2019-11-10
|
||||
- 新增 `WebSocket` 的注入支持
|
||||
- 2019-11-07
|
||||
- 新增 `@ms/type` 的 `jdk` 类型自动补全
|
||||
- 2019-09-27
|
||||
- 新增 `CatServer` MOD端的支持
|
||||
- 2019-09-25
|
||||
- 新增 `@ms/type` 的 `sponge` 类型自动补全
|
||||
- 2019-09-24
|
||||
- 新增 `@ms/type` 的 `bukkit` 类型自动补全
|
||||
|
||||
## 插件简介
|
||||
|
||||
- 此插件可以实现跨端使用 `TypeScript` 开发 脚本插件
|
||||
- 目前已经兼容 `Spigot` `Sponge` `Paper` `CatServer` `BungeeCord` `Nukkit`
|
||||
- 后续计划兼容 暂无
|
||||
|
||||
## 起源 (可以略过)
|
||||
|
||||
### 简介
|
||||
|
||||
> 这个坑是我自己刨的 但是发现坑太大 需要更多的人一起填
|
||||
|
||||
### 起源
|
||||
|
||||
- 诞生于 `2016年08月25日` 这是 Git 上的第一个提交 具体啥时候我也忘了
|
||||
- 起初 `MiaoScript` 只是用于服务器其他插件的变量执行 并且依赖于PAPI(不知道是啥的自己百度)
|
||||
- 比如 [`MiaoMenu`](http://w.yumc.pw/zc/MiaoMenu.html) 的部分复杂脚本
|
||||
- 比如 [`MiaoChat`](http://mcbbs.net/thread-631240-1-1.html) 的聊天变量
|
||||
- 突然有一天 圈内的大佬 `QSB` @qiu1995 过来找我 说能不能用脚本监听玩家的事件
|
||||
- PS: 这货自从用过 `DeluxeMenu` 之后就喜欢上了用JS写菜单
|
||||
- 当初感觉没啥问题 就出了第一个简易的 `MiaoScript` 版本 还是用 yml 做的配置文件
|
||||
- 但是由于设计 BukkitAPI 等内容 对Java要求太高 后来 邱也弃坑了 我也弃坑了
|
||||
|
||||
### 刨坑
|
||||
|
||||
- 时隔多年(也就一年) 看到了Sponge的兴起 (估摸着是MCPC系列的MOD端都弃坑了)
|
||||
- 同时 这期间 收到很多腐竹的单子 但是又是非常基础的东西
|
||||
- 比如 开服给玩家发一条消息啦
|
||||
- 比如 修改玩家某些数据啦
|
||||
- 这些东西实际上也就几行代码的事情
|
||||
- 同时 很多想入坑 插件开发 但是又有一些被卡死在环境搭建上
|
||||
- 比如 `Bukkit` 需要 `BukkitAPI`
|
||||
- `Sponge` 需要 `SpongeAPI` 如果涉及 `MOD` 还要 `Forge` 环境
|
||||
- 再或者 BungeeCord 的插件开发 我也是经常懒得搞
|
||||
- 当然 最主要的是 某个 咕咕咕的群 天天有人问我 喵系插件能不能支持 Sponge
|
||||
- 内心当然是拒绝的 现在要上班养老婆孩子(咳咳 不要以为我是大叔 我也才刚毕业而已) 那里还有时间免费给你们写插件
|
||||
- 于是乎 我又想起了当初的 `MiaoScript`
|
||||
- 突发奇想 一个插件的雏形出现在我的脑海中
|
||||
- 可以兼容多种服务器
|
||||
- 不需要开发环境 有记事本就可以开发
|
||||
- 语法要简单 比如 JavaScript
|
||||
- 能够自动搜索安装依赖(毕竟很多人天天问我为何喵系插件跑不起来 都是缺少PAPI)
|
||||
- 能够不重启更新插件(当然得保证代码安全的前提下)
|
||||
- 在 2017年9月14号(距离 第一个版本正式版发布(2016-09-21) 相差一年整)
|
||||
- 一个全新的 `MiaoScript` 诞生了
|
||||
- Java部分代码 只有一个启动类
|
||||
- 核心全部由 JS 编写
|
||||
- 兼容 `CommonJS` 规范
|
||||
- 实时重载
|
||||
- 2019年9月14号 emm 咸鱼2年之后
|
||||
- TypeScript 重构版本横空出世
|
||||
- 只保留 基础Java启动类 三个环境初始化js
|
||||
- 完整的服务端Java类自动补全
|
||||
- 全新的 IOC容器 注入功能
|
||||
- 注解式 注册命令 注册事件
|
||||
- 2020年3月2日 发布0.3.0版本
|
||||
- 支持 Bukkit Nukkit BungeeCord Sponge
|
||||
|
||||
### 进展
|
||||
|
||||
- [项目发布](https://git.yumc.pw/502647092/MiaoScript/releases)
|
||||
- [项目代码](https://git.yumc.pw/502647092/MiaoScript)
|
||||
- [项目脑图](http://naotu.baidu.com/file/293b9a0fc7cef23c69de81c55e3617d5?token=1eee8fd759198eb7)
|
||||
|
||||
### 规划
|
||||
|
||||
- 初期只会支持JS类型的插件开发
|
||||
- 二期会出一个建议版本的MS脚本 可以用简单的语法实现简单的功能
|
||||
- 各个层级会有依赖控制 比如 `MS脚本 => JS脚本 => 调用Java原生API`
|
||||
|
||||
## 框架设计
|
||||
|
||||
### MiaoScript TS 实现
|
||||
|
||||
项目具体实现 由 TypeScript 进行编写 然后编译至 `es5` 用于兼容 Java8 的 `Nashorn`
|
||||
|
||||
### Project Structure
|
||||
|
||||
```txt
|
||||
└─packages
|
||||
├─api 全平台兼容的接口
|
||||
├─core 核心代码 用于引导加载
|
||||
├─common 公共类库代码 例如 http reflect 模块
|
||||
├─client NodeJS的Minecraft客户端 用于调试插件
|
||||
├─container IOC容器 用于注入具体实现
|
||||
├─ployfill Nashorn 的一些自定义增强
|
||||
├─nashorn Nashorn 的类型定义
|
||||
├─bungee BungeeCordAPI内部实现
|
||||
├─bukkit BukkitAPI内部实现
|
||||
├─sponge SpongeAPI内部实现
|
||||
├─nukkit NukkitAPI内部实现
|
||||
├─ployfill JS环境的相关环境补全
|
||||
├─plugin 插件管理器
|
||||
├─websocket Netty的WebSocket注入
|
||||
├─type Java的类型定义
|
||||
| ├─bungee BungeeCord类型定义
|
||||
| ├─bukkit Bukkit类型定义
|
||||
| ├─sponge Sponge类型定义
|
||||
| └─nukkit Nukkit类型定义
|
||||
└─plugins 这里当然是插件啦
|
||||
├─bungee 只兼容BungeeCord的插件
|
||||
├─bukkit 只兼容Bukkit的插件
|
||||
├─sponge 只兼容Sponge的插件
|
||||
└─nukkit 只兼容Nukkit的插件
|
||||
```
|
||||
|
||||
详细的内容就不逼逼了 自己看代码吧
|
||||
|
||||
Github: https://github.com/circlecloud/ms
|
||||
YUMC: https://git.yumc.pw/circlecloud/ms
|
||||
|
||||
## 插件开发基础
|
||||
|
||||
### 开发IDE (推荐VSCode或者MiaoScrit在线IDE)
|
||||
|
||||
如果只是简单的开发 你可用记事本 (但是没有任何补全和错误提示)
|
||||
|
||||
### 开发环境准备(针对高级用户)
|
||||
|
||||
- 安装 `NodeJS` 和 `Yarn`
|
||||
- 拉取代码
|
||||
- `git clone https://github.com/circlecloud/ms.git`
|
||||
- 进入目录 `ms`
|
||||
- 安装 npm 包
|
||||
- `yarn`
|
||||
- 建立内部依赖链接
|
||||
- `yarn bs`
|
||||
- 编译一次生成对应的类库
|
||||
- `yarn build`
|
||||
- 编译插件
|
||||
- `yarn build:plugins`
|
||||
|
||||
### 直接在 MiaoScript Online WebIDE 开发
|
||||
|
||||
填坑中...
|
||||
|
||||
## 基本插件框架
|
||||
|
||||
### HelloWorld 示例插件
|
||||
|
||||
先来一个 `HelloWorld.ts` 插件示范!
|
||||
|
||||
```ts
|
||||
/// <reference types="@ms/types" />
|
||||
|
||||
import { server } from '@ms/api';
|
||||
import { inject } from '@ms/container';
|
||||
import { plugin, interfaces, cmd, listener, tab } from '@ms/plugin'
|
||||
|
||||
@plugin({ name: 'HelloWorld', version: '1.0.0', author: 'MiaoWoo', source: __filename })
|
||||
export class HelloWorld extends interfaces.Plugin {
|
||||
@inject(server.Server)
|
||||
private Server: server.Server
|
||||
@config()
|
||||
private config = {
|
||||
version: 1.0.0
|
||||
}
|
||||
|
||||
load() {
|
||||
this.logger.log('Plugin load from MiaoScript Plugin System...');
|
||||
}
|
||||
enable() {
|
||||
this.logger.log('Plugin enable from MiaoScript Plugin System...');
|
||||
}
|
||||
disable() {
|
||||
this.logger.log('Plugin disable from MiaoScript Plugin System...');
|
||||
}
|
||||
|
||||
bukkitload() {
|
||||
this.logger.log('Load When ServerType is Bukkit!')
|
||||
}
|
||||
bukkitenable() {
|
||||
this.logger.log('Enable When ServerType is Bukkit!')
|
||||
}
|
||||
bukkitdisable() {
|
||||
this.logger.log('Disable When ServerType is Bukkit!')
|
||||
}
|
||||
|
||||
spongeload() {
|
||||
this.logger.log('Load When ServerType is Sponge!')
|
||||
}
|
||||
spongeenable() {
|
||||
this.logger.log('Enable When ServerType is Sponge!')
|
||||
}
|
||||
spongedisable() {
|
||||
this.logger.log('Disable When ServerType is Sponge!')
|
||||
}
|
||||
|
||||
bungeeload() {
|
||||
this.logger.log('Load When ServerType is BungeeCord!')
|
||||
}
|
||||
bungeeenable() {
|
||||
this.logger.log('Enable When ServerType is BungeeCord!')
|
||||
}
|
||||
bungeedisable() {
|
||||
this.logger.log('Disable When ServerType is BungeeCord!')
|
||||
}
|
||||
|
||||
nukkitload() {
|
||||
this.logger.log('Load When ServerType is Nukkit!')
|
||||
}
|
||||
nukkitenable() {
|
||||
this.logger.log('Enable When ServerType is Nukkit!')
|
||||
}
|
||||
nukkitdisable() {
|
||||
this.logger.log('Disable When ServerType is Nukkit!')
|
||||
}
|
||||
|
||||
@cmd()
|
||||
hello(sender: any, command: string, args: string[]) {
|
||||
this.logger.log(sender, command, args);
|
||||
sender.sendMessage(JSON.stringify({ command, ...args }))
|
||||
}
|
||||
|
||||
@tab()
|
||||
tabhello(_sender: any, _command: string, _args: string[]) {
|
||||
return ['world']
|
||||
}
|
||||
|
||||
// bukkit nukkit 大部分API神似 可以直接用
|
||||
@listener({ servers: ['bukkit', 'nukkit'] })
|
||||
PlayerJoin(event: org.bukkit.event.player.PlayerJoinEvent) {
|
||||
let plyaer = event.getPlayer();
|
||||
this.logger.console(`§cBukkit §aPlayerJoinEvent: §b${plyaer.getName()}`)
|
||||
setTimeout(() => this.sendWelcome(plyaer), 10);
|
||||
}
|
||||
|
||||
@listener({ servers: ['sponge'] })
|
||||
ClientConnectionEvent$Join(event: org.spongepowered.api.event.network.ClientConnectionEvent.Join) {
|
||||
this.logger.console(`§cSponge §aClientConnectionEvent.Join: §b${event.getTargetEntity().getName()}`)
|
||||
setTimeout(() => this.sendWelcome(event.getTargetEntity()), 10);
|
||||
}
|
||||
|
||||
private sendWelcome(player: any) {
|
||||
this.logger.sender(player, `§a欢迎来到 §bMiaoScript §a的世界!`)
|
||||
this.logger.sender(player, `§6当前版本: §c${this.Server.getVersion()}`)
|
||||
}
|
||||
|
||||
@listener({ servers: ['bungee'] })
|
||||
ServerConnected(e: any) {
|
||||
let event = e as net.md_5.bungee.api.event.ServerConnectedEvent
|
||||
this.logger.console(`§cBungeeCord §aServerConnectedEvent: §b${event.getPlayer().getDisplayName()}`)
|
||||
setTimeout(() => this.logger.sender(event.getPlayer(), `§a欢迎来到 §bMiaoScript §a的世界 §6来自 §cBungeeCord §6的问候!`), 10);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- 进入 `ms`目录
|
||||
- 执行编译 `yarn build:plugins`
|
||||
- 从 `packages/plugins/dist` 中复制 `HelloWorld.js` 和 `HelloWorld.js.map`(可选 用于显示插件原有行数) 文件 到对应的插件目录
|
||||
- Bungee: plugins/MiaoScript/plugins/
|
||||
- Bukkit: plugins/MiaoScript/plugins/
|
||||
- Sponge: config/miaoscript/plugins/
|
||||
- Nukkit: plugins/MiaoScript/plugins/
|
||||
- 重载 `MiaoScript`
|
||||
- 打开客户端进入游戏 预览一下效果
|
||||
- 从 Spigot 服务端进入
|
||||

|
||||

|
||||
- 从 Sponge 服务端进入
|
||||

|
||||

|
||||
|
||||
## 注册插件
|
||||
|
||||
- 从上面的示例可以看到 一个插件 通过注解 `@plugin` 即可启动
|
||||
- 此注解接受一个 `PluginMetadata` 对象 定义如下
|
||||
```ts
|
||||
export interface PluginMetadata {
|
||||
/**
|
||||
* 插件名称
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* 支持的服务器列表 为空则代表所有
|
||||
*/
|
||||
servers?: string[];
|
||||
/**
|
||||
* 前缀
|
||||
*/
|
||||
prefix?: string;
|
||||
/**
|
||||
* 插件版本
|
||||
*/
|
||||
version: string;
|
||||
/**
|
||||
* 插件版本
|
||||
*/
|
||||
author: string | string[];
|
||||
/**
|
||||
* 插件源文件 必须指定为 __filename
|
||||
*/
|
||||
source: string;
|
||||
/**
|
||||
* 插件本体
|
||||
*/
|
||||
target?: any;
|
||||
}
|
||||
```
|
||||
|
||||
### 插件生命周期
|
||||
|
||||
MiaoScript 的生命周期遵循了 Bukkit 的生命周期
|
||||
|
||||
MiaoScript 针对不同的服务端 提供了扩展的周期
|
||||
以服务端类型开头阶段名结束 例如 `bukkitload` `spongeenbale` `bungeedisable`
|
||||
扩展的生命周期只会在特定的服务器执行
|
||||
|
||||
### load 加载阶段
|
||||
|
||||
此阶段通常用于初始化基础配置 数据库链接等
|
||||
某些对外提供功能的插件 需要在此阶段初始化完成
|
||||
|
||||
### enable 启动阶段
|
||||
|
||||
此阶段通常用于注册命令 注册事件等
|
||||
由于命令和事件 MiaoScript 已经托管了 所以开发者可以直接用注解实现
|
||||
|
||||
### disable 关闭阶段
|
||||
|
||||
此阶段通常用于注销命令 注销事件等
|
||||
由于命令和事件 MiaoScript 已经托管了 所以开发者可以直接用注解实现
|
||||
|
||||
## 注册命令/补全
|
||||
|
||||
### cmd 命令
|
||||
|
||||
命令 就是玩家在Minecraft中执行命令 下面是一个示例的命令
|
||||
|
||||
- 命令是一个 `function` 通过 `@cmd` 注解注册
|
||||
- 由于不同的服务端有不同的逻辑 所以支持通过 `servers` 指定注册的类型 加上 `!` 代表不注册 不指定 `servers` 则注册所有的类型
|
||||
- 命令注册时默认使用方法名称为命令名称 当前你可以传入 name 参数指定命令名称 例如 `{name: 'test'}`
|
||||
- 接受三个参数 `sender: any, command: string, args: string[]`
|
||||
- 分别代表 命令发送者 命令名称 命令参数
|
||||
|
||||
```ts
|
||||
@cmd({ servers: ["bukkit", "sponge", "!bungee"] })
|
||||
hello(sender: any, command: string, args: string[]) {
|
||||
this.logger.log(sender, command, args);
|
||||
this.logger.sender(sender, JSON.stringify({ command, args }));
|
||||
}
|
||||
```
|
||||
|
||||
### tab 补全
|
||||
|
||||
补全就是 玩家在Minecraft执行命令时 使用 Tab键 补全
|
||||
|
||||
- 补全是一个 `function` 一般以 `tab` 开头 需要补全的命令结尾 通过 `@tab` 注解注册
|
||||
- 补全注册时默认使用方法名称为补全名称 当前你可以传入 name 参数指定命令名称 例如 `{name: 'test'}`
|
||||
- 接受三个参数 `sender: any, command: string, args: string[]`
|
||||
- 分别代表 命令发送者 命令名称 命令参数
|
||||
|
||||
_注意: 当补全命令未注册时 补全无效! 且补全和命令必须在同一个Class内!_
|
||||
|
||||
```ts
|
||||
@tab()
|
||||
tabhello(_sender: any, _command: string, _args: string[]) {
|
||||
return ['world']
|
||||
}
|
||||
```
|
||||
|
||||
## 监听事件
|
||||
|
||||
事件是指 Minecraft 中发生的各种事情
|
||||
|
||||
- 监听事件是一个 `function` 通过 `@listener` 注册
|
||||
- 由于不同的服务端有不同的逻辑 所以支持通过 `servers` 指定注册的类型 加上 `!` 代表不注册 不指定 `servers` 则注册所有的类型
|
||||
- 事件名称默认为方法名称
|
||||
- 所有类型服务端的事件 MiaoScript 都会进行一次映射 方便使用
|
||||
- 例如 `PlayerJoinEvent` 会映射为 `PlayerJoinEvent, playerjoinevent, playerjoin` 等
|
||||
- 一般规则就是 类名直接小写 如果遇到子类 则保留 `$`
|
||||
- 例如 `ClientConnectionEvent.Join` 会映射为 `clientconnectionevent$join`
|
||||
- 事件的注可以传入 `servertype` 来指定这个事件类型的服务端加载 默认是所有服务端都加载
|
||||
- 事件监听方法的第一个参数就是本次事件的具体内容 (这里就需要自己去查询对应的JavaDoc了)
|
||||
|
||||
```ts
|
||||
// bukkit nukkit 大部分API神似 可以直接用
|
||||
@listener({ servers: ['bukkit', 'nukkit'] })
|
||||
PlayerJoin(event: org.bukkit.event.player.PlayerJoinEvent) {
|
||||
let plyaer = event.getPlayer();
|
||||
this.logger.console(`§cBukkit §aPlayerJoinEvent: §b${plyaer.getName()}`)
|
||||
setTimeout(() => this.sendWelcome(plyaer), 10);
|
||||
}
|
||||
|
||||
@listener({ servers: ['sponge'] })
|
||||
ClientConnectionEvent$Join(event: org.spongepowered.api.event.network.ClientConnectionEvent.Join) {
|
||||
this.logger.console(`§cSponge §aClientConnectionEvent.Join: §b${event.getTargetEntity().getName()}`)
|
||||
setTimeout(() => this.sendWelcome(event.getTargetEntity()), 10);
|
||||
}
|
||||
|
||||
private sendWelcome(player: any) {
|
||||
this.logger.sender(player, `§a欢迎来到 §bMiaoScript §a的世界!`)
|
||||
this.logger.sender(player, `§6当前版本: §c${this.Server.getVersion()}`)
|
||||
}
|
||||
|
||||
@listener({ servers: ['bungee'] })
|
||||
ServerConnected(e: any) {
|
||||
let event = e as net.md_5.bungee.api.event.ServerConnectedEvent
|
||||
this.logger.console(`§cBungeeCord §aServerConnectedEvent: §b${event.getPlayer().getDisplayName()}`)
|
||||
setTimeout(() => this.logger.sender(event.getPlayer(), `§a欢迎来到 §bMiaoScript §a的世界 §6来自 §cBungeeCord §6的问候!`), 10);
|
||||
}
|
||||
```
|
||||
|
||||
## 配置文件
|
||||
|
||||
配置文件 默认读取的是 `MiaoScript根目录/plugins/插件名称/配置名称.配置格式`
|
||||
|
||||
例如下面文件 默认处理的是 `plugins/MiaoScript/plugins/HelloWorld/config.yml`
|
||||
|
||||
```ts
|
||||
@config()
|
||||
private config = {
|
||||
version: 1.0.0
|
||||
}
|
||||
```
|
||||
|
||||
## 插件列表
|
||||
|
||||
暂无
|
||||
|
||||
> 注意: 一楼的列表是老版本的 新版本无法加载!
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "0.0.0",
|
||||
"version": "0.4.0",
|
||||
"useWorkspaces": true,
|
||||
"npmClient": "yarn",
|
||||
"packages": [
|
||||
@@ -13,4 +13,4 @@
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
15
package.json
15
package.json
@@ -6,15 +6,18 @@
|
||||
"author": "MiaoWoo <admin@yumc.pw>",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"clean": "npx lerna run clean",
|
||||
"watch": "npx lerna run watch --parallel",
|
||||
"build": "npx lerna run build",
|
||||
"lp": "npx lerna publish"
|
||||
"bs": "lerna bootstrap",
|
||||
"clean": "lerna run clean",
|
||||
"watch": "lerna run watch --parallel",
|
||||
"build": "lerna run build --scope=\"@ms/!(plugins)\"",
|
||||
"build:plugins": "lerna run build --scope=\"@ms/plugins\"",
|
||||
"ug": "yarn upgrade-interactive --latest",
|
||||
"lp": "lerna publish"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"devDependencies": {
|
||||
"lerna": "^3.16.4"
|
||||
"lerna": "^3.20.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
4
packages/api/.gitignore
vendored
4
packages/api/.gitignore
vendored
@@ -1,4 +0,0 @@
|
||||
/node_modules
|
||||
/dist
|
||||
/package-lock.json
|
||||
/yarn.lock
|
||||
@@ -1,22 +0,0 @@
|
||||
src
|
||||
test
|
||||
typings
|
||||
bundled
|
||||
build
|
||||
coverage
|
||||
docs
|
||||
wiki
|
||||
gulpfile.js
|
||||
bower.json
|
||||
karma.conf.js
|
||||
tsconfig.json
|
||||
typings.json
|
||||
CONTRIBUTING.md
|
||||
ISSUE_TEMPLATE.md
|
||||
PULL_REQUEST_TEMPLATE.md
|
||||
tslint.json
|
||||
wallaby.js
|
||||
.travis.yml
|
||||
.gitignore
|
||||
.vscode
|
||||
type_definitions
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ms/api",
|
||||
"version": "0.0.0",
|
||||
"version": "0.4.0",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -13,21 +13,22 @@
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm/"
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf dist",
|
||||
"watch": "npx tsc --watch",
|
||||
"build": "yarn clean && npx tsc",
|
||||
"watch": "tsc --watch",
|
||||
"build": "yarn clean && tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ms/common": "^0.0.0",
|
||||
"@ms/container": "^0.0.0"
|
||||
"@ms/container": "^0.4.0",
|
||||
"@ms/ployfill": "^0.4.0",
|
||||
"source-map-builder": "^0.0.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.0",
|
||||
"typescript": "^3.6.2"
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^3.8.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
66
packages/api/src/channel.ts
Normal file
66
packages/api/src/channel.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { injectable } from "@ms/container";
|
||||
|
||||
export namespace channel {
|
||||
/**
|
||||
* handle plugin message
|
||||
* @param data byte[]
|
||||
*/
|
||||
export type ChannelListener = (data: any, exts?: any) => void
|
||||
|
||||
@injectable()
|
||||
export abstract class Channel {
|
||||
private listenerMap = [];
|
||||
/**
|
||||
* 注册通道
|
||||
* @param plugin 插件
|
||||
* @param channel 通道
|
||||
* @param exec 执行器
|
||||
*/
|
||||
listen(plugin: any, channel: string, exec: ChannelListener) {
|
||||
if (!plugin || !plugin.description || !plugin.description.name) throw new TypeError('Plugin can\'t be undefiend!');
|
||||
let name = plugin.description.name;
|
||||
let listener = this.register(channel, exec)
|
||||
if (!this.listenerMap[name]) this.listenerMap[name] = [];
|
||||
let offExec = () => {
|
||||
this.unregister(channel, listener);
|
||||
console.debug(`[${name}] unregister channel ${channel}`);
|
||||
};
|
||||
var off = {
|
||||
channel,
|
||||
listener,
|
||||
off: offExec
|
||||
};
|
||||
this.listenerMap[name].push(off);
|
||||
console.debug(`[${name}] register channel ${channel} => ${exec.name || '[anonymous]'}`);
|
||||
return off;
|
||||
}
|
||||
/**
|
||||
* 关闭插件注册的通道
|
||||
* @param plugin 插件
|
||||
*/
|
||||
disable(plugin: any) {
|
||||
var channelCache = this.listenerMap[plugin.description.name];
|
||||
if (channelCache) {
|
||||
channelCache.forEach(t => t.off());
|
||||
delete this.listenerMap[plugin.description.name];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Send Channel Message
|
||||
* @param player recover target
|
||||
* @param channel ChannelName
|
||||
* @param data byte[]
|
||||
*/
|
||||
abstract send(player: any, channel: string, data: any)
|
||||
/**
|
||||
* register channel
|
||||
* @param channel ChannelName
|
||||
*/
|
||||
abstract register(channel: string, listener: ChannelListener): any
|
||||
/**
|
||||
* unregister channel
|
||||
* @param channel ChannelName
|
||||
*/
|
||||
abstract unregister(channel: string, listener?: any): void
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,75 @@
|
||||
import i18n from '@ms/i18n'
|
||||
import { injectable } from "@ms/container";
|
||||
|
||||
export namespace command {
|
||||
@injectable()
|
||||
export abstract class Command {
|
||||
/**
|
||||
* 注册插件命令
|
||||
* @param plugin 插件
|
||||
* @param name 命令
|
||||
* @param exec 执行器
|
||||
*/
|
||||
on(plugin: any, name: string, exec: { cmd: Function, tab?: Function }) {
|
||||
var cmd = this.create(plugin, { name: name });
|
||||
console.debug(`插件 ${plugin.description.name} 创建命令 ${name}(${cmd})...`)
|
||||
var cmd = this.create(plugin, name);
|
||||
console.debug(i18n.translate("ms.api.command.register", { plugin: plugin.description.name, name, cmd }))
|
||||
if (exec.cmd && typeof exec.cmd === "function") {
|
||||
this.onCommand(plugin, cmd, exec.cmd)
|
||||
this.onCommand(plugin, cmd, exec.cmd);
|
||||
} else {
|
||||
throw Error("CommandExec Must be a function... Input: " + exec.cmd)
|
||||
throw Error(i18n.translate("ms.api.command.register.input.error", { exec: exec.cmd }))
|
||||
}
|
||||
if (exec.tab && typeof exec.tab === "function") {
|
||||
this.onTabComplete(plugin, cmd, exec.tab)
|
||||
this.onTabComplete(plugin, cmd, exec.tab);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Create Server Command Object
|
||||
* 取消命令注册
|
||||
* @param plugin 插件
|
||||
* @param name 命令
|
||||
*/
|
||||
abstract create(plugin: object, opts: { name: string });
|
||||
abstract onCommand(plugin: object, command: any, opts: { name: string });
|
||||
abstract onTabComplete(plugin: object, command: any, opts: { name: string });
|
||||
off(plugin: any, name: string) {
|
||||
console.debug(i18n.translate("ms.api.command.unregister", { plugin: plugin.description.name, name }))
|
||||
this.remove(plugin, name);
|
||||
}
|
||||
|
||||
protected abstract create(plugin: any, command: string);
|
||||
protected abstract remove(plugin: any, command: string);
|
||||
protected abstract onCommand(plugin: any, command: any, executor: Function);
|
||||
protected abstract onTabComplete(plugin: any, command: any, tabCompleter: Function);
|
||||
protected setExecutor(plugin: any, command: any, executor: Function) {
|
||||
return (sender: any, _: any, command: string, args: string[]) => {
|
||||
try {
|
||||
return executor(sender, command, Java.from(args));
|
||||
} catch (ex) {
|
||||
console.i18n("ms.api.command.execute.error", { sender: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex })
|
||||
console.ex(ex);
|
||||
console.sender(sender, [i18n.translate("ms.api.command.execute.error", { sender: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex }), ...console.stack(ex)])
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected setTabCompleter(plugin: any, command: any, tabCompleter: Function) {
|
||||
return (sender: any, _: any, command: string, args: string[]) => {
|
||||
try {
|
||||
var token = args[args.length - 1];
|
||||
var complete = tabCompleter(sender, command, Java.from(args)) || [];
|
||||
return this.copyPartialMatches(complete, token);
|
||||
} catch (ex) {
|
||||
console.i18n("ms.api.command.tab.completer.error", { sender: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex })
|
||||
console.ex(ex);
|
||||
console.sender(sender, [i18n.translate("ms.api.command.tab.completer.error", { sender: sender.name, plugin: plugin.description.name, command, args: Java.from(args).join(' '), ex }), ...console.stack(ex)]);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
protected copyPartialMatches(complete: string[], token: string, array: string[] = []): string[] {
|
||||
if (!token) { return complete }
|
||||
complete.forEach(function (e) {
|
||||
if (typeof e === "string" && e.toLowerCase().startsWith(token.toLowerCase())) {
|
||||
array.push(e)
|
||||
}
|
||||
});
|
||||
return array
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,30 @@
|
||||
let Arrays = Java.type('java.util.Arrays');
|
||||
let Level = Java.type('java.util.logging.Level');
|
||||
let ignoreLogPrefix = ['java.', 'net.minecraft.', 'org.bukkit.', 'jdk.nashorn.'];
|
||||
import i18m from '@ms/i18n'
|
||||
import { SourceMapBuilder } from 'source-map-builder'
|
||||
|
||||
const Arrays = Java.type('java.util.Arrays');
|
||||
const Level = Java.type('java.util.logging.Level');
|
||||
const JavaString = Java.type('java.lang.String');
|
||||
const Files = Java.type('java.nio.file.Files');
|
||||
const Paths = Java.type('java.nio.file.Paths');
|
||||
const ignoreLogPrefix = ['java.', 'net.minecraft.', 'org.bukkit.', 'jdk.nashorn.', 'io.netty.', 'org.spongepowered.'];
|
||||
|
||||
enum LogLevel {
|
||||
ALL,
|
||||
TRACE,
|
||||
DEBUG,
|
||||
INFO,
|
||||
WARN,
|
||||
ERROR,
|
||||
FATAL,
|
||||
OFF
|
||||
}
|
||||
|
||||
export class MiaoScriptConsole implements Console {
|
||||
Console: NodeJS.ConsoleConstructor;
|
||||
|
||||
private sourceMaps: { [key: string]: SourceMapBuilder } = {};
|
||||
private _name: string = '';
|
||||
private _level: LogLevel = LogLevel.INFO;
|
||||
|
||||
protected logger: any;
|
||||
protected prefix: string = '§6[§bMiaoScript§6]§r ';
|
||||
@@ -13,6 +32,12 @@ export class MiaoScriptConsole implements Console {
|
||||
constructor(name?: string) {
|
||||
this.name = name;
|
||||
this.logger = global.logger;
|
||||
if (global.debug) {
|
||||
this._level = LogLevel.DEBUG
|
||||
}
|
||||
if (global.level?.toUpperCase() === "TRACE") {
|
||||
this._level = LogLevel.TRACE
|
||||
}
|
||||
}
|
||||
|
||||
get name() {
|
||||
@@ -26,53 +51,94 @@ export class MiaoScriptConsole implements Console {
|
||||
this.prefix = `§6[§cMS§6][§b${name}§6]§r `;
|
||||
}
|
||||
}
|
||||
log(...args): void {
|
||||
log(...args: any[]): void {
|
||||
this.logger.info(this.name + args.join(' '));
|
||||
}
|
||||
info(...args) {
|
||||
info(...args: any[]) {
|
||||
this.logger.info(this.name + args.join(' '));
|
||||
};
|
||||
warn(...args) {
|
||||
}
|
||||
warn(...args: any[]) {
|
||||
this.logger.warning(this.name + args.join(' '));
|
||||
};
|
||||
error(...args) {
|
||||
}
|
||||
error(...args: any[]) {
|
||||
this.logger.log(Level.SEVERE, this.name + args.join(' '));
|
||||
};
|
||||
debug(...args) {
|
||||
}
|
||||
debug(...args: any[]) {
|
||||
if (global.debug) {
|
||||
this.logger.info(this.name + '[DEBUG] ' + args.join(' '));
|
||||
}
|
||||
};
|
||||
}
|
||||
trace(...args: any[]): void {
|
||||
if (this._level <= LogLevel.TRACE) {
|
||||
this.logger.info(this.name + '[TRACE] ' + args.join(' '));
|
||||
}
|
||||
}
|
||||
sender(...args) {
|
||||
this.info(args)
|
||||
}
|
||||
console(...args) {
|
||||
this.info(args)
|
||||
}
|
||||
i18n(name: string, param?: { [key: string]: any }) {
|
||||
this.console(i18m.translate(name, param))
|
||||
}
|
||||
object(obj) {
|
||||
for (var i in obj) {
|
||||
this.logger(i, '=>', obj[i])
|
||||
this.info(i, '=>', obj[i])
|
||||
}
|
||||
};
|
||||
}
|
||||
ex(ex: Error) {
|
||||
this.stack(ex).forEach(line => this.console(line))
|
||||
};
|
||||
stack(ex: Error | any): string[] {
|
||||
}
|
||||
readSourceMap(fileName: string, lineNumber: number) {
|
||||
try {
|
||||
if (fileName.endsWith('js')) {
|
||||
var file = Paths.get(fileName + '.map');
|
||||
if (this.sourceMaps[fileName] === undefined) {
|
||||
if (file.toFile().exists()) {
|
||||
var sourceMapObj = JSON.parse(new JavaString(Files.readAllBytes(file), "UTF-8"))
|
||||
this.sourceMaps[fileName] = new SourceMapBuilder(sourceMapObj)
|
||||
} else {
|
||||
this.sourceMaps[fileName] = null;
|
||||
}
|
||||
}
|
||||
if (this.sourceMaps[fileName]) {
|
||||
var sourceMapping = this.sourceMaps[fileName].getSource(lineNumber, 25, true);
|
||||
if (sourceMapping) {
|
||||
if (lineNumber != sourceMapping.mapping.sourceLine) {
|
||||
fileName = fileName.replace(".js", ".ts");
|
||||
lineNumber = sourceMapping.mapping.sourceLine;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.debug('search source map', fileName, 'line', lineNumber, 'error:', error)
|
||||
}
|
||||
return {
|
||||
fileName,
|
||||
lineNumber
|
||||
}
|
||||
}
|
||||
stack(ex: Error): string[] {
|
||||
var stack = ex.getStackTrace();
|
||||
var cache = ['§4' + ex];
|
||||
var cache = ['§c' + ex];
|
||||
//@ts-ignore
|
||||
if (stack.class) {
|
||||
stack = Arrays.asList(stack)
|
||||
}
|
||||
stack.forEach(function(trace) {
|
||||
stack.forEach(trace => {
|
||||
if (trace.className.startsWith('<')) {
|
||||
var fileName = trace.fileName
|
||||
var { fileName, lineNumber } = this.readSourceMap(trace.fileName, trace.lineNumber)
|
||||
if (fileName.startsWith(root)) { fileName = fileName.split(root)[1] }
|
||||
if (fileName.startsWith('/runtime')) { fileName = fileName.split('/runtime')[1] }
|
||||
cache.push(` §e->§c ${fileName} => §4${trace.methodName}:${trace.lineNumber}`)
|
||||
cache.push(` §e->§c ${fileName} => §4${trace.methodName}:${lineNumber}`)
|
||||
} else {
|
||||
var className = trace.className;
|
||||
var fileName = trace.fileName as string;
|
||||
if (className.startsWith('jdk.nashorn.internal.scripts')) {
|
||||
className = className.substr(className.lastIndexOf('$') + 1)
|
||||
var { fileName, lineNumber } = this.readSourceMap(trace.fileName, trace.lineNumber)
|
||||
if (fileName.startsWith(root)) { fileName = fileName.split(root)[1] }
|
||||
} else {
|
||||
for (var prefix in ignoreLogPrefix) {
|
||||
if (className.startsWith(ignoreLogPrefix[prefix])) {
|
||||
@@ -80,7 +146,7 @@ export class MiaoScriptConsole implements Console {
|
||||
}
|
||||
}
|
||||
}
|
||||
cache.push(` §e->§c ${className}.${trace.methodName}(§4${trace.fileName}:${trace.lineNumber}§c)`);
|
||||
cache.push(` §e->§c ${className}.${trace.methodName}(§4${fileName}:${lineNumber}§c)`);
|
||||
}
|
||||
});
|
||||
return cache;
|
||||
@@ -124,9 +190,6 @@ export class MiaoScriptConsole implements Console {
|
||||
timeLog(label?: string, ...data: any[]): void {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
trace(message?: any, ...optionalParams: any[]): void {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
markTimeline(label?: string): void {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
|
||||
@@ -1,128 +1,140 @@
|
||||
'use strict';
|
||||
/**
|
||||
* MiaoScript Event处理类
|
||||
*/
|
||||
import '@ms/core'
|
||||
import '@ms/nashorn'
|
||||
import { injectable } from '@ms/container'
|
||||
import i18n from '@ms/i18n'
|
||||
import { injectable, unmanaged } from '@ms/container'
|
||||
|
||||
const Thread = Java.type("java.lang.Thread");
|
||||
const Thread = Java.type('java.lang.Thread');
|
||||
|
||||
export namespace event {
|
||||
/**
|
||||
* 事件监听优先级
|
||||
*/
|
||||
export enum EventPriority {
|
||||
LOWEST = "LOWEST",
|
||||
LOW = "LOW",
|
||||
NORMAL = "NORMAL",
|
||||
HIGH = "HIGH",
|
||||
HIGHEST = "HIGHEST",
|
||||
MONITOR = "MONITOR",
|
||||
}
|
||||
|
||||
@injectable()
|
||||
export abstract class Event {
|
||||
private mapEvent = [];
|
||||
private listenerMap = [];
|
||||
private baseEventDir = '';
|
||||
|
||||
constructor(baseEventDir: string) {
|
||||
protected baseEventDir = '';
|
||||
|
||||
constructor(@unmanaged() baseEventDir: string) {
|
||||
this.baseEventDir = baseEventDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描包 org.bukkit.event 下的所有事件
|
||||
* 映射简写名称 org.bukkit.event.player.PlayerLoginEvent => playerloginevent
|
||||
* abstract event map function
|
||||
* ig: org.bukkit.event.player.PlayerLoginEvent => playerloginevent
|
||||
* org.spongepowered.api.event.game.GameRegistryEvent.Register => gameregistryevent$register
|
||||
*/
|
||||
mapEventName() {
|
||||
if (this.baseEventDir === "") {
|
||||
throw new Error("事件基础包名为空 无法进行事件映射!");
|
||||
}
|
||||
var count = 0;
|
||||
var dirs = Thread.currentThread().getContextClassLoader().getResources(this.baseEventDir);
|
||||
while (dirs.hasMoreElements()) {
|
||||
var url = dirs.nextElement();
|
||||
var protocol = url.protocol;
|
||||
if (protocol === "jar") {
|
||||
// noinspection JSUnresolvedVariable
|
||||
var jar = url.openConnection().jarFile;
|
||||
var entries = jar.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
var entry = entries.nextElement();
|
||||
var name = entry.name;
|
||||
// 以 org/bukkit/event 开头 并且以 .class 结尾
|
||||
if (name.startsWith(this.baseEventDir) && name.endsWith(".class")) {
|
||||
var i = name.replaceAll('/', '.');
|
||||
try {
|
||||
var clz = base.getClass(i.substring(0, i.length - 6));
|
||||
// 继承于 org.bukkit.event.Event 访问符为Public
|
||||
if (this.isValidEvent(clz)) {
|
||||
var simpleName = this.class2Name(clz).toLowerCase();
|
||||
console.debug(`Mapping Event [${clz.canonicalName}] => ${simpleName}`);
|
||||
this.mapEvent[simpleName] = clz;
|
||||
count++;
|
||||
}
|
||||
} catch (ex) {
|
||||
//ignore already loaded class
|
||||
}
|
||||
if (this.baseEventDir === "") { throw new Error(i18n.translate('ms.api.event.empty.event.dir')); }
|
||||
let count = 0;
|
||||
let jar = this.getJarFile(this.baseEventDir);
|
||||
let entries = jar.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
let entry = entries.nextElement();
|
||||
let name = entry.name;
|
||||
if (name.startsWith(this.baseEventDir) && name.endsWith(".class")) {
|
||||
// replace name to qualifiedName
|
||||
let qualifiedName = name.replaceAll('/', '.');
|
||||
try {
|
||||
let clazz = base.getClass(qualifiedName.substring(0, qualifiedName.length - 6));
|
||||
if (this.isValidEvent(clazz)) {
|
||||
let simpleName = this.class2Name(clazz).toLowerCase();
|
||||
console.trace(i18n.translate("ms.api.event.mapping", { canonicalName: clazz.canonicalName, simpleName }));
|
||||
this.mapEvent[simpleName] = clazz;
|
||||
count++;
|
||||
}
|
||||
} catch (ex) {
|
||||
//ignore already loaded class
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
};
|
||||
}
|
||||
|
||||
class2Name(clazz) {
|
||||
getJarFile(resource: string) {
|
||||
let dirs = Thread.currentThread().getContextClassLoader().getResources(resource);
|
||||
if (dirs.hasMoreElements()) {
|
||||
let url = dirs.nextElement();
|
||||
if (url.protocol === "jar") { return url.openConnection().jarFile; }
|
||||
}
|
||||
throw new Error(i18n.translate("ms.api.event.resource.not.found", { resource }))
|
||||
}
|
||||
|
||||
class2Name(clazz: any) {
|
||||
return clazz.simpleName;
|
||||
};
|
||||
}
|
||||
|
||||
name2Class(name, event) {
|
||||
var eventCls = this.mapEvent[event.toLowerCase()] || this.mapEvent[event.toLowerCase() + 'event'];
|
||||
name2Class(name: any, event: string) {
|
||||
let eventCls = this.mapEvent[event.toLowerCase()] || this.mapEvent[event.toLowerCase() + 'event'];
|
||||
if (!eventCls) {
|
||||
try {
|
||||
eventCls = base.getClass(eventCls);
|
||||
this.mapEvent[event] = eventCls;
|
||||
} catch (ex) {
|
||||
console.console(`§6插件 §b${name} §6注册事件 §c${event} §6失败 §4事件未找到!`);
|
||||
console.ex(new Error(`插件 ${name} 注册事件 ${event} 失败 事件未找到!`));
|
||||
console.i18n("ms.api.event.not.found", { name, event })
|
||||
return;
|
||||
}
|
||||
}
|
||||
return eventCls;
|
||||
};
|
||||
}
|
||||
|
||||
execute(name, exec, eventCls) {
|
||||
return (...args) => {
|
||||
return (...args: any[]) => {
|
||||
try {
|
||||
var time = new Date().getTime()
|
||||
exec(args[args.length - 1]);
|
||||
var cost = new Date().getTime() - time;
|
||||
if (cost > 20) {
|
||||
console.console(`§c注意! §6插件 §b${name} §6处理 §d${this.class2Name(eventCls)} §6事件 §c耗时 §4${cost}ms !`)
|
||||
let event = args[args.length - 1];
|
||||
if (eventCls.isAssignableFrom(event.getClass())) {
|
||||
let time = Date.now()
|
||||
exec(event);
|
||||
let cost = Date.now() - time;
|
||||
if (cost > 20) {
|
||||
console.i18n("ms.api.event.execute.slow", { name, event: this.class2Name(eventCls), cost })
|
||||
}
|
||||
}
|
||||
} catch (ex) {
|
||||
console.console(`§6插件 §b${name} §6处理 §d${this.class2Name(eventCls)} §6事件时发生异常 §4${ex}`);
|
||||
console.i18n("ms.api.event.execute.error", { name, event: this.class2Name(eventCls), ex })
|
||||
console.ex(ex);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加事件监听
|
||||
* @param jsp
|
||||
* @param event
|
||||
* @param plugin {any}
|
||||
* @param event {string}
|
||||
* @param exec {function}
|
||||
* @param priority [LOWEST,LOW,NORMAL,HIGH,HIGHEST,MONITOR]
|
||||
* @param priority {string} [LOWEST,LOW,NORMAL,HIGH,HIGHEST,MONITOR]
|
||||
* @param ignoreCancel
|
||||
*/
|
||||
listen(jsp, event, exec, priority, ignoreCancel) {
|
||||
if (!jsp || !jsp.description || !jsp.description.name) throw new TypeError('插件名称为空 请检查传入参数!');
|
||||
var name = jsp.description.name;
|
||||
listen(plugin: any, event: string, exec: (event: any) => void, priority: EventPriority = EventPriority.NORMAL, ignoreCancel = false) {
|
||||
if (!plugin || !plugin.description || !plugin.description.name) throw new TypeError(i18n.translate("ms.api.event.listen.plugin.name.empty"));
|
||||
var name = plugin.description.name;
|
||||
var eventCls = this.name2Class(name, event);
|
||||
if (!eventCls) { return; }
|
||||
if (typeof priority === 'boolean') {
|
||||
ignoreCancel = priority;
|
||||
priority = 'NORMAL';
|
||||
priority = EventPriority.NORMAL;
|
||||
}
|
||||
priority = priority || 'NORMAL';
|
||||
priority = priority || EventPriority.NORMAL;
|
||||
ignoreCancel = ignoreCancel || false;
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
var listener = this.register(eventCls, this.execute(name, exec, eventCls), priority, ignoreCancel);
|
||||
var listenerMap = this.listenerMap;
|
||||
// 添加到缓存 用于关闭插件的时候关闭事件
|
||||
// add to cache Be used for close plugin to close event
|
||||
if (!listenerMap[name]) listenerMap[name] = [];
|
||||
var offExec = () => {
|
||||
this.unregister(eventCls, listener);
|
||||
console.debug(`插件 ${name} 注销事件 ${this.class2Name(eventCls)}`);
|
||||
console.debug(i18n.translate("ms.api.event.unregister", { name, event: this.class2Name(eventCls) }));
|
||||
};
|
||||
var off = {
|
||||
event: eventCls,
|
||||
@@ -131,10 +143,14 @@ export namespace event {
|
||||
};
|
||||
listenerMap[name].push(off);
|
||||
// noinspection JSUnresolvedVariable
|
||||
console.debug(`插件 ${name} 注册事件 ${this.class2Name(eventCls)} => ${exec.name || '匿名方法'}`);
|
||||
console.debug(i18n.translate("ms.api.event.register", { name, event: this.class2Name(eventCls) }));
|
||||
return off;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭插件监听任务
|
||||
* @param plugin 插件
|
||||
*/
|
||||
disable(plugin: any) {
|
||||
var eventCache = this.listenerMap[plugin.description.name];
|
||||
if (eventCache) {
|
||||
@@ -143,8 +159,24 @@ export namespace event {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断
|
||||
* @param clazz 事件类
|
||||
*/
|
||||
abstract isValidEvent(clazz: any): boolean;
|
||||
/**
|
||||
* 注册事件
|
||||
* @param eventCls 事件类
|
||||
* @param exec 执行器
|
||||
* @param priority 优先级
|
||||
* @param ignoreCancel 是否忽略已取消的事件
|
||||
*/
|
||||
abstract register(eventCls: any, exec: Function, priority: any, ignoreCancel: boolean): any;
|
||||
/**
|
||||
* 取消监听事件
|
||||
* @param event 事件
|
||||
* @param listener 监听器
|
||||
*/
|
||||
abstract unregister(event: any, listener: any): void;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import './typings/global'
|
||||
|
||||
import "@ms/nashorn"
|
||||
export * from './task'
|
||||
export * from './event'
|
||||
export * from './console'
|
||||
export * from './channel'
|
||||
export * from './command'
|
||||
export * from './interfaces'
|
||||
|
||||
@@ -1,25 +1,30 @@
|
||||
import { Container } from "inversify";
|
||||
|
||||
export namespace plugin {
|
||||
/**
|
||||
* MiaoScript Plugin
|
||||
*/
|
||||
export const Plugin = Symbol("Plugin");
|
||||
/**
|
||||
* MiaoScript Plugin Folder
|
||||
*/
|
||||
export const PluginFolder = Symbol("PluginFolder");
|
||||
/**
|
||||
* Runtime Plugin Instance
|
||||
*/
|
||||
export const PluginInstance = Symbol("PluginInstance");
|
||||
/**
|
||||
* MiaoScript Plugin Manager
|
||||
* MiaoScript Plugin Manager Symbol
|
||||
*/
|
||||
export const PluginManager = Symbol("PluginManager");
|
||||
/**
|
||||
* MiaoScript Plugin Manager
|
||||
* MiaoScript Plugin Manager Interface
|
||||
*/
|
||||
export interface PluginManager {
|
||||
scan(folder: string): void;
|
||||
load(container: Container): void;
|
||||
enable(): void;
|
||||
disable(): void;
|
||||
build(): void;
|
||||
load(...args: any[]): void;
|
||||
enable(...args: any[]): void;
|
||||
disable(...args: any[]): void;
|
||||
reload(...args: any[]): void;
|
||||
getPlugins(): Map<string, any>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
export namespace server {
|
||||
export const ServerType = Symbol("ServerType");
|
||||
export const Console = Symbol("Console");
|
||||
}
|
||||
35
packages/api/src/interfaces/server/index.ts
Normal file
35
packages/api/src/interfaces/server/index.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { NativePluginManager } from './native_plugin'
|
||||
|
||||
export namespace server {
|
||||
/**
|
||||
* Runtime ServerType
|
||||
*/
|
||||
export const ServerType = Symbol("ServerType");
|
||||
/**
|
||||
* Runtime Console
|
||||
*/
|
||||
export const Console = Symbol("Console");
|
||||
/**
|
||||
* MiaoScript Server
|
||||
*/
|
||||
export const Server = Symbol("Server");
|
||||
/**
|
||||
* Runtime Server Instance
|
||||
*/
|
||||
export const ServerInstance = Symbol("ServerInstance");
|
||||
/**
|
||||
* MiaoScript Server
|
||||
*/
|
||||
export interface Server {
|
||||
getVersion(): string;
|
||||
getPlayer(name: string): any;
|
||||
getOnlinePlayers(): any[];
|
||||
getConsoleSender(): any;
|
||||
getService(service: string): any;
|
||||
dispatchCommand(sender: string | any, command: string): boolean;
|
||||
dispatchConsoleCommand(command: string): boolean;
|
||||
getPluginsFolder(): string;
|
||||
getNativePluginManager(): NativePluginManager;
|
||||
sendJson(sender: string | any, json: object | string): void;
|
||||
}
|
||||
}
|
||||
6
packages/api/src/interfaces/server/native_plugin.ts
Normal file
6
packages/api/src/interfaces/server/native_plugin.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export interface NativePluginManager {
|
||||
load(name: string): boolean;
|
||||
unload(name: string): boolean;
|
||||
reload(name: string): boolean;
|
||||
delete(name: string): boolean;
|
||||
}
|
||||
77
packages/api/src/task.ts
Normal file
77
packages/api/src/task.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
export namespace task {
|
||||
export const TaskManager = Symbol('TaskManager')
|
||||
export interface TaskManager {
|
||||
/**
|
||||
* 创建任务
|
||||
* @param func 任务内容
|
||||
*/
|
||||
create(func: Function): task.Task;
|
||||
/**
|
||||
* 在主线程执行代码
|
||||
* @param func 执行内容
|
||||
*/
|
||||
callSyncMethod(func: Function): any;
|
||||
}
|
||||
/**
|
||||
* 任务抽象
|
||||
*/
|
||||
export abstract class Task {
|
||||
protected plugin: any;
|
||||
protected func: Function;
|
||||
protected isAsync: boolean = false;
|
||||
protected laterTime: number = 0;
|
||||
protected interval: number = 0;
|
||||
|
||||
constructor(plugin: any, func: Function) {
|
||||
this.plugin = plugin;
|
||||
this.func = func;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置任务异步执行
|
||||
* @param isAsync 是否异步
|
||||
*/
|
||||
async(isAsync: boolean = true): task.Task {
|
||||
this.isAsync = isAsync;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置任务延时执行
|
||||
* @param tick 延时 Tick
|
||||
*/
|
||||
later(tick: number): task.Task {
|
||||
this.laterTime = tick;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置任务循环执行
|
||||
* @param tick 循环时间 Tick
|
||||
*/
|
||||
timer(tick: number): task.Task {
|
||||
this.interval = tick;
|
||||
return this;
|
||||
}
|
||||
|
||||
protected run(): void {
|
||||
try {
|
||||
this.func();
|
||||
} catch (ex) {
|
||||
console.console('§4插件执行任务时发生错误', ex)
|
||||
console.ex(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交任务
|
||||
*/
|
||||
abstract submit(): Cancelable;
|
||||
}
|
||||
/**
|
||||
* 返可取消的对象
|
||||
*/
|
||||
export interface Cancelable {
|
||||
cancel(): boolean;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
logger: any;
|
||||
debug: boolean;
|
||||
noop: Function;
|
||||
console: Console;
|
||||
}
|
||||
}
|
||||
var root: string;
|
||||
var base: Core;
|
||||
var ScriptEngineContextHolder: any;
|
||||
function engineLoad(str: string): any;
|
||||
interface Core {
|
||||
getClass(name: String);
|
||||
}
|
||||
interface Console {
|
||||
ex(err: Error): void;
|
||||
stack(err: Error): string[];
|
||||
sender(...args: any): void;
|
||||
console(...args: any): void;
|
||||
}
|
||||
}
|
||||
export { }
|
||||
@@ -1,13 +0,0 @@
|
||||
export interface CommandInfo {
|
||||
aliases: string[];
|
||||
description: string;
|
||||
}
|
||||
export interface PluginInfo {
|
||||
description: PluginDescription;
|
||||
}
|
||||
export interface PluginDescription {
|
||||
name: string;
|
||||
version: string;
|
||||
author: string;
|
||||
commands: { [key: string]: CommandInfo };
|
||||
}
|
||||
4
packages/bukkit/.gitignore
vendored
4
packages/bukkit/.gitignore
vendored
@@ -1,4 +0,0 @@
|
||||
/node_modules
|
||||
/dist
|
||||
/package-lock.json
|
||||
/yarn.lock
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@ms/bukkit",
|
||||
"version": "0.0.0",
|
||||
"description": "MiaoScript api package",
|
||||
"version": "0.4.0",
|
||||
"description": "MiaoScript bukkit package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
@@ -13,22 +13,22 @@
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm/"
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf dist",
|
||||
"watch": "npx tsc --watch",
|
||||
"build": "yarn clean && npx tsc",
|
||||
"watch": "tsc --watch",
|
||||
"build": "yarn clean && tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.0",
|
||||
"typescript": "^3.6.2"
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ms/api": "^0.0.0",
|
||||
"@ms/common": "^0.0.0",
|
||||
"@ms/container": "^0.0.0"
|
||||
"@ms/api": "^0.4.0",
|
||||
"@ms/common": "^0.4.0",
|
||||
"@ms/container": "^0.4.0"
|
||||
}
|
||||
}
|
||||
|
||||
28
packages/bukkit/src/channel.ts
Normal file
28
packages/bukkit/src/channel.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { channel, plugin } from '@ms/api'
|
||||
import { inject, provideSingleton } from '@ms/container'
|
||||
|
||||
const Bukkit = org.bukkit.Bukkit
|
||||
const PluginMessageListener = Java.type("org.bukkit.plugin.messaging.PluginMessageListener")
|
||||
const Messenger = Bukkit.getMessenger()
|
||||
|
||||
@provideSingleton(channel.Channel)
|
||||
export class BukkitChannel extends channel.Channel {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any;
|
||||
|
||||
send(player: any, channel: string, data: any) {
|
||||
player.sendPluginMessage(this.pluginInstance, channel, data);
|
||||
}
|
||||
register(channel: string, listener: channel.ChannelListener) {
|
||||
Messenger.registerIncomingPluginChannel(this.pluginInstance, channel, new PluginMessageListener({
|
||||
onPluginMessageReceived: (/**String */ channel, /**Player */ player, /**byte[] */data) => {
|
||||
listener(data, { channel, player, data })
|
||||
}
|
||||
}));
|
||||
Messenger.registerOutgoingPluginChannel(this.pluginInstance, channel);
|
||||
}
|
||||
unregister(channel: string, listener: any) {
|
||||
Messenger.unregisterIncomingPluginChannel(this.pluginInstance, channel)
|
||||
Messenger.unregisterOutgoingPluginChannel(this.pluginInstance, channel)
|
||||
}
|
||||
}
|
||||
@@ -2,15 +2,14 @@ import '@ms/nashorn'
|
||||
|
||||
import { command, plugin } from '@ms/api'
|
||||
import * as reflect from '@ms/common/dist/reflect'
|
||||
import { injectable, postConstruct, inject } from '@ms/container'
|
||||
import { provideSingleton, postConstruct, inject } from '@ms/container'
|
||||
|
||||
let Bukkit = Java.type("org.bukkit.Bukkit");
|
||||
let Arrays = Java.type('java.util.Arrays');
|
||||
let Bukkit = org.bukkit.Bukkit;
|
||||
let TabCompleter = Java.type('org.bukkit.command.TabCompleter');
|
||||
let PluginCommand = Java.type('org.bukkit.command.PluginCommand');
|
||||
let CommandExecutor = Java.type('org.bukkit.command.CommandExecutor');
|
||||
|
||||
@injectable()
|
||||
@provideSingleton(command.Command)
|
||||
export class BukkitCommand extends command.Command {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any
|
||||
@@ -18,75 +17,31 @@ export class BukkitCommand extends command.Command {
|
||||
|
||||
@postConstruct()
|
||||
init() {
|
||||
this.commandMap = reflect.on(Bukkit.pluginManager).get('commandMap').get();
|
||||
this.commandMap = reflect.on(Bukkit.getPluginManager()).get('commandMap').get();
|
||||
}
|
||||
|
||||
enable(jsp) {
|
||||
var commands = jsp.description.commands;
|
||||
if (commands) {
|
||||
var pluginCommands = [];
|
||||
for (var name in commands) {
|
||||
var command = commands[name];
|
||||
if (typeof command !== 'object') continue;
|
||||
command.name = name;
|
||||
var newCmd = this.create(jsp, command);
|
||||
if (command.description) newCmd.setDescription(command.description);
|
||||
if (command.usage) newCmd.setUsage(command.usage);
|
||||
if (command.aliases) newCmd.setAliases(Arrays.asList(command.aliases));
|
||||
if (command.permission) newCmd.setPermission(command.permission);
|
||||
if (command['permission-message']) newCmd.setPermissionMessage(command['permission-message']);
|
||||
pluginCommands.push(newCmd);
|
||||
console.debug(`插件 ${jsp.description.name} 注册命令 ${name} ...`);
|
||||
}
|
||||
this.commandMap.registerAll(jsp.description.name, Arrays.asList(pluginCommands));
|
||||
}
|
||||
}
|
||||
|
||||
disable(jsp) {
|
||||
var commands = jsp.description.commands;
|
||||
if (commands) {
|
||||
for (var name in commands) {
|
||||
//TODO 删除插件命令
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
create(jsp, command) {
|
||||
var cmd = this.commandMap.getCommand(command.name)
|
||||
create(plugin: any, command: string) {
|
||||
var cmd = this.commandMap.getCommand(command)
|
||||
if (cmd && cmd instanceof PluginCommand) { return cmd };
|
||||
cmd = reflect.on(PluginCommand).create(command.name, this.pluginInstance).get();
|
||||
this.commandMap.register(jsp.description.name, cmd);
|
||||
cmd = reflect.on(PluginCommand).create(command, this.pluginInstance).get();
|
||||
this.commandMap.register(plugin.description.name, cmd);
|
||||
return cmd;
|
||||
}
|
||||
|
||||
onCommand(jsp, c, cmd) {
|
||||
remove(plugin: any, command: string) {
|
||||
var cmd = this.commandMap.getCommand(command)
|
||||
if (cmd && cmd instanceof PluginCommand) {
|
||||
cmd.unregister(this.commandMap);
|
||||
}
|
||||
}
|
||||
onCommand(plugin: any, command: any, executor: Function) {
|
||||
// 必须指定需要实现的接口类型 否则MOD服会报错
|
||||
c.setExecutor(new CommandExecutor({
|
||||
onCommand: function(sender, _, command, args) {
|
||||
try {
|
||||
return cmd(sender, command, Java.from(args));
|
||||
} catch (ex) {
|
||||
console.console(`§6玩家 §a${sender.name} §6执行 §b${jsp.description.name} §6插件 §d${command} ${Java.from(args).join(' ')} §6命令时发生异常 §4${ex}`);
|
||||
console.ex(ex);
|
||||
}
|
||||
}
|
||||
command.setExecutor(new CommandExecutor({
|
||||
onCommand: super.setExecutor(plugin, command, executor)
|
||||
}));
|
||||
}
|
||||
|
||||
onTabComplete(jsp, c, tab) {
|
||||
onTabComplete(plugin: any, command: any, tabCompleter: Function) {
|
||||
// 必须指定需要实现的接口类型 否则MOD服会报错
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
c.setTabCompleter(new TabCompleter({
|
||||
onTabComplete: function(sender, _, command, args) {
|
||||
try {
|
||||
var token = args[args.length - 1];
|
||||
var complete = tab(sender, command, Java.from(args)) || [];
|
||||
return Arrays.asList(complete.copyPartialMatches(token, []));
|
||||
} catch (ex) {
|
||||
console.console(`§6玩家 §a${sender.name} §6执行 §b${jsp.description.name} §6插件 §d${command} ${Java.from(args).join(' ')} §6补全时发生异常 §4${ex}`);
|
||||
console.ex(ex);
|
||||
}
|
||||
}
|
||||
command.setTabCompleter(new TabCompleter({
|
||||
onTabComplete: super.setTabCompleter(plugin, command, tabCompleter)
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
import { MiaoScriptConsole } from '@ms/api'
|
||||
|
||||
let Bukkit = Java.type("org.bukkit.Bukkit");
|
||||
let CommandSender = Java.type("org.bukkit.command.CommandSender");
|
||||
let Bukkit = org.bukkit.Bukkit;
|
||||
|
||||
export class BukkitConsole extends MiaoScriptConsole {
|
||||
sender(sender, ...args) {
|
||||
if (!(sender instanceof CommandSender)) {
|
||||
this.error("第一个参数未实现 org.bukkit.command.CommandSender 无法发送消息!")
|
||||
if (!(sender instanceof Java.type('org.bukkit.command.CommandSender'))) {
|
||||
this.error(`First parameter ${sender} not instanceof org.bukkit.command.CommandSender can't send message!`)
|
||||
return;
|
||||
}
|
||||
if (args[0].toString() === "[object Array]") {
|
||||
if (Object.prototype.toString.call(args[0]) === "[object Array]") {
|
||||
args[0].forEach(line => sender.sendMessage(this.prefix + line))
|
||||
} else {
|
||||
sender.sendMessage(this.prefix + args.join(' '));
|
||||
}
|
||||
}
|
||||
console(...args): void {
|
||||
this.sender(Bukkit.consoleSender, args.join(' '));
|
||||
console(...args: string[]): void {
|
||||
this.sender(Bukkit.getConsoleSender(), args.join(' '));
|
||||
}
|
||||
}
|
||||
|
||||
114
packages/bukkit/src/enhance/chat.ts
Normal file
114
packages/bukkit/src/enhance/chat.ts
Normal file
@@ -0,0 +1,114 @@
|
||||
/*global Java, base, module, exports, require*/
|
||||
var nmsChatSerializerClass;
|
||||
var nmsChatSerializerMethod;
|
||||
var packetTypeConstructor;
|
||||
var nmsChatMessageTypeClass;
|
||||
var chatMessageTypes;
|
||||
|
||||
var RemapUtils;
|
||||
|
||||
var playerConnectionFieldName;
|
||||
var sendPacketMethod;
|
||||
|
||||
var downgrade = false;
|
||||
/**
|
||||
* 获取NMS版本
|
||||
*/
|
||||
//@ts-ignore
|
||||
var nmsVersion = org.bukkit.Bukkit.server.class.name.split('.')[3];
|
||||
/**
|
||||
* 获取NMS类
|
||||
*/
|
||||
function nmsCls(name) {
|
||||
return base.getClass(['net.minecraft.server', nmsVersion, name].join('.'))
|
||||
}
|
||||
|
||||
function remapMethod(clazz: any, origin: string, test: string, params) {
|
||||
try {
|
||||
return clazz.getMethod(origin, params)
|
||||
} catch (ex) {
|
||||
if (RemapUtils) {
|
||||
return clazz.getMethod(RemapUtils.mapMethod(clazz, origin, params), params)
|
||||
} else {
|
||||
return clazz.getMethod(test, params)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function remapFieldName(clazz: any, origin: string, test: string) {
|
||||
try {
|
||||
return clazz.getField(origin)
|
||||
} catch (ex) {
|
||||
if (RemapUtils) {
|
||||
return clazz.getField(RemapUtils.mapFieldName(clazz, origin))
|
||||
} else {
|
||||
return clazz.getField(test)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function init() {
|
||||
try {
|
||||
RemapUtils = Java.type('catserver.server.remapper.RemapUtils');
|
||||
} catch (ex) {
|
||||
}
|
||||
nmsChatSerializerClass = nmsCls(nmsVersion.split("_")[1] > 7 ? "IChatBaseComponent$ChatSerializer" : "ChatSerializer");
|
||||
nmsChatSerializerMethod = remapMethod(nmsChatSerializerClass, 'a', 'func_150699_a', base.getClass('java.lang.String'))
|
||||
var packetTypeClass = nmsCls("PacketPlayOutChat");
|
||||
Java.from(packetTypeClass.constructors).forEach(function(c) {
|
||||
if (c.parameterTypes.length === 2) {
|
||||
packetTypeConstructor = c
|
||||
}
|
||||
});
|
||||
nmsChatMessageTypeClass = packetTypeConstructor.parameterTypes[1];
|
||||
if (nmsChatMessageTypeClass.isEnum()) {
|
||||
chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants();
|
||||
} else {
|
||||
switch (nmsChatMessageTypeClass.name) {
|
||||
case "int":
|
||||
//@ts-ignore
|
||||
nmsChatMessageTypeClass = java.lang.Integer;
|
||||
break;
|
||||
case "byte":
|
||||
//@ts-ignore
|
||||
nmsChatMessageTypeClass = java.lang.Byte;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var entityPlayerClass = nmsCls('EntityPlayer');
|
||||
var packetClass = nmsCls('Packet');
|
||||
var playerConnectionField = remapFieldName(entityPlayerClass, 'playerConnection', 'field_71135_a')
|
||||
playerConnectionFieldName = playerConnectionField.getName()
|
||||
sendPacketMethod = remapMethod(playerConnectionField.getType(), 'sendPacket', 'func_179290_a', packetClass)
|
||||
}
|
||||
|
||||
function json(sender, json) {
|
||||
if (downgrade) {
|
||||
return '/tellraw ' + sender.name + ' ' + json
|
||||
} else {
|
||||
send(sender, json, 0);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function send(sender, json, type) {
|
||||
//@ts-ignore
|
||||
sendPacket(sender, packetTypeConstructor.newInstance(nmsChatSerializerMethod.invoke(null, json), chatMessageTypes == null ? nmsChatMessageTypeClass.valueOf(java.lang.String.valueOf(type)) : chatMessageTypes[type]))
|
||||
}
|
||||
|
||||
function sendPacket(player, p) {
|
||||
sendPacketMethod.invoke(player.handle[playerConnectionFieldName], p)
|
||||
}
|
||||
|
||||
try {
|
||||
init();
|
||||
} catch (ex) {
|
||||
org.bukkit.Bukkit.getConsoleSender().sendMessage(`§6[§cMS§6][§bbukkit§6][§achat§6] §cNMS Inject Error §4${ex} §cDowngrade to Command Mode...`)
|
||||
downgrade = true;
|
||||
}
|
||||
|
||||
let chat = {
|
||||
json
|
||||
}
|
||||
|
||||
export default chat
|
||||
48
packages/bukkit/src/event.ts
Normal file
48
packages/bukkit/src/event.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { event, plugin } from '@ms/api'
|
||||
import { inject, provideSingleton } from '@ms/container';
|
||||
import * as reflect from '@ms/common/dist/reflect'
|
||||
|
||||
const Bukkit = Java.type("org.bukkit.Bukkit");
|
||||
const Event = Java.type("org.bukkit.event.Event");
|
||||
const Modifier = Java.type("java.lang.reflect.Modifier");
|
||||
const Listener = Java.type("org.bukkit.event.Listener");
|
||||
const EventPriority = Java.type("org.bukkit.event.EventPriority");
|
||||
const EventExecutor = Java.type("org.bukkit.plugin.EventExecutor");
|
||||
|
||||
@provideSingleton(event.Event)
|
||||
export class BukkitEvent extends event.Event {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any
|
||||
|
||||
constructor() {
|
||||
super('org/bukkit/event');
|
||||
}
|
||||
|
||||
getJarFile(resource: string) {
|
||||
return super.getJarFile('org/bukkit/Bukkit.class')
|
||||
}
|
||||
isValidEvent(clazz: any): boolean {
|
||||
// 继承于 org.bukkit.event.Event
|
||||
return Event.class.isAssignableFrom(clazz) &&
|
||||
// 访问符为Public
|
||||
Modifier.isPublic(clazz.getModifiers()) &&
|
||||
// 不是抽象类
|
||||
!Modifier.isAbstract(clazz.getModifiers());
|
||||
}
|
||||
register(eventCls: any, exec: Function, priority: event.EventPriority, ignoreCancel: boolean) {
|
||||
let listener = new Listener({});
|
||||
Bukkit.pluginManager.registerEvent(
|
||||
eventCls,
|
||||
listener,
|
||||
EventPriority[priority],
|
||||
new EventExecutor({
|
||||
execute: exec
|
||||
}),
|
||||
this.pluginInstance,
|
||||
ignoreCancel);
|
||||
return listener;
|
||||
}
|
||||
unregister(event: any, listener: any): void {
|
||||
reflect.on(event).call('getHandlerList').get().unregister(listener);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,15 @@
|
||||
import { server, plugin, command } from '@ms/api'
|
||||
import { DefaultContainer as container } from '@ms/container'
|
||||
/// <reference types="@ms/types/dist/typings/bukkit" />
|
||||
|
||||
import { BukkitConsole } from './console'
|
||||
import { BukkitCommand } from './command';
|
||||
import { server } from '@ms/api'
|
||||
import { Container } from '@ms/container'
|
||||
|
||||
let BukkitServerType = 'bukkit';
|
||||
let Bukkit = Java.type("org.bukkit.Bukkit");
|
||||
import { BukkitConsole } from './console';
|
||||
import './event';
|
||||
import './server';
|
||||
import './command';
|
||||
import './channel';
|
||||
import './task';
|
||||
|
||||
container.bind(server.Console).toConstantValue(BukkitConsole);
|
||||
container.bind(server.ServerType).toConstantValue(BukkitServerType);
|
||||
container.bind(plugin.PluginInstance).toConstantValue(Bukkit.pluginManager.getPlugin('MiaoScript'));
|
||||
|
||||
container.bind(command.Command).to(BukkitCommand).inSingletonScope();
|
||||
export default function BukkitImpl(container: Container) {
|
||||
container.bind(server.Console).toConstantValue(BukkitConsole);
|
||||
}
|
||||
|
||||
55
packages/bukkit/src/server.ts
Normal file
55
packages/bukkit/src/server.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { server } from '@ms/api'
|
||||
import { provideSingleton } from '@ms/container';
|
||||
|
||||
import chat from './enhance/chat'
|
||||
|
||||
let Bukkit = org.bukkit.Bukkit;
|
||||
|
||||
@provideSingleton(server.Server)
|
||||
export class BukkitServer implements server.Server {
|
||||
private pluginsFolder: string;
|
||||
|
||||
constructor() {
|
||||
this.pluginsFolder = Bukkit.getUpdateFolderFile().getParentFile().getCanonicalPath();
|
||||
}
|
||||
|
||||
getPlayer(name: string) {
|
||||
return Bukkit.getPlayer(name)
|
||||
}
|
||||
getVersion(): string {
|
||||
return Bukkit.getVersion()
|
||||
}
|
||||
getOnlinePlayers() {
|
||||
return Bukkit.getOnlinePlayers() as unknown as any[]
|
||||
}
|
||||
getConsoleSender() {
|
||||
return Bukkit.getConsoleSender()
|
||||
}
|
||||
getService(service: string) {
|
||||
return Bukkit.getServicesManager().getRegistration(base.getClass(service))?.getProvider()
|
||||
}
|
||||
dispatchCommand(sender: string | any, command: string): boolean {
|
||||
if (typeof sender === 'string') {
|
||||
sender = this.getPlayer(sender)
|
||||
}
|
||||
return Bukkit.dispatchCommand(sender, command)
|
||||
}
|
||||
dispatchConsoleCommand(command: string): boolean {
|
||||
return Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command)
|
||||
}
|
||||
getPluginsFolder(): string {
|
||||
return this.pluginsFolder;
|
||||
}
|
||||
getNativePluginManager() {
|
||||
return Bukkit.getPluginManager() as any;
|
||||
}
|
||||
sendJson(sender: string | any, json: object | string): void {
|
||||
if (typeof sender === "string") {
|
||||
sender = this.getPlayer(sender)
|
||||
}
|
||||
let result = chat.json(sender, json)
|
||||
if (result !== false) {
|
||||
this.dispatchConsoleCommand(result)
|
||||
}
|
||||
}
|
||||
}
|
||||
34
packages/bukkit/src/task.ts
Normal file
34
packages/bukkit/src/task.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { task, plugin } from '@ms/api'
|
||||
import { inject, provideSingleton } from '@ms/container';
|
||||
|
||||
const Bukkit = Java.type('org.bukkit.Bukkit');
|
||||
const BukkitRunnable = Java.type('org.bukkit.scheduler.BukkitRunnable');
|
||||
const Callable = Java.type('java.util.concurrent.Callable')
|
||||
|
||||
@provideSingleton(task.TaskManager)
|
||||
export class BukkitTaskManager implements task.TaskManager {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any;
|
||||
|
||||
create(func: Function): task.Task {
|
||||
if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !'); };
|
||||
return new BukkitTask(this.pluginInstance, func);
|
||||
}
|
||||
callSyncMethod(func: Function): any {
|
||||
return Bukkit.getScheduler().callSyncMethod(this.pluginInstance, new Callable({ call: () => func() })).get()
|
||||
}
|
||||
}
|
||||
|
||||
export class BukkitTask extends task.Task {
|
||||
submit(): task.Cancelable {
|
||||
let run = new BukkitRunnable({
|
||||
run: () => this.run()
|
||||
})
|
||||
let funcName = `runTask${this.interval ? 'Timer' : 'Later'}${this.isAsync ? 'Asynchronously' : ''}`
|
||||
if (this.interval) {
|
||||
return run[funcName](this.plugin, this.laterTime, this.interval)
|
||||
} else {
|
||||
return run[funcName](this.plugin, this.laterTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
34
packages/bungee/package.json
Normal file
34
packages/bungee/package.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "@ms/bungee",
|
||||
"version": "0.4.0",
|
||||
"description": "MiaoScript bungee package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
"bukkit",
|
||||
"sponge"
|
||||
],
|
||||
"author": "MiaoWoo <admin@yumc.pw>",
|
||||
"homepage": "https://github.com/circlecloud/ms.git",
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf dist",
|
||||
"watch": "tsc --watch",
|
||||
"build": "yarn clean && tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ms/api": "^0.4.0",
|
||||
"@ms/common": "^0.4.0",
|
||||
"@ms/container": "^0.4.0"
|
||||
}
|
||||
}
|
||||
25
packages/bungee/src/channel.ts
Normal file
25
packages/bungee/src/channel.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { channel, event } from '@ms/api'
|
||||
import { provideSingleton, inject } from '@ms/container'
|
||||
|
||||
const Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy()
|
||||
|
||||
@provideSingleton(channel.Channel)
|
||||
export class BungeeChannel extends channel.Channel {
|
||||
@inject(event.Event)
|
||||
private eventManager: event.Event;
|
||||
|
||||
send(player: any, channel: string, data: any) {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
register(channel: string, listener: channel.ChannelListener) {
|
||||
Bungee.registerChannel(channel);
|
||||
// console.console('§6[§eWARN§6] §eMiaoScript channel in BungeeCord only register. you need self hanler PluginMessageEvent!')
|
||||
return this.eventManager.listen({ description: { name: channel } }, "PluginMessageEvent", (event: net.md_5.bungee.api.event.PluginMessageEvent) => {
|
||||
listener(event.getData(), event)
|
||||
})
|
||||
}
|
||||
unregister(channel: string, listener: any) {
|
||||
Bungee.unregisterChannel(channel);
|
||||
listener.off();
|
||||
}
|
||||
}
|
||||
65
packages/bungee/src/command.ts
Normal file
65
packages/bungee/src/command.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { command, plugin } from "@ms/api";
|
||||
import { inject, provideSingleton } from "@ms/container";
|
||||
|
||||
const Arrays = Java.type('java.util.Arrays')
|
||||
const Command = Java.extend(Java.type('net.md_5.bungee.api.plugin.Command'), Java.type('net.md_5.bungee.api.plugin.TabExecutor'));
|
||||
const createCommand = eval(`
|
||||
function(cls, name, exec, tab){
|
||||
return new cls(name) {
|
||||
execute: exec,
|
||||
onTabComplete: tab
|
||||
}
|
||||
}
|
||||
`)
|
||||
|
||||
@provideSingleton(command.Command)
|
||||
export class BungeeCommand extends command.Command {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any;
|
||||
private pluginManager: net.md_5.bungee.api.plugin.PluginManager = base.getInstance().getProxy().getPluginManager();
|
||||
private commandMapping: any[] = [];
|
||||
|
||||
create(plugin: any, command: string) {
|
||||
let commandKey = this.getCommandKey(plugin, command);
|
||||
let commandCallable = new SimpleCommand(command);
|
||||
this.pluginManager.registerCommand(this.pluginInstance, commandCallable.callable)
|
||||
this.commandMapping[commandKey] = commandCallable.callable;
|
||||
return commandCallable;
|
||||
}
|
||||
remove(plugin: any, command: string) {
|
||||
var commandKey = this.getCommandKey(plugin, command);
|
||||
if (this.commandMapping[commandKey]) {
|
||||
this.pluginManager.unregisterCommand(this.commandMapping[commandKey])
|
||||
delete this.commandMapping[commandKey];
|
||||
}
|
||||
}
|
||||
onCommand(plugin: any, command: any, executor: Function) {
|
||||
command.setExecutor(super.setExecutor(plugin, command, executor));
|
||||
}
|
||||
onTabComplete(plugin: any, command: any, tabCompleter: Function) {
|
||||
command.setTabComplete(super.setTabCompleter(plugin, command, tabCompleter))
|
||||
}
|
||||
|
||||
private getCommandKey(plugin: any, command: string) {
|
||||
return plugin.description.name.toLowerCase() + ":" + command;
|
||||
}
|
||||
}
|
||||
|
||||
class SimpleCommand {
|
||||
public callable: any;
|
||||
private name: string;
|
||||
private executor: Function;
|
||||
private tabComplete: Function = () => [];
|
||||
|
||||
constructor(command: string) {
|
||||
this.name = command;
|
||||
this.callable = createCommand(Command, command,
|
||||
(sender, args) => this.executor(sender, '', command, args),
|
||||
(sender, args) => Arrays.asList(this.tabComplete(sender, '', command, args))
|
||||
);
|
||||
}
|
||||
|
||||
setExecutor = (executor: Function) => this.executor = executor;
|
||||
setTabComplete = (tabComplete: Function) => this.tabComplete = tabComplete;
|
||||
toString = () => `Bungee SimpleCommand(${this.name})`
|
||||
}
|
||||
27
packages/bungee/src/console.ts
Normal file
27
packages/bungee/src/console.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import '@ms/nashorn'
|
||||
import { plugin, MiaoScriptConsole } from '@ms/api'
|
||||
import { inject, injectable } from "@ms/container";
|
||||
|
||||
let CommandSender = Java.type("net.md_5.bungee.api.CommandSender")
|
||||
|
||||
@injectable()
|
||||
export class BungeeConsole extends MiaoScriptConsole {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any
|
||||
private proxyServer: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
|
||||
|
||||
sender(sender, ...args) {
|
||||
if (!(sender instanceof CommandSender)) {
|
||||
this.error('第一个参数未实现 net.md_5.bungee.api.CommandSender 无法发送消息!')
|
||||
return
|
||||
}
|
||||
if (Object.prototype.toString.call(args[0]) === '[object Array]') {
|
||||
args[0].forEach(line => sender.sendMessage(this.prefix + line))
|
||||
} else {
|
||||
sender.sendMessage(this.prefix + args.join(' '));
|
||||
}
|
||||
}
|
||||
console(...args): void {
|
||||
this.sender(this.proxyServer.getConsole(), args.join(' '));
|
||||
}
|
||||
}
|
||||
117
packages/bungee/src/event.ts
Normal file
117
packages/bungee/src/event.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
import { event } from '@ms/api'
|
||||
import { provideSingleton, postConstruct } from '@ms/container'
|
||||
import * as reflect from '@ms/common/dist/reflect'
|
||||
|
||||
const Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
|
||||
const Event = Java.type("net.md_5.bungee.api.plugin.Event");
|
||||
const Modifier = Java.type("java.lang.reflect.Modifier");
|
||||
const ProxyClass = Java.type(base.getProxyClass().name);
|
||||
const ProxyMethod = reflect.on(base.getProxyClass()).method("method");
|
||||
const HashMap = Java.type('java.util.HashMap');
|
||||
const ReflectMethodArray = Java.type('java.lang.reflect.Method[]');
|
||||
|
||||
const Byte = Java.type('java.lang.Byte');
|
||||
const EventPriority = [];
|
||||
EventPriority[event.EventPriority.LOWEST] = Byte.valueOf(-64);
|
||||
EventPriority[event.EventPriority.LOW] = -Byte.valueOf(32);
|
||||
EventPriority[event.EventPriority.NORMAL] = Byte.valueOf(0);
|
||||
EventPriority[event.EventPriority.HIGH] = Byte.valueOf(32);
|
||||
EventPriority[event.EventPriority.HIGHEST] = Byte.valueOf(64);
|
||||
|
||||
/**
|
||||
* Bungee Event Impl
|
||||
*/
|
||||
@provideSingleton(event.Event)
|
||||
export class BungeeEvent extends event.Event {
|
||||
private pluginManager = Bungee.getPluginManager()
|
||||
|
||||
// EventBus
|
||||
private eventBus: any;
|
||||
// private final Lock lock = new ReentrantLock();
|
||||
private lock: any;
|
||||
// private final Map<Class<?>, Map<Byte, Map<Object, Method[]>>> byListenerAndPriority = new HashMap<>();
|
||||
private byListenerAndPriority: any;
|
||||
// bakeHandlers(Class<?> eventClass)
|
||||
private bakeHandlers: any;
|
||||
|
||||
constructor() {
|
||||
super('net/md_5/bungee/api/event');
|
||||
}
|
||||
|
||||
@postConstruct()
|
||||
init() {
|
||||
this.eventBus = reflect.on(this.pluginManager).get('eventBus').get();
|
||||
this.lock = reflect.on(this.eventBus).get('lock').get()
|
||||
this.byListenerAndPriority = reflect.on(this.eventBus).get('byListenerAndPriority').get();
|
||||
this.bakeHandlers = reflect.accessible(reflect.on(this.eventBus).method("bakeHandlers"));
|
||||
}
|
||||
|
||||
isValidEvent(clazz: any): boolean {
|
||||
//继承于 net.md_5.bungee.api.plugin.Event
|
||||
return Event.class.isAssignableFrom(clazz) &&
|
||||
// 访问符为Public
|
||||
Modifier.isPublic(clazz.getModifiers()) &&
|
||||
// 不是抽象类
|
||||
!Modifier.isAbstract(clazz.getModifiers());
|
||||
}
|
||||
|
||||
register(eventCls: any, exec: Function, priority: event.EventPriority = event.EventPriority.NORMAL, ignoreCancel: boolean = true) {
|
||||
this.lock.lock()
|
||||
try {
|
||||
// private final Map<类, Map<优先级, Map<监听器, 方法[]>>> byListenerAndPriority = new HashMap<>();
|
||||
// this.byListenerAndPriority.put(eventCls)
|
||||
// Map<优先级, Map<监听器, 方法[]>>
|
||||
let prioritiesMap = this.byListenerAndPriority.get(eventCls);
|
||||
if (prioritiesMap == null) {
|
||||
prioritiesMap = new HashMap();
|
||||
this.byListenerAndPriority.put(eventCls, prioritiesMap);
|
||||
}
|
||||
// Map<监听器, 方法[]>
|
||||
let currentPriorityMap = prioritiesMap.get(EventPriority[priority]);
|
||||
if (currentPriorityMap == null) {
|
||||
currentPriorityMap = new HashMap();
|
||||
prioritiesMap.put(EventPriority[priority], currentPriorityMap);
|
||||
}
|
||||
let listener = new ProxyClass(ScriptEngineContextHolder.getEngine(), "exec(args)", { exec, priority: EventPriority[priority] })
|
||||
// 方法[]
|
||||
let methods = new ReflectMethodArray(1);
|
||||
methods[0] = ProxyMethod;
|
||||
currentPriorityMap.put(listener, methods);
|
||||
this.bakeHandlers.invoke(this.eventBus, eventCls);
|
||||
return listener;
|
||||
} catch (ex) {
|
||||
console.ex(ex)
|
||||
} finally {
|
||||
this.lock.unlock()
|
||||
}
|
||||
}
|
||||
|
||||
unregister(eventCls: any, listener: any): void {
|
||||
this.lock.lock()
|
||||
try {
|
||||
// private final Map<类, Map<优先级, Map<监听器, 方法[]>>> byListenerAndPriority = new HashMap<>();
|
||||
// Map<优先级, Map<监听器, 方法[]>>
|
||||
let prioritiesMap = this.byListenerAndPriority.get(eventCls);
|
||||
if (prioritiesMap != null) {
|
||||
let bindings = reflect.on(listener).get("bindings").get();
|
||||
let priority = bindings["priority"];
|
||||
// Map<监听器, 方法[]>
|
||||
let currentPriorityMap = prioritiesMap.get(priority);
|
||||
if (currentPriorityMap != null) {
|
||||
currentPriorityMap.remove(listener);
|
||||
if (currentPriorityMap.isEmpty()) {
|
||||
prioritiesMap.remove(priority);
|
||||
}
|
||||
}
|
||||
if (prioritiesMap.isEmpty()) {
|
||||
this.byListenerAndPriority.remove(eventCls);
|
||||
}
|
||||
this.bakeHandlers.invoke(this.eventBus, eventCls);
|
||||
}
|
||||
} catch (ex) {
|
||||
console.ex(ex)
|
||||
} finally {
|
||||
this.lock.unlock()
|
||||
}
|
||||
}
|
||||
}
|
||||
15
packages/bungee/src/index.ts
Normal file
15
packages/bungee/src/index.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/// <reference types="@ms/types/dist/typings/bungee" />
|
||||
|
||||
import { server } from '@ms/api'
|
||||
import { Container } from '@ms/container'
|
||||
|
||||
import { BungeeConsole } from './console';
|
||||
import './event';
|
||||
import './server';
|
||||
import './command';
|
||||
import './channel';
|
||||
import './task';
|
||||
|
||||
export default function BungeeImpl(container: Container) {
|
||||
container.bind(server.Console).toConstantValue(BungeeConsole);
|
||||
}
|
||||
47
packages/bungee/src/server.ts
Normal file
47
packages/bungee/src/server.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { server } from '@ms/api'
|
||||
import { provideSingleton } from '@ms/container';
|
||||
|
||||
let Bungee: net.md_5.bungee.api.ProxyServer = base.getInstance().getProxy();
|
||||
|
||||
@provideSingleton(server.Server)
|
||||
export class BungeeServer implements server.Server {
|
||||
private pluginsFolder: string;
|
||||
|
||||
constructor() {
|
||||
this.pluginsFolder = Bungee.getPluginsFolder().getCanonicalPath();
|
||||
}
|
||||
|
||||
getPlayer(name: string) {
|
||||
return Bungee.getPlayer(name);
|
||||
}
|
||||
getVersion(): string {
|
||||
return Bungee.getVersion()
|
||||
}
|
||||
getOnlinePlayers() {
|
||||
return Bungee.getPlayers()
|
||||
}
|
||||
getConsoleSender() {
|
||||
return Bungee.getConsole()
|
||||
}
|
||||
getService(service: string) {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
dispatchCommand(sender: string | any, command: string): boolean {
|
||||
if (typeof sender === 'string') {
|
||||
sender = this.getPlayer(sender)
|
||||
}
|
||||
return Bungee.getPluginManager().dispatchCommand(sender, command)
|
||||
}
|
||||
dispatchConsoleCommand(command: string): boolean {
|
||||
return Bungee.getPluginManager().dispatchCommand(Bungee.getConsole(), command)
|
||||
}
|
||||
getPluginsFolder(): string {
|
||||
return this.pluginsFolder;
|
||||
}
|
||||
getNativePluginManager() {
|
||||
return Bungee.getPluginManager() as any
|
||||
}
|
||||
sendJson(sender: string | any, json: string): void {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}
|
||||
33
packages/bungee/src/task.ts
Normal file
33
packages/bungee/src/task.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { task, plugin } from '@ms/api'
|
||||
import { inject, provideSingleton } from '@ms/container';
|
||||
|
||||
var Runnable = Java.type('java.lang.Runnable')
|
||||
let TimeUnit = Java.type('java.util.concurrent.TimeUnit')
|
||||
|
||||
@provideSingleton(task.TaskManager)
|
||||
export class BungeeTaskManager implements task.TaskManager {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any;
|
||||
|
||||
create(func: Function): task.Task {
|
||||
if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !'); };
|
||||
return new BungeeTask(this.pluginInstance, func);
|
||||
}
|
||||
callSyncMethod(func: Function): any {
|
||||
return func();
|
||||
}
|
||||
}
|
||||
|
||||
export class BungeeTask extends task.Task {
|
||||
submit(): task.Cancelable {
|
||||
let run = new Runnable({ run: () => this.run() })
|
||||
if (this.isAsync) {
|
||||
return this.plugin.getProxy().getScheduler().runAsync(this.plugin, run)
|
||||
}
|
||||
if (this.interval) {
|
||||
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime, this.interval, TimeUnit.MILLISECONDS)
|
||||
} else {
|
||||
return this.plugin.getProxy().getScheduler().schedule(this.plugin, run, this.laterTime, TimeUnit.MILLISECONDS)
|
||||
}
|
||||
}
|
||||
}
|
||||
8
packages/bungee/tsconfig.json
Normal file
8
packages/bungee/tsconfig.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "src",
|
||||
"outDir": "dist",
|
||||
"allowJs": true
|
||||
}
|
||||
}
|
||||
35
packages/client/package.json
Normal file
35
packages/client/package.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"private": true,
|
||||
"name": "@ms/client",
|
||||
"version": "0.4.0",
|
||||
"description": "MiaoScript client package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
"bukkit",
|
||||
"sponge"
|
||||
],
|
||||
"author": "MiaoWoo <admin@yumc.pw>",
|
||||
"homepage": "https://github.com/circlecloud/ms.git",
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "ts-node-dev --respawn --debounce=1500 src/index.ts",
|
||||
"clean": "rimraf dist",
|
||||
"watch": "tsc --watch",
|
||||
"build": "yarn clean && tsc",
|
||||
"start": "node dist/index.js",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"minecraft-protocol": "^1.11.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^6.14.2",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^3.8.3"
|
||||
}
|
||||
}
|
||||
101
packages/client/src/color.ts
Normal file
101
packages/client/src/color.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
class MessagePart {
|
||||
text: string
|
||||
color: string
|
||||
clickEvent: MessagePartEvent
|
||||
hoverEvent: MessagePartEvent
|
||||
translate: string
|
||||
with: MessagePart[]
|
||||
extra: MessagePart[]
|
||||
}
|
||||
|
||||
class MessagePartEvent {
|
||||
action: string
|
||||
value: string
|
||||
}
|
||||
|
||||
var colorMap = []
|
||||
colorMap['0'] = '38;5;0'
|
||||
colorMap['1'] = '38;5;4'
|
||||
colorMap['2'] = '38;5;2'
|
||||
colorMap['3'] = '38;5;6'
|
||||
colorMap['4'] = '38;5;1'
|
||||
colorMap['5'] = '38;5;5'
|
||||
colorMap['6'] = '38;5;3'
|
||||
colorMap['7'] = '38;5;7'
|
||||
colorMap['8'] = '38;5;8'
|
||||
colorMap['9'] = '38;5;12'
|
||||
colorMap['a'] = '38;5;10'
|
||||
colorMap['b'] = '38;5;14'
|
||||
colorMap['c'] = '38;5;9'
|
||||
colorMap['d'] = '38;5;13'
|
||||
colorMap['e'] = '38;5;11'
|
||||
colorMap['f'] = '38;5;15'
|
||||
colorMap['r'] = '0'
|
||||
colorMap['l'] = '1'
|
||||
colorMap['n'] = '4'
|
||||
var regexMap = []
|
||||
for (const c in colorMap) {
|
||||
regexMap[colorMap[c]] = new RegExp(`§${c}`, "g")
|
||||
}
|
||||
function mcColor2ANSI(str) {
|
||||
for (const regex in regexMap) {
|
||||
str = str.replace(regexMap[regex], `\u001b[${regex}m`)
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
let jsonColorMap = {
|
||||
"black": '0',
|
||||
"dark_blue": '1',
|
||||
"dark_green": '2',
|
||||
"dark_aqua": '3',
|
||||
"dark_red": '4',
|
||||
"dark_purple": '5',
|
||||
"gold": '6',
|
||||
"gray": '7',
|
||||
"dark_gray": '8',
|
||||
"blue": '9',
|
||||
"green": 'a',
|
||||
"aqua": 'b',
|
||||
"red": 'c',
|
||||
"light_purple": 'd',
|
||||
"yellow": 'e',
|
||||
"white": 'f',
|
||||
"obfuscated": 'k',
|
||||
"bold": 'l',
|
||||
"strikethrough": 'm',
|
||||
"underline": 'n',
|
||||
"italic": 'o',
|
||||
"reset": 'r',
|
||||
};
|
||||
|
||||
function json2text(json: MessagePart): string {
|
||||
let temp = "";
|
||||
if (json.color) {
|
||||
temp += `§${jsonColorMap[json.color]}`
|
||||
}
|
||||
temp += json.text || json.translate || ''
|
||||
if (json.extra) {
|
||||
json.extra.forEach((ext) => {
|
||||
temp += json2text(ext)
|
||||
})
|
||||
}
|
||||
return temp += '§r'
|
||||
}
|
||||
|
||||
function $(input: any) {
|
||||
if (typeof input === "string") {
|
||||
input = JSON.parse(input)
|
||||
}
|
||||
input = json2text(input) + '§r'
|
||||
if (input.startsWith('§卐')) {
|
||||
input = input.substring(2)
|
||||
}
|
||||
return mcColor2ANSI(input)
|
||||
}
|
||||
|
||||
export {
|
||||
json2text,
|
||||
mcColor2ANSI,
|
||||
$
|
||||
}
|
||||
27
packages/client/src/event.ts
Normal file
27
packages/client/src/event.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { $ } from './color'
|
||||
|
||||
export function attachEvents(client) {
|
||||
client.on('chat', (packet) => {
|
||||
// Listen for chat messages and echo them back.
|
||||
var jsonMsg = JSON.parse(packet.message);
|
||||
console.log($(jsonMsg))
|
||||
})
|
||||
client.on('state', (newState, oldState) => {
|
||||
console.log('Client Change State', oldState, 'to', newState)
|
||||
let targetServer = process.argv[3]
|
||||
if (newState == "play" && targetServer) {
|
||||
setTimeout(() => {
|
||||
client.write('chat', {
|
||||
message: '/server ' + targetServer
|
||||
})
|
||||
}, 3000)
|
||||
}
|
||||
})
|
||||
client.on('update_health', (packet) => {
|
||||
if (packet.health <= 0) {
|
||||
console.log("Player Dead Auto Respawn...")
|
||||
client.write('client_command', { payload: 0 })
|
||||
} else if (packet.health > 0) {
|
||||
}
|
||||
})
|
||||
}
|
||||
14
packages/client/src/forge.ts
Normal file
14
packages/client/src/forge.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
export function attachForge(client) {
|
||||
client.on('custom_payload', function(packet) {
|
||||
if (packet.channel === 'FML|HS') {
|
||||
client.write('custom_payload', {
|
||||
channel: 'FML|HS',
|
||||
data: Buffer.of(0x01, 0x02)
|
||||
});
|
||||
client.write('custom_payload', {
|
||||
channel: 'FML|HS',
|
||||
data: Buffer.of(0x02, 0x00)
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
77
packages/client/src/index.ts
Normal file
77
packages/client/src/index.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
import { createInterface } from 'readline'
|
||||
import { createClient } from 'minecraft-protocol'
|
||||
|
||||
import { attachForge } from './forge'
|
||||
import { attachEvents } from './event'
|
||||
|
||||
let username = process.argv[2] || 'Mr_jtb'
|
||||
let client = createConnection('192.168.2.5', 25577, username)
|
||||
|
||||
function createConnection(host: string, port: number, username: string) {
|
||||
let client = createClient({
|
||||
version: '1.12.2',
|
||||
host,
|
||||
port,
|
||||
username,
|
||||
skipValidation: true
|
||||
})
|
||||
|
||||
attachForge(client)
|
||||
attachEvents(client)
|
||||
return client;
|
||||
}
|
||||
|
||||
client.on('error', (error) => {
|
||||
console.log("Client Error", error)
|
||||
})
|
||||
|
||||
client.on('end', (resone) => {
|
||||
console.log("Client End Resone:", resone)
|
||||
client = createConnection('192.168.2.5', 25577, username)
|
||||
})
|
||||
|
||||
const rl = createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
completer: (line, func) => {
|
||||
let args = line.split(' ')
|
||||
let comp = args[args.length - 1]
|
||||
client.once('tab_complete', (msg) => {
|
||||
let mcts = msg.matches.filter(s => s)
|
||||
func(null, [mcts, comp])
|
||||
})
|
||||
client.write('tab_complete', {
|
||||
text: line
|
||||
})
|
||||
},
|
||||
terminal: true,
|
||||
prompt: ''
|
||||
})
|
||||
|
||||
rl.on('line', function (line) {
|
||||
switch (line) {
|
||||
case "":
|
||||
break;
|
||||
case "eval":
|
||||
break;
|
||||
case "write":
|
||||
break;
|
||||
case "/respawn":
|
||||
client.write('client_command', { payload: 0 })
|
||||
break;
|
||||
case "//reco":
|
||||
client.end("")
|
||||
client = createConnection('192.168.2.5', 25577, username)
|
||||
break;
|
||||
case "//quit":
|
||||
console.info('Disconnected')
|
||||
client.end("")
|
||||
break;
|
||||
case "//end":
|
||||
console.info('Forcibly ended client')
|
||||
process.exit(0)
|
||||
default:
|
||||
client.write('chat', { message: line })
|
||||
}
|
||||
rl.prompt()
|
||||
})
|
||||
7
packages/client/tsconfig.json
Normal file
7
packages/client/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "src",
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
4
packages/common/.gitignore
vendored
4
packages/common/.gitignore
vendored
@@ -1,4 +0,0 @@
|
||||
/node_modules
|
||||
/dist
|
||||
/package-lock.json
|
||||
/yarn.lock
|
||||
@@ -1,22 +0,0 @@
|
||||
src
|
||||
test
|
||||
typings
|
||||
bundled
|
||||
build
|
||||
coverage
|
||||
docs
|
||||
wiki
|
||||
gulpfile.js
|
||||
bower.json
|
||||
karma.conf.js
|
||||
tsconfig.json
|
||||
typings.json
|
||||
CONTRIBUTING.md
|
||||
ISSUE_TEMPLATE.md
|
||||
PULL_REQUEST_TEMPLATE.md
|
||||
tslint.json
|
||||
wallaby.js
|
||||
.travis.yml
|
||||
.gitignore
|
||||
.vscode
|
||||
type_definitions
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ms/common",
|
||||
"version": "0.0.0",
|
||||
"version": "0.4.0",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -13,20 +13,21 @@
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm/"
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf dist",
|
||||
"watch": "npx tsc --watch",
|
||||
"build": "yarn clean && npx tsc",
|
||||
"watch": "tsc --watch",
|
||||
"build": "yarn clean && tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.0",
|
||||
"typescript": "^3.6.2"
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ms/nashorn": "^0.0.0"
|
||||
}
|
||||
"@ms/nashorn": "^0.4.0"
|
||||
},
|
||||
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ const StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
|
||||
/**
|
||||
* 用文件分割符合并路径
|
||||
*/
|
||||
export function concat() {
|
||||
return Array.prototype.join.call(arguments, separatorChar);
|
||||
export function concat(...args: string[]) {
|
||||
return args.join(separatorChar);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,12 +23,12 @@ export function concat() {
|
||||
* @returns {*}
|
||||
*/
|
||||
export function file(...opts: any[]): any {
|
||||
if (!arguments[0]) {
|
||||
if (!opts[0]) {
|
||||
console.warn("文件名称不得为 undefined 或者 null !");
|
||||
}
|
||||
switch (arguments.length) {
|
||||
switch (opts.length) {
|
||||
case 1:
|
||||
var f = arguments[0];
|
||||
var f = opts[0];
|
||||
if (f instanceof File) {
|
||||
return f;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ export function file(...opts: any[]): any {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return new File(file(arguments[0]), arguments[1]);
|
||||
return new File(file(opts[0]), opts[1]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ export function file(...opts: any[]): any {
|
||||
* 创建目录
|
||||
* @param path
|
||||
*/
|
||||
export function mkdirs(path) {
|
||||
export function mkdirs(path: any) {
|
||||
// noinspection JSUnresolvedVariable
|
||||
file(path).parentFile.mkdirs();
|
||||
}
|
||||
@@ -57,7 +57,7 @@ export function mkdirs(path) {
|
||||
* 创建文件
|
||||
* @param file
|
||||
*/
|
||||
export function create(path) {
|
||||
export function create(path: any) {
|
||||
var f = file(path);
|
||||
if (!f.exists()) {
|
||||
mkdirs(f);
|
||||
@@ -70,7 +70,7 @@ export function create(path) {
|
||||
* @param file
|
||||
* @returns {*}
|
||||
*/
|
||||
export function path(f) {
|
||||
export function path(f: any) {
|
||||
return file(f).canonicalPath;
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ export function path(f) {
|
||||
* @param target 目标文件
|
||||
* @param override 是否覆盖
|
||||
*/
|
||||
export function copy(inputStream, target, override) {
|
||||
export function copy(inputStream: any, target: any, override: any) {
|
||||
Files.copy(inputStream, target.toPath(), StandardCopyOption[override ? 'REPLACE_EXISTING' : 'ATOMIC_MOVE']);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,155 +1,54 @@
|
||||
'use strict';
|
||||
/**
|
||||
* HTTP 网络类
|
||||
* Created by 蒋天蓓 on 2017/2/9 0009.
|
||||
*/
|
||||
const URL = Java.type('java.net.URL')
|
||||
const Paths = Java.type('java.nio.file.Paths');
|
||||
const Files = Java.type('java.nio.file.Files');
|
||||
const StandardCopyOption = Java.type('java.nio.file.StandardCopyOption');
|
||||
|
||||
/*global Java, base, module, exports, require, __FILE__*/
|
||||
export type Method =
|
||||
| 'get' | 'GET'
|
||||
| 'delete' | 'DELETE'
|
||||
| 'head' | 'HEAD'
|
||||
| 'options' | 'OPTIONS'
|
||||
| 'post' | 'POST'
|
||||
| 'put' | 'PUT'
|
||||
| 'patch' | 'PATCH'
|
||||
|
||||
var URL = Java.type("java.net.URL");
|
||||
var UUID = Java.type("java.util.UUID");
|
||||
var System = Java.type("java.lang.System");
|
||||
var Files = Java.type("java.nio.file.Files");
|
||||
var Paths = Java.type("java.nio.file.Paths");
|
||||
var JavaString = Java.type("java.lang.String");
|
||||
var SecureRandom = Java.type("java.security.SecureRandom");
|
||||
|
||||
var SSLContext = Java.type("javax.net.ssl.SSLContext");
|
||||
var HttpsURLConnection = Java.type("javax.net.ssl.HttpsURLConnection");
|
||||
|
||||
var HostnameVerifier = Java.type("javax.net.ssl.HostnameVerifier");
|
||||
var X509TrustManager = Java.type("javax.net.ssl.X509TrustManager");
|
||||
|
||||
// noinspection JSUnusedGlobalSymbols,JSUnusedLocalSymbols
|
||||
var TrustAnyHostnameVerifier = new HostnameVerifier({
|
||||
verify: function(hostname, session) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
var SSLSocketFactory = function initSSLSocketFactory() {
|
||||
var sslContext = SSLContext.getInstance("TLS");
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
sslContext.init(null, [new X509TrustManager({
|
||||
getAcceptedIssuers: function() {
|
||||
return null;
|
||||
},
|
||||
checkClientTrusted: function(chain, authType) {
|
||||
},
|
||||
checkServerTrusted: function(chain, authType) {
|
||||
}
|
||||
})], new SecureRandom());
|
||||
return sslContext.getSocketFactory();
|
||||
}();
|
||||
|
||||
var config = {
|
||||
Charset: 'UTF-8',
|
||||
ConnectTimeout: 10000,
|
||||
ReadTimeout: 10000,
|
||||
Debug: false
|
||||
};
|
||||
|
||||
function open(url, method, header) {
|
||||
// conn.setRequestProperty
|
||||
var conn = new URL(url).openConnection();
|
||||
if (conn instanceof HttpsURLConnection) {
|
||||
conn.setHostnameVerifier(TrustAnyHostnameVerifier);
|
||||
conn.setSSLSocketFactory(SSLSocketFactory);
|
||||
}
|
||||
conn.setRequestMethod(method);
|
||||
conn.setDoOutput(true);
|
||||
conn.setDoInput(true);
|
||||
conn.setConnectTimeout(config.ConnectTimeout);
|
||||
conn.setReadTimeout(config.ReadTimeout);
|
||||
if (header) {
|
||||
for (var key in header) {
|
||||
// noinspection JSUnfilteredForInLoop
|
||||
conn.setRequestProperty(key, header[key]);
|
||||
}
|
||||
}
|
||||
return conn;
|
||||
interface RequestConfig {
|
||||
url?: string;
|
||||
method?: Method;
|
||||
headers?: { [key: string]: string };
|
||||
params?: { [key: string]: string };
|
||||
data?: any;
|
||||
}
|
||||
|
||||
function buildUrl(url, params) {
|
||||
if (params && Object.keys(params).length > 0) {
|
||||
var queryStart = url.indexOf('?');
|
||||
if (queryStart === -1) {
|
||||
url += '?';
|
||||
}
|
||||
return url += object2URLSearchParams(params);
|
||||
function request(config: RequestConfig) {
|
||||
// @ts-ignore
|
||||
let xhr = new XMLHttpRequest();
|
||||
xhr.open(config.method, config.url, false);
|
||||
for (const header in config.headers) {
|
||||
xhr.setRequestHeader(header, config.headers[header]);
|
||||
}
|
||||
return url;
|
||||
xhr.send(config.data);
|
||||
if ((xhr.getResponseHeader("Content-Type") + '').indexOf('application/json') != -1) {
|
||||
xhr.responseType = "json"
|
||||
}
|
||||
return xhr.get();
|
||||
}
|
||||
|
||||
function request(config) {
|
||||
var conn = open(buildUrl(config.url, config.query), config.method, config.header);
|
||||
try {
|
||||
conn.connect();
|
||||
var data = config.data;
|
||||
if (data) {
|
||||
var out = conn.getOutputStream();
|
||||
if (typeof data === "object") {
|
||||
var type = config.header['Content-Type'];
|
||||
switch (type) {
|
||||
case "application/x-www-form-urlencoded":
|
||||
data = object2URLSearchParams(data);
|
||||
break;
|
||||
default:
|
||||
data = JSON.stringify(data)
|
||||
}
|
||||
}
|
||||
out.write(new JavaString(data).getBytes(config.Charset));
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
return response(conn);
|
||||
} finally {
|
||||
conn.disconnect();
|
||||
function download(url: string, target: string) {
|
||||
console.debug(`Start Download file ${target} from ${url}....`)
|
||||
Files.copy(new URL(url).openStream(), Paths.get(target), StandardCopyOption.REPLACE_EXISTING);
|
||||
console.debug(`File ${target} Download Complate...`)
|
||||
}
|
||||
|
||||
function _proxy(method: Method) {
|
||||
return function (url: string, data?: any, config?: RequestConfig) {
|
||||
return request({ url, method, data, ...config });
|
||||
}
|
||||
}
|
||||
|
||||
function response(conn) {
|
||||
var temp = Paths.get(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
|
||||
Files.copy(conn.getInputStream(), temp);
|
||||
var result = new JavaString(Files.readAllBytes(temp), config.Charset);
|
||||
var tempFile = temp.toFile();
|
||||
tempFile.delete() || tempFile.deleteOnExit();
|
||||
return result;
|
||||
export default {
|
||||
get: _proxy('GET'),
|
||||
post: _proxy('POST'),
|
||||
request,
|
||||
download
|
||||
}
|
||||
|
||||
function object2URLSearchParams(params) {
|
||||
var temp: string[] = [];
|
||||
for (var key in params) {
|
||||
temp.push(`${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
|
||||
}
|
||||
return temp.join('&')
|
||||
}
|
||||
|
||||
var http = {
|
||||
config: config,
|
||||
request: request
|
||||
};
|
||||
|
||||
['GET', 'DELETE', 'HEAD', 'OPTIONS'].forEach(function(method) {
|
||||
http[method.toLowerCase()] = function __likeGet__(url, data, config = {}) {
|
||||
return this.request({
|
||||
...config,
|
||||
url: url,
|
||||
method: method,
|
||||
query: data
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
['POST', 'PUT', 'PATCH'].forEach(function(method) {
|
||||
http[method.toLowerCase()] = function __likePost__(url, data, config) {
|
||||
return this.request({
|
||||
...config,
|
||||
url: url,
|
||||
method: method,
|
||||
data: data
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export = http;
|
||||
|
||||
@@ -1,24 +1,26 @@
|
||||
import '@ms/core'
|
||||
/**
|
||||
* 反射工具类
|
||||
* Created by 蒋天蓓 on 2017/2/9 0009.
|
||||
* Created by MiaoWoo on 2017/2/9 0009.
|
||||
*/
|
||||
var JavaClass = Java.type('java.lang.Class');
|
||||
var JavaObject = Java.type('java.lang.Object')
|
||||
var NoSuchFieldException = Java.type('java.lang.NoSuchFieldException');
|
||||
var methodCache = [];
|
||||
const JavaClass = Java.type('java.lang.Class');
|
||||
const JavaObject = Java.type('java.lang.Object')
|
||||
const NoSuchFieldException = Java.type('java.lang.NoSuchFieldException');
|
||||
const methodCache = [];
|
||||
|
||||
class Reflect {
|
||||
private obj: any;
|
||||
private class: any
|
||||
|
||||
constructor(obj: any) {
|
||||
// if (obj === undefined || obj === null) { throw Error(`reflect object can't be ${obj}!`) }
|
||||
if (obj instanceof JavaClass) {
|
||||
this.obj = null;
|
||||
this.class = obj;
|
||||
} else {
|
||||
this.obj = obj;
|
||||
this.class = obj.class;
|
||||
if (obj !== null && obj !== undefined && obj.class) {
|
||||
this.class = obj.class;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +32,10 @@ class Reflect {
|
||||
return Java.from(declaredMethods(this.class));
|
||||
}
|
||||
|
||||
field(name) {
|
||||
field(name): Reflect {
|
||||
try {
|
||||
// Try getting a public field
|
||||
var field = this.class.field(name);
|
||||
let field = this.class.field(name);
|
||||
return on(field.get(this.obj));
|
||||
} catch (ex) {
|
||||
// Try again, getting a non-public field
|
||||
@@ -41,36 +43,34 @@ class Reflect {
|
||||
}
|
||||
};
|
||||
|
||||
fields(declared) {
|
||||
fields(declared = false) {
|
||||
return Java.from(declared ? this.class.declaredFields : this.class.fields);
|
||||
}
|
||||
|
||||
values(declared) {
|
||||
var cache = {};
|
||||
var feds = declared ? this.class.declaredFields : this.class.fields;
|
||||
Java.from(feds).forEach(function(fed) {
|
||||
cache[fed.name] = this.field(fed.name).get();
|
||||
}.bind(this))
|
||||
values(declared = false) {
|
||||
let cache = {};
|
||||
this.fields(declared).forEach(fed => cache[fed.name] = this.field(fed.name).get())
|
||||
return cache;
|
||||
}
|
||||
|
||||
call(...args) {
|
||||
var params = args.slice(1);
|
||||
var method = declaredMethod(this.class, args[0], types(params));
|
||||
return on(method.invoke(this.get(), params));
|
||||
call(...args): Reflect {
|
||||
let params = args.slice(1);
|
||||
let method = accessible(declaredMethod(this.class, args[0], types(params)));
|
||||
let result = method.invoke(this.get(), params);
|
||||
return result && on(result);
|
||||
};
|
||||
|
||||
get(...args) {
|
||||
get(...args): Reflect | any {
|
||||
return args.length === 1 ? this.field(args[0]) : this.obj;
|
||||
};
|
||||
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
set(name, value) {
|
||||
set(name, value): Reflect {
|
||||
accessible(declaredField(this.class, name)).set(this.obj, value);
|
||||
return this;
|
||||
};
|
||||
|
||||
create(...args) {
|
||||
create(...args): Reflect {
|
||||
return on(declaredConstructor(this.class, args).newInstance(args));
|
||||
};
|
||||
}
|
||||
@@ -82,7 +82,7 @@ function types(values, def?) {
|
||||
if (values === null) {
|
||||
return [];
|
||||
}
|
||||
var result = [];
|
||||
let result: any[] = [];
|
||||
values.forEach(t => result.push((t || def) ? JavaObject.class : t instanceof JavaClass ? t : t.class));
|
||||
return result;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ function accessible(accessible) {
|
||||
}
|
||||
|
||||
function declaredConstructor(clazz, param) {
|
||||
var constructor;
|
||||
let constructor;
|
||||
try {
|
||||
constructor = clazz.getDeclaredConstructor(types(param));
|
||||
} catch (ex) {
|
||||
@@ -112,16 +112,17 @@ function declaredConstructor(clazz, param) {
|
||||
}
|
||||
|
||||
function declaredField(clazz, name) {
|
||||
var field = null;
|
||||
if (!clazz) { throw Error(`target class can't be ${clazz}!`) }
|
||||
let target = clazz;
|
||||
let field = null;
|
||||
// noinspection JSUnresolvedVariable
|
||||
while (clazz !== JavaObject.class) {
|
||||
while (target !== JavaObject.class) {
|
||||
try {
|
||||
field = clazz.getDeclaredField(name);
|
||||
if (field !== null) {
|
||||
break;
|
||||
}
|
||||
field = target.getDeclaredField(name);
|
||||
if (field !== null) { break; }
|
||||
} catch (e) {
|
||||
clazz = clazz.getSuperclass();
|
||||
if (target === undefined) { break; }
|
||||
target = target.getSuperclass();
|
||||
}
|
||||
}
|
||||
if (field === null) {
|
||||
@@ -131,12 +132,21 @@ function declaredField(clazz, name) {
|
||||
}
|
||||
|
||||
function declaredMethod(clazz, name, clazzs) {
|
||||
var key = clazz.name + '.' + name + ':' + (clazzs || []).join(':');
|
||||
let key = clazz.name + '.' + name + ':' + (clazzs || []).join(':');
|
||||
if (!methodCache[key]) {
|
||||
try {
|
||||
methodCache[key] = clazz.getMethod(name, clazzs);
|
||||
} catch (ex) {
|
||||
methodCache[key] = clazz.getDeclaredMethod(name, clazzs);
|
||||
try {
|
||||
methodCache[key] = clazz.getDeclaredMethod(name, clazzs);
|
||||
} catch (ex) {
|
||||
for (const m of Java.from(declaredMethods(clazz))) {
|
||||
if (m.name == name) {
|
||||
methodCache[key] = m;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return methodCache[key];
|
||||
@@ -146,21 +156,21 @@ function declaredMethods(clazz) {
|
||||
return clazz.declaredMethods;
|
||||
}
|
||||
|
||||
var classMethodsCache = [];
|
||||
let classMethodsCache: any[] = [];
|
||||
|
||||
function mapToObject(javaObj) {
|
||||
if (!javaObj || !javaObj.class) { throw new TypeError(`参数 ${javaObj} 不是一个Java对象!`) }
|
||||
var target = {};
|
||||
let target = {};
|
||||
getJavaObjectMethods(javaObj).forEach(t => mapMethod(target, javaObj, t));
|
||||
return target;
|
||||
}
|
||||
|
||||
function getJavaObjectMethods(javaObj) {
|
||||
var className = javaObj.class.name;
|
||||
let className = javaObj.class.name;
|
||||
if (!classMethodsCache[className]) {
|
||||
var names = [];
|
||||
var methods = javaObj.class.methods;
|
||||
for (var i in methods) {
|
||||
let names: any[] = [];
|
||||
let methods = javaObj.class.methods;
|
||||
for (let i in methods) {
|
||||
names.push(methods[i].name);
|
||||
}
|
||||
classMethodsCache[className] = names;
|
||||
@@ -179,7 +189,7 @@ function mapMethod(target, source, name) {
|
||||
}
|
||||
|
||||
function on(obj) {
|
||||
if (!obj || !obj.class) { throw new TypeError(`参数 ${obj} 不是一个Java对象!`) }
|
||||
// if (!obj || !obj.class) { throw new TypeError(`参数 ${obj} 不是一个Java对象!`) }
|
||||
return new Reflect(obj);
|
||||
}
|
||||
|
||||
|
||||
109
packages/common/src/tellraw.ts
Normal file
109
packages/common/src/tellraw.ts
Normal file
@@ -0,0 +1,109 @@
|
||||
class ChatMessagePart {
|
||||
private internal: any = {}
|
||||
|
||||
get text() {
|
||||
return this.internal.text
|
||||
}
|
||||
set text(text: string) {
|
||||
this.internal.text = text
|
||||
}
|
||||
|
||||
click(action: string, value: string) {
|
||||
this.internal.clickEvent = { action, value }
|
||||
}
|
||||
|
||||
hover(action: string, value: string) {
|
||||
this.internal.hoverEvent = { action, value }
|
||||
}
|
||||
|
||||
convert() {
|
||||
return this.internal;
|
||||
}
|
||||
}
|
||||
|
||||
class Tellraw {
|
||||
static duplicateChar = '§卐'
|
||||
static create() {
|
||||
return new Tellraw().then(Tellraw.duplicateChar);
|
||||
}
|
||||
|
||||
private cache: string = '';
|
||||
private parts = [new ChatMessagePart()];
|
||||
|
||||
then(part: ChatMessagePart | string) {
|
||||
if (typeof part === "string") {
|
||||
var newPart = new ChatMessagePart();
|
||||
newPart.text = part
|
||||
this.then(newPart);
|
||||
return this;
|
||||
}
|
||||
var last = this.latest();
|
||||
if (!last.text) {
|
||||
last.text = part.text;
|
||||
} else {
|
||||
this.parts.push(part);
|
||||
}
|
||||
this.cache = null;
|
||||
}
|
||||
|
||||
text(text: string) {
|
||||
this.latest().text = text;
|
||||
return this;
|
||||
}
|
||||
|
||||
tip(text: string) {
|
||||
this.latest().hover("show_text", text);
|
||||
return this;
|
||||
}
|
||||
|
||||
item(text: string) {
|
||||
this.latest().hover("show_item", text);
|
||||
return this;
|
||||
}
|
||||
|
||||
command(command: string) {
|
||||
this.latest().click("run_command", command);
|
||||
return this;
|
||||
}
|
||||
|
||||
suggest(url: string) {
|
||||
this.latest().click("suggest_command", url);
|
||||
return this;
|
||||
}
|
||||
|
||||
file(path: string) {
|
||||
this.latest().click("open_file", path);
|
||||
return this;
|
||||
}
|
||||
|
||||
link(url: string) {
|
||||
this.latest().click("open_url", url);
|
||||
return this;
|
||||
}
|
||||
|
||||
latest() {
|
||||
return this.parts[this.parts.length - 1];
|
||||
}
|
||||
|
||||
json() {
|
||||
if (!this.cache) {
|
||||
var temp = [];
|
||||
this.parts.forEach(t => {
|
||||
temp.push(t.convert());
|
||||
});
|
||||
this.cache = JSON.stringify(temp);
|
||||
console.trace(this.cache);
|
||||
}
|
||||
return this.cache;
|
||||
}
|
||||
|
||||
string() {
|
||||
var temp = '';
|
||||
this.parts.forEach(t => {
|
||||
temp += t.text
|
||||
});
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
|
||||
export default Tellraw
|
||||
@@ -1,25 +1,30 @@
|
||||
function Template(tpl: string) {
|
||||
var match: RegExpExecArray;
|
||||
var code = ['var r=[];'];
|
||||
var re = /\{\{\s*([a-zA-Z\.\_0-9()]+)\s*\}\}/m;
|
||||
function addLine(text: string) {
|
||||
code.push('r.push(\'' + text.replace(/\'/g, '\\\'').replace(/\n/g, '\\n').replace(/\r/g, '\\r') + '\');');
|
||||
};
|
||||
while (match = re.exec(tpl)) {
|
||||
if (match.index > 0) {
|
||||
addLine(tpl.slice(0, match.index));
|
||||
class Template {
|
||||
private renderFunc: Function;
|
||||
|
||||
constructor(tpl: string) {
|
||||
var match: RegExpExecArray;
|
||||
var code = ['var r=[];'];
|
||||
var re = /\{\{\s*([a-zA-Z\.\_0-9()]+)\s*\}\}/m;
|
||||
|
||||
while (match = re.exec(tpl)) {
|
||||
if (match.index > 0) {
|
||||
this.addLine(code, tpl.slice(0, match.index));
|
||||
}
|
||||
code.push('r.push(this.' + match[1] + ');');
|
||||
tpl = tpl.substring(match.index + match[0].length);
|
||||
}
|
||||
code.push('r.push(this.' + match[1] + ');');
|
||||
tpl = tpl.substring(match.index + match[0].length);
|
||||
this.addLine(code, tpl);
|
||||
code.push('return r.join(\'\');');
|
||||
// 创建函数:
|
||||
this.renderFunc = new Function(code.join('\n'));
|
||||
}
|
||||
addLine(code: string[], text: string) {
|
||||
code.push('r.push(\'' + text.replace(/\'/g, '\\\'').replace(/\n/g, '\\n').replace(/\r/g, '\\r') + '\');');
|
||||
}
|
||||
addLine(tpl);
|
||||
code.push('return r.join(\'\');');
|
||||
// 创建函数:
|
||||
var fn = new Function(code.join('\n'));
|
||||
// 用render()调用函数并绑定this参数:
|
||||
this.render = function(model) {
|
||||
return fn.apply(model);
|
||||
};
|
||||
render(model: object) {
|
||||
return this.renderFunc.apply(model);
|
||||
}
|
||||
}
|
||||
|
||||
export = {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "src",
|
||||
"outDir": "dist",
|
||||
"declaration": true
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
29
packages/compile/package.json
Normal file
29
packages/compile/package.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "@ms/compile",
|
||||
"version": "0.4.0",
|
||||
"description": "MiaoScript compile package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
"bukkit",
|
||||
"sponge"
|
||||
],
|
||||
"author": "MiaoWoo <admin@yumc.pw>",
|
||||
"homepage": "https://github.com/circlecloud/ms.git",
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf dist",
|
||||
"watch": "tsc --watch",
|
||||
"build": "yarn clean && tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^3.8.3"
|
||||
}
|
||||
}
|
||||
5
packages/compile/src/index.ts
Normal file
5
packages/compile/src/index.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import * as ts from 'typescript'
|
||||
|
||||
let scan = ts.createScanner(ts.ScriptTarget.ES5, true, ts.LanguageVariant.Standard)
|
||||
scan.setText('let a = 1')
|
||||
scan.tryScan(() => { })
|
||||
7
packages/compile/tsconfig.json
Normal file
7
packages/compile/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "src",
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
4
packages/container/.gitignore
vendored
4
packages/container/.gitignore
vendored
@@ -1,4 +0,0 @@
|
||||
/node_modules
|
||||
/dist
|
||||
/package-lock.json
|
||||
/yarn.lock
|
||||
@@ -1,22 +0,0 @@
|
||||
src
|
||||
test
|
||||
typings
|
||||
bundled
|
||||
build
|
||||
coverage
|
||||
docs
|
||||
wiki
|
||||
gulpfile.js
|
||||
bower.json
|
||||
karma.conf.js
|
||||
tsconfig.json
|
||||
typings.json
|
||||
CONTRIBUTING.md
|
||||
ISSUE_TEMPLATE.md
|
||||
PULL_REQUEST_TEMPLATE.md
|
||||
tslint.json
|
||||
wallaby.js
|
||||
.travis.yml
|
||||
.gitignore
|
||||
.vscode
|
||||
type_definitions
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ms/container",
|
||||
"version": "0.0.0",
|
||||
"version": "0.4.0",
|
||||
"description": "MiaoScript container package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -13,20 +13,21 @@
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm/"
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf dist",
|
||||
"watch": "npx tsc --watch",
|
||||
"build": "yarn clean && npx tsc",
|
||||
"watch": "tsc --watch",
|
||||
"build": "yarn clean && tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.0",
|
||||
"typescript": "^3.6.2"
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"inversify": "^5.0.1",
|
||||
"inversify-binding-decorators": "^4.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { interfaces, Container } from "inversify";
|
||||
|
||||
let _container: Container;
|
||||
|
||||
const CONTAINER = Symbol.for("@ms/ioc:Container");
|
||||
const ContainerInstance = Symbol.for("@ms/ioc:Container");
|
||||
const INJECTION = Symbol.for("INJECTION");
|
||||
|
||||
function _proxyGetter(
|
||||
@@ -11,7 +11,7 @@ function _proxyGetter(
|
||||
resolve: () => any,
|
||||
doCache: boolean
|
||||
) {
|
||||
function getter() {
|
||||
function getter(this: object) {
|
||||
if (doCache && !Reflect.hasMetadata(INJECTION, this, key)) {
|
||||
Reflect.defineMetadata(INJECTION, resolve(), this, key);
|
||||
}
|
||||
@@ -22,7 +22,7 @@ function _proxyGetter(
|
||||
}
|
||||
}
|
||||
|
||||
function setter(newVal: any) {
|
||||
function setter(this: object, newVal: any) {
|
||||
Reflect.defineMetadata(INJECTION, newVal, this, key);
|
||||
}
|
||||
|
||||
@@ -35,12 +35,12 @@ function _proxyGetter(
|
||||
}
|
||||
|
||||
function initContainer(container: Container) {
|
||||
Reflect.defineMetadata(CONTAINER, container, Reflect);
|
||||
Reflect.defineMetadata(ContainerInstance, container, Reflect);
|
||||
_container = container;
|
||||
}
|
||||
|
||||
function getContainer(): Container {
|
||||
return _container || Reflect.getMetadata(CONTAINER, Reflect)
|
||||
return _container || Reflect.getMetadata(ContainerInstance, Reflect)
|
||||
}
|
||||
|
||||
function makePropertyInjectDecorator(doCache: boolean) {
|
||||
@@ -97,6 +97,7 @@ let lazyMultiInject = makePropertyMultiInjectDecorator(doCache)
|
||||
export {
|
||||
initContainer,
|
||||
getContainer,
|
||||
ContainerInstance,
|
||||
lazyInject,
|
||||
lazyInjectNamed,
|
||||
lazyInjectTagged,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import "reflect-metadata";
|
||||
import { initContainer } from './decorators'
|
||||
import { interfaces, Container } from 'inversify';
|
||||
import { fluentProvide } from 'inversify-binding-decorators';
|
||||
|
||||
@@ -11,6 +12,7 @@ const provideSingleton = (identifier: interfaces.ServiceIdentifier<any>) => {
|
||||
};
|
||||
|
||||
const DefaultContainer = new Container();
|
||||
initContainer(DefaultContainer);
|
||||
|
||||
export * from 'inversify'
|
||||
export * from './decorators'
|
||||
|
||||
4
packages/core/.gitignore
vendored
4
packages/core/.gitignore
vendored
@@ -1,4 +0,0 @@
|
||||
/node_modules
|
||||
/dist
|
||||
/package-lock.json
|
||||
/yarn.lock
|
||||
@@ -1,22 +0,0 @@
|
||||
src
|
||||
test
|
||||
typings
|
||||
bundled
|
||||
build
|
||||
coverage
|
||||
docs
|
||||
wiki
|
||||
gulpfile.js
|
||||
bower.json
|
||||
karma.conf.js
|
||||
tsconfig.json
|
||||
typings.json
|
||||
CONTRIBUTING.md
|
||||
ISSUE_TEMPLATE.md
|
||||
PULL_REQUEST_TEMPLATE.md
|
||||
tslint.json
|
||||
wallaby.js
|
||||
.travis.yml
|
||||
.gitignore
|
||||
.vscode
|
||||
type_definitions
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ms/core",
|
||||
"version": "0.0.0",
|
||||
"version": "0.4.0",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -13,21 +13,22 @@
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm/"
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf dist",
|
||||
"watch": "npx tsc --watch",
|
||||
"build": "yarn clean && npx tsc",
|
||||
"watch": "tsc --watch",
|
||||
"build": "yarn clean && tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.0",
|
||||
"typescript": "^3.6.2"
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ms/container": "^0.0.0",
|
||||
"@ms/plugin": "^0.0.0"
|
||||
}
|
||||
"@ms/api": "^0.4.0",
|
||||
"@ms/container": "^0.4.0"
|
||||
},
|
||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||
}
|
||||
|
||||
@@ -1,28 +1,96 @@
|
||||
import '@ms/nashorn'
|
||||
let containerStartTime = Date.now();
|
||||
console.i18n("ms.core.ioc.initialize");
|
||||
import { plugin, server, task } from '@ms/api'
|
||||
import { DefaultContainer as container, inject, provideSingleton, ContainerInstance, buildProviderModule } from '@ms/container'
|
||||
console.i18n("ms.core.ioc.completed", { time: (Date.now() - containerStartTime) / 1000 })
|
||||
|
||||
import { plugin, server } from '@ms/api'
|
||||
import { DefaultContainer as container } from '@ms/container'
|
||||
import { PluginManagerImpl } from '@ms/plugin'
|
||||
@provideSingleton(MiaoScriptCore)
|
||||
class MiaoScriptCore {
|
||||
@inject(server.Console)
|
||||
private Console: Console;
|
||||
@inject(task.TaskManager)
|
||||
private taskManager: task.TaskManager;
|
||||
@inject(plugin.PluginFolder)
|
||||
private pluginFolder: string;
|
||||
@inject(plugin.PluginManager)
|
||||
private pluginManager: plugin.PluginManager;
|
||||
|
||||
try {
|
||||
Java.type("org.bukkit.Bukkit");
|
||||
require('@ms/bukkit');
|
||||
} catch (ex) {
|
||||
enable() {
|
||||
this.loadServerConsole();
|
||||
this.loadTaskFunction();
|
||||
global.level = "TRACE"
|
||||
this.loadPlugins();
|
||||
return () => this.disable();
|
||||
}
|
||||
|
||||
loadServerConsole() {
|
||||
// @ts-ignore
|
||||
console = new this.Console();
|
||||
}
|
||||
|
||||
loadTaskFunction() {
|
||||
//@ts-ignore
|
||||
global.setTimeout = (func: Function, tick: number, async: boolean = false) => this.taskManager.create(func).later(tick).async(async).submit()
|
||||
//@ts-ignore
|
||||
global.setInterval = (func: Function, tick: number, async: boolean = false) => this.taskManager.create(func).timer(tick).async(async).submit()
|
||||
}
|
||||
|
||||
loadPlugins() {
|
||||
let loadPluginStartTime = new Date().getTime()
|
||||
console.i18n("ms.core.plugin.initialize")
|
||||
this.pluginManager.scan(this.pluginFolder);
|
||||
this.pluginManager.build();
|
||||
this.pluginManager.load();
|
||||
this.pluginManager.enable();
|
||||
console.i18n("ms.core.plugin.completed", { time: (new Date().getTime() - loadPluginStartTime) / 1000 })
|
||||
}
|
||||
|
||||
disable() {
|
||||
console.i18n("ms.core.engine.disable")
|
||||
this.pluginManager.disable();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
Java.type("org.spongepowered.api.Sponge");
|
||||
require('@ms/sponge');
|
||||
} catch (ex) {
|
||||
function detectServer() {
|
||||
try {
|
||||
Java.type("org.bukkit.Bukkit");
|
||||
return 'bukkit'
|
||||
} catch (ex) {
|
||||
}
|
||||
try {
|
||||
Java.type("org.spongepowered.api.Sponge");
|
||||
return 'sponge'
|
||||
} catch (ex) {
|
||||
}
|
||||
try {
|
||||
Java.type("cn.nukkit.Nukkit");
|
||||
return 'nukkit'
|
||||
} catch (ex) {
|
||||
}
|
||||
try {
|
||||
Java.type("net.md_5.bungee.api.ProxyServer");
|
||||
return 'bungee'
|
||||
} catch (ex) {
|
||||
}
|
||||
throw Error('Unknow Server Type...')
|
||||
}
|
||||
|
||||
let Console = container.get(server.Console);
|
||||
//@ts-ignore
|
||||
global.console = new Console();
|
||||
function initialize() {
|
||||
let corePackageStartTime = new Date().getTime()
|
||||
container.bind(ContainerInstance).toConstantValue(container);
|
||||
container.bind(plugin.PluginInstance).toConstantValue(base.getInstance());
|
||||
container.bind(plugin.PluginFolder).toConstantValue('plugins');
|
||||
let type = detectServer();
|
||||
console.i18n("ms.core.initialize.detect", { type });
|
||||
container.bind(server.ServerType).toConstantValue(type);
|
||||
console.i18n("ms.core.package.initialize", { type });
|
||||
require(`@ms/${type}`).default(container);
|
||||
require('@ms/plugin')
|
||||
container.load(buildProviderModule());
|
||||
console.i18n("ms.core.package.completed", { type, time: (Date.now() - corePackageStartTime) / 1000 });
|
||||
let disable = container.get<MiaoScriptCore>(MiaoScriptCore).enable()
|
||||
console.i18n("ms.core.engine.completed", { time: (Date.now() - global.NashornEngineStartTime) / 1000 });
|
||||
return disable;
|
||||
}
|
||||
|
||||
container.bind(plugin.PluginManager).to(PluginManagerImpl).inSingletonScope();
|
||||
|
||||
let manager = container.get<plugin.PluginManager>(plugin.PluginManager);
|
||||
manager.scan('plugins');
|
||||
manager.load(container);
|
||||
manager.enable();
|
||||
export default initialize();
|
||||
|
||||
40
packages/i18n/languages/en.yml
Normal file
40
packages/i18n/languages/en.yml
Normal file
@@ -0,0 +1,40 @@
|
||||
ms.ployfill.initialize: "Initialization Java Nashorn ployfill. Please wait..."
|
||||
ms.ployfill.completed: "Java Nashorn ployfill loading completed... Cost ({time}s)!"
|
||||
|
||||
ms.core.ioc.initialize: "Initialization MiaoScript IOC Container @ms/container. Please wait..."
|
||||
ms.core.ioc.completed: "MiaoScript IOC Container @ms/container loading completed({time}s)!"
|
||||
ms.core.initialize.detect: "Detect Compatible Server set ServerType to {type} ..."
|
||||
ms.core.package.initialize: "Initialization MiaoScript Package @ms/core @ms/{type} @ms/plugin. Please wait..."
|
||||
ms.core.package.completed: "MiaoScript Package @ms/core @ms/{type} @ms/plugin loading completed({time}s)!"
|
||||
ms.core.plugin.initialize: "Initialization MiaoScript Plugin System. Please wait..."
|
||||
ms.core.plugin.completed: "MiaoScript Plugin System loading completed({time}s)!"
|
||||
ms.core.engine.completed: "MiaoScript ScriptEngine loading completed... Done({time}s)!"
|
||||
ms.core.engine.disable: "Disable MiaoScript Engine..."
|
||||
|
||||
ms.api.event.resource.not.found: "Can't Mapping Event Because not found Resources {resource}!"
|
||||
ms.api.event.empty.event.dir: "base event dir is empty, can't map event name !"
|
||||
ms.api.event.mapping: "Mapping Event [{canonicalName}] => {simpleName}"
|
||||
ms.api.event.not.found: "§6Plugin §b{name} §6register {event} error. event not found!"
|
||||
ms.api.event.execute.slow: "§cWARN! §6Plugin §b{name} §6execute §d{event} §6evnet §ccost §4{cost}ms !"
|
||||
ms.api.event.execute.error: "§6Plugin §b{name} §6execute §d{event} §6event error §4{ex}"
|
||||
ms.api.event.listen.plugin.name.empty: "Plugin name can't be empty!"
|
||||
ms.api.event.register: "[{name}] register event {event}"
|
||||
ms.api.event.unregister: "[{name}] unregister event {event}"
|
||||
ms.api.command.register.input.error: "CommandExec Must be a function... Input: {exec}"
|
||||
ms.api.command.register: "[{plugin}] register command {name}({cmd})..."
|
||||
ms.api.command.unregister: "[{plugin}] unregister command {name}..."
|
||||
ms.api.command.execute.error: "§6Player {player} §6exec §b{plugin} §6Plugin Command §d{command} {args} §6error §4{ex}"
|
||||
ms.api.command.tab.completer.error: "§6Player {player} §6exec §b{plugin} §6Plugin TabComplete §d{command} {args} §6error §4{ex}"
|
||||
|
||||
ms.plugin.initialize: "Initialization MiaoScript Plugin System: {plugin} ..."
|
||||
ms.plugin.event.map: "Total {count} {type} Event Mapping Complate..."
|
||||
ms.plugin.manager.scan: "Scanning Plugins in {folder} ..."
|
||||
ms.plugin.manager.initialize.error: "§6Plugin §b{name} §6initialize error §4{ex}"
|
||||
ms.plugin.manager.stage: "{stage} {plugin} version {version} by {author}"
|
||||
ms.plugin.manager.stage.load: "Loading"
|
||||
ms.plugin.manager.stage.enable: "Enabling"
|
||||
ms.plugin.manager.stage.disable: "Disabling"
|
||||
ms.plugin.manager.build.update: "Auto Update Plugin {name} ..."
|
||||
ms.plugin.manager.build.not.extends: "§4Found error plugin §b{source} §4it's not extends interfaces.Plugin, the plugin will be ignore!"
|
||||
ms.plugin.manager.build.exists: "§4Found duplicate plugin §b{exists} §4and §b{source}§4. the first plugin will be ignore!"
|
||||
ms.plugin.manager.config.save.default: "[{plugin}] config {name}.{format} not exists. auto create from default variable..."
|
||||
40
packages/i18n/languages/zh_cn.yml
Normal file
40
packages/i18n/languages/zh_cn.yml
Normal file
@@ -0,0 +1,40 @@
|
||||
ms.ployfill.initialize: "加载 Java Nashorn 补丁. 请稍候..."
|
||||
ms.ployfill.completed: "Java Nashorn 补丁 加载完成... 耗时 ({time}s)!"
|
||||
|
||||
ms.core.ioc.initialize: "初始化 MiaoScript IOC 容器 @ms/container. 请稍候..."
|
||||
ms.core.ioc.completed: "MiaoScript IOC 容器 @ms/container 加载完成 耗时({time}s)"
|
||||
ms.core.initialize.detect: "检测到兼容的服务器类型. 设置 ServerType 值 {type} ..."
|
||||
ms.core.package.initialize: "初始化 MiaoScript 扩展 @ms/core @ms/{type} @ms/plugin. 请稍候..."
|
||||
ms.core.package.completed: "MiaoScript 扩展 @ms/core @ms/{type} @ms/plugin 加载完成 耗时({time}s)"
|
||||
ms.core.plugin.initialize: "MiaoScript 开始引导插件系统. 请稍候..."
|
||||
ms.core.plugin.completed: "MiaoScript 插件加载完毕 耗时({time}s)!"
|
||||
ms.core.engine.completed: "MiaoScript 脚本引擎 加载完毕... 耗时({time}s)!"
|
||||
ms.core.engine.disable: "关闭 MiaoScript 引擎..."
|
||||
|
||||
ms.api.event.resource.not.found: "无法映射事件 未找到资源文件 {resource}!"
|
||||
ms.api.event.empty.event.dir: "事件基础目录为空, 无法映射事件!"
|
||||
ms.api.event.mapping: "映射事件 [{canonicalName}] => {simpleName}"
|
||||
ms.api.event.not.found: "§6插件 §b{name} §6注册事件 §c{event} §6失败. §4事件未找到!"
|
||||
ms.api.event.execute.slow: "§c注意! §6插件 §b{name} §6处理 §d{event} §6事件 §c耗时 §4{cost}ms !"
|
||||
ms.api.event.execute.error: "§6插件 §b{name} §6处理 §d{event} §6事件时发生异常 §4{ex}"
|
||||
ms.api.event.listen.plugin.name.empty: "插件名称为空 请检查传入参数!"
|
||||
ms.api.event.register: "[{name}] 注册事件 {event}"
|
||||
ms.api.event.unregister: "[{name}] 注销事件 {event}"
|
||||
ms.api.command.register.input.error: "CommandExec 必须为一个函数... 输入: {exec}"
|
||||
ms.api.command.register: "[{plugin}] 注册命令 {name}({cmd})..."
|
||||
ms.api.command.unregister: "[{plugin}] 注销命令 {name}..."
|
||||
ms.api.command.execute.error: "§6玩家 §a{player} §6执行 §b{plugin} §6插件 §d{command} {args} §6命令时发生异常 §4{ex}"
|
||||
ms.api.command.tab.completer.error: "§6玩家 §a{player} §6执行 §b{plugin} §6插件 §d{command} {args} §6补全时发生异常 §4{ex}"
|
||||
|
||||
ms.plugin.initialize: "初始化 MiaoScript 插件系统: {plugin} ..."
|
||||
ms.plugin.event.map: "总计 {count} 个 {type} 事件 映射完成..."
|
||||
ms.plugin.manager.scan: "扫描 {folder} 文件夹中插件..."
|
||||
ms.plugin.manager.initialize.error: "§6插件 §b{name} §6初始化错误 §4{ex}"
|
||||
ms.plugin.manager.stage: "{stage} {plugin} 版本 {version} 作者 {author}"
|
||||
ms.plugin.manager.stage.load: "加载"
|
||||
ms.plugin.manager.stage.enable: "启用"
|
||||
ms.plugin.manager.stage.disable: "关闭"
|
||||
ms.plugin.manager.build.update: "自动更新插件 {name} ..."
|
||||
ms.plugin.manager.build.not.extends: "§4发现错误的插件 §b{source} §4未继承接口 interfaces.Plugin, 将不会被载入到服务器!"
|
||||
ms.plugin.manager.build.duplicate: "§4发现已存在插件 §b{exists} §4和 §b{source}§4 存在冲突. 已存在插件将会被替换!"
|
||||
ms.plugin.manager.config.save.default: "[{plugin}] 配置 {name}.{format} 不存在. 从默认值自动创建保存..."
|
||||
35
packages/i18n/package.json
Normal file
35
packages/i18n/package.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "@ms/i18n",
|
||||
"version": "0.4.0",
|
||||
"description": "MiaoScript i18n package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
"bukkit",
|
||||
"sponge"
|
||||
],
|
||||
"author": "MiaoWoo <admin@yumc.pw>",
|
||||
"homepage": "https://github.com/circlecloud/ms.git",
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf dist",
|
||||
"watch": "tsc --watch",
|
||||
"build": "yarn clean && tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/js-yaml": "^3.12.2",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ms/nashorn": "^0.4.0",
|
||||
"js-yaml": "^3.13.1"
|
||||
},
|
||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||
}
|
||||
51
packages/i18n/src/index.ts
Normal file
51
packages/i18n/src/index.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/// <reference types="@ms/nashorn" />
|
||||
import * as yaml from 'js-yaml'
|
||||
|
||||
const File = Java.type("java.io.File");
|
||||
const separatorChar = File.separatorChar;
|
||||
|
||||
let langMap = {};
|
||||
let fallbackMap = {};
|
||||
|
||||
type TranslateParam = { [key: string]: any }
|
||||
|
||||
function translate(name: string, param?: TranslateParam) {
|
||||
let langText: string = langMap[name] || fallbackMap[name];
|
||||
if (!langText) { return '[WARN] @ms/i18n miss lang translate: ' + name }
|
||||
for (const key in param) {
|
||||
langText = langText.replace("{" + key + "}", param[key])
|
||||
}
|
||||
return langText;
|
||||
}
|
||||
|
||||
function initialize(lang: string = 'zh_cn', fallback: string = 'zh_cn') {
|
||||
langMap = readYamlFile(root, lang) || readYamlFile(concat(__dirname, '..'), lang)
|
||||
fallbackMap = readYamlFile(root, fallback) || readYamlFile(concat(__dirname, '..'), fallback)
|
||||
console.i18n = function i18n(name: string, param?: TranslateParam) {
|
||||
console.log(translate(name, param))
|
||||
}
|
||||
}
|
||||
|
||||
function readYamlFile(dir: string, name: string) {
|
||||
let langFile = concat(dir, 'languages', name + '.yml');
|
||||
return exists(langFile) && yaml.safeLoad(base.read(langFile))
|
||||
}
|
||||
|
||||
function concat(...args: string[]) {
|
||||
return args.join(separatorChar)
|
||||
}
|
||||
|
||||
function exists(path: string) {
|
||||
return new File(path).exists()
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Console {
|
||||
i18n(name: string, param?: TranslateParam);
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
initialize,
|
||||
translate
|
||||
};
|
||||
7
packages/i18n/tsconfig.json
Normal file
7
packages/i18n/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "src",
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
4
packages/nashorn/.gitignore
vendored
4
packages/nashorn/.gitignore
vendored
@@ -1,4 +0,0 @@
|
||||
/node_modules
|
||||
/dist
|
||||
/package-lock.json
|
||||
/yarn.lock
|
||||
@@ -1,22 +0,0 @@
|
||||
src
|
||||
test
|
||||
typings
|
||||
bundled
|
||||
build
|
||||
coverage
|
||||
docs
|
||||
wiki
|
||||
gulpfile.js
|
||||
bower.json
|
||||
karma.conf.js
|
||||
tsconfig.json
|
||||
typings.json
|
||||
CONTRIBUTING.md
|
||||
ISSUE_TEMPLATE.md
|
||||
PULL_REQUEST_TEMPLATE.md
|
||||
tslint.json
|
||||
wallaby.js
|
||||
.travis.yml
|
||||
.gitignore
|
||||
.vscode
|
||||
type_definitions
|
||||
12
packages/nashorn/build.sh
Executable file
12
packages/nashorn/build.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
# sponge bukkit jdk bungee nukkit
|
||||
TYPE=nukkit
|
||||
TARGET=../types/dist/typings
|
||||
npx tsc src/build.ts --outDir dist
|
||||
cd dist
|
||||
rm -rf temp
|
||||
mkdir -p temp
|
||||
node build.js ${TYPE}
|
||||
cd ../
|
||||
rm -rf ${TARGET}/${TYPE}
|
||||
mkdir -p ${TARGET}/${TYPE}
|
||||
cp dist/temp/* ${TARGET}/${TYPE}/ -R
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ms/nashorn",
|
||||
"version": "0.0.0",
|
||||
"version": "0.4.0",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -14,17 +14,17 @@
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm/"
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf dist",
|
||||
"watch": "npx tsc --watch",
|
||||
"build": "yarn clean && npx tsc",
|
||||
"watch": "tsc --watch",
|
||||
"build": "yarn clean && tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.0",
|
||||
"typescript": "^3.6.2"
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^3.8.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
200
packages/nashorn/src/build.ts
Normal file
200
packages/nashorn/src/build.ts
Normal file
@@ -0,0 +1,200 @@
|
||||
import * as fs from "fs";
|
||||
|
||||
function convertJson2TypeDefiend(infile: string, outDir: string) {
|
||||
const file = infile.split(".json")[0];
|
||||
const json = fs.readFileSync(`${inDir}/${file}.json`).toString();
|
||||
const obj = JSON.parse(json);
|
||||
const qnas: string[] = obj.qualifiedName.split(".");
|
||||
let closeBuk = 0;
|
||||
let temp = `declare namespace ${qnas[0]} {\n`;
|
||||
closeBuk++;
|
||||
const nms = qnas.slice(1, qnas.length - 1);
|
||||
for (const nm of nms) {
|
||||
temp += `${' '.repeat(closeBuk)}namespace ${nm.replace('function', 'function$')} {\n`;
|
||||
closeBuk++;
|
||||
}
|
||||
let classModifier = formatClassModifier(obj.modifiers)
|
||||
temp += `${' '.repeat(closeBuk)}// @ts-ignore\n`
|
||||
temp += `${' '.repeat(closeBuk)}${classModifier}${qnas[qnas.length - 1]}`
|
||||
let isInterface = classModifier.includes('interface')
|
||||
let safeInterface = [];
|
||||
for (const ifs of obj.interfaces) {
|
||||
if (!ifs.qualifiedName.startsWith('java')) {
|
||||
safeInterface.push(ifs)
|
||||
}
|
||||
}
|
||||
if (isInterface) {
|
||||
if (safeInterface.length > 0) {
|
||||
temp += ' extends '
|
||||
for (const ifs of safeInterface) {
|
||||
temp += ifs.qualifiedName;
|
||||
temp += ', '
|
||||
}
|
||||
temp = temp.substr(0, temp.length - 2);
|
||||
}
|
||||
} else {
|
||||
temp += `${(obj.superclass) ? (' extends ' + (obj.superclass.qualifiedName == "<any>" ? "object" : obj.superclass.qualifiedName)) : ''}`;
|
||||
if (safeInterface.length > 0) {
|
||||
temp += ' implements '
|
||||
for (const ifs of safeInterface) {
|
||||
temp += ifs.qualifiedName;
|
||||
temp += ', '
|
||||
}
|
||||
temp = temp.substr(0, temp.length - 2);
|
||||
}
|
||||
}
|
||||
temp += ' {\n'
|
||||
closeBuk++;
|
||||
for (const constructor of obj.constructors) {
|
||||
temp += `${formatDoc(constructor.docString, closeBuk)}${' '.repeat(closeBuk)}// @ts-ignore\n${' '.repeat(closeBuk)}constructor(${formatParameters(constructor.parameters)})\n`;
|
||||
}
|
||||
|
||||
let members = [];
|
||||
|
||||
let methods = '';
|
||||
for (const method of obj.methods) {
|
||||
let methodModifier = isInterface ? '' : replaceModifiers(method.modifiers, classModifier.includes('abstract'))
|
||||
if (!whiteKey.includes(method.name)) {
|
||||
if (members[method.name] && methodModifier.includes('abstract')) {
|
||||
continue;
|
||||
}
|
||||
members[method.name] = methodModifier;
|
||||
}
|
||||
methods += `${formatDoc(method.docString, closeBuk)}${' '.repeat(closeBuk)}// @ts-ignore\n${' '.repeat(closeBuk)}${methodModifier} ${method.name}(${formatParameters(method.parameters)}): ${mappingType(method.returnType.type)};\n`;
|
||||
}
|
||||
|
||||
let fields = '';
|
||||
for (const field of obj.fields) {
|
||||
if (members[field.name]) {
|
||||
continue;
|
||||
}
|
||||
fields += `${' '.repeat(closeBuk)}// @ts-ignore\n${' '.repeat(closeBuk)}${isInterface ? '' : replaceModifiers(field.modifiers)} ${field.name}: ${mappingType(field.type ? field.type.type : "any")};\n`;
|
||||
}
|
||||
|
||||
temp += fields + methods;
|
||||
|
||||
for (let index = 0; index < closeBuk; index++) {
|
||||
temp += `${' '.repeat(closeBuk - index - 1)}}\n`;
|
||||
}
|
||||
|
||||
fs.writeFileSync(`${outDir}/${file}.${suffix}`, temp);
|
||||
return `${file}.${suffix}`;
|
||||
}
|
||||
|
||||
function formatClassModifier(modifiers: string) {
|
||||
let tempm = modifiers.replace('public', '').replace('static', '').replace('final', '').trim();
|
||||
if (!modifiers.includes('interface')) { tempm += ' class' }
|
||||
return tempm.length > 0 ? (tempm + ' ') : '';
|
||||
}
|
||||
|
||||
function formatDoc(doc: string, closeBuk: number) {
|
||||
let middleDoc = '';
|
||||
for (const line of doc.split('\n')) {
|
||||
if (line.trim().length != 0) {
|
||||
middleDoc += `${' '.repeat(closeBuk)} * ${line.trim()}\n`
|
||||
}
|
||||
}
|
||||
return middleDoc.length > 0 ? `${' '.repeat(closeBuk)}/**\n${middleDoc}${' '.repeat(closeBuk)} */\n` : '';
|
||||
}
|
||||
|
||||
function replaceModifiers(modifiers: string, absClass = false): string {
|
||||
// modifiers = modifiers.replace(' final', ' readonly');
|
||||
modifiers = modifiers.split(" final")[0];
|
||||
modifiers = modifiers.split(" native")[0];
|
||||
modifiers = modifiers.split(" volatile")[0];
|
||||
modifiers = modifiers.split(" transient")[0];
|
||||
modifiers = modifiers.split(" synchronized")[0];
|
||||
if (!absClass) {
|
||||
modifiers = modifiers.split(" abstract")[0];
|
||||
}
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
function formatParameters(params: any[]) {
|
||||
let tempParam = '';
|
||||
for (const p of params) {
|
||||
tempParam += `${mappingName(p.name)}: ${mappingType(p.type ? p.type.qualifiedName : 'any')}, `
|
||||
}
|
||||
return tempParam.substr(0, tempParam.length - 2);
|
||||
}
|
||||
|
||||
const nameMap = [];
|
||||
nameMap['function'] = 'func'
|
||||
nameMap['in'] = 'input'
|
||||
nameMap['var'] = 'variable'
|
||||
|
||||
function mappingName(name: string) {
|
||||
if (whiteKey.includes(name)) { return name }
|
||||
let outName = nameMap[name] || name || '';
|
||||
return outName;
|
||||
}
|
||||
|
||||
let whiteKey = ['shift', "map", 'filter', 'values', 'valueOf', 'toString', 'length', 'includes', 'entries', 'keys', 'join', 'fill']
|
||||
|
||||
const typeMap = [];
|
||||
typeMap['int'] = 'number';
|
||||
typeMap['int[]'] = 'number[]';
|
||||
typeMap['int[][]'] = 'number[][]';
|
||||
typeMap['byte'] = 'number';
|
||||
typeMap['byte[]'] = 'number[]';
|
||||
typeMap['double'] = 'number';
|
||||
typeMap['double[]'] = 'number[]';
|
||||
typeMap['short'] = 'number';
|
||||
typeMap['short[]'] = 'number[]';
|
||||
typeMap['float'] = 'number';
|
||||
typeMap['float[]'] = 'number[]';
|
||||
typeMap['long'] = 'number';
|
||||
typeMap['long[]'] = 'number[]';
|
||||
typeMap['<any>'] = 'any';
|
||||
typeMap['char'] = 'string';
|
||||
typeMap['char[]'] = 'string[]';
|
||||
typeMap['java.lang.String'] = "string";
|
||||
// typeMap['java.util.Date'] = 'any /*java.util.Date*/'
|
||||
// typeMap['java.util.List'] = 'any[] /*java.util.List*/'
|
||||
// typeMap['java.util.Set'] = 'any[] /*java.util.Set*/'
|
||||
// typeMap['java.util.Collection'] = 'any[] /*java.util.Collection*/'
|
||||
// typeMap['java.util.Map'] = 'Map<any, any> /*java.util.Map*/'
|
||||
// Sponge
|
||||
typeMap['Vectori'] = 'any /*Vector3i*/'
|
||||
typeMap['Vectord'] = 'any /*Vector3d*/'
|
||||
typeMap['Vectorf'] = 'any /*Vector3f*/'
|
||||
typeMap['Vector2i'] = 'any /*Vector2i*/'
|
||||
typeMap['Vector2d'] = 'any /*Vector2d*/'
|
||||
typeMap['Vector2f'] = 'any /*Vector2f*/'
|
||||
typeMap['Vector3i'] = 'any /*Vector3i*/'
|
||||
typeMap['Vector3d'] = 'any /*Vector3d*/'
|
||||
typeMap['Vector3f'] = 'any /*Vector3f*/'
|
||||
typeMap['Type'] = 'any /*Type*/'
|
||||
typeMap['Gson'] = 'any /*Gson*/'
|
||||
typeMap['Logger'] = 'any /*Logger*/'
|
||||
typeMap['MethodVisitor'] = 'any /*MethodVisitor*/'
|
||||
typeMap['ConfigurationNode'] = 'any /*ConfigurationNode*/'
|
||||
typeMap['TypeSerializerCollection'] = 'any /*TypeSerializerCollection*/'
|
||||
typeMap['Quaterniond'] = 'any /*Quaterniond*/'
|
||||
typeMap['Matrix2d'] = 'any /*Matrix2d*/'
|
||||
typeMap['Matrix3d'] = 'any /*Matrix3d*/'
|
||||
typeMap['Matrix4d'] = 'any /*Matrix4d*/'
|
||||
|
||||
function mappingType(type: string): string {
|
||||
let outType = typeMap[type] || type || 'any';
|
||||
if (outType.indexOf('.') != -1) {
|
||||
if (outType.startsWith('java.') || outType.startsWith('org.') || outType.startsWith('net.') || outType.startsWith('cn.')) {
|
||||
|
||||
} else {
|
||||
outType = `any /*${outType}*/`
|
||||
}
|
||||
}
|
||||
return outType.replace('function', 'function$');
|
||||
}
|
||||
|
||||
var args = process.argv.splice(2)
|
||||
|
||||
const suffix = 'd.ts'
|
||||
const inDir = `../docs/${args[0]}`
|
||||
const outDir = "./temp";
|
||||
const files = fs.readdirSync(inDir);
|
||||
let index = '';
|
||||
for (const file of files) {
|
||||
index += `/// <reference path="./${convertJson2TypeDefiend(file, outDir)}" />\n`;
|
||||
}
|
||||
fs.writeFileSync(`${outDir}/index.${suffix}`, index);
|
||||
@@ -1,8 +1,73 @@
|
||||
declare global {
|
||||
const __FILE__: string;
|
||||
const __LINE__: number;
|
||||
const __DIR__: string;
|
||||
let Packages: any;
|
||||
|
||||
function print(...message: any[]): void;
|
||||
function load(script: string | object);
|
||||
function loadWithNewGlobal(script: string | object);
|
||||
function exit(code?: number);
|
||||
function quit(code?: number);
|
||||
function JavaImporter(...className: string[]);
|
||||
|
||||
namespace Java {
|
||||
function type(clazz: string): any;
|
||||
function from(javaObj: any): any[];
|
||||
function to(array: any[]): any;
|
||||
function extend(...parentTypes: any[]);
|
||||
//@ts-ignore
|
||||
// function super(type: any);
|
||||
}
|
||||
|
||||
interface Error {
|
||||
readonly lineNumber?: number;
|
||||
readonly columnNumber?: number;
|
||||
readonly fileName?: string;
|
||||
dumpStack?: Function;
|
||||
printStackTrace?: Function;
|
||||
getStackTrace?: () => any[];
|
||||
}
|
||||
|
||||
interface String {
|
||||
trimLeft();
|
||||
trimRight();
|
||||
}
|
||||
|
||||
interface Object {
|
||||
setPrototypeOf(obj: object, prototype: object);
|
||||
bindProperties(to: object, from: object);
|
||||
}
|
||||
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
logger: any;
|
||||
debug: boolean;
|
||||
level: string;
|
||||
NashornEngineStartTime: number;
|
||||
setGlobal: (key: string, value: any) => void;
|
||||
noop: () => void;
|
||||
console: Console;
|
||||
}
|
||||
}
|
||||
var root: string;
|
||||
var base: Core;
|
||||
var ScriptEngineContextHolder: any;
|
||||
function engineLoad(str: string): any;
|
||||
interface Core {
|
||||
getClass(name: String): any;
|
||||
getProxyClass(): any;
|
||||
getInstance(): any;
|
||||
read(path: string): string;
|
||||
save(path: string, content: string): void;
|
||||
delete(path: string): void;
|
||||
}
|
||||
interface Console {
|
||||
ex(err: Error): void;
|
||||
stack(err: Error): string[];
|
||||
sender(...args: any): void;
|
||||
console(...args: any): void;
|
||||
i18n(name: string, ...params: any[]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
33
packages/nodejs/package.json
Normal file
33
packages/nodejs/package.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "@ms/nodejs",
|
||||
"version": "0.4.0",
|
||||
"description": "MiaoScript nodejs package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
"bukkit",
|
||||
"sponge"
|
||||
],
|
||||
"author": "MiaoWoo <admin@yumc.pw>",
|
||||
"homepage": "https://github.com/circlecloud/ms.git",
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf dist",
|
||||
"watch": "tsc --watch",
|
||||
"build": "yarn clean && tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ms/nashorn": "^0.4.0"
|
||||
},
|
||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||
}
|
||||
455
packages/nodejs/src/events/index.ts
Normal file
455
packages/nodejs/src/events/index.ts
Normal file
@@ -0,0 +1,455 @@
|
||||
// Copyright Joyent, Inc. and other Node contributors.
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
||||
// persons to whom the Software is furnished to do so, subject to the
|
||||
// following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included
|
||||
// in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
||||
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
||||
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
'use strict';
|
||||
var R = typeof Reflect === 'object' ? Reflect : null
|
||||
var ReflectApply = R && typeof R.apply === 'function'
|
||||
? R.apply
|
||||
: function ReflectApply(target, receiver, args) {
|
||||
return Function.prototype.apply.call(target, receiver, args);
|
||||
}
|
||||
|
||||
var ReflectOwnKeys
|
||||
if (R && typeof R.ownKeys === 'function') {
|
||||
ReflectOwnKeys = R.ownKeys
|
||||
} else if (Object.getOwnPropertySymbols) {
|
||||
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
||||
return Object.getOwnPropertyNames(target)
|
||||
// @ts-ignore
|
||||
.concat(Object.getOwnPropertySymbols(target));
|
||||
};
|
||||
} else {
|
||||
ReflectOwnKeys = function ReflectOwnKeys(target) {
|
||||
return Object.getOwnPropertyNames(target);
|
||||
};
|
||||
}
|
||||
|
||||
function ProcessEmitWarning(warning) {
|
||||
if (console && console.warn) console.warn(warning);
|
||||
}
|
||||
|
||||
var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
|
||||
return value !== value;
|
||||
}
|
||||
|
||||
function EventEmitter(this: any) {
|
||||
EventEmitter.init.call(this);
|
||||
}
|
||||
module.exports = EventEmitter;
|
||||
|
||||
// Backwards-compat with node 0.10.x
|
||||
EventEmitter.EventEmitter = EventEmitter;
|
||||
|
||||
EventEmitter.prototype._events = undefined;
|
||||
EventEmitter.prototype._eventsCount = 0;
|
||||
EventEmitter.prototype._maxListeners = undefined;
|
||||
|
||||
// By default EventEmitters will print a warning if more than 10 listeners are
|
||||
// added to it. This is a useful default which helps finding memory leaks.
|
||||
var defaultMaxListeners = 10;
|
||||
|
||||
function checkListener(listener) {
|
||||
if (typeof listener !== 'function') {
|
||||
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
|
||||
enumerable: true,
|
||||
get: function () {
|
||||
return defaultMaxListeners;
|
||||
},
|
||||
set: function (arg) {
|
||||
if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
|
||||
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
|
||||
}
|
||||
defaultMaxListeners = arg;
|
||||
}
|
||||
});
|
||||
|
||||
EventEmitter.init = function () {
|
||||
// @ts-ignore
|
||||
if (this._events === undefined ||
|
||||
// @ts-ignore
|
||||
this._events === Object.getPrototypeOf(this)._events) {
|
||||
// @ts-ignore
|
||||
this._events = Object.create(null);
|
||||
// @ts-ignore
|
||||
this._eventsCount = 0;
|
||||
}
|
||||
// @ts-ignore
|
||||
this._maxListeners = this._maxListeners || undefined;
|
||||
};
|
||||
|
||||
// Obviously not all Emitters should be limited to 10. This function allows
|
||||
// that to be increased. Set to zero for unlimited.
|
||||
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
|
||||
if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
|
||||
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
|
||||
}
|
||||
this._maxListeners = n;
|
||||
return this;
|
||||
};
|
||||
|
||||
function _getMaxListeners(that) {
|
||||
if (that._maxListeners === undefined)
|
||||
// @ts-ignore
|
||||
return EventEmitter.defaultMaxListeners;
|
||||
return that._maxListeners;
|
||||
}
|
||||
|
||||
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
|
||||
return _getMaxListeners(this);
|
||||
};
|
||||
|
||||
EventEmitter.prototype.emit = function emit(type) {
|
||||
var args = [];
|
||||
for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
|
||||
var doError = (type === 'error');
|
||||
|
||||
var events = this._events;
|
||||
if (events !== undefined)
|
||||
doError = (doError && events.error === undefined);
|
||||
else if (!doError)
|
||||
return false;
|
||||
|
||||
// If there is no 'error' event listener then throw.
|
||||
if (doError) {
|
||||
var er;
|
||||
if (args.length > 0)
|
||||
er = args[0];
|
||||
if (er instanceof Error) {
|
||||
// Note: The comments on the `throw` lines are intentional, they show
|
||||
// up in Node's output if this results in an unhandled exception.
|
||||
throw er; // Unhandled 'error' event
|
||||
}
|
||||
// At least give some kind of context to the user
|
||||
var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
|
||||
// @ts-ignore
|
||||
err.context = er;
|
||||
throw err; // Unhandled 'error' event
|
||||
}
|
||||
|
||||
var handler = events[type];
|
||||
|
||||
if (handler === undefined)
|
||||
return false;
|
||||
|
||||
if (typeof handler === 'function') {
|
||||
ReflectApply(handler, this, args);
|
||||
} else {
|
||||
var len = handler.length;
|
||||
var listeners = arrayClone(handler, len);
|
||||
for (var i = 0; i < len; ++i)
|
||||
ReflectApply(listeners[i], this, args);
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
function _addListener(target, type, listener, prepend) {
|
||||
var m;
|
||||
var events;
|
||||
var existing;
|
||||
|
||||
checkListener(listener);
|
||||
|
||||
events = target._events;
|
||||
if (events === undefined) {
|
||||
events = target._events = Object.create(null);
|
||||
target._eventsCount = 0;
|
||||
} else {
|
||||
// To avoid recursion in the case that type === "newListener"! Before
|
||||
// adding it to the listeners, first emit "newListener".
|
||||
if (events.newListener !== undefined) {
|
||||
target.emit('newListener', type,
|
||||
listener.listener ? listener.listener : listener);
|
||||
|
||||
// Re-assign `events` because a newListener handler could have caused the
|
||||
// this._events to be assigned to a new object
|
||||
events = target._events;
|
||||
}
|
||||
existing = events[type];
|
||||
}
|
||||
|
||||
if (existing === undefined) {
|
||||
// Optimize the case of one listener. Don't need the extra array object.
|
||||
existing = events[type] = listener;
|
||||
++target._eventsCount;
|
||||
} else {
|
||||
if (typeof existing === 'function') {
|
||||
// Adding the second element, need to change to array.
|
||||
existing = events[type] =
|
||||
prepend ? [listener, existing] : [existing, listener];
|
||||
// If we've already got an array, just append.
|
||||
} else if (prepend) {
|
||||
existing.unshift(listener);
|
||||
} else {
|
||||
existing.push(listener);
|
||||
}
|
||||
|
||||
// Check for listener leak
|
||||
m = _getMaxListeners(target);
|
||||
if (m > 0 && existing.length > m && !existing.warned) {
|
||||
existing.warned = true;
|
||||
// No error code for this since it is a Warning
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
var w = new Error('Possible EventEmitter memory leak detected. ' +
|
||||
existing.length + ' ' + String(type) + ' listeners ' +
|
||||
'added. Use emitter.setMaxListeners() to ' +
|
||||
'increase limit');
|
||||
w.name = 'MaxListenersExceededWarning';
|
||||
// @ts-ignore
|
||||
w.emitter = target;
|
||||
// @ts-ignore
|
||||
w.type = type;
|
||||
// @ts-ignore
|
||||
w.count = existing.length;
|
||||
ProcessEmitWarning(w);
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
EventEmitter.prototype.addListener = function addListener(type, listener) {
|
||||
return _addListener(this, type, listener, false);
|
||||
};
|
||||
|
||||
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
|
||||
|
||||
EventEmitter.prototype.prependListener =
|
||||
function prependListener(type, listener) {
|
||||
return _addListener(this, type, listener, true);
|
||||
};
|
||||
|
||||
function onceWrapper(this: any) {
|
||||
if (!this.fired) {
|
||||
this.target.removeListener(this.type, this.wrapFn);
|
||||
this.fired = true;
|
||||
if (arguments.length === 0)
|
||||
return this.listener.call(this.target);
|
||||
return this.listener.apply(this.target, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
function _onceWrap(target, type, listener) {
|
||||
var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
|
||||
var wrapped = onceWrapper.bind(state);
|
||||
// @ts-ignore
|
||||
wrapped.listener = listener;
|
||||
state.wrapFn = wrapped;
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
EventEmitter.prototype.once = function once(type, listener) {
|
||||
checkListener(listener);
|
||||
this.on(type, _onceWrap(this, type, listener));
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.prependOnceListener =
|
||||
function prependOnceListener(type, listener) {
|
||||
checkListener(listener);
|
||||
this.prependListener(type, _onceWrap(this, type, listener));
|
||||
return this;
|
||||
};
|
||||
|
||||
// Emits a 'removeListener' event if and only if the listener was removed.
|
||||
EventEmitter.prototype.removeListener =
|
||||
function removeListener(type, listener) {
|
||||
var list, events, position, i, originalListener;
|
||||
|
||||
checkListener(listener);
|
||||
|
||||
events = this._events;
|
||||
if (events === undefined)
|
||||
return this;
|
||||
|
||||
list = events[type];
|
||||
if (list === undefined)
|
||||
return this;
|
||||
|
||||
if (list === listener || list.listener === listener) {
|
||||
if (--this._eventsCount === 0)
|
||||
this._events = Object.create(null);
|
||||
else {
|
||||
delete events[type];
|
||||
if (events.removeListener)
|
||||
this.emit('removeListener', type, list.listener || listener);
|
||||
}
|
||||
} else if (typeof list !== 'function') {
|
||||
position = -1;
|
||||
|
||||
for (i = list.length - 1; i >= 0; i--) {
|
||||
if (list[i] === listener || list[i].listener === listener) {
|
||||
originalListener = list[i].listener;
|
||||
position = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (position < 0)
|
||||
return this;
|
||||
|
||||
if (position === 0)
|
||||
list.shift();
|
||||
else {
|
||||
spliceOne(list, position);
|
||||
}
|
||||
|
||||
if (list.length === 1)
|
||||
events[type] = list[0];
|
||||
|
||||
if (events.removeListener !== undefined)
|
||||
this.emit('removeListener', type, originalListener || listener);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
||||
|
||||
EventEmitter.prototype.removeAllListeners =
|
||||
function removeAllListeners(type) {
|
||||
var listeners, events, i;
|
||||
|
||||
events = this._events;
|
||||
if (events === undefined)
|
||||
return this;
|
||||
|
||||
// not listening for removeListener, no need to emit
|
||||
if (events.removeListener === undefined) {
|
||||
if (arguments.length === 0) {
|
||||
this._events = Object.create(null);
|
||||
this._eventsCount = 0;
|
||||
} else if (events[type] !== undefined) {
|
||||
if (--this._eventsCount === 0)
|
||||
this._events = Object.create(null);
|
||||
else
|
||||
delete events[type];
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
// emit removeListener for all listeners on all events
|
||||
if (arguments.length === 0) {
|
||||
var keys = Object.keys(events);
|
||||
var key;
|
||||
for (i = 0; i < keys.length; ++i) {
|
||||
key = keys[i];
|
||||
if (key === 'removeListener') continue;
|
||||
this.removeAllListeners(key);
|
||||
}
|
||||
this.removeAllListeners('removeListener');
|
||||
this._events = Object.create(null);
|
||||
this._eventsCount = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
listeners = events[type];
|
||||
|
||||
if (typeof listeners === 'function') {
|
||||
this.removeListener(type, listeners);
|
||||
} else if (listeners !== undefined) {
|
||||
// LIFO order
|
||||
for (i = listeners.length - 1; i >= 0; i--) {
|
||||
this.removeListener(type, listeners[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
function _listeners(target, type, unwrap) {
|
||||
var events = target._events;
|
||||
|
||||
if (events === undefined)
|
||||
return [];
|
||||
|
||||
var evlistener = events[type];
|
||||
if (evlistener === undefined)
|
||||
return [];
|
||||
|
||||
if (typeof evlistener === 'function')
|
||||
return unwrap ? [evlistener.listener || evlistener] : [evlistener];
|
||||
|
||||
return unwrap ?
|
||||
unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
|
||||
}
|
||||
|
||||
EventEmitter.prototype.listeners = function listeners(type) {
|
||||
return _listeners(this, type, true);
|
||||
};
|
||||
|
||||
EventEmitter.prototype.rawListeners = function rawListeners(type) {
|
||||
return _listeners(this, type, false);
|
||||
};
|
||||
|
||||
EventEmitter.listenerCount = function (emitter, type) {
|
||||
if (typeof emitter.listenerCount === 'function') {
|
||||
return emitter.listenerCount(type);
|
||||
} else {
|
||||
return listenerCount.call(emitter, type);
|
||||
}
|
||||
};
|
||||
|
||||
EventEmitter.prototype.listenerCount = listenerCount;
|
||||
function listenerCount(this: any, type) {
|
||||
var events = this._events;
|
||||
|
||||
if (events !== undefined) {
|
||||
var evlistener = events[type];
|
||||
|
||||
if (typeof evlistener === 'function') {
|
||||
return 1;
|
||||
} else if (evlistener !== undefined) {
|
||||
return evlistener.length;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
EventEmitter.prototype.eventNames = function eventNames() {
|
||||
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
|
||||
};
|
||||
|
||||
function arrayClone(arr, n) {
|
||||
var copy = new Array(n);
|
||||
for (var i = 0; i < n; ++i)
|
||||
copy[i] = arr[i];
|
||||
return copy;
|
||||
}
|
||||
|
||||
function spliceOne(list, index) {
|
||||
for (; index + 1 < list.length; index++)
|
||||
list[index] = list[index + 1];
|
||||
list.pop();
|
||||
}
|
||||
|
||||
function unwrapListeners(arr) {
|
||||
var ret = new Array(arr.length);
|
||||
for (var i = 0; i < ret.length; ++i) {
|
||||
ret[i] = arr[i].listener || arr[i];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
51
packages/nodejs/src/index.ts
Normal file
51
packages/nodejs/src/index.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
/// <reference types="@ms/nashorn" />
|
||||
import * as yaml from 'js-yaml'
|
||||
|
||||
const File = Java.type("java.io.File");
|
||||
const separatorChar = File.separatorChar;
|
||||
|
||||
let langMap = {};
|
||||
let fallbackMap = {};
|
||||
|
||||
type TranslateParam = { [key: string]: any }
|
||||
|
||||
function translate(name: string, param?: TranslateParam) {
|
||||
let langText: string = langMap[name] || fallbackMap[name];
|
||||
if (!langText) { return '[WARN] @ms/i18n miss lang translate: ' + name }
|
||||
for (const key in param) {
|
||||
langText = langText.replace("{" + key + "}", param[key])
|
||||
}
|
||||
return langText;
|
||||
}
|
||||
|
||||
function initialize(lang: string = 'zh_cn', fallback: string = 'zh_cn') {
|
||||
langMap = readYamlFile(root, lang) || readYamlFile(concat(__dirname, '..'), lang)
|
||||
fallbackMap = readYamlFile(root, fallback) || readYamlFile(concat(__dirname, '..'), fallback)
|
||||
console.i18n = function i18n(name: string, param?: TranslateParam) {
|
||||
console.log(translate(name, param))
|
||||
}
|
||||
}
|
||||
|
||||
function readYamlFile(dir: string, name: string) {
|
||||
let langFile = concat(dir, 'languages', name + '.yml');
|
||||
return exists(langFile) && yaml.safeLoad(base.read(langFile))
|
||||
}
|
||||
|
||||
function concat(...args: string[]) {
|
||||
return args.join(separatorChar)
|
||||
}
|
||||
|
||||
function exists(path: string) {
|
||||
return new File(path).exists()
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface Console {
|
||||
i18n(name: string, param?: TranslateParam);
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
initialize,
|
||||
translate
|
||||
};
|
||||
7
packages/nodejs/tsconfig.json
Normal file
7
packages/nodejs/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "src",
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
34
packages/nukkit/package.json
Normal file
34
packages/nukkit/package.json
Normal file
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"name": "@ms/nukkit",
|
||||
"version": "0.4.0",
|
||||
"description": "MiaoScript nukkit package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
"minecraft",
|
||||
"bukkit",
|
||||
"sponge"
|
||||
],
|
||||
"author": "MiaoWoo <admin@yumc.pw>",
|
||||
"homepage": "https://github.com/circlecloud/ms.git",
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf dist",
|
||||
"watch": "tsc --watch",
|
||||
"build": "yarn clean && tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ms/api": "^0.4.0",
|
||||
"@ms/common": "^0.4.0",
|
||||
"@ms/container": "^0.4.0"
|
||||
}
|
||||
}
|
||||
40
packages/nukkit/src/command.ts
Normal file
40
packages/nukkit/src/command.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import '@ms/nashorn'
|
||||
|
||||
import { command, plugin } from '@ms/api'
|
||||
import { inject, provideSingleton, postConstruct } from '@ms/container'
|
||||
|
||||
let PluginCommand = Java.type('cn.nukkit.command.PluginCommand');
|
||||
let CommandExecutor = Java.type('cn.nukkit.command.CommandExecutor');
|
||||
|
||||
@provideSingleton(command.Command)
|
||||
export class NukkitCommand extends command.Command {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any
|
||||
private commandMap: any;
|
||||
|
||||
@postConstruct()
|
||||
init() {
|
||||
this.commandMap = base.getInstance().getServer().getCommandMap();
|
||||
}
|
||||
create(plugin: any, command: string) {
|
||||
var cmd = this.commandMap.getCommand(command)
|
||||
if (cmd && cmd instanceof PluginCommand) { return cmd };
|
||||
cmd = new PluginCommand(command, this.pluginInstance)
|
||||
this.commandMap.register(plugin.description.name, cmd);
|
||||
return cmd;
|
||||
}
|
||||
remove(plugin: any, command: string) {
|
||||
var cmd = this.commandMap.getCommand(command)
|
||||
if (cmd && cmd instanceof PluginCommand) {
|
||||
cmd.unregister(this.commandMap);
|
||||
}
|
||||
}
|
||||
onCommand(plugin: any, command: any, executor: Function) {
|
||||
command.setExecutor(new CommandExecutor({
|
||||
onCommand: super.setExecutor(plugin, command, executor)
|
||||
}));
|
||||
}
|
||||
onTabComplete(plugin: any, command: any, tabCompleter: Function) {
|
||||
// Not Support
|
||||
}
|
||||
}
|
||||
21
packages/nukkit/src/console.ts
Normal file
21
packages/nukkit/src/console.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { MiaoScriptConsole } from '@ms/api'
|
||||
|
||||
let Nukkit = base.getInstance().getServer();
|
||||
let CommandSender = Java.type('cn.nukkit.command.CommandSender')
|
||||
|
||||
export class NukkitConsole extends MiaoScriptConsole {
|
||||
sender(sender, ...args) {
|
||||
if (!(sender instanceof CommandSender)) {
|
||||
this.error(`First parameter ${sender} not instanceof cn.nukkit.command.CommandSender can't send message!`)
|
||||
return;
|
||||
}
|
||||
if (Object.prototype.toString.call(args[0]) === "[object Array]") {
|
||||
args[0].forEach(line => sender.sendMessage(this.prefix + line))
|
||||
} else {
|
||||
sender.sendMessage(this.prefix + args.join(' '));
|
||||
}
|
||||
}
|
||||
console(...args: string[]): void {
|
||||
this.sender(Nukkit.getConsoleSender(), args.join(' '));
|
||||
}
|
||||
}
|
||||
47
packages/nukkit/src/event.ts
Normal file
47
packages/nukkit/src/event.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { event, plugin } from '@ms/api'
|
||||
import { inject, provideSingleton } from '@ms/container'
|
||||
|
||||
const Nukkit: cn.nukkit.Server = base.getInstance().getServer();
|
||||
const Event = Java.type("cn.nukkit.event.Event");
|
||||
const Modifier = Java.type("java.lang.reflect.Modifier");
|
||||
const Listener = Java.type("cn.nukkit.event.Listener");
|
||||
const EventPriority = Java.type("cn.nukkit.event.EventPriority");
|
||||
const EventExecutor = Java.type("cn.nukkit.plugin.EventExecutor");
|
||||
|
||||
@provideSingleton(event.Event)
|
||||
export class NukkitEvent extends event.Event {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any
|
||||
|
||||
constructor() {
|
||||
super('cn/nukkit/event');
|
||||
}
|
||||
|
||||
getJarFile(resource: string) {
|
||||
return super.getJarFile('cn/nukkit/Nukkit.class')
|
||||
}
|
||||
isValidEvent(clazz: any): boolean {
|
||||
// 继承于 org.bukkit.event.Event
|
||||
return Event.class.isAssignableFrom(clazz) &&
|
||||
// 访问符为Public
|
||||
Modifier.isPublic(clazz.getModifiers()) &&
|
||||
// 不是抽象类
|
||||
!Modifier.isAbstract(clazz.getModifiers());
|
||||
}
|
||||
register(eventCls: any, exec: Function, priority: event.EventPriority, ignoreCancel: boolean) {
|
||||
let listener = new Listener({});
|
||||
Nukkit.getPluginManager().registerEvent(
|
||||
eventCls,
|
||||
listener,
|
||||
EventPriority[priority],
|
||||
new EventExecutor({
|
||||
execute: exec
|
||||
}),
|
||||
this.pluginInstance,
|
||||
ignoreCancel);
|
||||
return listener;
|
||||
}
|
||||
unregister(event: any, listener: any): void {
|
||||
event.getMethod('getHandlers').invoke(null).unregister(listener);
|
||||
}
|
||||
}
|
||||
14
packages/nukkit/src/index.ts
Normal file
14
packages/nukkit/src/index.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/// <reference types="@ms/types/dist/typings/nukkit" />
|
||||
|
||||
import { server } from '@ms/api'
|
||||
import { Container } from '@ms/container'
|
||||
|
||||
import { NukkitConsole } from './console';
|
||||
import './event';
|
||||
import './server';
|
||||
import './command';
|
||||
import './task';
|
||||
|
||||
export default function NukkitImpl(container: Container) {
|
||||
container.bind(server.Console).toConstantValue(NukkitConsole);
|
||||
}
|
||||
48
packages/nukkit/src/server.ts
Normal file
48
packages/nukkit/src/server.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { server } from '@ms/api'
|
||||
import { provideSingleton } from '@ms/container';
|
||||
|
||||
let Nukkit: cn.nukkit.Server = base.getInstance().getServer();
|
||||
const File = Java.type("java.io.File");
|
||||
|
||||
@provideSingleton(server.Server)
|
||||
export class NukkitServer implements server.Server {
|
||||
private pluginsFolder: string;
|
||||
|
||||
constructor() {
|
||||
this.pluginsFolder = new File(base.getInstance().getClass().getProtectionDomain().getCodeSource().getLocation().getPath()).getParentFile().getCanonicalPath()
|
||||
}
|
||||
|
||||
getPlayer(name: string) {
|
||||
return Nukkit.getPlayer(name)
|
||||
}
|
||||
getVersion(): string {
|
||||
return Nukkit.getVersion()
|
||||
}
|
||||
getOnlinePlayers() {
|
||||
return Nukkit.getOnlinePlayers() as unknown as any[]
|
||||
}
|
||||
getConsoleSender() {
|
||||
return Nukkit.getConsoleSender()
|
||||
}
|
||||
getService(service: string) {
|
||||
return Nukkit.getServiceManager().getProvider(base.getClass(service))
|
||||
}
|
||||
dispatchCommand(sender: string | any, command: string): boolean {
|
||||
if (typeof sender === 'string') {
|
||||
sender = this.getPlayer(sender)
|
||||
}
|
||||
return Nukkit.dispatchCommand(sender, command)
|
||||
}
|
||||
dispatchConsoleCommand(command: string): boolean {
|
||||
return Nukkit.dispatchCommand(Nukkit.getConsoleSender(), command)
|
||||
}
|
||||
getPluginsFolder(): string {
|
||||
return this.pluginsFolder;
|
||||
}
|
||||
getNativePluginManager() {
|
||||
return Nukkit.getPluginManager() as any;
|
||||
}
|
||||
sendJson(sender: string | any, json: object | string): void {
|
||||
throw new Error("Method not implemented.");
|
||||
}
|
||||
}
|
||||
33
packages/nukkit/src/task.ts
Normal file
33
packages/nukkit/src/task.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { task, plugin } from '@ms/api'
|
||||
import { inject, provideSingleton } from '@ms/container';
|
||||
|
||||
const NukkitRunnable = Java.type('cn.nukkit.scheduler.NukkitRunnable');
|
||||
|
||||
@provideSingleton(task.TaskManager)
|
||||
export class NukkitTaskManager implements task.TaskManager {
|
||||
@inject(plugin.PluginInstance)
|
||||
private pluginInstance: any;
|
||||
|
||||
create(func: Function): task.Task {
|
||||
if (Object.prototype.toString.call(func) !== "[object Function]") { throw TypeError('第一个参数 Task 必须为 function !'); };
|
||||
return new NukkitTask(this.pluginInstance, func);
|
||||
}
|
||||
callSyncMethod(func: Function): any {
|
||||
return func()
|
||||
}
|
||||
}
|
||||
|
||||
export class NukkitTask extends task.Task {
|
||||
submit(): task.Cancelable {
|
||||
let run = new NukkitRunnable({
|
||||
run: () => this.run()
|
||||
})
|
||||
let funcName = `runTask${this.interval ? 'Timer' : 'Later'}${this.isAsync ? 'Asynchronously' : ''}`
|
||||
if (this.interval) {
|
||||
run[funcName](this.plugin, this.laterTime, this.interval);
|
||||
} else {
|
||||
run[funcName](this.plugin, this.laterTime);
|
||||
}
|
||||
return run;
|
||||
}
|
||||
}
|
||||
7
packages/nukkit/tsconfig.json
Normal file
7
packages/nukkit/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "src",
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
29
packages/ployfill/package.json
Normal file
29
packages/ployfill/package.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "@ms/ployfill",
|
||||
"version": "0.4.0",
|
||||
"description": "MiaoScript ployfill package",
|
||||
"author": "MiaoWoo <admin@yumc.pw>",
|
||||
"homepage": "https://github.com/circlecloud/ms.git",
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf dist",
|
||||
"watch": "tsc --watch",
|
||||
"build": "yarn clean && tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ms/i18n": "^0.4.0",
|
||||
"@ms/nashorn": "^0.4.0",
|
||||
"core-js": "^3.6.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^3.8.3"
|
||||
}
|
||||
}
|
||||
26
packages/ployfill/src/es5-ext.ts
Normal file
26
packages/ployfill/src/es5-ext.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
// ES2015 String ployfill must force overwrite to js method
|
||||
Object.defineProperty(String.prototype, 'contains', {
|
||||
value: require(`es5-ext/string/#/contains/shim`),
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: true
|
||||
})
|
||||
Object.defineProperty(String.prototype, 'repeat', {
|
||||
value: require(`es5-ext/string/#/repeat/shim`),
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: true
|
||||
})
|
||||
Object.defineProperty(String.prototype, 'startsWith', {
|
||||
value: require(`es5-ext/string/#/starts-with/shim`),
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: true
|
||||
})
|
||||
Object.defineProperty(String.prototype, 'endsWith', {
|
||||
value: require(`es5-ext/string/#/ends-with/shim`),
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
writable: true
|
||||
})
|
||||
|
||||
12
packages/ployfill/src/index.ts
Normal file
12
packages/ployfill/src/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
/// <reference types="@ms/nashorn" />
|
||||
|
||||
import i18n from '@ms/i18n'
|
||||
let ployfillStartTime = new Date().getTime();
|
||||
i18n.initialize();
|
||||
console.i18n("ms.ployfill.initialize");
|
||||
require('./es5-ext');
|
||||
require('core-js');
|
||||
global.setGlobal('Proxy', require('./proxy').Proxy)
|
||||
global.setGlobal('XMLHttpRequest', require('./xml-http-request').XMLHttpRequest)
|
||||
global.setGlobal('Blob', require('blob-polyfill').Blob)
|
||||
console.i18n("ms.ployfill.completed", { time: (new Date().getTime() - ployfillStartTime) / 1000 });
|
||||
31
packages/ployfill/src/proxy.ts
Normal file
31
packages/ployfill/src/proxy.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
// Nashorn JSAdapter See https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions#Nashornextensions-JSAdapterconstructor
|
||||
let createProxy = eval(`
|
||||
function(handle){ return new JSAdapter(handle) }
|
||||
`)
|
||||
export interface ProxyHandle extends ProxyHandler<any> {
|
||||
// get: (target: any, name: string) => any
|
||||
// set: (target: any, name: string, value: any) => boolean
|
||||
// construct: (target: any, ...args: any[]) => any
|
||||
// has: (target: any, name: string) => boolean
|
||||
// ownKeys: (target: any) => string[]
|
||||
values: (target: any) => any[];
|
||||
// call: (target: any, name: string, ...args: any[]) => any
|
||||
// deleteProperty: (target: any, name: string) => boolean
|
||||
}
|
||||
export class Proxy {
|
||||
static newProxy(target: any, handle: Partial<ProxyHandle>): any {
|
||||
return new Proxy(target, handle)
|
||||
}
|
||||
constructor(target: any, handle: Partial<ProxyHandle>) {
|
||||
return createProxy({
|
||||
__get__: (name: string) => handle.get ? handle.get(target, name, undefined) : target[name],
|
||||
__put__: (name: string, value: any) => handle.set ? handle.set(target, name, value, undefined) : target[name] = value,
|
||||
__call__: (name: string, ...args: any) => handle.apply ? handle.apply(target, name, args) : target[name].apply(target, args),
|
||||
__new__: (...args: any) => handle.construct ? handle.construct(target, args, target) : new target(...args),
|
||||
__getIds__: () => handle.ownKeys ? handle.ownKeys(target) : Object.keys(target),
|
||||
__getValues__: () => handle.values ? handle.values(target) : Object.values(target),
|
||||
__has__: (name: string) => handle.has ? handle.has(target, name) : Object.getOwnPropertyDescriptor(target, name) != undefined,
|
||||
__delete__: (name: string) => handle.deleteProperty ? handle.deleteProperty(target, name) : delete target[name]
|
||||
})
|
||||
}
|
||||
}
|
||||
141
packages/ployfill/src/task.ts
Normal file
141
packages/ployfill/src/task.ts
Normal file
@@ -0,0 +1,141 @@
|
||||
(function nashornEventLoopMain(context) {
|
||||
'use strict';
|
||||
|
||||
var Thread = Java.type('java.lang.Thread');
|
||||
var Phaser = Java.type('java.util.concurrent.Phaser');
|
||||
var ArrayDeque = Java.type('java.util.ArrayDeque');
|
||||
var HashMap = Java.type('java.util.HashMap');
|
||||
var TimeUnit = Java.type("java.util.concurrent.TimeUnit");
|
||||
var Runnable = Java.type('java.lang.Runnable');
|
||||
|
||||
var globalTimerId;
|
||||
var timerMap;
|
||||
var eventLoop;
|
||||
var phaser = new Phaser();
|
||||
|
||||
// __NASHORN_POLYFILL_TIMER__ type is ScheduledExecutorService
|
||||
var scheduler = context.__NASHORN_POLYFILL_TIMER__;
|
||||
|
||||
resetEventLoop();
|
||||
|
||||
// console.log('main javasript thread ' + Thread.currentThread().getName());
|
||||
|
||||
function resetEventLoop() {
|
||||
globalTimerId = 1;
|
||||
if (timerMap) {
|
||||
timerMap.forEach(function(key, value) {
|
||||
value.cancel(true);
|
||||
})
|
||||
}
|
||||
timerMap = new HashMap();
|
||||
eventLoop = new ArrayDeque();
|
||||
}
|
||||
|
||||
function waitForMessages() {
|
||||
phaser.register();
|
||||
var wait = !(eventLoop.size() === 0);
|
||||
phaser.arriveAndDeregister();
|
||||
return wait;
|
||||
}
|
||||
|
||||
function processNextMessages() {
|
||||
var remaining = 1;
|
||||
while (remaining) {
|
||||
phaser.register();
|
||||
var message = eventLoop.removeFirst();
|
||||
remaining = eventLoop.size();
|
||||
phaser.arriveAndDeregister();
|
||||
|
||||
var fn = message.fn;
|
||||
var args = message.args;
|
||||
|
||||
try {
|
||||
fn.apply(context, args);
|
||||
} catch (e) {
|
||||
console.trace(e);
|
||||
console.trace(fn);
|
||||
console.trace(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context.nashornEventLoop = {
|
||||
process: function() {
|
||||
while (waitForMessages()) {
|
||||
processNextMessages()
|
||||
}
|
||||
},
|
||||
reset: resetEventLoop
|
||||
};
|
||||
|
||||
|
||||
function createRunnable(fn, timerId, args, repeated) {
|
||||
return new Runnable({
|
||||
run: function() {
|
||||
try {
|
||||
var phase = phaser.register();
|
||||
eventLoop.addLast({
|
||||
fn: fn,
|
||||
args: args
|
||||
});
|
||||
} catch (e) {
|
||||
console.trace(e);
|
||||
} finally {
|
||||
if (!repeated) timerMap.remove(timerId);
|
||||
phaser.arriveAndDeregister();
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
var setTimeout = function(fn, millis /* [, args...] */) {
|
||||
var args = [].slice.call(arguments, 2, arguments.length);
|
||||
|
||||
var timerId = globalTimerId++;
|
||||
var runnable = createRunnable(fn, timerId, args, false);
|
||||
|
||||
var task = scheduler.schedule(runnable, millis, TimeUnit.MILLISECONDS);
|
||||
timerMap.put(timerId, task);
|
||||
|
||||
return timerId;
|
||||
};
|
||||
|
||||
var setImmediate = function(fn /* [, args...] */) {
|
||||
var args = [].slice.call(arguments, 1, arguments.length);
|
||||
// @ts-ignore
|
||||
return setTimeout(fn, 0, args);
|
||||
}
|
||||
|
||||
var clearImmediate = function(timerId) {
|
||||
clearTimeout(timerId);
|
||||
}
|
||||
|
||||
var clearTimeout = function(timerId) {
|
||||
var task = timerMap.get(timerId);
|
||||
if (task) {
|
||||
task.cancel(true);
|
||||
timerMap.remove(timerId);
|
||||
}
|
||||
};
|
||||
|
||||
var setInterval = function(fn, delay /* [, args...] */) {
|
||||
var args = [].slice.call(arguments, 2, arguments.length);
|
||||
var timerId = globalTimerId++;
|
||||
var runnable = createRunnable(fn, timerId, args, true);
|
||||
var task = scheduler.scheduleWithFixedDelay(runnable, delay, delay, TimeUnit.MILLISECONDS);
|
||||
timerMap.put(timerId, task);
|
||||
return timerId;
|
||||
};
|
||||
|
||||
var clearInterval = function(timerId) {
|
||||
clearTimeout(timerId);
|
||||
};
|
||||
|
||||
context.setTimeout = setTimeout;
|
||||
context.clearTimeout = clearTimeout;
|
||||
context.setImmediate = setImmediate;
|
||||
context.clearImmediate = clearImmediate;
|
||||
context.setInterval = setInterval;
|
||||
context.clearInterval = clearInterval;
|
||||
// @ts-ignore
|
||||
})(typeof global !== "undefined" && global || typeof self !== "undefined" && self || this);
|
||||
246
packages/ployfill/src/xml-http-request.ts
Normal file
246
packages/ployfill/src/xml-http-request.ts
Normal file
@@ -0,0 +1,246 @@
|
||||
import '@ms/nashorn'
|
||||
|
||||
const URL = Java.type("java.net.URL");
|
||||
const Files = Java.type("java.nio.file.Files");
|
||||
const StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
|
||||
const JavaString = Java.type("java.lang.String");
|
||||
const SecureRandom = Java.type("java.security.SecureRandom");
|
||||
const SSLContext = Java.type("javax.net.ssl.SSLContext");
|
||||
const HttpsURLConnection = Java.type("javax.net.ssl.HttpsURLConnection");
|
||||
const HostnameVerifier = Java.type("javax.net.ssl.HostnameVerifier");
|
||||
const X509TrustManager = Java.type("javax.net.ssl.X509TrustManager");
|
||||
|
||||
const SocketTimeoutException = Java.type('java.net.SocketTimeoutException');
|
||||
|
||||
const Callable = Java.type('java.util.concurrent.Callable');
|
||||
const Executors = Java.type('java.util.concurrent.Executors')
|
||||
|
||||
const UTF_8 = "UTF-8"
|
||||
|
||||
const TrustAnyHostnameVerifier = new HostnameVerifier({ verify: () => true });
|
||||
|
||||
const SSLSocketFactory = function initSSLSocketFactory() {
|
||||
let sslContext = SSLContext.getInstance("TLS");
|
||||
sslContext.init(null, [new X509TrustManager({
|
||||
getAcceptedIssuers: () => null,
|
||||
checkClientTrusted: () => { },
|
||||
checkServerTrusted: () => { }
|
||||
})], new SecureRandom());
|
||||
return sslContext.getSocketFactory();
|
||||
}();
|
||||
|
||||
interface Future<T> {
|
||||
cancel(): boolean;
|
||||
isCancelled(): boolean;
|
||||
isDone(): boolean;
|
||||
get(): T;
|
||||
}
|
||||
|
||||
enum ReadyState {
|
||||
UNSENT,//Client has been created. open() not called yet.
|
||||
OPENED,//open() has been called.
|
||||
HEADERS_RECEIVED,//send() has been called, and headers and status are available.
|
||||
LOADING,//Downloading; responseText holds partial data.
|
||||
DONE,//The operation is complete.
|
||||
}
|
||||
type RequestMethod =
|
||||
| 'get' | 'GET'
|
||||
| 'delete' | 'DELETE'
|
||||
| 'head' | 'HEAD'
|
||||
| 'options' | 'OPTIONS'
|
||||
| 'post' | 'POST'
|
||||
| 'put' | 'PUT'
|
||||
| 'patch' | 'PATCH';
|
||||
type ResponseType =
|
||||
| 'arraybuffer'
|
||||
| 'blob'
|
||||
| 'document'
|
||||
| 'json'
|
||||
| 'text'
|
||||
| 'stream';
|
||||
type EventType =
|
||||
| 'load'
|
||||
| 'error'
|
||||
| 'abort'
|
||||
| 'progress'
|
||||
| 'timeout'
|
||||
| 'loadend'
|
||||
| 'loadstart';
|
||||
type HttpHeader = { [key: string]: string };
|
||||
|
||||
|
||||
const executor = Executors.newCachedThreadPool();
|
||||
|
||||
export class XMLHttpRequest {
|
||||
private _timeout: number;
|
||||
private _responseType: ResponseType = 'text';
|
||||
private _withCredentials: boolean;
|
||||
|
||||
private _readyState: ReadyState = ReadyState.UNSENT;
|
||||
|
||||
private _method: RequestMethod;
|
||||
private _url: string;
|
||||
private _async: boolean;
|
||||
private _mimeType: string;
|
||||
|
||||
private _status: number = 0;
|
||||
private _statusText: string = null;
|
||||
private _response: any;
|
||||
private _responseURL: string;
|
||||
private _responseHeaders: HttpHeader;
|
||||
|
||||
private _connection = null;
|
||||
|
||||
get timeout() {
|
||||
return this._timeout;
|
||||
}
|
||||
set timeout(timeout: number) {
|
||||
this._timeout = timeout
|
||||
}
|
||||
get readyState() {
|
||||
return this._readyState;
|
||||
}
|
||||
set responseType(type: ResponseType) {
|
||||
this._responseType = type;
|
||||
}
|
||||
get responseType() {
|
||||
return this._responseType;
|
||||
}
|
||||
|
||||
get status() {
|
||||
return this._status;
|
||||
}
|
||||
get statusText() {
|
||||
return this._statusText;
|
||||
}
|
||||
get response() {
|
||||
return this._response ? JSON.parse(this._response) : this._response;
|
||||
}
|
||||
get responseText() {
|
||||
return this._response;
|
||||
}
|
||||
get responseXML() {
|
||||
return this._response;
|
||||
}
|
||||
get responseURL() {
|
||||
return this._responseURL;
|
||||
}
|
||||
|
||||
onload() { }
|
||||
onerror(ex: Error) { }
|
||||
onabort() { }
|
||||
onprogress() { }
|
||||
ontimeout(ex: Error) { }
|
||||
onloadend() { }
|
||||
onloadstart() { }
|
||||
onreadystatechange() { }
|
||||
|
||||
setRequestHeader(key: string, val: string) {
|
||||
this._connection.setRequestProperty(key, val);
|
||||
}
|
||||
getResponseHeader(key: string): string {
|
||||
return this._responseHeaders[key];
|
||||
}
|
||||
getAllResponseHeaders(): any {
|
||||
return this._responseHeaders;
|
||||
}
|
||||
addEventListener(event: EventType, callback: Function) {
|
||||
this[`on${event.toLowerCase()}`] = callback;
|
||||
}
|
||||
overrideMimeType(mimeType: string) {
|
||||
this._mimeType = mimeType;
|
||||
}
|
||||
open(method: RequestMethod, url: string, async: boolean = true, user?: string, password?: string) {
|
||||
this._method = method;
|
||||
this._url = url;
|
||||
this._async = async;
|
||||
|
||||
this._connection = new URL(this._url).openConnection()
|
||||
if (this._connection instanceof HttpsURLConnection) {
|
||||
this._connection.setHostnameVerifier(TrustAnyHostnameVerifier);
|
||||
this._connection.setSSLSocketFactory(SSLSocketFactory);
|
||||
}
|
||||
this._connection.setRequestMethod(this._method);
|
||||
this._connection.setDoOutput(true);
|
||||
this._connection.setDoInput(true);
|
||||
this._connection.setConnectTimeout(this._timeout);
|
||||
this._connection.setReadTimeout(this._timeout);
|
||||
|
||||
this.setReadyState(ReadyState.OPENED);
|
||||
}
|
||||
send(body?: string | object): Future<string> {
|
||||
if (this._readyState !== ReadyState.OPENED) { throw new Error(`Error Status ${this._readyState}!`) }
|
||||
let future = executor.submit(new Callable({ call: () => this._send(body) }));
|
||||
if (!this._async) { future.get() }
|
||||
return future;
|
||||
}
|
||||
get() {
|
||||
switch (this._responseType) {
|
||||
case "json":
|
||||
return this.response;
|
||||
case "text":
|
||||
return this.responseText;
|
||||
default:
|
||||
throw Error(`Unsupport ResponseType: ${this._responseType} !`)
|
||||
}
|
||||
}
|
||||
abort() {
|
||||
this._connection.disconnect();
|
||||
this.onabort();
|
||||
}
|
||||
|
||||
private _send(body?: string | object) {
|
||||
try {
|
||||
this._connection.connect();
|
||||
this.onloadstart();
|
||||
if (body) {
|
||||
let bodyType = Object.prototype.toString.call(body);
|
||||
if (bodyType !== '[object String]') { throw new Error(`body(${bodyType}) must be string!`) }
|
||||
var out = this._connection.getOutputStream();
|
||||
out.write(new JavaString(body).getBytes(UTF_8));
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
this.setReadyState(ReadyState.LOADING);
|
||||
this._status = this._connection.getResponseCode();
|
||||
this._statusText = this._connection.getResponseMessage();
|
||||
this.setResponseHeaders(this._connection.getHeaderFields());
|
||||
if (this._status >= 0 && this._status < 300) {
|
||||
this._response = this.readOutput(this._connection.getInputStream());
|
||||
} else if (this._status >= 300 && this._status < 400) {
|
||||
this._responseURL = this.getResponseHeader('Location');
|
||||
} else {
|
||||
this._response = this.readOutput(this._connection.getErrorStream());
|
||||
}
|
||||
this.onloadend();
|
||||
} catch (ex) {
|
||||
if (ex instanceof SocketTimeoutException && this.ontimeout) {
|
||||
return this.ontimeout(ex)
|
||||
} else if (this.onerror) {
|
||||
return this.onerror(ex);
|
||||
}
|
||||
throw ex;
|
||||
} finally {
|
||||
this._connection.disconnect();
|
||||
this.setReadyState(ReadyState.DONE);
|
||||
}
|
||||
}
|
||||
|
||||
private setResponseHeaders(header: any) {
|
||||
this._responseHeaders = {};
|
||||
header.forEach((key, value) => {
|
||||
this._responseHeaders[key] = value[value.length - 1]
|
||||
});
|
||||
}
|
||||
|
||||
private setReadyState(state: ReadyState) {
|
||||
this._readyState = state;
|
||||
this.onreadystatechange();
|
||||
}
|
||||
|
||||
private readOutput(input: any) {
|
||||
var tempFile = Files.createTempFile('xhr', '.response');
|
||||
Files.copy(input, tempFile, StandardCopyOption['REPLACE_EXISTING']); tempFile.toFile().deleteOnExit();
|
||||
return new JavaString(Files.readAllBytes(tempFile), 'UTF-8');
|
||||
}
|
||||
}
|
||||
7
packages/ployfill/tsconfig.json
Normal file
7
packages/ployfill/tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"baseUrl": "src",
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
||||
4
packages/plugin/.gitignore
vendored
4
packages/plugin/.gitignore
vendored
@@ -1,4 +0,0 @@
|
||||
/node_modules
|
||||
/dist
|
||||
/package-lock.json
|
||||
/yarn.lock
|
||||
@@ -1,22 +0,0 @@
|
||||
src
|
||||
test
|
||||
typings
|
||||
bundled
|
||||
build
|
||||
coverage
|
||||
docs
|
||||
wiki
|
||||
gulpfile.js
|
||||
bower.json
|
||||
karma.conf.js
|
||||
tsconfig.json
|
||||
typings.json
|
||||
CONTRIBUTING.md
|
||||
ISSUE_TEMPLATE.md
|
||||
PULL_REQUEST_TEMPLATE.md
|
||||
tslint.json
|
||||
wallaby.js
|
||||
.travis.yml
|
||||
.gitignore
|
||||
.vscode
|
||||
type_definitions
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ms/plugin",
|
||||
"version": "0.0.0",
|
||||
"version": "0.4.0",
|
||||
"description": "MiaoScript api package",
|
||||
"keywords": [
|
||||
"miaoscript",
|
||||
@@ -13,22 +13,25 @@
|
||||
"license": "ISC",
|
||||
"main": "dist/index.js",
|
||||
"publishConfig": {
|
||||
"registry": "https://repo.yumc.pw/repository/npm/"
|
||||
"registry": "https://repo.yumc.pw/repository/npm-hosted/"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf dist",
|
||||
"watch": "npx tsc --watch",
|
||||
"build": "yarn clean && npx tsc",
|
||||
"watch": "tsc --watch",
|
||||
"build": "yarn clean && tsc",
|
||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/js-yaml": "^3.12.2",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.0",
|
||||
"typescript": "^3.6.2"
|
||||
"rimraf": "^3.0.2",
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ms/api": "^0.0.0",
|
||||
"@ms/common": "^0.0.0",
|
||||
"@ms/container": "^0.0.0"
|
||||
"@ms/api": "^0.4.0",
|
||||
"@ms/common": "^0.4.0",
|
||||
"@ms/container": "^0.4.0",
|
||||
"@ms/i18n": "^0.4.0",
|
||||
"js-yaml": "^3.13.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user