Compare commits
55 Commits
v0.23.0
...
v0.28.0-be
| Author | SHA1 | Date | |
|---|---|---|---|
| 3e8d1f7029 | |||
| 9fac585e5e | |||
| 1d26a1e318 | |||
| 5f5df3452d | |||
| fce3c1a284 | |||
| 21b35b0036 | |||
| 2b7588cf04 | |||
| 4435a239d4 | |||
| 4cc5e75f1d | |||
| 188641d57a | |||
| 9a25362140 | |||
| 54eaae96bd | |||
| 5bf4b1c09e | |||
| 54bea62735 | |||
| 0e4ae5d74f | |||
| bdad4136ec | |||
| a0866c1085 | |||
| afd3f91a3f | |||
| e70c78a255 | |||
| 9cfac1672a | |||
| 9126ec8035 | |||
| 23bc6068b5 | |||
| 27b428fbe2 | |||
| c07f1131c4 | |||
| 002f2c47c6 | |||
| 8633d9ea95 | |||
| 07a5d0c8de | |||
| dd76e563c8 | |||
| 7b85ff5b7c | |||
| 359aeb9d63 | |||
| 3901d9fb5f | |||
| c2867da047 | |||
| 65832c9fae | |||
| d9dffa704d | |||
| b39f29de6a | |||
| 56334c6f6e | |||
| 72673b2a67 | |||
| 597bdb721a | |||
| 6e0456d777 | |||
| fb67b06230 | |||
| 203560dcf2 | |||
| 3f58f5992c | |||
| ac16754c9c | |||
| 42d637dd63 | |||
| df0d246136 | |||
| e563e1b507 | |||
| 3b822c613a | |||
| 2967c2a1fe | |||
| 1c579c9789 | |||
| 2fe9bce2ea | |||
| 496d278a93 | |||
| bdf674b678 | |||
| 67fe13deac | |||
| 30846cdc87 | |||
| d8d03149df |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,8 +1,4 @@
|
|||||||
|
.yarn*
|
||||||
.vscode
|
.vscode
|
||||||
.theia
|
|
||||||
node_modules
|
node_modules
|
||||||
dist
|
dist
|
||||||
package-lock.json
|
|
||||||
yarn.lock
|
|
||||||
packages/nashorn/docs
|
|
||||||
!packages/types/dist
|
|
||||||
|
|||||||
25
.npmignore
25
.npmignore
@@ -1,25 +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
|
|
||||||
.theia
|
|
||||||
type_definitions
|
|
||||||
tsconfig.tsbuildinfo
|
|
||||||
*.tsbuildinfo
|
|
||||||
27
README.MD
27
README.MD
@@ -11,24 +11,25 @@
|
|||||||
├─api 全平台兼容的接口
|
├─api 全平台兼容的接口
|
||||||
├─core 核心代码 用于引导加载
|
├─core 核心代码 用于引导加载
|
||||||
├─common 公共类库代码 例如 http reflect 模块
|
├─common 公共类库代码 例如 http reflect 模块
|
||||||
├─client NodeJS的Minecraft客户端 用于调试插件
|
├─compile 编译器相关功能
|
||||||
|
├─client NodeJS 的 Minecraft 客户端 已迁移至 ms-client
|
||||||
├─container IOC容器 用于注入具体实现
|
├─container IOC容器 用于注入具体实现
|
||||||
├─ployfill Nashorn 的一些自定义增强
|
├─database 数据库相关功能
|
||||||
|
├─protocol 协议处理相关功能
|
||||||
|
├─service 服务相关功能
|
||||||
|
├─i18n 多语言环境相关支持
|
||||||
|
├─polyfill Nashorn 的一些自定义增强
|
||||||
├─nashorn Nashorn 的类型定义
|
├─nashorn Nashorn 的类型定义
|
||||||
|
├─nodejs NodeJS 的部分 Java 实现
|
||||||
├─bungee BungeeCordAPI 内部实现
|
├─bungee BungeeCordAPI 内部实现
|
||||||
├─bukkit BukkitAPI 内部实现
|
├─bukkit BukkitAPI 内部实现
|
||||||
├─sponge SpongeAPI 内部实现
|
├─sponge SpongeAPI 内部实现
|
||||||
├─nukkit NukkitAPI 内部实现
|
├─nukkit NukkitAPI 内部实现
|
||||||
|
├─molang MoLang 解析库
|
||||||
|
├─qrcode 二维码相关类库
|
||||||
├─plugin 插件管理器
|
├─plugin 插件管理器
|
||||||
├─websocket Netty的WebSocket注入
|
├─websocket WebSocket 相关实现
|
||||||
├─type Java的类型定义
|
| ├─client 基于 Netty 的 WebSocket 客户端
|
||||||
| ├─bungee BungeeCord类型定义
|
| └─server 基于 Netty 的 WebSocket 服务端
|
||||||
| ├─bukkit Bukkit类型定义
|
└─type 类型定义 已迁移到 @javatypes
|
||||||
| ├─sponge Sponge类型定义
|
|
||||||
| └─nukkit Nukkit类型定义
|
|
||||||
└─plugins 这里当然是插件啦
|
|
||||||
├─bungee 只兼容BungeeCord的插件
|
|
||||||
├─bukkit 只兼容Bukkit的插件
|
|
||||||
├─sponge 只兼容Sponge的插件
|
|
||||||
└─nukkit 只兼容Nukkit的插件
|
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
{
|
{
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"useWorkspaces": true,
|
"npmClient": "pnpm",
|
||||||
"npmClient": "yarn",
|
|
||||||
"packages": [
|
|
||||||
"packages/*"
|
|
||||||
],
|
|
||||||
"command": {
|
"command": {
|
||||||
"run": {
|
"run": {
|
||||||
"stream": true
|
"stream": true
|
||||||
|
|||||||
28
package.json
28
package.json
@@ -6,20 +6,30 @@
|
|||||||
"author": "MiaoWoo <admin@yumc.pw>",
|
"author": "MiaoWoo <admin@yumc.pw>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"bs": "lerna bootstrap",
|
"bs": "pnpm install",
|
||||||
"clean": "lerna run clean",
|
"clean": "lerna run clean",
|
||||||
"watch": "lerna run watch --parallel",
|
"watch": "lerna run watch --parallel",
|
||||||
"build": "lerna run build",
|
"build": "lerna run build",
|
||||||
"ug": "yarn upgrade-interactive --latest",
|
"ug": "pnpm up -r -i",
|
||||||
"np": "./script/push.sh",
|
"np": "./script/push.sh",
|
||||||
"lsp": "npm login --registry=https://registry.npmjs.org --scope=@ccms",
|
"lsp": "npm login -scope=@ccms",
|
||||||
"lp": "lerna publish --registry https://registry.npmjs.org",
|
"lp": "lerna publish --force-publish",
|
||||||
"lpb": "lerna publish --registry https://registry.npmjs.org --canary --preid beta --pre-dist-tag beta"
|
"lpb": "lerna publish prerelease --preid beta --dist-tag beta --force-publish",
|
||||||
|
"lpc": "lerna publish --canary --preid beta --pre-dist-tag beta --force-publish",
|
||||||
|
"lpf": "lerna publish from-package --dist-tag beta --yes",
|
||||||
|
"sync": "./script/sync.sh",
|
||||||
|
"postpublish": "pnpm sync"
|
||||||
},
|
},
|
||||||
"workspaces": [
|
|
||||||
"packages/*"
|
|
||||||
],
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"lerna": "^4.0.0"
|
"@ccms/nashorn": "^0.28.0-beta.3",
|
||||||
|
"@javatypes/jdk": "^0.0.3",
|
||||||
|
"@lerna-lite/cli": "^2.6.0",
|
||||||
|
"@lerna-lite/publish": "^2.6.0",
|
||||||
|
"@lerna-lite/run": "^2.6.0",
|
||||||
|
"@types/node": "^20.8.8",
|
||||||
|
"reflect-metadata": "^0.1.13",
|
||||||
|
"rimraf": "^5.0.5",
|
||||||
|
"tslib": "^2.6.2",
|
||||||
|
"typescript": "^5.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@ccms/amqp",
|
|
||||||
"version": "0.23.0",
|
|
||||||
"description": "MiaoScript amqp package",
|
|
||||||
"keywords": [
|
|
||||||
"miaoscript",
|
|
||||||
"minecraft",
|
|
||||||
"bukkit",
|
|
||||||
"sponge"
|
|
||||||
],
|
|
||||||
"author": "MiaoWoo <admin@yumc.pw>",
|
|
||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
|
||||||
"license": "ISC",
|
|
||||||
"main": "dist/index.js",
|
|
||||||
"scripts": {
|
|
||||||
"clean": "rimraf dist",
|
|
||||||
"watch": "tsc --watch",
|
|
||||||
"build": "yarn clean && tsc",
|
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@ccms/api": "^0.23.0",
|
|
||||||
"@ccms/common": "^0.23.0",
|
|
||||||
"@ccms/container": "^0.23.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@ccms/nashorn": "^0.23.0",
|
|
||||||
"@javatypes/amqp-client": "^0.0.3",
|
|
||||||
"@javatypes/spring-amqp": "^0.0.3",
|
|
||||||
"@javatypes/spring-rabbit": "^0.0.3",
|
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import { ConnectionFactoryAdapter } from "./connection"
|
|
||||||
import { RabbitTemplateAdapter } from "./template"
|
|
||||||
import { JSClass } from "@ccms/container"
|
|
||||||
|
|
||||||
export const RabbitAdmin = Java.type('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
|
||||||
|
|
||||||
export class RabbitAdminAdapter {
|
|
||||||
@JSClass('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
|
||||||
private RabbitAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin
|
|
||||||
private _Handler: org.springframework.amqp.rabbit.core.RabbitAdmin
|
|
||||||
constructor(config: RabbitTemplateAdapter | org.springframework.amqp.rabbit.core.RabbitTemplate | ConnectionFactoryAdapter | org.springframework.amqp.rabbit.connection.ConnectionFactory) {
|
|
||||||
this._Handler = new RabbitAdmin((config instanceof RabbitTemplateAdapter || config instanceof ConnectionFactoryAdapter) ? config.getHandler() : config)
|
|
||||||
}
|
|
||||||
getHandler(): org.springframework.amqp.rabbit.core.RabbitAdmin {
|
|
||||||
return this._Handler
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
export const ConfirmCallback = Java.type('org.springframework.amqp.rabbit.core.RabbitTemplate.ConfirmCallback')
|
|
||||||
export const ReturnCallback = Java.type('org.springframework.amqp.rabbit.core.RabbitTemplate.ReturnCallback')
|
|
||||||
|
|
||||||
export abstract class ConfirmCallbackAdapter {
|
|
||||||
private _Handler: org.springframework.amqp.rabbit.core.RabbitTemplate.ConfirmCallback
|
|
||||||
constructor() {
|
|
||||||
let ConfirmCallbackImpl = Java.extend(ReturnCallback, {
|
|
||||||
confirm: (correlationData: org.springframework.amqp.rabbit.connection.CorrelationData, ack: boolean, cause: string) => this.confirm(correlationData, ack, cause)
|
|
||||||
})
|
|
||||||
this._Handler = new ConfirmCallbackImpl()
|
|
||||||
}
|
|
||||||
abstract confirm(correlationData: org.springframework.amqp.rabbit.connection.CorrelationData, ack: boolean, cause: string)
|
|
||||||
getHandler() {
|
|
||||||
return this._Handler
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export abstract class ReturnCallbackAdapter {
|
|
||||||
private _Handler: org.springframework.amqp.rabbit.core.RabbitTemplate.ReturnCallback
|
|
||||||
constructor() {
|
|
||||||
let ReturnCallbackImpl = Java.extend(ReturnCallback, {
|
|
||||||
returnedMessage: (message: org.springframework.amqp.core.Message, replyCode: number, replyText: string, exchange: string, routingKey: string) => this.returnedMessage(message, replyCode, replyText, exchange, routingKey)
|
|
||||||
})
|
|
||||||
this._Handler = new ReturnCallbackImpl()
|
|
||||||
}
|
|
||||||
abstract returnedMessage(message: org.springframework.amqp.core.Message, replyCode: number, replyText: string, exchange: string, routingKey: string)
|
|
||||||
getHandler() {
|
|
||||||
return this._Handler
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
import threadPool from '@ccms/common/dist/thread-pool'
|
|
||||||
|
|
||||||
export const ConnectionFactory = Java.type('org.springframework.amqp.rabbit.connection.ConnectionFactory')
|
|
||||||
const CachingConnectionFactory = Java.type('org.springframework.amqp.rabbit.connection.CachingConnectionFactory')
|
|
||||||
interface ConnectionConfig {
|
|
||||||
url: string,
|
|
||||||
username?: string,
|
|
||||||
password?: string,
|
|
||||||
publisherConfirms?: boolean
|
|
||||||
cacheSize?: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ConnectionFactoryAdapter {
|
|
||||||
private _Handler: org.springframework.amqp.rabbit.connection.CachingConnectionFactory
|
|
||||||
|
|
||||||
constructor(config: ConnectionConfig) {
|
|
||||||
if (!config.url) { throw new Error('Connection UrI Can\'t be undefiend!') }
|
|
||||||
config = { publisherConfirms: true, cacheSize: 50, ...config }
|
|
||||||
this._Handler = new CachingConnectionFactory(new java.net.URI(config.url))
|
|
||||||
config.username && this._Handler.setUsername(config.username)
|
|
||||||
config.password && this._Handler.setPassword(config.password)
|
|
||||||
this._Handler.setPublisherConfirms(config.publisherConfirms)
|
|
||||||
this._Handler.setExecutor(threadPool.create({
|
|
||||||
groupName: '@ccms/amqp-rabbit'
|
|
||||||
}))
|
|
||||||
this._Handler.setChannelCacheSize(config.cacheSize)
|
|
||||||
}
|
|
||||||
getHandler() {
|
|
||||||
return this._Handler
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
import { ConnectionFactoryAdapter, ConnectionFactory } from "./connection"
|
|
||||||
import { ChannelAwareMessageListenerAdapter, ChannelAwareMessageListener } from "./listener"
|
|
||||||
|
|
||||||
export const SimpleMessageListenerContainer = org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
|
|
||||||
export const AcknowledgeMode = org.springframework.amqp.core.AcknowledgeMode
|
|
||||||
interface ContainerConfig {
|
|
||||||
connectionFactory: ConnectionFactoryAdapter | typeof ConnectionFactory
|
|
||||||
queueNames: string[]
|
|
||||||
messageListener: ChannelAwareMessageListenerAdapter | typeof ChannelAwareMessageListener
|
|
||||||
maxConcurrentConsumers?: number
|
|
||||||
concurrentConsumers?: number
|
|
||||||
acknowledgeMode?: org.springframework.amqp.core.AcknowledgeMode
|
|
||||||
}
|
|
||||||
|
|
||||||
export class MessageListenerContainerAdapter {
|
|
||||||
private _Handler: org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer
|
|
||||||
constructor(config: ContainerConfig) {
|
|
||||||
config = { concurrentConsumers: 5, maxConcurrentConsumers: 10, acknowledgeMode: AcknowledgeMode.AUTO, ...config }
|
|
||||||
this._Handler = new SimpleMessageListenerContainer(config.connectionFactory instanceof ConnectionFactoryAdapter ? config.connectionFactory.getHandler() : config.connectionFactory)
|
|
||||||
//@ts-ignore
|
|
||||||
this._Handler.setQueueNames(config.queueNames)
|
|
||||||
this._Handler.setMaxConcurrentConsumers(config.maxConcurrentConsumers)
|
|
||||||
this._Handler.setConcurrentConsumers(config.concurrentConsumers)
|
|
||||||
this._Handler.setAcknowledgeMode(config.acknowledgeMode)
|
|
||||||
this._Handler.setMessageListener(config.messageListener instanceof ChannelAwareMessageListenerAdapter ? config.messageListener.getHandler() : config.messageListener)
|
|
||||||
}
|
|
||||||
getHandler() {
|
|
||||||
return this._Handler
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
const JavaString = Java.type('java.lang.String')
|
|
||||||
const MessageProperties = org.springframework.amqp.core.MessageProperties
|
|
||||||
const Message = org.springframework.amqp.core.Message
|
|
||||||
|
|
||||||
export const MessageConverter = Java.type('org.springframework.amqp.support.converter.MessageConverter')
|
|
||||||
|
|
||||||
export class MessageConverterAdapter {
|
|
||||||
private _Handler: org.springframework.amqp.support.converter.MessageConverter
|
|
||||||
constructor() {
|
|
||||||
var MessageConverterImpl = Java.extend(MessageConverter, {
|
|
||||||
toMessage: (object: any, messageProperties: org.springframework.amqp.core.MessageProperties) => this.toMessage(object, messageProperties),
|
|
||||||
fromMessage: (message: org.springframework.amqp.core.Message) => this.fromMessage(message)
|
|
||||||
})
|
|
||||||
this._Handler = new MessageConverterImpl()
|
|
||||||
}
|
|
||||||
toMessage(object: any, messageProperties: org.springframework.amqp.core.MessageProperties) {
|
|
||||||
if (typeof object == "string") {
|
|
||||||
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN)
|
|
||||||
return new Message(new JavaString(object).getBytes(), messageProperties)
|
|
||||||
} else {
|
|
||||||
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON)
|
|
||||||
return new Message(new JavaString(JSON.stringify(object)).getBytes(), messageProperties)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fromMessage(message: org.springframework.amqp.core.Message) {
|
|
||||||
if (message.getMessageProperties().getContentType() == MessageProperties.CONTENT_TYPE_TEXT_PLAIN) {
|
|
||||||
return new JavaString(message.getBody(), message.getMessageProperties().getContentEncoding())
|
|
||||||
}
|
|
||||||
if (message.getMessageProperties().getContentType() == MessageProperties.CONTENT_TYPE_JSON) {
|
|
||||||
return JSON.parse(new JavaString(message.getBody(), message.getMessageProperties().getContentEncoding()))
|
|
||||||
}
|
|
||||||
return message
|
|
||||||
}
|
|
||||||
getHandler() {
|
|
||||||
return this._Handler
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
export * from './admin'
|
|
||||||
export * from './callback'
|
|
||||||
export * from './connection'
|
|
||||||
export * from './container'
|
|
||||||
export * from './converter'
|
|
||||||
export * from './listener'
|
|
||||||
export * from './template'
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
const JavaString = Java.type('java.lang.String')
|
|
||||||
export const MessageProperties = org.springframework.amqp.core.MessageProperties
|
|
||||||
export const ChannelAwareMessageListener = Java.type('org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener')
|
|
||||||
export const AmqpRejectAndDontRequeueException = org.springframework.amqp.AmqpRejectAndDontRequeueException
|
|
||||||
export const Channel: com.rabbitmq.client.Channel = Java.type('com.rabbitmq.client.Channel')
|
|
||||||
export const Message = org.springframework.amqp.core.Message
|
|
||||||
export type MessageHandler<T> = (content: T, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) => any
|
|
||||||
export abstract class ChannelAwareMessageListenerAdapter<T = any> {
|
|
||||||
private _Handler: org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener
|
|
||||||
constructor(manual: boolean = false) {
|
|
||||||
let ChannelAwareMessageListenerImpl = Java.extend(ChannelAwareMessageListener, {
|
|
||||||
onMessage: (message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) => {
|
|
||||||
let content = new JavaString(message.getBody(), message.getMessageProperties().getContentEncoding() || "UTF-8")
|
|
||||||
try {
|
|
||||||
if (message.getMessageProperties().getContentType() == MessageProperties.CONTENT_TYPE_JSON) {
|
|
||||||
content = JSON.parse(content)
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
|
||||||
if (manual) {
|
|
||||||
channel.basicReject(message.getMessageProperties().getDeliveryTag(), true)
|
|
||||||
} else {
|
|
||||||
throw new AmqpRejectAndDontRequeueException(`${error}`, error)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
manual ? this.manualOnMessage(content, message, channel) : this.onMessage(content, message, channel)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
this._Handler = new ChannelAwareMessageListenerImpl()
|
|
||||||
}
|
|
||||||
abstract onMessage(content: T, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel): any
|
|
||||||
onError(error: Error, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel): any { }
|
|
||||||
getHandler() {
|
|
||||||
return this._Handler
|
|
||||||
}
|
|
||||||
private manualOnMessage(content: T, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) {
|
|
||||||
let deliveryTag = message.getMessageProperties().getDeliveryTag()
|
|
||||||
try {
|
|
||||||
if (this.onMessage(content, message, channel)) {
|
|
||||||
channel.basicAck(deliveryTag, false)
|
|
||||||
} else if (message.getMessageProperties().getRedelivered()) {
|
|
||||||
channel.basicReject(deliveryTag, true)
|
|
||||||
} else {
|
|
||||||
channel.basicNack(deliveryTag, false, true)
|
|
||||||
}
|
|
||||||
} catch (error: any) {
|
|
||||||
channel.basicReject(deliveryTag, this.onError(error, message, channel))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import { MessageConverterAdapter } from "./converter"
|
|
||||||
import { ConnectionFactoryAdapter } from "./connection"
|
|
||||||
import { ConfirmCallbackAdapter, ReturnCallbackAdapter } from "./callback"
|
|
||||||
|
|
||||||
export const RabbitTemplate = Java.type('org.springframework.amqp.rabbit.core.RabbitTemplate')
|
|
||||||
|
|
||||||
interface TemplateConfig {
|
|
||||||
connectionFactory: ConnectionFactoryAdapter | org.springframework.amqp.rabbit.connection.ConnectionFactory
|
|
||||||
confirmCallback?: ConfirmCallbackAdapter
|
|
||||||
returnCallback?: ReturnCallbackAdapter
|
|
||||||
messageConverter?: MessageConverterAdapter
|
|
||||||
}
|
|
||||||
export class RabbitTemplateAdapter {
|
|
||||||
private _Handler: org.springframework.amqp.rabbit.core.RabbitTemplate
|
|
||||||
constructor(config: TemplateConfig) {
|
|
||||||
config = { messageConverter: new MessageConverterAdapter(), ...config }
|
|
||||||
console.debug(JSON.stringify(config))
|
|
||||||
this._Handler = new RabbitTemplate(config.connectionFactory instanceof ConnectionFactoryAdapter ? config.connectionFactory.getHandler() : config.connectionFactory)
|
|
||||||
config.returnCallback && this._Handler.setReturnCallback(config.returnCallback.getHandler())
|
|
||||||
config.confirmCallback && this._Handler.setConfirmCallback(config.confirmCallback.getHandler())
|
|
||||||
config.messageConverter && this._Handler.setMessageConverter(config.messageConverter.getHandler())
|
|
||||||
}
|
|
||||||
|
|
||||||
getHandler() {
|
|
||||||
return this._Handler
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
import { JSClass } from "@ccms/container"
|
|
||||||
import { RabbitAdminAdapter, MessageListenerContainerAdapter, AcknowledgeMode, MessageHandler, ChannelAwareMessageListenerAdapter } from "./adapter"
|
|
||||||
|
|
||||||
export class AmqpAdmin {
|
|
||||||
@JSClass('org.springframework.amqp.core.TopicExchange')
|
|
||||||
private TopicExchange: typeof org.springframework.amqp.core.TopicExchange
|
|
||||||
@JSClass('org.springframework.amqp.core.Queue')
|
|
||||||
private Queue: typeof org.springframework.amqp.core.Queue
|
|
||||||
@JSClass('org.springframework.amqp.core.Binding')
|
|
||||||
private Binding: typeof org.springframework.amqp.core.Binding
|
|
||||||
@JSClass('org.springframework.amqp.rabbit.core.RabbitAdmin')
|
|
||||||
private RabbitAdmin: typeof org.springframework.amqp.rabbit.core.RabbitAdmin
|
|
||||||
@JSClass('org.springframework.amqp.core.Binding.DestinationType')
|
|
||||||
private DestinationType: org.springframework.amqp.core.Binding.DestinationType
|
|
||||||
|
|
||||||
private amqpAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin
|
|
||||||
|
|
||||||
constructor(amqpAdmin: org.springframework.amqp.rabbit.core.RabbitAdmin | any) {
|
|
||||||
if (amqpAdmin instanceof this.RabbitAdmin) {
|
|
||||||
this.amqpAdmin = amqpAdmin
|
|
||||||
} else if (amqpAdmin instanceof RabbitAdminAdapter) {
|
|
||||||
this.amqpAdmin = amqpAdmin.getHandler()
|
|
||||||
} else {
|
|
||||||
this.amqpAdmin = new RabbitAdminAdapter(amqpAdmin).getHandler()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
getHandler() {
|
|
||||||
return this.amqpAdmin
|
|
||||||
}
|
|
||||||
|
|
||||||
getQueueProperties(name: string) {
|
|
||||||
return this.amqpAdmin.getQueueProperties(name)
|
|
||||||
}
|
|
||||||
|
|
||||||
declareExchange(name: string) {
|
|
||||||
let exchange = new this.TopicExchange(name, true, false)
|
|
||||||
this.amqpAdmin.declareExchange(exchange)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
declareQueue(name: string) {
|
|
||||||
let queue = new this.Queue(name, true)
|
|
||||||
this.amqpAdmin.declareQueue(queue)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
declareBinding(queue: string, exchange: string, routerKey: string, argument: any = null) {
|
|
||||||
let binding = new this.Binding(queue, org.springframework.amqp.core.Binding.DestinationType.QUEUE, exchange, routerKey, argument)
|
|
||||||
this.amqpAdmin.declareBinding(binding)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
declareQueueAndBindExchange(queue: string, exchange: string, routerKey: string) {
|
|
||||||
return this.declareQueue(queue).declareExchange(exchange).declareBinding(queue, exchange, routerKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
createContainer<T>(queue: string, listener: MessageHandler<T>, acknowledgeMode = AcknowledgeMode.AUTO) {
|
|
||||||
let connection = this.amqpAdmin.getRabbitTemplate().getConnectionFactory()
|
|
||||||
return new MessageListenerContainerAdapter({
|
|
||||||
connectionFactory: connection,
|
|
||||||
queueNames: [queue],
|
|
||||||
messageListener: new SimpleMessageHandler(listener),
|
|
||||||
acknowledgeMode: acknowledgeMode
|
|
||||||
}).getHandler()
|
|
||||||
}
|
|
||||||
|
|
||||||
send()
|
|
||||||
send() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
getTemplate() {
|
|
||||||
return this.amqpAdmin.getRabbitTemplate()
|
|
||||||
}
|
|
||||||
|
|
||||||
close() {
|
|
||||||
this.getTemplate().stop()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SimpleMessageHandler extends ChannelAwareMessageListenerAdapter {
|
|
||||||
constructor(private handler: MessageHandler<any>) {
|
|
||||||
super()
|
|
||||||
}
|
|
||||||
onMessage(content: any, message: org.springframework.amqp.core.Message, channel: com.rabbitmq.client.Channel) {
|
|
||||||
return this.handler(content, message, channel)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
export const METADATA_KEY = {
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
/// <reference types="@ccms/nashorn" />
|
|
||||||
/// <reference types="@javatypes/jdk" />
|
|
||||||
/// <reference types="@javatypes/spring-amqp" />
|
|
||||||
/// <reference types="@javatypes/spring-rabbit" />
|
|
||||||
/// <reference types="@javatypes/amqp-client" />
|
|
||||||
|
|
||||||
import { amqp } from '@ccms/api'
|
|
||||||
import { getContainer, reduceMetadata } from '@ccms/container'
|
|
||||||
|
|
||||||
function init() {
|
|
||||||
const beanFactory = base.getInstance().getAutowireCapableBeanFactory()
|
|
||||||
getContainer().bind(amqp.rabbit.Template).toDynamicValue((ctx) => {
|
|
||||||
let metadata = reduceMetadata(ctx)
|
|
||||||
if (!metadata.named) {
|
|
||||||
return beanFactory.getBean('rabbitTemplate')
|
|
||||||
} else {
|
|
||||||
return beanFactory.getBean(`${metadata.named}-rabbitTemplate`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
getContainer().bind(amqp.rabbit.Admin).toDynamicValue((ctx) => {
|
|
||||||
let metadata = reduceMetadata(ctx)
|
|
||||||
if (!metadata.named) {
|
|
||||||
return beanFactory.getBean('rabbitAdmin')
|
|
||||||
} else {
|
|
||||||
return beanFactory.getBean(`${metadata.named}-rabbitAdmin`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
init()
|
|
||||||
|
|
||||||
export * from './admin'
|
|
||||||
export * from './adapter'
|
|
||||||
export * from './manager'
|
|
||||||
export * from './constants'
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
export class AmqpListener {
|
|
||||||
constructor() {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
import { amqp } from "@ccms/api"
|
|
||||||
import { provideSingleton } from "@ccms/container"
|
|
||||||
|
|
||||||
import { ConnectionFactoryAdapter, RabbitTemplateAdapter, RabbitAdminAdapter } from "./adapter"
|
|
||||||
import { AmqpAdmin } from "./admin"
|
|
||||||
|
|
||||||
@provideSingleton(amqp.Manager)
|
|
||||||
export class AmqpManager {
|
|
||||||
createConnection(url: string, username: string, password: string) {
|
|
||||||
return new ConnectionFactoryAdapter({ url, username, password })
|
|
||||||
}
|
|
||||||
createTemplate(adapter: ConnectionFactoryAdapter) {
|
|
||||||
return new RabbitTemplateAdapter({ connectionFactory: adapter })
|
|
||||||
}
|
|
||||||
createAdmin(adapter: RabbitTemplateAdapter | ConnectionFactoryAdapter) {
|
|
||||||
return new AmqpAdmin(new RabbitAdminAdapter(adapter))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/api",
|
"name": "@ccms/api",
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"description": "MiaoScript api package",
|
"description": "MiaoScript api package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,23 +12,26 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist/**/*.js",
|
||||||
|
"dist/**/*.ts",
|
||||||
|
"dist/**/*.map"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "yarn clean && tsc",
|
"build": "pnpm clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/common": "^0.23.0",
|
"@ccms/common": "^0.28.0-beta.8",
|
||||||
"@ccms/container": "^0.23.0",
|
"@ccms/container": "^0.28.0-beta.8",
|
||||||
"@ccms/polyfill": "^0.23.0",
|
"@ccms/i18n": "^0.28.0-beta.8",
|
||||||
|
"@ccms/polyfill": "^0.28.0-beta.8",
|
||||||
"base64-js": "^1.5.1",
|
"base64-js": "^1.5.1",
|
||||||
"source-map-builder": "^0.0.7"
|
"source-map-builder": "^0.0.7"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/base64-js": "^1.3.0",
|
"@types/base64-js": "^1.3.0"
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
export namespace amqp {
|
|
||||||
export const Manager = Symbol('AmqpManager')
|
|
||||||
export namespace rabbit {
|
|
||||||
export const Admin = Symbol('RabbitAdmin')
|
|
||||||
export const Template = Symbol('RabbitTemplate')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,6 +5,12 @@ import { plugin } from './plugin'
|
|||||||
export namespace command {
|
export namespace command {
|
||||||
@injectable()
|
@injectable()
|
||||||
export abstract class Command {
|
export abstract class Command {
|
||||||
|
/**
|
||||||
|
* first time script engine need optimize jit code
|
||||||
|
* so ignore first slow exec notify
|
||||||
|
*/
|
||||||
|
private cacheSlowKeys = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册插件命令
|
* 注册插件命令
|
||||||
* @param plugin 插件
|
* @param plugin 插件
|
||||||
@@ -46,36 +52,13 @@ export namespace command {
|
|||||||
try {
|
try {
|
||||||
let time = Date.now()
|
let time = Date.now()
|
||||||
let result = executor(sender, command, Java.from(args))
|
let result = executor(sender, command, Java.from(args))
|
||||||
let cost = Date.now() - time
|
this.checkSlow(Date.now() - time,
|
||||||
if (cost > global.ScriptSlowExecuteTime) {
|
"ms.api.command.execute.slow",
|
||||||
console.i18n("ms.api.command.execute.slow", {
|
plugin, command, sender, args)
|
||||||
player: sender.name,
|
|
||||||
plugin: plugin.description.name,
|
|
||||||
command,
|
|
||||||
args: Java.from(args).join(' '),
|
|
||||||
cost
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return result
|
return result
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
console.i18n("ms.api.command.execute.error", {
|
this.printError(ex, "ms.api.command.execute.error",
|
||||||
player: sender.name,
|
plugin, command, sender, args)
|
||||||
plugin: plugin.description.name,
|
|
||||||
command,
|
|
||||||
args: Java.from(args).join(' '),
|
|
||||||
ex
|
|
||||||
})
|
|
||||||
console.ex(ex)
|
|
||||||
if (sender.name != 'CONSOLE') {
|
|
||||||
console.sender(sender, [i18n.translate("ms.api.command.execute.error", {
|
|
||||||
player: sender.name,
|
|
||||||
plugin: plugin.description.name,
|
|
||||||
command,
|
|
||||||
args: Java.from(args).join(' '),
|
|
||||||
ex
|
|
||||||
}),
|
|
||||||
...console.stack(ex)])
|
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,42 +70,18 @@ export namespace command {
|
|||||||
var token = args[args.length - 1]
|
var token = args[args.length - 1]
|
||||||
var complete = tabCompleter(sender, command, Java.from(args)) || []
|
var complete = tabCompleter(sender, command, Java.from(args)) || []
|
||||||
let result = this.copyPartialMatches(complete, token)
|
let result = this.copyPartialMatches(complete, token)
|
||||||
let cost = Date.now() - time
|
this.checkSlow(Date.now() - time,
|
||||||
if (cost > global.ScriptSlowExecuteTime) {
|
"ms.api.command.tab.completer.slow",
|
||||||
console.i18n("ms.api.command.tab.completer.slow", {
|
plugin, command, sender, args)
|
||||||
player: sender.name,
|
|
||||||
plugin: plugin.description.name,
|
|
||||||
command,
|
|
||||||
args: Java.from(args).join(' '),
|
|
||||||
cost
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return result
|
return result
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
console.i18n("ms.api.command.tab.completer.error", {
|
this.printError(ex, "ms.api.command.tab.completer.error",
|
||||||
player: sender.name,
|
plugin, command, sender, args)
|
||||||
plugin: plugin.description.name,
|
|
||||||
command,
|
|
||||||
args: Java.from(args).join(' '),
|
|
||||||
ex
|
|
||||||
})
|
|
||||||
console.ex(ex)
|
|
||||||
if (sender.name != 'CONSOLE') {
|
|
||||||
console.sender(sender, [
|
|
||||||
i18n.translate("ms.api.command.tab.completer.error", {
|
|
||||||
player: sender.name,
|
|
||||||
plugin: plugin.description.name,
|
|
||||||
command,
|
|
||||||
args: Java.from(args).join(' '),
|
|
||||||
ex
|
|
||||||
}),
|
|
||||||
...console.stack(ex)
|
|
||||||
])
|
|
||||||
}
|
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected copyPartialMatches(complete: string[], token: string, array: string[] = []): string[] {
|
protected copyPartialMatches(complete: string[], token: string, array: string[] = []): string[] {
|
||||||
if (!token) { return complete }
|
if (!token) { return complete }
|
||||||
complete.forEach(function (e) {
|
complete.forEach(function (e) {
|
||||||
@@ -132,5 +91,35 @@ export namespace command {
|
|||||||
})
|
})
|
||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private checkSlow(cost: number, key: string, plugin: plugin.Plugin, command: string, sender: any, args: any[]) {
|
||||||
|
if (cost > global.ScriptSlowExecuteTime) {
|
||||||
|
let completerKey = `${plugin.description.name}-${key}-${command}-${sender.name}`
|
||||||
|
if (!this.cacheSlowKeys[completerKey]) {
|
||||||
|
return this.cacheSlowKeys[completerKey] = cost
|
||||||
|
}
|
||||||
|
console.i18n(key, {
|
||||||
|
player: sender.name,
|
||||||
|
plugin: plugin.description.name,
|
||||||
|
command,
|
||||||
|
args: Java.from(args).join(' '),
|
||||||
|
cost
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private printError(error: Error, key: string, plugin: plugin.Plugin, command: string, sender: any, args: any[]) {
|
||||||
|
let message = i18n.translate(key, {
|
||||||
|
player: sender.name,
|
||||||
|
plugin: plugin.description.name,
|
||||||
|
command,
|
||||||
|
args: Java.from(args).join(' '),
|
||||||
|
error
|
||||||
|
})
|
||||||
|
console.console(message)
|
||||||
|
console.ex(error)
|
||||||
|
if (sender.name != 'CONSOLE') {
|
||||||
|
console.sender(sender, [message, ...console.stack(error)])
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,13 +44,13 @@ export namespace jsconsole {
|
|||||||
let file = Paths.get(Paths.get(fileName, '..', sourceMappingURL).toFile().getCanonicalPath()).toFile()
|
let file = Paths.get(Paths.get(fileName, '..', sourceMappingURL).toFile().getCanonicalPath()).toFile()
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
sourceContent = base.read(file)
|
sourceContent = base.read(file)
|
||||||
|
sourceFileMaps[fileName] = file.getCanonicalPath()
|
||||||
} else if (global.debug) {
|
} else if (global.debug) {
|
||||||
console.debug('readSourceMap can\'t found', fileName, 'source map file', sourceMappingURL)
|
console.debug('readSourceMap can\'t found', fileName, 'source map file', sourceMappingURL)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sourceContent) {
|
if (sourceContent) {
|
||||||
sourceMaps[fileName] = new SourceMapBuilder(JSON.parse(sourceContent))
|
sourceMaps[fileName] = new SourceMapBuilder(JSON.parse(sourceContent))
|
||||||
sourceFileMaps[fileName] = Paths.get(fileName, '..', sourceMaps[fileName].sources[0]).toFile().getCanonicalPath()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,9 +88,9 @@ export namespace jsconsole {
|
|||||||
let { fileName, lineNumber } = readSourceMap(trace.fileName, trace.lineNumber)
|
let { fileName, lineNumber } = readSourceMap(trace.fileName, trace.lineNumber)
|
||||||
if (fileName.startsWith(root)) { fileName = fileName.split(root)[1] }
|
if (fileName.startsWith(root)) { fileName = fileName.split(root)[1] }
|
||||||
if (color) {
|
if (color) {
|
||||||
cache.push(` §e->§c ${fileName}:${lineNumber} => §4${trace.methodName}`)
|
cache.push(` §e->§c ${fileName}:${lineNumber}(${trace.lineNumber}) => §4${trace.methodName}`)
|
||||||
} else {
|
} else {
|
||||||
cache.push(` -> ${fileName}:${lineNumber} => ${trace.methodName}`)
|
cache.push(` -> ${fileName}:${lineNumber}(${trace.lineNumber}) => ${trace.methodName}`)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let className = trace.className
|
let className = trace.className
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ export namespace database {
|
|||||||
* 链接属性
|
* 链接属性
|
||||||
*/
|
*/
|
||||||
properties?: { [key: string]: any }
|
properties?: { [key: string]: any }
|
||||||
|
/**
|
||||||
|
* 调试模式
|
||||||
|
*/
|
||||||
|
debug?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
|
|||||||
@@ -25,7 +25,8 @@ export namespace event {
|
|||||||
public EventPriority = EventPriority;
|
public EventPriority = EventPriority;
|
||||||
|
|
||||||
private mapEvent = [];
|
private mapEvent = [];
|
||||||
private listenerMap = [];
|
private pluginEventMap = [];
|
||||||
|
private cacheSlowEventKey = {};
|
||||||
|
|
||||||
protected baseEventDir = '';
|
protected baseEventDir = '';
|
||||||
|
|
||||||
@@ -92,18 +93,24 @@ export namespace event {
|
|||||||
return eventCls
|
return eventCls
|
||||||
}
|
}
|
||||||
|
|
||||||
execute(name, exec, eventCls) {
|
/**
|
||||||
|
* 创建命令执行器
|
||||||
|
* @param name 插件名称
|
||||||
|
* @param exec 执行方法
|
||||||
|
* @param eventCls 事件类
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
createExecute(name, exec, eventCls) {
|
||||||
return (...args: any[]) => {
|
return (...args: any[]) => {
|
||||||
try {
|
|
||||||
let event = args[args.length - 1]
|
let event = args[args.length - 1]
|
||||||
if (eventCls.isAssignableFrom(event.getClass())) {
|
try {
|
||||||
let time = Date.now()
|
if (!eventCls.isAssignableFrom(event.getClass())) { return }
|
||||||
exec(event)
|
let time = Date.now(); exec(event); let cost = Date.now() - time
|
||||||
let cost = Date.now() - time
|
if (cost > global.ScriptSlowExecuteTime && !event.async) {
|
||||||
if (cost > global.ScriptSlowExecuteTime) {
|
let eventKey = `${name}-${this.class2Name(eventCls)}`
|
||||||
|
if (!this.cacheSlowEventKey[eventKey]) { return this.cacheSlowEventKey[eventKey] = cost }
|
||||||
console.i18n("ms.api.event.execute.slow", { name, event: this.class2Name(eventCls), cost })
|
console.i18n("ms.api.event.execute.slow", { name, event: this.class2Name(eventCls), cost })
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
console.i18n("ms.api.event.execute.error", { name, event: this.class2Name(eventCls), ex })
|
console.i18n("ms.api.event.execute.error", { name, event: this.class2Name(eventCls), ex })
|
||||||
console.ex(ex)
|
console.ex(ex)
|
||||||
@@ -113,17 +120,17 @@ export namespace event {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加事件监听
|
* 添加事件监听
|
||||||
* @param plugin {any}
|
* @param plugin {any} 插件
|
||||||
* @param event {string}
|
* @param event {string} 事件名称
|
||||||
* @param exec {function}
|
* @param exec {function} 事件执行器
|
||||||
* @param priority {string} [LOWEST,LOW,NORMAL,HIGH,HIGHEST,MONITOR]
|
* @param priority {string} [LOWEST,LOW,NORMAL,HIGH,HIGHEST,MONITOR] 优先级
|
||||||
* @param ignoreCancel
|
* @param ignoreCancel 是否忽略已取消事件
|
||||||
*/
|
*/
|
||||||
listen(plugin: any, event: string, exec: (event: any) => void, priority: EventPriority = EventPriority.NORMAL, ignoreCancel = false) {
|
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"))
|
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 name = plugin.description.name
|
||||||
var eventCls = this.name2Class(name, event)
|
var eventCls = this.name2Class(name, event)
|
||||||
if (!eventCls) { return }
|
if (!eventCls) { return () => { console.warn('event ' + event + ' not found ignore off listener.') } }
|
||||||
if (typeof priority === 'boolean') {
|
if (typeof priority === 'boolean') {
|
||||||
ignoreCancel = priority
|
ignoreCancel = priority
|
||||||
priority = EventPriority.NORMAL
|
priority = EventPriority.NORMAL
|
||||||
@@ -133,16 +140,15 @@ export namespace event {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
let executor = exec.name || exec.executor || '[anonymous]'
|
let executor = exec.name || exec.executor || '[anonymous]'
|
||||||
// noinspection JSUnusedGlobalSymbols
|
// noinspection JSUnusedGlobalSymbols
|
||||||
var listener = this.register(
|
let listener = this.register(
|
||||||
eventCls,
|
eventCls,
|
||||||
this.execute(name, exec, eventCls),
|
this.createExecute(name, exec, eventCls),
|
||||||
priority,
|
priority,
|
||||||
ignoreCancel
|
ignoreCancel
|
||||||
)
|
)
|
||||||
var listenerMap = this.listenerMap
|
|
||||||
// add to cache Be used for close plugin to close event
|
// add to cache Be used for close plugin to close event
|
||||||
if (!listenerMap[name]) listenerMap[name] = []
|
if (!this.pluginEventMap[name]) this.pluginEventMap[name] = []
|
||||||
var off = () => {
|
let off = () => {
|
||||||
if (off['offed']) return
|
if (off['offed']) return
|
||||||
off['offed'] = true
|
off['offed'] = true
|
||||||
this.unregister(eventCls, listener)
|
this.unregister(eventCls, listener)
|
||||||
@@ -152,7 +158,7 @@ export namespace event {
|
|||||||
exec: executor
|
exec: executor
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
listenerMap[name].push(off)
|
this.pluginEventMap[name].push(off)
|
||||||
// noinspection JSUnresolvedVariable
|
// noinspection JSUnresolvedVariable
|
||||||
console.debug(i18n.translate("ms.api.event.register", {
|
console.debug(i18n.translate("ms.api.event.register", {
|
||||||
name,
|
name,
|
||||||
@@ -169,10 +175,10 @@ export namespace event {
|
|||||||
* @param plugin 插件
|
* @param plugin 插件
|
||||||
*/
|
*/
|
||||||
disable(plugin: any) {
|
disable(plugin: any) {
|
||||||
var eventCache = this.listenerMap[plugin.description.name]
|
var eventCache = this.pluginEventMap[plugin.description.name]
|
||||||
if (eventCache) {
|
if (eventCache) {
|
||||||
eventCache.forEach(off => off())
|
eventCache.forEach((off: () => any) => off())
|
||||||
delete this.listenerMap[plugin.description.name]
|
delete this.pluginEventMap[plugin.description.name]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import "@ccms/nashorn"
|
import "@ccms/nashorn"
|
||||||
|
|
||||||
export * from './web'
|
|
||||||
export * from './amqp'
|
|
||||||
export * from './chat'
|
export * from './chat'
|
||||||
export * from './task'
|
export * from './task'
|
||||||
export * from './item'
|
export * from './item'
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ export namespace item {
|
|||||||
export abstract class Item {
|
export abstract class Item {
|
||||||
abstract builder(): ItemBuilder
|
abstract builder(): ItemBuilder
|
||||||
abstract toJson(item: any): string
|
abstract toJson(item: any): string
|
||||||
abstract fromJSON(json: string): any
|
abstract fromJson(json: string): any
|
||||||
}
|
}
|
||||||
export interface ItemBuilder {
|
export interface ItemBuilder {
|
||||||
from(item: any): ItemBuilder
|
from(item: any): ItemBuilder
|
||||||
|
|||||||
@@ -6,6 +6,12 @@ const UUID = Java.type('java.util.UUID')
|
|||||||
const Math = Java.type('java.lang.Math')
|
const Math = Java.type('java.lang.Math')
|
||||||
|
|
||||||
export namespace particle {
|
export namespace particle {
|
||||||
|
@injectable()
|
||||||
|
export abstract class ParticleSpawner {
|
||||||
|
abstract spawn(location: any, particle: Particle)
|
||||||
|
abstract spawnToPlayer(player: any, location: any, particle: Particle)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 表示一个特效对象
|
* 表示一个特效对象
|
||||||
*
|
*
|
||||||
@@ -23,6 +29,11 @@ export namespace particle {
|
|||||||
private extra: number = 0;
|
private extra: number = 0;
|
||||||
private data: Object = null;
|
private data: Object = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only Show To Player
|
||||||
|
*/
|
||||||
|
private player: any
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.uuid = UUID.randomUUID().toString()
|
this.uuid = UUID.randomUUID().toString()
|
||||||
}
|
}
|
||||||
@@ -105,6 +116,15 @@ export namespace particle {
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getPlayer() {
|
||||||
|
return this.player
|
||||||
|
}
|
||||||
|
|
||||||
|
setPlayer(player) {
|
||||||
|
this.player = player
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过给定一个坐标就可以使用已经指定的参数来播放粒子
|
* 通过给定一个坐标就可以使用已经指定的参数来播放粒子
|
||||||
*
|
*
|
||||||
@@ -112,9 +132,14 @@ export namespace particle {
|
|||||||
*/
|
*/
|
||||||
spawn(location: any) {
|
spawn(location: any) {
|
||||||
if (!this.spawner) throw new Error(`particle ${this.uuid} not set spawner can't spawn!`)
|
if (!this.spawner) throw new Error(`particle ${this.uuid} not set spawner can't spawn!`)
|
||||||
|
if (this.player) {
|
||||||
|
this.spawner.spawnToPlayer(this.player, location, this)
|
||||||
|
} else {
|
||||||
this.spawner.spawn(location, this)
|
this.spawner.spawn(location, this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 表示一条线
|
* 表示一条线
|
||||||
*
|
*
|
||||||
@@ -158,8 +183,7 @@ export namespace particle {
|
|||||||
|
|
||||||
show() {
|
show() {
|
||||||
for (let i = 0; i < this.length; i += this.step) {
|
for (let i = 0; i < this.length; i += this.step) {
|
||||||
let vectorTemp = this.vector.clone().multiply(i)
|
this.spawn(this.start.clone().add(this.vector.clone().multiply(i)))
|
||||||
this.spawn(this.start.clone().add(vectorTemp))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -234,15 +258,6 @@ export namespace particle {
|
|||||||
this.length = this.vector.length()
|
this.length = this.vector.length()
|
||||||
this.vector.normalize()
|
this.vector.normalize()
|
||||||
}
|
}
|
||||||
|
|
||||||
public static buildLine(locA: any, locB: any, step: number, particle: any) {
|
|
||||||
let vectorAB = locB.clone().subtract(locA).toVector()
|
|
||||||
let vectorLength = vectorAB.length()
|
|
||||||
vectorAB.normalize()
|
|
||||||
for (let i = 0; i < vectorLength; i += step) {
|
|
||||||
ParticleManager.globalSpawner.spawn(locA.clone().add(vectorAB.clone().multiply(i)), particle)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 表示一个弧
|
* 表示一个弧
|
||||||
@@ -331,9 +346,10 @@ export namespace particle {
|
|||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export abstract class ParticleManager {
|
export abstract class ParticleManager {
|
||||||
public static globalSpawner: ParticleSpawner = undefined
|
|
||||||
@Autowired()
|
@Autowired()
|
||||||
private taskManager: task.TaskManager
|
private taskManager: task.TaskManager
|
||||||
|
@Autowired()
|
||||||
|
private particleSpawner: particle.ParticleSpawner
|
||||||
|
|
||||||
protected taskId: java.util.concurrent.atomic.AtomicInteger
|
protected taskId: java.util.concurrent.atomic.AtomicInteger
|
||||||
protected cacheTasks = new Map<string, ParticleTask>()
|
protected cacheTasks = new Map<string, ParticleTask>()
|
||||||
@@ -354,6 +370,10 @@ export namespace particle {
|
|||||||
return this.taskManager
|
return this.taskManager
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getParticleSpawner() {
|
||||||
|
return this.particleSpawner
|
||||||
|
}
|
||||||
|
|
||||||
public create(particle: Particle, plugin?: plugin.Plugin) {
|
public create(particle: Particle, plugin?: plugin.Plugin) {
|
||||||
let uuid = particle.getUUID()
|
let uuid = particle.getUUID()
|
||||||
if (this.cacheTasks.has(uuid)) {
|
if (this.cacheTasks.has(uuid)) {
|
||||||
@@ -389,14 +409,12 @@ export namespace particle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected create0(owner: plugin.Plugin, particle: Particle): ParticleTask {
|
protected create0(owner: plugin.Plugin, particle: Particle): ParticleTask {
|
||||||
particle.setSpawner(this.getGlobalSpawner())
|
particle.setSpawner(this.getParticleSpawner())
|
||||||
return new ParticleTask(owner, particle, this)
|
return new ParticleTask(owner, particle, this)
|
||||||
}
|
}
|
||||||
protected abstract getGlobalSpawner(): ParticleSpawner
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ParticleTask {
|
export class ParticleTask {
|
||||||
|
|
||||||
private particle: Particle
|
private particle: Particle
|
||||||
private isAsync: boolean = false
|
private isAsync: boolean = false
|
||||||
private interval: number = 0
|
private interval: number = 0
|
||||||
@@ -486,9 +504,4 @@ export namespace particle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class ParticleSpawner {
|
|
||||||
abstract spawnParticle(location: any, particle: any, count: number)
|
|
||||||
abstract spawn(location: any, particle: Particle)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,7 +155,11 @@ export namespace plugin {
|
|||||||
*/
|
*/
|
||||||
cname?: string
|
cname?: string
|
||||||
/**
|
/**
|
||||||
* 插件等级 付费插件自动注入
|
* 付费插件ID
|
||||||
|
*/
|
||||||
|
pid?: number
|
||||||
|
/**
|
||||||
|
* 付费插件等级 付费插件自动注入
|
||||||
*/
|
*/
|
||||||
level?: number
|
level?: number
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ export namespace server {
|
|||||||
origin: any
|
origin: any
|
||||||
[key: string]: any
|
[key: string]: any
|
||||||
}
|
}
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export abstract class NativePluginManager {
|
export abstract class NativePluginManager {
|
||||||
list(): NativePlugin[] {
|
list(): NativePlugin[] {
|
||||||
@@ -53,6 +54,7 @@ export namespace server {
|
|||||||
throw new Error("Method not implemented.")
|
throw new Error("Method not implemented.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MiaoScript Server
|
* MiaoScript Server
|
||||||
*/
|
*/
|
||||||
@@ -98,6 +100,7 @@ export namespace server {
|
|||||||
throw new Error("Method not implemented.")
|
throw new Error("Method not implemented.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class ServerChecker {
|
export class ServerChecker {
|
||||||
@Autowired(ServerType)
|
@Autowired(ServerType)
|
||||||
@@ -116,6 +119,22 @@ export namespace server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class NativePluginChecker {
|
||||||
|
@Autowired(NativePluginManager)
|
||||||
|
private nativePluginManager: NativePluginManager
|
||||||
|
|
||||||
|
check(plugins: string[]) {
|
||||||
|
// Not set plugins -> allow
|
||||||
|
if (!plugins || !plugins.length) return true
|
||||||
|
for (const plugin of plugins) {
|
||||||
|
if (!this.nativePluginManager.has(plugin)) { return false }
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export abstract class ReflectServer extends server.Server {
|
export abstract class ReflectServer extends server.Server {
|
||||||
@Autowired(ContainerInstance)
|
@Autowired(ContainerInstance)
|
||||||
@@ -172,13 +191,23 @@ export namespace server {
|
|||||||
}
|
}
|
||||||
protected reflectRootLogger(consoleServer: any) {
|
protected reflectRootLogger(consoleServer: any) {
|
||||||
try {
|
try {
|
||||||
this.rootLogger = reflect.on(consoleServer).get('LOGGER').get().parent
|
this.rootLogger = reflect.on(consoleServer).get('LOGGER').get()
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (global.debug) {
|
if (global.debug) {
|
||||||
console.ex(error)
|
console.ex(error)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.rootLogger = reflect.on(consoleServer).get(0).get().parent
|
this.rootLogger = reflect.on(consoleServer).get(0).get()
|
||||||
|
} catch (error: any) {
|
||||||
|
if (global.debug) {
|
||||||
|
console.ex(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.rootLogger.class.name.indexOf('slf4j') !== -1) {
|
||||||
|
try {
|
||||||
|
let LogManager = Java.type('org.apache.logging.log4j.LogManager')
|
||||||
|
this.rootLogger = LogManager.getLogger('ROOT')
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (global.debug) {
|
if (global.debug) {
|
||||||
console.ex(error)
|
console.ex(error)
|
||||||
@@ -189,11 +218,11 @@ export namespace server {
|
|||||||
console.error('Error Logger Class: ' + this.rootLogger.class.name)
|
console.error('Error Logger Class: ' + this.rootLogger.class.name)
|
||||||
this.rootLogger = undefined
|
this.rootLogger = undefined
|
||||||
}
|
}
|
||||||
|
if (!this.rootLogger) { console.error("Can't found rootLogger!") }
|
||||||
// get root logger
|
// get root logger
|
||||||
for (let index = 0; index < 5 && this.rootLogger.parent; index++) {
|
for (let index = 0; index < 5 && this.rootLogger.parent; index++) {
|
||||||
this.rootLogger = this.rootLogger.parent
|
this.rootLogger = this.rootLogger.parent
|
||||||
}
|
}
|
||||||
if (!this.rootLogger) { console.error("Can't found rootLogger!") }
|
|
||||||
this.container.bind(constants.ServiceIdentifier.RootLogger).toConstantValue(this.rootLogger)
|
this.container.bind(constants.ServiceIdentifier.RootLogger).toConstantValue(this.rootLogger)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { plugin } from './index'
|
import { EventEmitter } from 'events'
|
||||||
import { injectable } from '@ccms/container'
|
import { injectable } from '@ccms/container'
|
||||||
|
|
||||||
|
import { plugin } from './index'
|
||||||
|
|
||||||
const AtomicInteger = Java.type("java.util.concurrent.atomic.AtomicInteger")
|
const AtomicInteger = Java.type("java.util.concurrent.atomic.AtomicInteger")
|
||||||
|
|
||||||
export namespace task {
|
export namespace task {
|
||||||
@@ -32,9 +34,7 @@ export namespace task {
|
|||||||
|
|
||||||
protected pluginDisable(plugin: plugin.Plugin) {
|
protected pluginDisable(plugin: plugin.Plugin) {
|
||||||
if (this.pluginCacheTasks.has(plugin.description.name)) {
|
if (this.pluginCacheTasks.has(plugin.description.name)) {
|
||||||
this.pluginCacheTasks.get(plugin.description.name).forEach((task) => {
|
this.pluginCacheTasks.get(plugin.description.name).forEach((task) => task.cancel())
|
||||||
task.cancel()
|
|
||||||
})
|
|
||||||
this.pluginCacheTasks.delete(plugin.description.name)
|
this.pluginCacheTasks.delete(plugin.description.name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ export namespace task {
|
|||||||
/**
|
/**
|
||||||
* 任务抽象
|
* 任务抽象
|
||||||
*/
|
*/
|
||||||
export abstract class Task implements Cancelable {
|
export abstract class Task extends EventEmitter implements Cancelable {
|
||||||
protected func: Function
|
protected func: Function
|
||||||
protected isAsync: boolean = false;
|
protected isAsync: boolean = false;
|
||||||
protected laterTime: number = 0;
|
protected laterTime: number = 0;
|
||||||
@@ -88,7 +88,10 @@ export namespace task {
|
|||||||
protected taskId: number
|
protected taskId: number
|
||||||
protected innerTask: any
|
protected innerTask: any
|
||||||
|
|
||||||
|
private cancelled: boolean = false
|
||||||
|
|
||||||
constructor(owner: plugin.Plugin, func: Function, id: number) {
|
constructor(owner: plugin.Plugin, func: Function, id: number) {
|
||||||
|
super()
|
||||||
this.owner = owner
|
this.owner = owner
|
||||||
this.func = func
|
this.func = func
|
||||||
this.taskId = id
|
this.taskId = id
|
||||||
@@ -134,18 +137,34 @@ export namespace task {
|
|||||||
*/
|
*/
|
||||||
cancel(): boolean {
|
cancel(): boolean {
|
||||||
let result = this.cancel0()
|
let result = this.cancel0()
|
||||||
process.emit('task.finish', this)
|
this.finish()
|
||||||
|
this.cancelled = true
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
protected run(...args: any[]): void {
|
protected run(...args: any[]): void {
|
||||||
try {
|
try {
|
||||||
|
this.emit('before', this)
|
||||||
|
if (this.cancelled) { return }
|
||||||
this.func(...args)
|
this.func(...args)
|
||||||
!this.interval && process.emit('task.finish', this)
|
this.emit('after', this)
|
||||||
} catch (ex: any) {
|
} catch (error: any) {
|
||||||
console.console('§4插件执行任务时发生错误', ex)
|
try {
|
||||||
console.ex(ex)
|
this.emit('error', error)
|
||||||
|
} catch (ignore) {
|
||||||
|
console.console('§4插件执行任务时发生错误', error)
|
||||||
|
console.ex(error)
|
||||||
|
this.cancel()
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
this.emit('finally', this)
|
||||||
|
if (!this.interval && !this.cancelled) { this.finish() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected finish() {
|
||||||
|
process.emit('task.finish', this)
|
||||||
|
this.emit('finish', this)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -161,7 +180,7 @@ export namespace task {
|
|||||||
* 提交任务
|
* 提交任务
|
||||||
* @param args 任务参数
|
* @param args 任务参数
|
||||||
*/
|
*/
|
||||||
protected abstract submit0(...args: any[]): any
|
protected abstract submit0(...args: any[]): Cancelable
|
||||||
/**
|
/**
|
||||||
* 取消任务
|
* 取消任务
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,3 +0,0 @@
|
|||||||
export namespace web {
|
|
||||||
export const Server = Symbol('Server')
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/bukkit",
|
"name": "@ccms/bukkit",
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"description": "MiaoScript bukkit package",
|
"description": "MiaoScript bukkit package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,21 +12,23 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist/**/*.js",
|
||||||
|
"dist/**/*.ts",
|
||||||
|
"dist/**/*.map"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "yarn clean && tsc",
|
"build": "pnpm clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@javatypes/spigot-api": "^0.0.3",
|
"@javatypes/spigot-api": "^0.0.3"
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.23.0",
|
"@ccms/api": "^0.28.0-beta.8",
|
||||||
"@ccms/common": "^0.23.0",
|
"@ccms/common": "^0.28.0-beta.8",
|
||||||
"@ccms/container": "^0.23.0"
|
"@ccms/container": "^0.28.0-beta.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ abstract class BukkitChatInvoke {
|
|||||||
if (nmsChatMessageTypeClass.isEnum()) {
|
if (nmsChatMessageTypeClass.isEnum()) {
|
||||||
this.chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants()
|
this.chatMessageTypes = nmsChatMessageTypeClass.getEnumConstants()
|
||||||
break
|
break
|
||||||
|
} else if (nmsChatMessageTypeClass.getName() == 'int') {
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -159,16 +161,17 @@ class BukkitChatInvoke_1_17_1 extends BukkitChatInvoke_1_16_5 {
|
|||||||
return base.getClass('net.minecraft.network.protocol.Packet')
|
return base.getClass('net.minecraft.network.protocol.Packet')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
class BukkitChatInvoke_1_18_2 extends BukkitChatInvoke_1_17_1 {
|
||||||
class BukkitChatInvoke_1_19 extends BukkitChatInvoke_1_17_1 {
|
|
||||||
getSendPacketMethodName(playerConnectionClass: any) {
|
getSendPacketMethodName(playerConnectionClass: any) {
|
||||||
return playerConnectionClass.getMethod('a', this.getPacketClass()).getName()
|
return playerConnectionClass.getMethod('a', this.getPacketClass()).getName()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
class BukkitChatInvoke_1_19 extends BukkitChatInvoke_1_18_2 {
|
||||||
getPacketPlayOutChatClass() {
|
getPacketPlayOutChatClass() {
|
||||||
return base.getClass('net.minecraft.network.protocol.game.ClientboundSystemChatPacket')
|
return base.getClass('net.minecraft.network.protocol.game.ClientboundSystemChatPacket')
|
||||||
}
|
}
|
||||||
getPacketPlayOutChat(sender: any, json: any, type: number) {
|
getPacketPlayOutChat(sender: any, json: any, type: number) {
|
||||||
return new this.PacketPlayOutChat(this.ChatSerializer[this.nmsChatSerializerMethodName](json), type == 0 ? 1 : type)
|
return new this.PacketPlayOutChat(this.ChatSerializer[this.nmsChatSerializerMethodName](json), type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,6 +182,8 @@ try {
|
|||||||
let nmsSubVersion = nmsVersion.split("_")[1]
|
let nmsSubVersion = nmsVersion.split("_")[1]
|
||||||
if (nmsSubVersion >= 19) {
|
if (nmsSubVersion >= 19) {
|
||||||
bukkitChatInvoke = new BukkitChatInvoke_1_19(nmsVersion)
|
bukkitChatInvoke = new BukkitChatInvoke_1_19(nmsVersion)
|
||||||
|
} else if (nmsSubVersion >= 18) {
|
||||||
|
bukkitChatInvoke = new BukkitChatInvoke_1_18_2(nmsVersion)
|
||||||
} else if (nmsSubVersion >= 17) {
|
} else if (nmsSubVersion >= 17) {
|
||||||
bukkitChatInvoke = new BukkitChatInvoke_1_17_1(nmsVersion)
|
bukkitChatInvoke = new BukkitChatInvoke_1_17_1(nmsVersion)
|
||||||
} else if (nmsSubVersion >= 16) {
|
} else if (nmsSubVersion >= 16) {
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export class BukkitItem extends item.Item {
|
|||||||
private NBTTagCompound: any
|
private NBTTagCompound: any
|
||||||
private nmsSaveNBTMethodName: any
|
private nmsSaveNBTMethodName: any
|
||||||
private MojangsonParser: any
|
private MojangsonParser: any
|
||||||
|
private nmsItemStack: any
|
||||||
private mpParseMethodName: any
|
private mpParseMethodName: any
|
||||||
private nmsVersion: any
|
private nmsVersion: any
|
||||||
constructor() {
|
constructor() {
|
||||||
@@ -25,8 +26,8 @@ export class BukkitItem extends item.Item {
|
|||||||
let nbt = new this.NBTTagCompound()
|
let nbt = new this.NBTTagCompound()
|
||||||
return this.CraftItemStack.asNMSCopy(item)[this.nmsSaveNBTMethodName](nbt).toString()
|
return this.CraftItemStack.asNMSCopy(item)[this.nmsSaveNBTMethodName](nbt).toString()
|
||||||
}
|
}
|
||||||
fromJSON(json: string) {
|
fromJson(json: string) {
|
||||||
return this.CraftItemStack.asBukkitCopy(this.MojangsonParser[this.mpParseMethodName](json))
|
return this.CraftItemStack.asBukkitCopy(new this.nmsItemStack(this.MojangsonParser[this.mpParseMethodName](json)))
|
||||||
}
|
}
|
||||||
private obcCls(name: string) {
|
private obcCls(name: string) {
|
||||||
return base.getClass(['org.bukkit.craftbukkit', this.nmsVersion, name].join('.'))
|
return base.getClass(['org.bukkit.craftbukkit', this.nmsVersion, name].join('.'))
|
||||||
@@ -44,6 +45,7 @@ export class BukkitItem extends item.Item {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
let asNMSCopyMethod = CraftItemStackClass.getMethod('asNMSCopy', ItemStack.class)
|
let asNMSCopyMethod = CraftItemStackClass.getMethod('asNMSCopy', ItemStack.class)
|
||||||
let nmsItemStackClass = asNMSCopyMethod.getReturnType()
|
let nmsItemStackClass = asNMSCopyMethod.getReturnType()
|
||||||
|
this.nmsItemStack = Java.type(nmsItemStackClass.getName())
|
||||||
let nmsNBTTagCompoundClass = undefined
|
let nmsNBTTagCompoundClass = undefined
|
||||||
for (let method of Java.from(nmsItemStackClass.getMethods())) {
|
for (let method of Java.from(nmsItemStackClass.getMethods())) {
|
||||||
let rt = method.getReturnType()
|
let rt = method.getReturnType()
|
||||||
@@ -61,7 +63,7 @@ export class BukkitItem extends item.Item {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
this.MojangsonParser = this.nmsCls('MojangsonParser')
|
this.MojangsonParser = this.nmsCls('MojangsonParser').static
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.MojangsonParser = Java.type('net.minecraft.nbt.MojangsonParser')
|
this.MojangsonParser = Java.type('net.minecraft.nbt.MojangsonParser')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,20 +3,11 @@ import { particle } from '@ccms/api'
|
|||||||
|
|
||||||
@provideSingleton(particle.ParticleManager)
|
@provideSingleton(particle.ParticleManager)
|
||||||
export class BukkitParticleManager extends particle.ParticleManager {
|
export class BukkitParticleManager extends particle.ParticleManager {
|
||||||
private globalSpawner = new BukkitParticleSpawner()
|
|
||||||
constructor() {
|
|
||||||
super()
|
|
||||||
particle.ParticleManager.globalSpawner = this.globalSpawner
|
|
||||||
}
|
|
||||||
protected getGlobalSpawner() {
|
|
||||||
return this.globalSpawner
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@provideSingleton(particle.ParticleSpawner)
|
||||||
export class BukkitParticleSpawner extends particle.ParticleSpawner {
|
export class BukkitParticleSpawner extends particle.ParticleSpawner {
|
||||||
spawnParticle(location: any, particle: any, count: number = 1) {
|
spawn(location: org.bukkit.Location, particle: particle.Particle) {
|
||||||
location.getWorld().spawnParticle(particle, location, count)
|
|
||||||
}
|
|
||||||
spawn(location: any, particle: particle.Particle) {
|
|
||||||
location.getWorld().spawnParticle(
|
location.getWorld().spawnParticle(
|
||||||
particle.getParticle(),
|
particle.getParticle(),
|
||||||
location,
|
location,
|
||||||
@@ -28,4 +19,15 @@ export class BukkitParticleSpawner extends particle.ParticleSpawner {
|
|||||||
particle.getData()
|
particle.getData()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
spawnToPlayer(player: org.bukkit.entity.Player, location: org.bukkit.Location, particle: particle.Particle) {
|
||||||
|
player.spawnParticle(
|
||||||
|
particle.getParticle(),
|
||||||
|
location,
|
||||||
|
particle.getCount(),
|
||||||
|
particle.getOffsetX(),
|
||||||
|
particle.getOffsetY(),
|
||||||
|
particle.getOffsetZ(),
|
||||||
|
particle.getExtra(),
|
||||||
|
particle.getData())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/bungee",
|
"name": "@ccms/bungee",
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"description": "MiaoScript bungee package",
|
"description": "MiaoScript bungee package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,21 +12,23 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist/**/*.js",
|
||||||
|
"dist/**/*.ts",
|
||||||
|
"dist/**/*.map"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "yarn clean && tsc",
|
"build": "pnpm clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@javatypes/bungee-api": "^0.0.3",
|
"@javatypes/bungee-api": "^0.0.3"
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.23.0",
|
"@ccms/api": "^0.28.0-beta.8",
|
||||||
"@ccms/common": "^0.23.0",
|
"@ccms/common": "^0.28.0-beta.8",
|
||||||
"@ccms/container": "^0.23.0"
|
"@ccms/container": "^0.28.0-beta.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
1
packages/client/.gitignore
vendored
1
packages/client/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
src/emp.ts
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
{
|
|
||||||
"private": true,
|
|
||||||
"name": "@ccms/client",
|
|
||||||
"version": "0.23.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",
|
|
||||||
"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",
|
|
||||||
"debug": "DEBUG=minecraft-protocol node dist/index.js",
|
|
||||||
"emp": "node dist/emp.js",
|
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"axios": "^0.27.2",
|
|
||||||
"minecraft-protocol": "^1.34.0",
|
|
||||||
"minecraft-protocol-forge": "^1.0.0",
|
|
||||||
"proxy-agent": "^5.0.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/node": "^17.0.25",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
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,
|
|
||||||
$
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
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[6]
|
|
||||||
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) {
|
|
||||||
}
|
|
||||||
})
|
|
||||||
client.on('kick_disconnect', (packet) => {
|
|
||||||
console.log($(packet.reason))
|
|
||||||
})
|
|
||||||
client.on('disconnect', (packet) => {
|
|
||||||
console.log($(packet.reason))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
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)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
@@ -1,124 +0,0 @@
|
|||||||
import { createInterface } from 'readline'
|
|
||||||
import { Client, createClient } from 'minecraft-protocol'
|
|
||||||
|
|
||||||
import { attachForge } from './forge'
|
|
||||||
import { attachEvents } from './event'
|
|
||||||
|
|
||||||
let readUserInfo = process.argv[2] || 'Mr_jtb'
|
|
||||||
let realUserInfo = readUserInfo.split(":")
|
|
||||||
let username = realUserInfo[0]
|
|
||||||
let password = realUserInfo[1] || ''
|
|
||||||
let version = process.argv[3] || '1.12.2'
|
|
||||||
let readAddress = process.argv[4] || '192.168.2.25:25565'
|
|
||||||
let realAddress = readAddress.split(":")
|
|
||||||
let address = realAddress[0]
|
|
||||||
let port = parseInt(realAddress[1] || "25565")
|
|
||||||
let client = commandLineCreateClient()
|
|
||||||
|
|
||||||
function commandLineCreateClient() {
|
|
||||||
return createConnection(address, port, username, password)
|
|
||||||
}
|
|
||||||
|
|
||||||
function createConnection(host: string, port: number, username: string, password: string) {
|
|
||||||
let clientOptions: any = {
|
|
||||||
version,
|
|
||||||
host,
|
|
||||||
port,
|
|
||||||
username,
|
|
||||||
password,
|
|
||||||
// clientToken: 'd02c7f39-2376-45da-a5a5-50e24fa8b185',
|
|
||||||
//@ts-ignore
|
|
||||||
// authServer: 'https://skin.yumc.pw/api/yggdrasil/authserver',
|
|
||||||
// sessionServer: 'https://skin.yumc.pw/api/yggdrasil/sessionserver'
|
|
||||||
}
|
|
||||||
if (clientOptions.password) {
|
|
||||||
clientOptions.clientToken = 'd02c7f39-2376-45da-a5a5-50e24fa8b185'
|
|
||||||
clientOptions.authServer = 'https://skin.yumc.pw/api/yggdrasil/authserver'
|
|
||||||
clientOptions.sessionServer = 'https://skin.yumc.pw/api/yggdrasil/sessionserver'
|
|
||||||
}
|
|
||||||
let client = createClient(clientOptions)
|
|
||||||
|
|
||||||
attachCommon(client)
|
|
||||||
attachForge(client)
|
|
||||||
attachEvents(client)
|
|
||||||
return client
|
|
||||||
}
|
|
||||||
|
|
||||||
function attachCommon(client: Client) {
|
|
||||||
client.on('login', () => {
|
|
||||||
// client.registerChannel('updater', ['string', []])
|
|
||||||
// client.registerChannel('updater-enabled', ['string', []])
|
|
||||||
// client.registerChannel('dragoncore', ['string', []])
|
|
||||||
// client.registerChannel('dragoncore:main', ['string', []])
|
|
||||||
client.on('REGISTER', (array) => {
|
|
||||||
for (const channel of array) {
|
|
||||||
client.on('channel', console.log)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
// client.on('dragoncore:main', (data) => {
|
|
||||||
// console.log(data)
|
|
||||||
// })
|
|
||||||
})
|
|
||||||
client.on('custom_payload', (data) => {
|
|
||||||
console.log('custom_payload' + JSON.stringify(data))
|
|
||||||
})
|
|
||||||
client.on('error', (error) => {
|
|
||||||
console.log("Client Error", error)
|
|
||||||
})
|
|
||||||
client.on('end', (resone) => {
|
|
||||||
console.log("Client End Resone:", resone)
|
|
||||||
if (`${resone}` != "SocketClosed") {
|
|
||||||
setTimeout(() => {
|
|
||||||
client = commandLineCreateClient()
|
|
||||||
}, 500)
|
|
||||||
} else {
|
|
||||||
process.exit(0)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = commandLineCreateClient()
|
|
||||||
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()
|
|
||||||
})
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
while :; do
|
|
||||||
yarn emp
|
|
||||||
echo 进程退出 休眠120秒!
|
|
||||||
sleep 120
|
|
||||||
done
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../../tsconfig.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"baseUrl": "src",
|
|
||||||
"outDir": "dist"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/common",
|
"name": "@ccms/common",
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"description": "MiaoScript common package",
|
"description": "MiaoScript common package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,18 +12,20 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist/**/*.js",
|
||||||
|
"dist/**/*.ts",
|
||||||
|
"dist/**/*.map"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "yarn clean && tsc",
|
"build": "pnpm clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.23.0",
|
"@ccms/nashorn": "^0.28.0-beta.8",
|
||||||
"@javatypes/jdk": "^0.0.3",
|
"@javatypes/jdk": "^0.0.3"
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
},
|
},
|
||||||
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
|
"gitHead": "562e2d00175c9d3a99c8b672aa07e6d92706a027"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,12 +19,20 @@ interface RequestConfig {
|
|||||||
method?: Method
|
method?: Method
|
||||||
headers?: { [key: string]: string }
|
headers?: { [key: string]: string }
|
||||||
params?: { [key: string]: string }
|
params?: { [key: string]: string }
|
||||||
data?: any
|
data?: any,
|
||||||
|
connectTimeout?: number,
|
||||||
|
readTimeout?: number,
|
||||||
}
|
}
|
||||||
|
|
||||||
function request(config: RequestConfig) {
|
function request(config: RequestConfig) {
|
||||||
// @ts-ignore XMLHttpRequest class only exist nashorn polyfill
|
// @ts-ignore XMLHttpRequest class only exist nashorn polyfill
|
||||||
let xhr = new XMLHttpRequest()
|
let xhr = new XMLHttpRequest()
|
||||||
|
if (config.connectTimeout) {
|
||||||
|
xhr.connectTimeout = config.connectTimeout
|
||||||
|
}
|
||||||
|
if (config.readTimeout) {
|
||||||
|
xhr.readTimeout = config.readTimeout
|
||||||
|
}
|
||||||
xhr.open(config.method, config.url, false)
|
xhr.open(config.method, config.url, false)
|
||||||
for (const header in config.headers) {
|
for (const header in config.headers) {
|
||||||
xhr.setRequestHeader(header, config.headers[header])
|
xhr.setRequestHeader(header, config.headers[header])
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ class Reflect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!field) throw new Error(`can't reflect field ${typeof nameOrIndex == "number" ? 'index' : 'name'} ${nameOrIndex} from ${this.class.getName()}!`)
|
if (!field) throw new Error(`can't reflect field ${typeof nameOrIndex == "number" ? 'index' : 'name'} ${nameOrIndex} from ${this.class.getName()}!`)
|
||||||
|
fieldCache.set(key, field)
|
||||||
return accessible(field)
|
return accessible(field)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,7 +137,7 @@ function declaredField(clazz: java.lang.Class<any>, name: string | java.lang.Str
|
|||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (target === undefined) { break }
|
if (target === undefined) { break }
|
||||||
target = target.getSuperclass()
|
target = target.getSuperclass()
|
||||||
console.debug(`切换到超类: ${target.getName()}`)
|
console.debug(`switch to super class: ${target.getName()}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (field === null) {
|
if (field === null) {
|
||||||
@@ -173,7 +174,7 @@ function declaredMethod(clazz: java.lang.Class<any>, nameOrIndex: string | numbe
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (target === undefined) { break }
|
if (target === undefined) { break }
|
||||||
target = target.getSuperclass()
|
target = target.getSuperclass()
|
||||||
console.debug(`切换到超类: ${target.getName()}`)
|
console.debug(`switch to super class: ${target.getName()}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,7 +187,7 @@ function declaredMethods(clazz: java.lang.Class<any>) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function mapToObject(javaObj) {
|
function mapToObject(javaObj) {
|
||||||
if (!Java.isJavaObject(javaObj)) { throw new TypeError(`参数 ${javaObj} 不是一个Java对象!`) }
|
if (!Java.isJavaObject(javaObj)) { throw new TypeError(`argument ${javaObj} is not a java object.`) }
|
||||||
let target = Proxy.newProxy(javaObj, {
|
let target = Proxy.newProxy(javaObj, {
|
||||||
apply: (target, name, args) => { return args ? javaObj[name](args) : javaObj[name]() }
|
apply: (target, name, args) => { return args ? javaObj[name](args) : javaObj[name]() }
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/compile",
|
"name": "@ccms/compile",
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"description": "MiaoScript compile package",
|
"description": "MiaoScript compile package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,15 +12,35 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist/**/*.js",
|
||||||
|
"dist/**/*.ts",
|
||||||
|
"dist/**/*.map"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "yarn clean && tsc",
|
"build": "pnpm clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"@ccms/api": "^0.28.0-beta.8",
|
||||||
"rimraf": "^3.0.2",
|
"@ccms/bukkit": "^0.28.0-beta.8",
|
||||||
"typescript": "^4.6.3"
|
"@ccms/bungee": "^0.28.0-beta.8",
|
||||||
|
"@ccms/common": "^0.28.0-beta.8",
|
||||||
|
"@ccms/container": "^0.28.0-beta.8",
|
||||||
|
"@ccms/core": "^0.28.0-beta.8",
|
||||||
|
"@ccms/database": "^0.28.0-beta.8",
|
||||||
|
"@ccms/i18n": "^0.28.0-beta.8",
|
||||||
|
"@ccms/molang": "^0.28.0-beta.8",
|
||||||
|
"@ccms/nashorn": "^0.28.0-beta.8",
|
||||||
|
"@ccms/nodejs": "^0.28.0-beta.8",
|
||||||
|
"@ccms/nukkit": "^0.28.0-beta.8",
|
||||||
|
"@ccms/plugin": "^0.28.0-beta.8",
|
||||||
|
"@ccms/polyfill": "^0.28.0-beta.8",
|
||||||
|
"@ccms/protocol": "^0.28.0-beta.8",
|
||||||
|
"@ccms/qrcode": "^0.28.0-beta.8",
|
||||||
|
"@ccms/sponge": "^0.28.0-beta.8",
|
||||||
|
"@ccms/websocket": "^0.28.0-beta.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/container",
|
"name": "@ccms/container",
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"description": "MiaoScript container package",
|
"description": "MiaoScript container package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,17 +12,19 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist/**/*.js",
|
||||||
|
"dist/**/*.ts",
|
||||||
|
"dist/**/*.map"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "yarn clean && tsc",
|
"build": "pnpm clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.23.0",
|
"@ccms/nashorn": "^0.28.0-beta.8"
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"inversify": "^6.0.1",
|
"inversify": "^6.0.1",
|
||||||
|
|||||||
@@ -32,18 +32,28 @@ export const provideSingletonNamed = (identifier: interfaces.ServiceIdentifier<a
|
|||||||
return fluentProvide(identifier).inSingletonScope().whenTargetNamed(name).done()
|
return fluentProvide(identifier).inSingletonScope().whenTargetNamed(name).done()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getJavaClass(className: string) {
|
||||||
|
try { return Java.type(className).class; return } catch (error: any) { }
|
||||||
|
try { return base.getClass(className); return } catch (error: any) { }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得一个 java.lang.Class
|
* 获得一个 java.lang.Class
|
||||||
* @param className Java全类名
|
* @param className Java全类名
|
||||||
*/
|
*/
|
||||||
export const JavaClass = (className: string) => {
|
export const JavaClass = (className: string) => {
|
||||||
return function (target: object, propertyKey: string, index?: number) {
|
return function (target: object, propertyKey: string, index?: number) {
|
||||||
try { target[propertyKey] = Java.type(className).class; return } catch (error: any) { }
|
_proxyGetter(target, propertyKey, () => {
|
||||||
try { target[propertyKey] = base.getClass(className); return } catch (error: any) { }
|
return getJavaClass(className) || console.warn('JavaClass', className, 'Inject target', target.constructor.name, 'propertyKey', propertyKey, 'failed!')
|
||||||
console.warn('JavaClass', className, 'Inject target', target.constructor.name, 'propertyKey', propertyKey, 'failed!')
|
}, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getJSClass(className: string) {
|
||||||
|
try { return Java.type(className) } catch (error: any) { }
|
||||||
|
try { return base.getClass(className).static } catch (error: any) { }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得一个JS的Java类
|
* 获得一个JS的Java类
|
||||||
* @param className Java 全类名
|
* @param className Java 全类名
|
||||||
@@ -51,9 +61,7 @@ export const JavaClass = (className: string) => {
|
|||||||
export const JSClass = (className: string) => {
|
export const JSClass = (className: string) => {
|
||||||
return function (target: object, propertyKey: string, index?: number) {
|
return function (target: object, propertyKey: string, index?: number) {
|
||||||
_proxyGetter(target, propertyKey, () => {
|
_proxyGetter(target, propertyKey, () => {
|
||||||
try { return Java.type(className) } catch (error: any) { }
|
return getJSClass(className) || console.warn('JSClass', className, 'Inject target', target.constructor.name, 'propertyKey', propertyKey, 'failed!')
|
||||||
try { return base.getClass(className).static } catch (error: any) { }
|
|
||||||
console.warn('JSClass', className, 'Inject target', target.constructor.name, 'propertyKey', propertyKey, 'failed!')
|
|
||||||
}, true)
|
}, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,8 +162,10 @@ export const reduceMetadata = (ctx: interfaces.Context): any => {
|
|||||||
function initAutowired(container: Container) {
|
function initAutowired(container: Container) {
|
||||||
container.bind(ioc.Autowired).toDynamicValue((ctx) => {
|
container.bind(ioc.Autowired).toDynamicValue((ctx) => {
|
||||||
var metadata: any = reduceMetadata(ctx)
|
var metadata: any = reduceMetadata(ctx)
|
||||||
let key = Object.toString.call(metadata.named)
|
let key = Object.prototype.toString.call(metadata.named)
|
||||||
if (key === "[object Function]" || key === "[object Symbol]") { return container.get(metadata.named) }
|
if (key === "[object Function]" || key === "[object Symbol]") { return container.get(metadata.named) }
|
||||||
|
console.warn('container Autowired', metadata.named, 'failed. Error: illegal serviceIdentifier type', key)
|
||||||
|
console.debug(metadata.named, 'metadata', JSON.stringify(metadata))
|
||||||
return undefined
|
return undefined
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/core",
|
"name": "@ccms/core",
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"description": "MiaoScript core package",
|
"description": "MiaoScript core package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,20 +12,28 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist/**/*.js",
|
||||||
|
"dist/**/*.ts",
|
||||||
|
"dist/**/*.map"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "pnpm rollup -c rollup.config.js --watch",
|
||||||
"build": "yarn clean && tsc",
|
"build": "pnpm clean && pnpm rollup -c rollup.config.js",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"reflect-metadata": "^0.1.13",
|
"@rollup/plugin-typescript": "^11.1.5",
|
||||||
"rimraf": "^3.0.2",
|
"rollup": "^2.79.1",
|
||||||
"typescript": "^4.6.3"
|
"rollup-obfuscator": "^3.0.2",
|
||||||
|
"rollup-plugin-peer-deps-external": "^2.2.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.23.0",
|
"@ccms/api": "^0.28.0-beta.8",
|
||||||
"@ccms/container": "^0.23.0"
|
"@ccms/common": "^0.28.0-beta.8",
|
||||||
|
"@ccms/container": "^0.28.0-beta.8",
|
||||||
|
"js-yaml": "^4.1.0"
|
||||||
},
|
},
|
||||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||||
}
|
}
|
||||||
|
|||||||
49
packages/core/rollup.config.js
Normal file
49
packages/core/rollup.config.js
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
import typescript from '@rollup/plugin-typescript'
|
||||||
|
import peerDepsExternal from 'rollup-plugin-peer-deps-external'
|
||||||
|
import { obfuscator } from 'rollup-obfuscator'
|
||||||
|
|
||||||
|
import pkg from './package.json'
|
||||||
|
|
||||||
|
const external = ['path', 'fs', 'typescript', 'tslib']
|
||||||
|
/**
|
||||||
|
* @type {import('rollup').RollupOptions}
|
||||||
|
*/
|
||||||
|
export default {
|
||||||
|
input: 'src/index.ts',
|
||||||
|
plugins: [
|
||||||
|
peerDepsExternal(),
|
||||||
|
typescript(),
|
||||||
|
obfuscator({
|
||||||
|
compact: true,
|
||||||
|
deadCodeInjection: true,
|
||||||
|
deadCodeInjectionThreshold: 1,
|
||||||
|
identifierNamesGenerator: 'mangled-shuffled',
|
||||||
|
numbersToExpressions: true,
|
||||||
|
simplify: true,
|
||||||
|
stringArray: true,
|
||||||
|
stringArrayThreshold: 1,
|
||||||
|
stringArrayEncoding: ['rc4'],
|
||||||
|
stringArrayCallsTransform: true,
|
||||||
|
stringArrayCallsTransformThreshold: 1,
|
||||||
|
stringArrayWrappersChainedCalls: true,
|
||||||
|
stringArrayWrappersParametersMaxCount: 3,
|
||||||
|
sourceMap: true,
|
||||||
|
sourceMapSourcesMode: 'sources',
|
||||||
|
inputFileName: `${pkg.name}.ts`,
|
||||||
|
transformObjectKeys: true,
|
||||||
|
unicodeEscapeSequence: true,
|
||||||
|
target: 'browser-no-eval'
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
external,
|
||||||
|
treeshake: false,
|
||||||
|
output: [
|
||||||
|
{
|
||||||
|
format: 'cjs',
|
||||||
|
interop: "auto",
|
||||||
|
exports: "named",
|
||||||
|
sourcemap: true,
|
||||||
|
file: pkg.main || `dist/${pkg.name}.js`
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
1
packages/core/src/.gitignore
vendored
Normal file
1
packages/core/src/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
script
|
||||||
@@ -9,6 +9,7 @@ import * as fs from '@ccms/common/dist/fs'
|
|||||||
import { VersionUtils } from '@ccms/common/dist/version'
|
import { VersionUtils } from '@ccms/common/dist/version'
|
||||||
|
|
||||||
const UUID = Java.type('java.util.UUID')
|
const UUID = Java.type('java.util.UUID')
|
||||||
|
const MiaoScriptAPI = Java.type('pw.yumc.MiaoScript.api.MiaoScriptAPI')
|
||||||
|
|
||||||
@provideSingleton(MiaoScriptCore)
|
@provideSingleton(MiaoScriptCore)
|
||||||
class MiaoScriptCore {
|
class MiaoScriptCore {
|
||||||
@@ -24,6 +25,10 @@ class MiaoScriptCore {
|
|||||||
enable() {
|
enable() {
|
||||||
process.emit('core.before.enable')
|
process.emit('core.before.enable')
|
||||||
this.loadServerConsole()
|
this.loadServerConsole()
|
||||||
|
try {
|
||||||
|
MiaoScriptAPI.setPluginManager(this.pluginManager)
|
||||||
|
} catch (error) {
|
||||||
|
}
|
||||||
this.loadPlugins()
|
this.loadPlugins()
|
||||||
process.emit('core.after.enable')
|
process.emit('core.after.enable')
|
||||||
console.i18n("ms.core.engine.completed", {
|
console.i18n("ms.core.engine.completed", {
|
||||||
@@ -105,7 +110,7 @@ function loadCoreScript(name) {
|
|||||||
try {
|
try {
|
||||||
let scriptname = name + (global.debug ? '-debug' : '')
|
let scriptname = name + (global.debug ? '-debug' : '')
|
||||||
engineLoad({
|
engineLoad({
|
||||||
script: http.get(`https://ms.yumc.pw/api/plugin/download/name/${scriptname}`),
|
script: http.get(`https://mscript.yumc.pw/api/plugin/download/name/${scriptname}`),
|
||||||
name: `core/${scriptname}.js`
|
name: `core/${scriptname}.js`
|
||||||
})
|
})
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -141,6 +146,7 @@ function createCore() {
|
|||||||
container.bind(server.ServerType).toConstantValue(type)
|
container.bind(server.ServerType).toConstantValue(type)
|
||||||
container.bind(server.ServerChecker).toSelf().inSingletonScope()
|
container.bind(server.ServerChecker).toSelf().inSingletonScope()
|
||||||
container.bind(server.NativePluginManager).toSelf().inSingletonScope()
|
container.bind(server.NativePluginManager).toSelf().inSingletonScope()
|
||||||
|
container.bind(server.NativePluginChecker).toSelf().inSingletonScope()
|
||||||
process.emit('core.after.initialize.detect')
|
process.emit('core.after.initialize.detect')
|
||||||
|
|
||||||
process.emit('core.before.package.initialize')
|
process.emit('core.before.package.initialize')
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/database",
|
"name": "@ccms/database",
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"description": "MiaoScript database package",
|
"description": "MiaoScript database package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,20 +12,22 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist/**/*.js",
|
||||||
|
"dist/**/*.ts",
|
||||||
|
"dist/**/*.map"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "yarn clean && tsc",
|
"build": "pnpm clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@javatypes/spring-jdbc": "^0.0.3",
|
"@javatypes/spring-jdbc": "^0.0.3"
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.23.0",
|
"@ccms/api": "^0.28.0-beta.8",
|
||||||
"@ccms/container": "^0.23.0"
|
"@ccms/container": "^0.28.0-beta.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/i18n",
|
"name": "@ccms/i18n",
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"description": "MiaoScript i18n package",
|
"description": "MiaoScript i18n package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,18 +12,21 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist/**/*.js",
|
||||||
|
"dist/**/*.ts",
|
||||||
|
"dist/**/*.map",
|
||||||
|
"languages"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "yarn clean && tsc",
|
"build": "pnpm clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.23.0",
|
"@ccms/nashorn": "^0.28.0-beta.8",
|
||||||
"@types/js-yaml": "^4.0.5",
|
"@types/js-yaml": "^4.0.5"
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"js-yaml": "^4.1.0"
|
"js-yaml": "^4.1.0"
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,36 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@ccms/keyvalue",
|
|
||||||
"version": "0.23.0",
|
|
||||||
"description": "MiaoScript keyvalue package",
|
|
||||||
"keywords": [
|
|
||||||
"miaoscript",
|
|
||||||
"minecraft",
|
|
||||||
"bukkit",
|
|
||||||
"sponge"
|
|
||||||
],
|
|
||||||
"author": "MiaoWoo <admin@yumc.pw>",
|
|
||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
|
||||||
"license": "ISC",
|
|
||||||
"main": "dist/index.js",
|
|
||||||
"scripts": {
|
|
||||||
"clean": "rimraf dist",
|
|
||||||
"watch": "tsc --watch",
|
|
||||||
"build": "yarn clean && tsc",
|
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@ccms/api": "^0.23.0",
|
|
||||||
"@ccms/common": "^0.23.0",
|
|
||||||
"@ccms/container": "^0.23.0"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@ccms/nashorn": "^0.23.0",
|
|
||||||
"@javatypes/amqp-client": "^0.0.3",
|
|
||||||
"@javatypes/spring-amqp": "^0.0.3",
|
|
||||||
"@javatypes/spring-rabbit": "^0.0.3",
|
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
},
|
|
||||||
"gitHead": "2589633069d24f646ac09261b1b2304c21d4ea75"
|
|
||||||
}
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
/// <reference types="@ccms/nashorn" />
|
|
||||||
/// <reference types="@javatypes/jdk" />
|
|
||||||
export { }
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../../tsconfig.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"baseUrl": "src",
|
|
||||||
"outDir": "dist"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +1,18 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/molang",
|
"name": "@ccms/molang",
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"description": "A fast parser for Minecraft's MoLang",
|
"description": "A fast parser for Minecraft's MoLang",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
"files": [
|
||||||
|
"dist/**/*.js",
|
||||||
|
"dist/**/*.ts",
|
||||||
|
"dist/**/*.map"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "yarn clean && tsc",
|
"build": "pnpm clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -21,9 +26,6 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/solvedDev/MoLang#readme",
|
"homepage": "https://github.com/solvedDev/MoLang#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^17.0.25",
|
"@types/node": "^18.17.15"
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"tslib": "^2.3.1",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nashorn",
|
"name": "@ccms/nashorn",
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"description": "MiaoScript nashorn package",
|
"description": "MiaoScript nashorn package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -13,15 +13,15 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
"files": [
|
||||||
|
"dist/**/*.js",
|
||||||
|
"dist/**/*.ts",
|
||||||
|
"dist/**/*.map"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "yarn clean && tsc",
|
"build": "pnpm clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,8 +64,18 @@ declare global {
|
|||||||
* 引擎渠道
|
* 引擎渠道
|
||||||
*/
|
*/
|
||||||
ScriptEngineChannel: string
|
ScriptEngineChannel: string
|
||||||
|
/**
|
||||||
|
* 慢执行检测时间
|
||||||
|
*/
|
||||||
ScriptSlowExecuteTime: number
|
ScriptSlowExecuteTime: number
|
||||||
ScriptEngineStartTime: number
|
ScriptEngineStartTime: number
|
||||||
|
/**
|
||||||
|
* 设置全局对象
|
||||||
|
* @param key 对象名称
|
||||||
|
* @param value 对象值
|
||||||
|
* @param config 对象属性
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
setGlobal: (key: string, value: any, config?: PropertyDescriptor & ThisType<any>) => void
|
setGlobal: (key: string, value: any, config?: PropertyDescriptor & ThisType<any>) => void
|
||||||
noop: () => void
|
noop: () => void
|
||||||
console: Console
|
console: Console
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nodejs",
|
"name": "@ccms/nodejs",
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"description": "MiaoScript nodejs package",
|
"description": "MiaoScript nodejs package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,18 +12,19 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist/**/*.js",
|
||||||
|
"dist/**/*.ts",
|
||||||
|
"dist/**/*.map"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "yarn clean && tsc",
|
"build": "pnpm clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.23.0",
|
"@ccms/nashorn": "^0.28.0-beta.8"
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"tslib": "^2.3.1",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
},
|
},
|
||||||
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
"gitHead": "781524f83e52cad26d7c480513e3c525df867121"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
var Throwable = Java.type('java.lang.Throwable')
|
||||||
var R = typeof Reflect === 'object' ? Reflect : null
|
var R = typeof Reflect === 'object' ? Reflect : null
|
||||||
var ReflectApply = R && typeof R.apply === 'function'
|
var ReflectApply = R && typeof R.apply === 'function'
|
||||||
? R.apply
|
? R.apply
|
||||||
@@ -136,13 +137,19 @@ EventEmitter.prototype.emit = function emit(type) {
|
|||||||
var er;
|
var er;
|
||||||
if (args.length > 0)
|
if (args.length > 0)
|
||||||
er = args[0];
|
er = args[0];
|
||||||
if (er instanceof Error) {
|
if (er instanceof Error || er instanceof Throwable) {
|
||||||
// Note: The comments on the `throw` lines are intentional, they show
|
// Note: The comments on the `throw` lines are intentional, they show
|
||||||
// up in Node's output if this results in an unhandled exception.
|
// up in Node's output if this results in an unhandled exception.
|
||||||
throw er; // Unhandled 'error' event
|
throw er; // Unhandled 'error' event
|
||||||
}
|
}
|
||||||
|
if (er.error instanceof Error || er.error instanceof Throwable) {
|
||||||
|
throw er.error; // Unhandled 'error' event
|
||||||
|
}
|
||||||
|
if (er.cause instanceof Error || er.cause instanceof Throwable) {
|
||||||
|
throw er.cause; // Unhandled 'error' event
|
||||||
|
}
|
||||||
// At least give some kind of context to the user
|
// At least give some kind of context to the user
|
||||||
var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
|
var err = new Error('Unhandled error.' + (er ? ' (' + (er.message || er.error || er.cause || er) + ')' : ''));
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
err.context = er;
|
err.context = er;
|
||||||
throw err; // Unhandled 'error' event
|
throw err; // Unhandled 'error' event
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const Path = Java.type("java.nio.file.Path");
|
|||||||
const JavaString = Java.type("java.lang.String");
|
const JavaString = Java.type("java.lang.String");
|
||||||
const File = Java.type("java.io.File");
|
const File = Java.type("java.io.File");
|
||||||
const Files = Java.type("java.nio.file.Files");
|
const Files = Java.type("java.nio.file.Files");
|
||||||
|
const Paths = Java.type("java.nio.file.Paths");
|
||||||
const Collector = Java.type("java.util.stream.Collector")
|
const Collector = Java.type("java.util.stream.Collector")
|
||||||
const separatorChar = File.separatorChar;
|
const separatorChar = File.separatorChar;
|
||||||
const StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
|
const StandardCopyOption = Java.type("java.nio.file.StandardCopyOption");
|
||||||
@@ -37,7 +38,7 @@ function javaFile(...opts: any[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function renameSync(oldPath: PathLike, newPath: PathLike): void {
|
export function renameSync(oldPath: PathLike, newPath: PathLike): void {
|
||||||
|
Files.move(Paths.get(oldPath), Paths.get(oldPath), StandardCopyOption['ATOMIC_MOVE'])
|
||||||
}
|
}
|
||||||
export function truncateSync() {
|
export function truncateSync() {
|
||||||
|
|
||||||
|
|||||||
@@ -715,6 +715,7 @@ function callbackify(original) {
|
|||||||
// implications (stack, `uncaughtException`, `async_hooks`)
|
// implications (stack, `uncaughtException`, `async_hooks`)
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
original.apply(this, args)
|
original.apply(this, args)
|
||||||
|
// @ts-ignore
|
||||||
.then(function (ret) { process.nextTick(cb.bind(null, null, ret)) },
|
.then(function (ret) { process.nextTick(cb.bind(null, null, ret)) },
|
||||||
function (rej) { process.nextTick(callbackifyOnRejected.bind(null, rej, cb)) });
|
function (rej) { process.nextTick(callbackifyOnRejected.bind(null, rej, cb)) });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/nukkit",
|
"name": "@ccms/nukkit",
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"description": "MiaoScript nukkit package",
|
"description": "MiaoScript nukkit package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,21 +12,23 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist/**/*.js",
|
||||||
|
"dist/**/*.ts",
|
||||||
|
"dist/**/*.map"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "yarn clean && tsc",
|
"build": "pnpm clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@javatypes/nukkit-api": "^0.0.3",
|
"@javatypes/nukkit-api": "^0.0.3"
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.23.0",
|
"@ccms/api": "^0.28.0-beta.8",
|
||||||
"@ccms/common": "^0.23.0",
|
"@ccms/common": "^0.28.0-beta.8",
|
||||||
"@ccms/container": "^0.23.0"
|
"@ccms/container": "^0.28.0-beta.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/plugin",
|
"name": "@ccms/plugin",
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"description": "MiaoScript plugin package",
|
"description": "MiaoScript plugin package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -12,25 +12,27 @@
|
|||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
"files": [
|
||||||
|
"dist/**/*.js",
|
||||||
|
"dist/**/*.ts",
|
||||||
|
"dist/**/*.map"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "yarn clean && tsc",
|
"build": "pnpm clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/crypto-js": "^4.1.1",
|
"@types/crypto-js": "^4.1.2",
|
||||||
"@types/js-yaml": "^4.0.5",
|
"@types/js-yaml": "^4.0.5"
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/api": "^0.23.0",
|
"@ccms/api": "^0.28.0-beta.8",
|
||||||
"@ccms/common": "^0.23.0",
|
"@ccms/common": "^0.28.0-beta.8",
|
||||||
"@ccms/container": "^0.23.0",
|
"@ccms/container": "^0.28.0-beta.8",
|
||||||
"@ccms/i18n": "^0.23.0",
|
"@ccms/i18n": "^0.28.0-beta.8",
|
||||||
"@ccms/verify": "^0.21.1",
|
"@ccms/verify": "^0.26.1",
|
||||||
"crypto-js": "^4.1.1",
|
"crypto-js": "^4.1.1",
|
||||||
"js-yaml": "^4.1.0"
|
"js-yaml": "^4.1.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,51 +15,51 @@ export class PluginCommandManager {
|
|||||||
process.on('plugin.after.disable', this.unregistryCommand.bind(this))
|
process.on('plugin.after.disable', this.unregistryCommand.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
private registryCommand(pluginInstance: plugin.Plugin) {
|
public registryCommand(pluginInstance: plugin.Plugin, executor: any = pluginInstance) {
|
||||||
let cmds = getPluginCommandMetadata(pluginInstance)
|
let cmds = getPluginCommandMetadata(executor)
|
||||||
let tabs = getPluginTabCompleterMetadata(pluginInstance)
|
let tabs = getPluginTabCompleterMetadata(executor)
|
||||||
for (const cmd of cmds) {
|
for (const cmd of cmds) {
|
||||||
if (!this.ServerChecker.check(cmd.servers)) {
|
if (!this.ServerChecker.check(cmd.servers)) {
|
||||||
console.debug(`[${pluginInstance.description.name}] ${cmd.target.constructor.name} incompatible command ${cmd.name} server(${cmd.servers}) ignore.`)
|
console.debug(`[${pluginInstance.description.name}] ${cmd.target.constructor.name} incompatible command ${cmd.name} server(${cmd.servers}) ignore.`)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for (let command of [cmd.name, ...cmd.alias]) {
|
for (let command of [cmd.name, ...cmd.alias]) {
|
||||||
let [cmdExecutor, cmdCompleter] = this.generateAutoMainCommand(pluginInstance, cmd, tabs.get(command))
|
let [cmdExecutor, cmdCompleter] = this.generateAutoMainCommand(pluginInstance, executor, cmd, tabs.get(command))
|
||||||
this.CommandManager.on(pluginInstance, command, {
|
this.CommandManager.on(pluginInstance, command, {
|
||||||
cmd: cmdExecutor.bind(pluginInstance),
|
cmd: cmdExecutor.bind(executor),
|
||||||
tab: cmdCompleter?.bind(pluginInstance)
|
tab: cmdCompleter?.bind(executor)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private unregistryCommand(pluginInstance: plugin.Plugin) {
|
public unregistryCommand(pluginInstance: plugin.Plugin, executor: any = pluginInstance) {
|
||||||
let cmds = getPluginCommandMetadata(pluginInstance)
|
let cmds = getPluginCommandMetadata(executor)
|
||||||
for (const cmd of cmds) {
|
for (const cmd of cmds) {
|
||||||
if (!this.ServerChecker.check(cmd.servers)) {
|
if (!this.ServerChecker.check(cmd.servers)) {
|
||||||
console.debug(`[${pluginInstance.description.name}] ${cmd.target.constructor.name} incompatible command ${cmd.name} server(${cmd.servers}) ignore.`)
|
console.debug(`[${pluginInstance.description.name}] ${cmd.target.constructor.name} incompatible command ${cmd.name} server(${cmd.servers}) ignore.`)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
for (let command of [cmd.name, ...cmd.alias]) {
|
for (let command of [cmd.name, ...cmd.alias]) {
|
||||||
this.CommandManager.off(pluginInstance, command)
|
this.CommandManager.off(executor, command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private generateAutoMainCommand(pluginInstance: plugin.Plugin, cmd: interfaces.CommandMetadata, tab: interfaces.CommandMetadata) {
|
private generateAutoMainCommand(pluginInstance: plugin.Plugin, executor: any, cmd: interfaces.CommandMetadata, tab: interfaces.CommandMetadata) {
|
||||||
let cmdExecutor = pluginInstance[cmd.executor]
|
let cmdExecutor = executor[cmd.executor]
|
||||||
let cmdCompleter = tab ? pluginInstance[tab.executor] : undefined
|
let cmdCompleter = tab ? executor[tab.executor] : undefined
|
||||||
let cmdSubCache = Object.keys(pluginInstance.constructor.prototype).filter(s => s.startsWith('cmd')).map(s => s.substring(3))
|
let cmdSubCache = Object.keys(executor.constructor.prototype).filter(s => s.startsWith('cmd')).map(s => s.substring(3))
|
||||||
if (cmd.autoMain) {
|
if (cmd.autoMain) {
|
||||||
cmdExecutor = (sender: any, command: string, args: string[]) => {
|
cmdExecutor = (sender: any, command: string, args: string[]) => {
|
||||||
let subcommand = args[0]
|
let subcommand = args[0]
|
||||||
let cmdKey = 'cmd' + subcommand
|
let cmdKey = 'cmd' + subcommand
|
||||||
if (!cmdSubCache.includes(subcommand)) {
|
if (!cmdSubCache.includes(subcommand)) {
|
||||||
if (!pluginInstance[cmd.executor].apply(pluginInstance, [sender, command, args])) {
|
if (!executor[cmd.executor].apply(executor, [sender, command, args])) {
|
||||||
subcommand && pluginInstance.logger.sender(sender, `§4未知的命令: §b/${command} §c${subcommand}`)
|
subcommand && pluginInstance.logger.sender(sender, `§4未知的命令: §b/${command} §c${subcommand}`)
|
||||||
pluginInstance.logger.sender(
|
pluginInstance.logger.sender(
|
||||||
sender,
|
sender,
|
||||||
pluginInstance['cmdhelp'] ?
|
executor['cmdhelp'] ?
|
||||||
`§6请执行 §b/${command} §ahelp §6查看帮助!` :
|
`§6请执行 §b/${command} §ahelp §6查看帮助!` :
|
||||||
[
|
[
|
||||||
`§6插件: §b${pluginInstance.description.name}`,
|
`§6插件: §b${pluginInstance.description.name}`,
|
||||||
@@ -69,7 +69,7 @@ export class PluginCommandManager {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let subcommandexec = pluginInstance[cmdKey]
|
let subcommandexec = executor[cmdKey]
|
||||||
let permission: string
|
let permission: string
|
||||||
if (cmd.permission && sender.hasPermission) {
|
if (cmd.permission && sender.hasPermission) {
|
||||||
if (typeof cmd.permission == "string") {
|
if (typeof cmd.permission == "string") {
|
||||||
@@ -78,11 +78,11 @@ export class PluginCommandManager {
|
|||||||
permission = `${pluginInstance.description.name.toLocaleLowerCase()}.${command}.${subcommand || 'main'}`
|
permission = `${pluginInstance.description.name.toLocaleLowerCase()}.${command}.${subcommand || 'main'}`
|
||||||
}
|
}
|
||||||
if (!sender.hasPermission(permission)) {
|
if (!sender.hasPermission(permission)) {
|
||||||
return pluginInstance.logger.sender(sender, `§c你需要 ${permission} 权限 才可执行此命令.`)
|
return pluginInstance.logger.sender(sender, `§c你需要 §4${permission} §c权限 才可执行此命令.`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
args.shift()
|
args.shift()
|
||||||
return subcommandexec.apply(pluginInstance, [sender, ...args])
|
return subcommandexec.apply(executor, [sender, ...args])
|
||||||
}
|
}
|
||||||
let originCompleter = cmdCompleter
|
let originCompleter = cmdCompleter
|
||||||
cmdCompleter = (sender: any, command: string, args: string[]) => {
|
cmdCompleter = (sender: any, command: string, args: string[]) => {
|
||||||
@@ -95,10 +95,10 @@ export class PluginCommandManager {
|
|||||||
}
|
}
|
||||||
if (!sender.hasPermission(permission)) { return [] }
|
if (!sender.hasPermission(permission)) { return [] }
|
||||||
}
|
}
|
||||||
return (args.length == 1 ? cmdSubCache : []).concat(originCompleter?.apply(pluginInstance, [sender, command, args]) || [])
|
return (args.length == 1 ? cmdSubCache : []).concat(originCompleter?.apply(executor, [sender, command, args]) || [])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!cmdCompleter) { console.warn(`[${pluginInstance.description.name}] command ${cmd.name} is not registry tabCompleter`) }
|
if (!cmdCompleter) { console.debug(`[${pluginInstance.description.name}] command ${cmd.name} is not registry tabCompleter`) }
|
||||||
return [cmdExecutor, cmdCompleter]
|
return [cmdExecutor, cmdCompleter]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ import { interfaces } from './interfaces'
|
|||||||
import { getPluginConfigMetadata } from './utils'
|
import { getPluginConfigMetadata } from './utils'
|
||||||
|
|
||||||
import { PluginConfigLoader } from './config/interfaces'
|
import { PluginConfigLoader } from './config/interfaces'
|
||||||
import './config/loader/json-loader'
|
import './config/loader'
|
||||||
import './config/loader/yaml-loader'
|
|
||||||
|
|
||||||
@provideSingleton(PluginConfigManager)
|
@provideSingleton(PluginConfigManager)
|
||||||
export class PluginConfigManager {
|
export class PluginConfigManager {
|
||||||
@@ -68,30 +67,25 @@ export class PluginConfigManager {
|
|||||||
private loadConfig0(plugin: plugin.Plugin, metadata: interfaces.ConfigMetadata) {
|
private loadConfig0(plugin: plugin.Plugin, metadata: interfaces.ConfigMetadata) {
|
||||||
try {
|
try {
|
||||||
let defaultValue = metadata.default ?? plugin[metadata.variable]
|
let defaultValue = metadata.default ?? plugin[metadata.variable]
|
||||||
let configValue = defaultValue || {}
|
|
||||||
if (defaultValue) {
|
|
||||||
metadata.file = fs.concat(
|
metadata.file = fs.concat(
|
||||||
fs.file(plugin.description.loadMetadata.file).parent,
|
fs.file(plugin.description.loadMetadata.file).parent,
|
||||||
plugin.description.name,
|
plugin.description.name,
|
||||||
metadata.filename
|
metadata.filename
|
||||||
)
|
)
|
||||||
let configLoader = this.getConfigLoader(metadata.format)
|
let configLoader = this.getConfigLoader(metadata.format)
|
||||||
if (!fs.exists(metadata.file)) {
|
if (!fs.exists(metadata.file) && defaultValue) {
|
||||||
base.save(metadata.file, configLoader.dump(defaultValue))
|
base.save(metadata.file, configLoader.dump(defaultValue))
|
||||||
console.i18n("ms.plugin.manager.config.save.default", {
|
console.i18n("ms.plugin.manager.config.save.default", {
|
||||||
plugin: plugin.description.name,
|
plugin: plugin.description.name,
|
||||||
name: metadata.name,
|
name: metadata.name,
|
||||||
format: metadata.format
|
format: metadata.format
|
||||||
})
|
})
|
||||||
} else if (metadata.migrate) {
|
}
|
||||||
configValue = configLoader.load(base.read(metadata.file)) || {}
|
let configValue = configLoader.load(base.read(metadata.file)) || {}
|
||||||
if (defaultValue && this.setDefaultValue(configValue, defaultValue, !!metadata.default)) {
|
if (metadata.migrate && defaultValue && this.setDefaultValue(configValue, defaultValue, !!metadata.default)) {
|
||||||
base.save(metadata.file, configLoader.dump(configValue))
|
base.save(metadata.file, configLoader.dump(configValue))
|
||||||
}
|
}
|
||||||
console.debug(`[${plugin.description.name}] Load Config ${metadata.variable} from file ${metadata.file} =>
|
console.debug(`[${plugin.description.name}] Load Config ${metadata.variable} from file ${metadata.file}`)
|
||||||
${JSON.stringify(configValue, undefined, 4).substring(0, 500)}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.defienConfigProp(plugin, metadata, configValue)
|
this.defienConfigProp(plugin, metadata, configValue)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.i18n("ms.plugin.manager.config.load.error", {
|
console.i18n("ms.plugin.manager.config.load.error", {
|
||||||
|
|||||||
@@ -5,9 +5,13 @@ import { getPluginListenerMetadata } from './utils'
|
|||||||
@provideSingleton(PluginEventManager)
|
@provideSingleton(PluginEventManager)
|
||||||
export class PluginEventManager {
|
export class PluginEventManager {
|
||||||
@Autowired()
|
@Autowired()
|
||||||
private EventManager: event.Event
|
private eventManager: event.Event
|
||||||
@Autowired()
|
@Autowired()
|
||||||
private ServerChecker: server.ServerChecker
|
private serverChecker: server.ServerChecker
|
||||||
|
@Autowired()
|
||||||
|
private nativePluginChecker: server.NativePluginChecker
|
||||||
|
|
||||||
|
private listenerMap = [];
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
process.on('plugin.before.enable', this.registryListener.bind(this))
|
process.on('plugin.before.enable', this.registryListener.bind(this))
|
||||||
@@ -15,26 +19,44 @@ export class PluginEventManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mapEventName() {
|
mapEventName() {
|
||||||
return this.EventManager.mapEventName().toFixed(0)
|
return this.eventManager.mapEventName().toFixed(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
private registryListener(pluginInstance: plugin.Plugin) {
|
public registryListener(pluginInstance: plugin.Plugin, listener: any = pluginInstance) {
|
||||||
let events = getPluginListenerMetadata(pluginInstance)
|
let events = getPluginListenerMetadata(listener)
|
||||||
|
let execes = []
|
||||||
for (const event of events) {
|
for (const event of events) {
|
||||||
// ignore space listener
|
// ignore space listener
|
||||||
if (!this.ServerChecker.check(event.servers)) {
|
if (!this.serverChecker.check(event.servers)) {
|
||||||
console.debug(`[${pluginInstance.description.name}] ${event.target.constructor.name} incompatible event ${event.name} server(${event.servers}) ignore.`)
|
console.debug(`[${pluginInstance.description.name}] ${event.target.constructor.name} incompatible server(${event.servers}) ignore event ${event.name}.`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// ignore space listener
|
||||||
|
if (!this.nativePluginChecker.check(event.plugins)) {
|
||||||
|
console.debug(`[${pluginInstance.description.name}] ${event.target.constructor.name} require native plugins(${event.plugins}) ignore event ${event.name}.`)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// here must bind this to pluginInstance
|
// here must bind this to pluginInstance
|
||||||
let exec = event.target[event.executor]
|
let exec = event.target[event.executor]
|
||||||
let execBinded = exec.bind(pluginInstance)
|
let execBinded = exec.bind(listener)
|
||||||
execBinded.executor = event.executor
|
execBinded.executor = event.executor
|
||||||
exec.off = this.EventManager.listen(pluginInstance, event.name, execBinded, event.priority, event.ignoreCancel)
|
exec.off = this.eventManager.listen(pluginInstance, event.name, execBinded, event.priority, event.ignoreCancel)
|
||||||
|
execes.push(exec)
|
||||||
}
|
}
|
||||||
|
let off = () => {
|
||||||
|
if (off['offed']) return
|
||||||
|
off['offed'] = true
|
||||||
|
execes.forEach((exec: { off: () => void }) => exec.off())
|
||||||
|
}
|
||||||
|
listener.off = off
|
||||||
}
|
}
|
||||||
|
|
||||||
private unregistryListener(pluginInstance: plugin.Plugin) {
|
public unregistryListener(pluginInstance: plugin.Plugin, listener: any = pluginInstance) {
|
||||||
this.EventManager.disable(pluginInstance)
|
if (listener && listener.off) {
|
||||||
|
listener.off()
|
||||||
|
}
|
||||||
|
if (pluginInstance) {
|
||||||
|
this.eventManager.disable(pluginInstance)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ export * from './manager'
|
|||||||
export * from './decorators'
|
export * from './decorators'
|
||||||
export * from './interfaces'
|
export * from './interfaces'
|
||||||
|
|
||||||
|
export * from './event'
|
||||||
|
export * from './command'
|
||||||
|
|
||||||
export {
|
export {
|
||||||
plugin as JSPlugin,
|
plugin as JSPlugin,
|
||||||
cmd as Cmd,
|
cmd as Cmd,
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { server, MiaoScriptConsole, event, plugin } from "@ccms/api"
|
import { server, MiaoScriptConsole, event, plugin, task, command } from "@ccms/api"
|
||||||
import { injectable, inject, postConstruct } from "@ccms/container"
|
import { injectable, inject, postConstruct, Autowired } from "@ccms/container"
|
||||||
import { getPluginMetadata } from "./utils"
|
import { getPluginMetadata } from "./utils"
|
||||||
|
import { PluginEventManager } from "./event"
|
||||||
|
import { PluginCommandManager } from "./command"
|
||||||
|
|
||||||
const File = Java.type('java.io.File')
|
const File = Java.type('java.io.File')
|
||||||
|
|
||||||
@@ -8,9 +10,15 @@ export namespace interfaces {
|
|||||||
@injectable()
|
@injectable()
|
||||||
export abstract class Plugin implements plugin.Plugin {
|
export abstract class Plugin implements plugin.Plugin {
|
||||||
public description: plugin.PluginMetadata
|
public description: plugin.PluginMetadata
|
||||||
public logger: Console
|
public logger: MiaoScriptConsole
|
||||||
@inject(server.Console)
|
@inject(server.Console)
|
||||||
private Console: MiaoScriptConsole
|
private Console: MiaoScriptConsole
|
||||||
|
@Autowired()
|
||||||
|
private taskManager: task.TaskManager
|
||||||
|
@Autowired()
|
||||||
|
private eventManager: PluginEventManager
|
||||||
|
@Autowired()
|
||||||
|
private commandManager: PluginCommandManager
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.description = getPluginMetadata(this)
|
this.description = getPluginMetadata(this)
|
||||||
@@ -28,6 +36,43 @@ export namespace interfaces {
|
|||||||
return dataFolder.getAbsolutePath()
|
return dataFolder.getAbsolutePath()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册命令
|
||||||
|
* @param executor 命令执行器
|
||||||
|
*/
|
||||||
|
public registryCommand(executor: any) {
|
||||||
|
this.commandManager.registryCommand(this, executor)
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 注销命令
|
||||||
|
* @param executor 命令执行器
|
||||||
|
*/
|
||||||
|
public unregistryCommand(executor: any) {
|
||||||
|
this.commandManager.unregistryCommand(this, executor)
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 注册事件
|
||||||
|
* @param listener 事件监听器
|
||||||
|
*/
|
||||||
|
public registryListener(listener: any) {
|
||||||
|
this.eventManager.registryListener(this, listener)
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 注销事件
|
||||||
|
* @param listener 事件监听器
|
||||||
|
*/
|
||||||
|
public unregistryListener(listener: any) {
|
||||||
|
this.eventManager.unregistryListener(this, listener)
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 创建任务
|
||||||
|
* @param func 任务内容
|
||||||
|
* @returns 任务
|
||||||
|
*/
|
||||||
|
public createTask(func: Function) {
|
||||||
|
return this.taskManager.create(func, this)
|
||||||
|
}
|
||||||
|
|
||||||
public load() { }
|
public load() { }
|
||||||
public enable() { }
|
public enable() { }
|
||||||
public disable() { }
|
public disable() { }
|
||||||
@@ -73,6 +118,10 @@ export namespace interfaces {
|
|||||||
* 是否忽略已取消的事件
|
* 是否忽略已取消的事件
|
||||||
*/
|
*/
|
||||||
ignoreCancel?: boolean
|
ignoreCancel?: boolean
|
||||||
|
/**
|
||||||
|
* 依赖插件 没有就不加载
|
||||||
|
*/
|
||||||
|
plugins?: string[]
|
||||||
}
|
}
|
||||||
export interface ConfigMetadata extends plugin.BaseMetadata {
|
export interface ConfigMetadata extends plugin.BaseMetadata {
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -2,12 +2,11 @@ import i18n from '@ccms/i18n'
|
|||||||
import { plugin, server } from '@ccms/api'
|
import { plugin, server } from '@ccms/api'
|
||||||
import { provideSingleton, Container, ContainerInstance, Autowired } from '@ccms/container'
|
import { provideSingleton, Container, ContainerInstance, Autowired } from '@ccms/container'
|
||||||
|
|
||||||
import './config'
|
|
||||||
import { interfaces } from './interfaces'
|
import { interfaces } from './interfaces'
|
||||||
import { PluginTaskManager } from './task'
|
import { PluginTaskManager } from './task'
|
||||||
import { PluginEventManager } from './event'
|
import { PluginEventManager } from './event'
|
||||||
import { PluginCommandManager } from './command'
|
|
||||||
import { PluginConfigManager } from './config'
|
import { PluginConfigManager } from './config'
|
||||||
|
import { PluginCommandManager } from './command'
|
||||||
|
|
||||||
const Thread = Java.type('java.lang.Thread')
|
const Thread = Java.type('java.lang.Thread')
|
||||||
|
|
||||||
@@ -93,18 +92,17 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
for (const [, scanner] of this.sacnnerMap) {
|
for (const [, scanner] of this.sacnnerMap) {
|
||||||
try {
|
try {
|
||||||
console.i18n('ms.plugin.manager.scan', { scanner: scanner.type, folder })
|
console.i18n('ms.plugin.manager.scan', { scanner: scanner.type, folder })
|
||||||
let plugins = scanner.scan(folder)
|
let loadMetadatas = scanner.scan(folder)
|
||||||
console.i18n('ms.plugin.manager.scan.finish', { scanner: scanner.type, folder, size: plugins.length })
|
console.i18n('ms.plugin.manager.scan.finish', { scanner: scanner.type, folder, size: loadMetadatas.length })
|
||||||
plugins.forEach(loadMetadata => {
|
for (const loadMetadata of loadMetadatas) {
|
||||||
try {
|
try {
|
||||||
this.loadAndRequirePlugin(loadMetadata)
|
this.loadAndRequirePlugin(loadMetadata)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(`plugin scanner ${scanner.type} load ${loadMetadata.file} occurred error ${error}`)
|
console.console(`§c扫描器 §4${scanner.type} §c文件 §4${loadMetadata.file.toString().replace(root, '')} §c编译失败 请提供下列错误给开发者`)
|
||||||
console.ex(error)
|
console.ex(error)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(`plugin scanner ${scanner.type} occurred error ${error}`)
|
|
||||||
console.ex(error)
|
console.ex(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -229,8 +227,16 @@ export class PluginManagerImpl implements plugin.PluginManager {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
has(name: string) {
|
||||||
|
return this.instanceMap.has(name)
|
||||||
|
}
|
||||||
|
|
||||||
|
get(name: string) {
|
||||||
|
return this.instanceMap.get(name) || null
|
||||||
|
}
|
||||||
|
|
||||||
getPlugin(name: string) {
|
getPlugin(name: string) {
|
||||||
return this.instanceMap.get(name)
|
return this.instanceMap.get(name) || null
|
||||||
}
|
}
|
||||||
|
|
||||||
getPlugins() {
|
getPlugins() {
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,27 +1,29 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/polyfill",
|
"name": "@ccms/polyfill",
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"description": "MiaoScript polyfill package",
|
"description": "MiaoScript polyfill package",
|
||||||
"author": "MiaoWoo <admin@yumc.pw>",
|
"author": "MiaoWoo <admin@yumc.pw>",
|
||||||
"homepage": "https://github.com/circlecloud/ms.git",
|
"homepage": "https://github.com/circlecloud/ms.git",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
"files": [
|
||||||
|
"dist/**/*.js",
|
||||||
|
"dist/**/*.ts",
|
||||||
|
"dist/**/*.map"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "yarn clean && tsc",
|
"build": "pnpm clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ccms/i18n": "^0.23.0",
|
"@ccms/i18n": "^0.28.0-beta.8",
|
||||||
"@ccms/nodejs": "^0.23.0",
|
"@ccms/nodejs": "^0.28.0-beta.8",
|
||||||
"core-js": "^3.22.1"
|
"core-js": "^3.33.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@ccms/nashorn": "^0.23.0",
|
"@ccms/nashorn": "^0.28.0-beta.8"
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
2134
packages/polyfill/src/buffer.ts
Normal file
2134
packages/polyfill/src/buffer.ts
Normal file
File diff suppressed because it is too large
Load Diff
239
packages/polyfill/src/core-js.ts
Normal file
239
packages/polyfill/src/core-js.ts
Normal file
@@ -0,0 +1,239 @@
|
|||||||
|
'use strict';
|
||||||
|
import 'core-js/modules/es.symbol';
|
||||||
|
import 'core-js/modules/es.symbol.description';
|
||||||
|
import 'core-js/modules/es.symbol.async-iterator';
|
||||||
|
import 'core-js/modules/es.symbol.has-instance';
|
||||||
|
import 'core-js/modules/es.symbol.is-concat-spreadable';
|
||||||
|
import 'core-js/modules/es.symbol.iterator';
|
||||||
|
import 'core-js/modules/es.symbol.match';
|
||||||
|
import 'core-js/modules/es.symbol.match-all';
|
||||||
|
import 'core-js/modules/es.symbol.replace';
|
||||||
|
import 'core-js/modules/es.symbol.search';
|
||||||
|
import 'core-js/modules/es.symbol.species';
|
||||||
|
import 'core-js/modules/es.symbol.split';
|
||||||
|
import 'core-js/modules/es.symbol.to-primitive';
|
||||||
|
import 'core-js/modules/es.symbol.to-string-tag';
|
||||||
|
import 'core-js/modules/es.symbol.unscopables';
|
||||||
|
import 'core-js/modules/es.array.at';
|
||||||
|
import 'core-js/modules/es.array.concat';
|
||||||
|
import 'core-js/modules/es.array.copy-within';
|
||||||
|
import 'core-js/modules/es.array.every';
|
||||||
|
import 'core-js/modules/es.array.fill';
|
||||||
|
import 'core-js/modules/es.array.filter';
|
||||||
|
import 'core-js/modules/es.array.find';
|
||||||
|
import 'core-js/modules/es.array.find-index';
|
||||||
|
import 'core-js/modules/es.array.find-last';
|
||||||
|
import 'core-js/modules/es.array.find-last-index';
|
||||||
|
import 'core-js/modules/es.array.flat';
|
||||||
|
import 'core-js/modules/es.array.flat-map';
|
||||||
|
import 'core-js/modules/es.array.for-each';
|
||||||
|
import 'core-js/modules/es.array.from';
|
||||||
|
import 'core-js/modules/es.array.includes';
|
||||||
|
import 'core-js/modules/es.array.index-of';
|
||||||
|
import 'core-js/modules/es.array.is-array';
|
||||||
|
import 'core-js/modules/es.array.iterator';
|
||||||
|
import 'core-js/modules/es.array.join';
|
||||||
|
import 'core-js/modules/es.array.last-index-of';
|
||||||
|
import 'core-js/modules/es.array.map';
|
||||||
|
import 'core-js/modules/es.array.of';
|
||||||
|
import 'core-js/modules/es.array.push';
|
||||||
|
import 'core-js/modules/es.array.reduce';
|
||||||
|
import 'core-js/modules/es.array.reduce-right';
|
||||||
|
import 'core-js/modules/es.array.reverse';
|
||||||
|
import 'core-js/modules/es.array.slice';
|
||||||
|
import 'core-js/modules/es.array.some';
|
||||||
|
import 'core-js/modules/es.array.sort';
|
||||||
|
import 'core-js/modules/es.array.species';
|
||||||
|
import 'core-js/modules/es.array.splice';
|
||||||
|
import 'core-js/modules/es.array.to-reversed';
|
||||||
|
import 'core-js/modules/es.array.to-sorted';
|
||||||
|
import 'core-js/modules/es.array.to-spliced';
|
||||||
|
import 'core-js/modules/es.array.unscopables.flat';
|
||||||
|
import 'core-js/modules/es.array.unscopables.flat-map';
|
||||||
|
import 'core-js/modules/es.array.unshift';
|
||||||
|
import 'core-js/modules/es.array.with';
|
||||||
|
import 'core-js/modules/es.array-buffer.constructor';
|
||||||
|
import 'core-js/modules/es.array-buffer.is-view';
|
||||||
|
import 'core-js/modules/es.array-buffer.slice';
|
||||||
|
import 'core-js/modules/es.data-view';
|
||||||
|
import 'core-js/modules/es.date.get-year';
|
||||||
|
import 'core-js/modules/es.date.now';
|
||||||
|
import 'core-js/modules/es.date.set-year';
|
||||||
|
import 'core-js/modules/es.date.to-gmt-string';
|
||||||
|
import 'core-js/modules/es.date.to-iso-string';
|
||||||
|
import 'core-js/modules/es.date.to-json';
|
||||||
|
import 'core-js/modules/es.date.to-primitive';
|
||||||
|
import 'core-js/modules/es.date.to-string';
|
||||||
|
import 'core-js/modules/es.escape';
|
||||||
|
import 'core-js/modules/es.function.bind';
|
||||||
|
import 'core-js/modules/es.function.has-instance';
|
||||||
|
import 'core-js/modules/es.function.name';
|
||||||
|
import 'core-js/modules/es.global-this';
|
||||||
|
import 'core-js/modules/es.json.stringify';
|
||||||
|
import 'core-js/modules/es.json.to-string-tag';
|
||||||
|
import 'core-js/modules/es.map';
|
||||||
|
import 'core-js/modules/es.math.acosh';
|
||||||
|
import 'core-js/modules/es.math.asinh';
|
||||||
|
import 'core-js/modules/es.math.atanh';
|
||||||
|
import 'core-js/modules/es.math.cbrt';
|
||||||
|
import 'core-js/modules/es.math.clz32';
|
||||||
|
import 'core-js/modules/es.math.cosh';
|
||||||
|
import 'core-js/modules/es.math.expm1';
|
||||||
|
import 'core-js/modules/es.math.fround';
|
||||||
|
import 'core-js/modules/es.math.hypot';
|
||||||
|
import 'core-js/modules/es.math.imul';
|
||||||
|
import 'core-js/modules/es.math.log10';
|
||||||
|
import 'core-js/modules/es.math.log1p';
|
||||||
|
import 'core-js/modules/es.math.log2';
|
||||||
|
import 'core-js/modules/es.math.sign';
|
||||||
|
import 'core-js/modules/es.math.sinh';
|
||||||
|
import 'core-js/modules/es.math.tanh';
|
||||||
|
import 'core-js/modules/es.math.to-string-tag';
|
||||||
|
import 'core-js/modules/es.math.trunc';
|
||||||
|
import 'core-js/modules/es.number.constructor';
|
||||||
|
import 'core-js/modules/es.number.epsilon';
|
||||||
|
import 'core-js/modules/es.number.is-finite';
|
||||||
|
import 'core-js/modules/es.number.is-integer';
|
||||||
|
import 'core-js/modules/es.number.is-nan';
|
||||||
|
import 'core-js/modules/es.number.is-safe-integer';
|
||||||
|
import 'core-js/modules/es.number.max-safe-integer';
|
||||||
|
import 'core-js/modules/es.number.min-safe-integer';
|
||||||
|
import 'core-js/modules/es.number.parse-float';
|
||||||
|
import 'core-js/modules/es.number.parse-int';
|
||||||
|
import 'core-js/modules/es.number.to-exponential';
|
||||||
|
import 'core-js/modules/es.number.to-fixed';
|
||||||
|
import 'core-js/modules/es.number.to-precision';
|
||||||
|
import 'core-js/modules/es.object.assign';
|
||||||
|
import 'core-js/modules/es.object.create';
|
||||||
|
import 'core-js/modules/es.object.define-getter';
|
||||||
|
import 'core-js/modules/es.object.define-properties';
|
||||||
|
import 'core-js/modules/es.object.define-property';
|
||||||
|
import 'core-js/modules/es.object.define-setter';
|
||||||
|
import 'core-js/modules/es.object.entries';
|
||||||
|
import 'core-js/modules/es.object.freeze';
|
||||||
|
import 'core-js/modules/es.object.from-entries';
|
||||||
|
import 'core-js/modules/es.object.get-own-property-descriptor';
|
||||||
|
import 'core-js/modules/es.object.get-own-property-descriptors';
|
||||||
|
import 'core-js/modules/es.object.get-own-property-names';
|
||||||
|
import 'core-js/modules/es.object.get-prototype-of';
|
||||||
|
import 'core-js/modules/es.object.has-own';
|
||||||
|
import 'core-js/modules/es.object.is';
|
||||||
|
import 'core-js/modules/es.object.is-extensible';
|
||||||
|
import 'core-js/modules/es.object.is-frozen';
|
||||||
|
import 'core-js/modules/es.object.is-sealed';
|
||||||
|
import 'core-js/modules/es.object.keys';
|
||||||
|
import 'core-js/modules/es.object.lookup-getter';
|
||||||
|
import 'core-js/modules/es.object.lookup-setter';
|
||||||
|
import 'core-js/modules/es.object.prevent-extensions';
|
||||||
|
import 'core-js/modules/es.object.proto';
|
||||||
|
import 'core-js/modules/es.object.seal';
|
||||||
|
import 'core-js/modules/es.object.values';
|
||||||
|
import 'core-js/modules/es.parse-float';
|
||||||
|
import 'core-js/modules/es.parse-int';
|
||||||
|
import 'core-js/modules/es.promise';
|
||||||
|
import 'core-js/modules/es.promise.all-settled';
|
||||||
|
import 'core-js/modules/es.promise.any';
|
||||||
|
import 'core-js/modules/es.promise.finally';
|
||||||
|
import 'core-js/modules/es.reflect.apply';
|
||||||
|
import 'core-js/modules/es.reflect.construct';
|
||||||
|
import 'core-js/modules/es.reflect.define-property';
|
||||||
|
import 'core-js/modules/es.reflect.delete-property';
|
||||||
|
import 'core-js/modules/es.reflect.get';
|
||||||
|
import 'core-js/modules/es.reflect.get-own-property-descriptor';
|
||||||
|
import 'core-js/modules/es.reflect.get-prototype-of';
|
||||||
|
import 'core-js/modules/es.reflect.has';
|
||||||
|
import 'core-js/modules/es.reflect.is-extensible';
|
||||||
|
import 'core-js/modules/es.reflect.own-keys';
|
||||||
|
import 'core-js/modules/es.reflect.prevent-extensions';
|
||||||
|
import 'core-js/modules/es.reflect.set';
|
||||||
|
import 'core-js/modules/es.reflect.set-prototype-of';
|
||||||
|
import 'core-js/modules/es.reflect.to-string-tag';
|
||||||
|
import 'core-js/modules/es.regexp.constructor';
|
||||||
|
import 'core-js/modules/es.regexp.dot-all';
|
||||||
|
import 'core-js/modules/es.regexp.exec';
|
||||||
|
import 'core-js/modules/es.regexp.flags';
|
||||||
|
import 'core-js/modules/es.regexp.sticky';
|
||||||
|
import 'core-js/modules/es.regexp.test';
|
||||||
|
import 'core-js/modules/es.regexp.to-string';
|
||||||
|
import 'core-js/modules/es.set';
|
||||||
|
import 'core-js/modules/es.string.at-alternative';
|
||||||
|
import 'core-js/modules/es.string.code-point-at';
|
||||||
|
import 'core-js/modules/es.string.ends-with';
|
||||||
|
import 'core-js/modules/es.string.from-code-point';
|
||||||
|
import 'core-js/modules/es.string.includes';
|
||||||
|
import 'core-js/modules/es.string.is-well-formed';
|
||||||
|
import 'core-js/modules/es.string.iterator';
|
||||||
|
import 'core-js/modules/es.string.match';
|
||||||
|
import 'core-js/modules/es.string.match-all';
|
||||||
|
import 'core-js/modules/es.string.pad-end';
|
||||||
|
import 'core-js/modules/es.string.pad-start';
|
||||||
|
import 'core-js/modules/es.string.raw';
|
||||||
|
import 'core-js/modules/es.string.repeat';
|
||||||
|
import 'core-js/modules/es.string.replace';
|
||||||
|
import 'core-js/modules/es.string.replace-all';
|
||||||
|
import 'core-js/modules/es.string.search';
|
||||||
|
import 'core-js/modules/es.string.split';
|
||||||
|
import 'core-js/modules/es.string.starts-with';
|
||||||
|
import 'core-js/modules/es.string.substr';
|
||||||
|
import 'core-js/modules/es.string.to-well-formed';
|
||||||
|
import 'core-js/modules/es.string.trim';
|
||||||
|
import 'core-js/modules/es.string.trim-end';
|
||||||
|
import 'core-js/modules/es.string.trim-start';
|
||||||
|
import 'core-js/modules/es.string.anchor';
|
||||||
|
import 'core-js/modules/es.string.big';
|
||||||
|
import 'core-js/modules/es.string.blink';
|
||||||
|
import 'core-js/modules/es.string.bold';
|
||||||
|
import 'core-js/modules/es.string.fixed';
|
||||||
|
import 'core-js/modules/es.string.fontcolor';
|
||||||
|
import 'core-js/modules/es.string.fontsize';
|
||||||
|
import 'core-js/modules/es.string.italics';
|
||||||
|
import 'core-js/modules/es.string.link';
|
||||||
|
import 'core-js/modules/es.string.small';
|
||||||
|
import 'core-js/modules/es.string.strike';
|
||||||
|
import 'core-js/modules/es.string.sub';
|
||||||
|
import 'core-js/modules/es.string.sup';
|
||||||
|
import 'core-js/modules/es.typed-array.float32-array';
|
||||||
|
import 'core-js/modules/es.typed-array.float64-array';
|
||||||
|
import 'core-js/modules/es.typed-array.int8-array';
|
||||||
|
import 'core-js/modules/es.typed-array.int16-array';
|
||||||
|
import 'core-js/modules/es.typed-array.int32-array';
|
||||||
|
import 'core-js/modules/es.typed-array.uint8-array';
|
||||||
|
import 'core-js/modules/es.typed-array.uint8-clamped-array';
|
||||||
|
import 'core-js/modules/es.typed-array.uint16-array';
|
||||||
|
import 'core-js/modules/es.typed-array.uint32-array';
|
||||||
|
import 'core-js/modules/es.typed-array.at';
|
||||||
|
import 'core-js/modules/es.typed-array.copy-within';
|
||||||
|
import 'core-js/modules/es.typed-array.every';
|
||||||
|
import 'core-js/modules/es.typed-array.fill';
|
||||||
|
import 'core-js/modules/es.typed-array.filter';
|
||||||
|
import 'core-js/modules/es.typed-array.find';
|
||||||
|
import 'core-js/modules/es.typed-array.find-index';
|
||||||
|
import 'core-js/modules/es.typed-array.find-last';
|
||||||
|
import 'core-js/modules/es.typed-array.find-last-index';
|
||||||
|
import 'core-js/modules/es.typed-array.for-each';
|
||||||
|
import 'core-js/modules/es.typed-array.from';
|
||||||
|
import 'core-js/modules/es.typed-array.includes';
|
||||||
|
import 'core-js/modules/es.typed-array.index-of';
|
||||||
|
import 'core-js/modules/es.typed-array.iterator';
|
||||||
|
import 'core-js/modules/es.typed-array.join';
|
||||||
|
import 'core-js/modules/es.typed-array.last-index-of';
|
||||||
|
import 'core-js/modules/es.typed-array.map';
|
||||||
|
import 'core-js/modules/es.typed-array.of';
|
||||||
|
import 'core-js/modules/es.typed-array.reduce';
|
||||||
|
import 'core-js/modules/es.typed-array.reduce-right';
|
||||||
|
import 'core-js/modules/es.typed-array.reverse';
|
||||||
|
import 'core-js/modules/es.typed-array.set';
|
||||||
|
import 'core-js/modules/es.typed-array.slice';
|
||||||
|
import 'core-js/modules/es.typed-array.some';
|
||||||
|
import 'core-js/modules/es.typed-array.sort';
|
||||||
|
import 'core-js/modules/es.typed-array.subarray';
|
||||||
|
import 'core-js/modules/es.typed-array.to-locale-string';
|
||||||
|
import 'core-js/modules/es.typed-array.to-reversed';
|
||||||
|
import 'core-js/modules/es.typed-array.to-sorted';
|
||||||
|
import 'core-js/modules/es.typed-array.to-string';
|
||||||
|
import 'core-js/modules/es.typed-array.with';
|
||||||
|
import 'core-js/modules/es.unescape';
|
||||||
|
import 'core-js/modules/es.weak-map';
|
||||||
|
import 'core-js/modules/es.weak-set';
|
||||||
|
|
||||||
|
module.exports = require('core-js/internals/path');
|
||||||
@@ -7,11 +7,12 @@ console.i18n("ms.polyfill.initialize")
|
|||||||
import './openjdk-nashorn-shim'
|
import './openjdk-nashorn-shim'
|
||||||
import './es5-ext'
|
import './es5-ext'
|
||||||
import './node-shim'
|
import './node-shim'
|
||||||
import 'core-js'
|
import './core-js'
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
process.on('exit', () => require.disable())
|
process.on('exit', () => require.disable())
|
||||||
global.setGlobal('Proxy', require('./proxy').Proxy)
|
global.setGlobal('Proxy', require('./proxy').Proxy)
|
||||||
global.setGlobal('XMLHttpRequest', require('./xml-http-request').XMLHttpRequest)
|
global.setGlobal('XMLHttpRequest', require('./xml-http-request').XMLHttpRequest)
|
||||||
|
global.setGlobal('Buffer', require('./buffer').Buffer)
|
||||||
global.setGlobal('Blob', require('blob-polyfill').Blob)
|
global.setGlobal('Blob', require('blob-polyfill').Blob)
|
||||||
console.i18n("ms.polyfill.completed", { time: (new Date().getTime() - polyfillStartTime) / 1000 })
|
console.i18n("ms.polyfill.completed", { time: (new Date().getTime() - polyfillStartTime) / 1000 })
|
||||||
export default true
|
export default true
|
||||||
|
|||||||
@@ -45,11 +45,13 @@ class Process extends EventEmitter {
|
|||||||
execArgv = ''
|
execArgv = ''
|
||||||
execPath = ''
|
execPath = ''
|
||||||
|
|
||||||
|
private queueMicrotaskExecuteTimeout = 5000
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
this.on('exit', () => {
|
this.on('exit', () => {
|
||||||
console.log(`await microTaskPool termination! queueTask: ${microTaskPool.shutdownNow().size()} remainTask: ${threadGroup.activeCount()}`)
|
console.log(`await microTaskPool termination! queueTask: ${microTaskPool.shutdownNow().size()} remainTask: ${threadGroup.activeCount()}`)
|
||||||
microTaskPool.awaitTermination(3000, TimeUnit.MILLISECONDS)
|
microTaskPool.awaitTermination(this.queueMicrotaskExecuteTimeout, TimeUnit.MILLISECONDS)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
on(event: string | symbol, listener: (...args: any[]) => void) {
|
on(event: string | symbol, listener: (...args: any[]) => void) {
|
||||||
@@ -67,7 +69,9 @@ class Process extends EventEmitter {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
nextTick(callback: Function, ...args: any[]): void {
|
nextTick(callback: Function, ...args: any[]): void {
|
||||||
microTaskPool.execute(() => {
|
try {
|
||||||
|
microTaskPool.submit(new Callable({
|
||||||
|
call: () => {
|
||||||
try {
|
try {
|
||||||
callback(args)
|
callback(args)
|
||||||
} catch (origin: any) {
|
} catch (origin: any) {
|
||||||
@@ -78,7 +82,17 @@ class Process extends EventEmitter {
|
|||||||
console.ex(error)
|
console.ex(error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
})).get(this.queueMicrotaskExecuteTimeout, TimeUnit.MILLISECONDS)
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error instanceof InterruptedException) {
|
||||||
|
return console.warn(`FixedThreadPool isInterrupted exit! Task ${callback.name || '<anonymous>'} exec exit!`)
|
||||||
|
}
|
||||||
|
if (error instanceof TimeoutException) {
|
||||||
|
return console.warn(`Task ${callback.name || '<anonymous>'} => ${callback} exec time greater than ${this.queueMicrotaskExecuteTimeout}ms!`)
|
||||||
|
}
|
||||||
|
throw error.getCause && error.getCause() || error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
exit(code: number) {
|
exit(code: number) {
|
||||||
console.log(`process exit by code ${code}!`)
|
console.log(`process exit by code ${code}!`)
|
||||||
@@ -120,12 +134,10 @@ class Process extends EventEmitter {
|
|||||||
throw new Error('MiaoScript unsupport kill.')
|
throw new Error('MiaoScript unsupport kill.')
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
toString() {
|
|
||||||
return "[object process]"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class EventLoop {
|
class EventLoop {
|
||||||
|
private threadCount = new AtomicInteger(0)
|
||||||
private eventLoopMainThread = undefined
|
private eventLoopMainThread = undefined
|
||||||
private eventLoopTaskQueue = new DelayQueue()
|
private eventLoopTaskQueue = new DelayQueue()
|
||||||
private taskExecuteTimeout = 3000
|
private taskExecuteTimeout = 3000
|
||||||
@@ -134,10 +146,10 @@ class EventLoop {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.taskExecuteTimeout = parseInt(process.env.MS_TASK_EXECUTE_TIMEOUT) || 3000
|
this.taskExecuteTimeout = parseInt(process.env.MS_TASK_EXECUTE_TIMEOUT) || 3000
|
||||||
this.fixedThreadPool = new ThreadPoolExecutor(
|
this.fixedThreadPool = new ThreadPoolExecutor(
|
||||||
1, 1, 0, TimeUnit.SECONDS,
|
8, 16, 0, TimeUnit.SECONDS,
|
||||||
new LinkedBlockingQueue(1024),
|
new LinkedBlockingQueue(1024),
|
||||||
new ThreadFactory((run: any) => {
|
new ThreadFactory((run: any) => {
|
||||||
let thread = new Thread(run, "@ccms/event-loop")
|
let thread = new Thread(run, "@ccms/event-loop-" + this.threadCount.incrementAndGet())
|
||||||
thread.setDaemon(true)
|
thread.setDaemon(true)
|
||||||
return thread
|
return thread
|
||||||
}))
|
}))
|
||||||
@@ -173,7 +185,7 @@ class EventLoop {
|
|||||||
this.eventLoopMainThread.interrupt()
|
this.eventLoopMainThread.interrupt()
|
||||||
this.fixedThreadPool.shutdownNow()
|
this.fixedThreadPool.shutdownNow()
|
||||||
console.log(`await fixedThreadPool termination!`)
|
console.log(`await fixedThreadPool termination!`)
|
||||||
this.fixedThreadPool.awaitTermination(3000, TimeUnit.MILLISECONDS)
|
this.fixedThreadPool.awaitTermination(this.taskExecuteTimeout, TimeUnit.MILLISECONDS)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,7 +210,7 @@ class EventLoop {
|
|||||||
try {
|
try {
|
||||||
callback.apply(undefined, args)
|
callback.apply(undefined, args)
|
||||||
} catch (cause: any) {
|
} catch (cause: any) {
|
||||||
cause = cause.getCause && cause.getCause() || cause
|
cause = cause.getCause ? cause.getCause() : cause
|
||||||
try {
|
try {
|
||||||
process.emit('error', cause)
|
process.emit('error', cause)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -213,7 +225,7 @@ class EventLoop {
|
|||||||
return console.warn(`FixedThreadPool isInterrupted exit! Task ${name} exec exit!`)
|
return console.warn(`FixedThreadPool isInterrupted exit! Task ${name} exec exit!`)
|
||||||
}
|
}
|
||||||
if (error instanceof TimeoutException) {
|
if (error instanceof TimeoutException) {
|
||||||
return console.warn(`Task ${name} => ${callback} exec time greater than ${this.taskExecuteTimeout}s!`)
|
return console.warn(`Task ${name} => ${callback} exec time greater than ${this.taskExecuteTimeout}ms!`)
|
||||||
}
|
}
|
||||||
throw error.getCause && error.getCause() || error
|
throw error.getCause && error.getCause() || error
|
||||||
}
|
}
|
||||||
@@ -260,7 +272,7 @@ class EventLoop {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
global.setGlobal('process', new Process(), {})
|
global.setGlobal('process', new Process(), {})
|
||||||
Object.defineProperty(process, require('core-js/es/symbol/to-string-tag'), { value: '[object process]' })
|
Object.defineProperty(process, require('core-js/es/symbol/to-string-tag'), { value: 'process' })
|
||||||
const eventLoop = new EventLoop()
|
const eventLoop = new EventLoop()
|
||||||
Object.defineProperty(process, 'eventLoop', { value: eventLoop })
|
Object.defineProperty(process, 'eventLoop', { value: eventLoop })
|
||||||
eventLoop.startEventLoop()
|
eventLoop.startEventLoop()
|
||||||
|
|||||||
@@ -68,13 +68,14 @@ type EventType =
|
|||||||
| 'timeout'
|
| 'timeout'
|
||||||
| 'loadend'
|
| 'loadend'
|
||||||
| 'loadstart'
|
| 'loadstart'
|
||||||
type HttpHeader = { [key: string]: string }
|
type RequestHttpHeader = { [key: string]: string }
|
||||||
|
type HttpHeader = { [key: string]: string[] }
|
||||||
|
|
||||||
const executor = Executors.newCachedThreadPool()
|
const executor = Executors.newCachedThreadPool()
|
||||||
|
|
||||||
export class XMLHttpRequest {
|
export class XMLHttpRequest {
|
||||||
private _timeout: number = 120000;
|
private _connectTimeout: number = 5000;
|
||||||
|
private _readTimeout: number = 120000;
|
||||||
private _responseType: ResponseType = 'text';
|
private _responseType: ResponseType = 'text';
|
||||||
private _withCredentials: boolean
|
private _withCredentials: boolean
|
||||||
|
|
||||||
@@ -84,7 +85,7 @@ export class XMLHttpRequest {
|
|||||||
private _url: string
|
private _url: string
|
||||||
private _async: boolean
|
private _async: boolean
|
||||||
private _mimeType: string
|
private _mimeType: string
|
||||||
private _requestHeaders: HttpHeader = {};
|
private _requestHeaders: RequestHttpHeader = {};
|
||||||
|
|
||||||
private _status: number = 0;
|
private _status: number = 0;
|
||||||
private _statusText: string = null;
|
private _statusText: string = null;
|
||||||
@@ -96,10 +97,22 @@ export class XMLHttpRequest {
|
|||||||
private _connection = null;
|
private _connection = null;
|
||||||
|
|
||||||
get timeout() {
|
get timeout() {
|
||||||
return this._timeout
|
return this._readTimeout
|
||||||
}
|
}
|
||||||
set timeout(timeout: number) {
|
set timeout(timeout: number) {
|
||||||
this._timeout = timeout
|
this._readTimeout = timeout
|
||||||
|
}
|
||||||
|
get connectTimeout() {
|
||||||
|
return this._connectTimeout
|
||||||
|
}
|
||||||
|
set connectTimeout(timeout: number) {
|
||||||
|
this._connectTimeout = timeout
|
||||||
|
}
|
||||||
|
get readTimeout() {
|
||||||
|
return this._readTimeout
|
||||||
|
}
|
||||||
|
set readTimeout(timeout: number) {
|
||||||
|
this._readTimeout = timeout
|
||||||
}
|
}
|
||||||
get readyState() {
|
get readyState() {
|
||||||
return this._readyState
|
return this._readyState
|
||||||
@@ -143,7 +156,7 @@ export class XMLHttpRequest {
|
|||||||
this._requestHeaders[key] = val
|
this._requestHeaders[key] = val
|
||||||
}
|
}
|
||||||
getResponseHeader(key: string): string {
|
getResponseHeader(key: string): string {
|
||||||
return this._responseHeaders[key]
|
return this._responseHeaders[key]?.[0]
|
||||||
}
|
}
|
||||||
getAllResponseHeaders(): any {
|
getAllResponseHeaders(): any {
|
||||||
return this._responseHeaders
|
return this._responseHeaders
|
||||||
@@ -169,8 +182,8 @@ export class XMLHttpRequest {
|
|||||||
this._connection.setRequestMethod(this._method)
|
this._connection.setRequestMethod(this._method)
|
||||||
this._connection.setDoOutput(true)
|
this._connection.setDoOutput(true)
|
||||||
this._connection.setDoInput(true)
|
this._connection.setDoInput(true)
|
||||||
this._connection.setConnectTimeout(this._timeout)
|
this._connection.setConnectTimeout(this._connectTimeout)
|
||||||
this._connection.setReadTimeout(this._timeout)
|
this._connection.setReadTimeout(this._readTimeout)
|
||||||
|
|
||||||
this.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
|
this.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
|
||||||
this.setReadyState(ReadyState.OPENED)
|
this.setReadyState(ReadyState.OPENED)
|
||||||
@@ -181,7 +194,7 @@ export class XMLHttpRequest {
|
|||||||
}
|
}
|
||||||
if (this._readyState !== ReadyState.OPENED) { throw new Error(`Error Status ${this._readyState}!`) }
|
if (this._readyState !== ReadyState.OPENED) { throw new Error(`Error Status ${this._readyState}!`) }
|
||||||
let future = executor.submit(new Callable({ call: () => this._send(body) }))
|
let future = executor.submit(new Callable({ call: () => this._send(body) }))
|
||||||
if (!this._async) { future.get(this._timeout, TimeUnit.MILLISECONDS) }
|
if (!this._async) { future.get(this._connectTimeout + this._readTimeout + 100, TimeUnit.MILLISECONDS) }
|
||||||
return future
|
return future
|
||||||
}
|
}
|
||||||
get() {
|
get() {
|
||||||
@@ -199,22 +212,23 @@ export class XMLHttpRequest {
|
|||||||
}
|
}
|
||||||
abort() {
|
abort() {
|
||||||
this._connection.disconnect()
|
this._connection.disconnect()
|
||||||
this.onabort && this.onabort()
|
this.onabort?.()
|
||||||
}
|
}
|
||||||
|
|
||||||
private _send(body?: string | object) {
|
private _send(body?: string | object) {
|
||||||
try {
|
try {
|
||||||
this._connection.connect()
|
this._connection.connect()
|
||||||
this.onloadstart && this.onloadstart()
|
this.onloadstart?.()
|
||||||
if (body) {
|
if (body) {
|
||||||
let bodyType = Object.prototype.toString.call(body)
|
let bodyType = Object.prototype.toString.call(body)
|
||||||
if (typeof body !== "string") { throw new Error(`body(${bodyType}) must be string!`) }
|
if (typeof body !== "string") { throw new Error(`body(${bodyType}) must be string.`) }
|
||||||
var out = this._connection.getOutputStream()
|
var out = this._connection.getOutputStream()
|
||||||
out.write(new JavaString(body).getBytes(UTF_8))
|
out.write(new JavaString(body).getBytes(UTF_8))
|
||||||
out.flush()
|
out.flush()
|
||||||
out.close()
|
out.close()
|
||||||
}
|
}
|
||||||
this.setReadyState(ReadyState.LOADING)
|
this.setReadyState(ReadyState.LOADING)
|
||||||
|
this.onload?.()
|
||||||
this._status = this._connection.getResponseCode()
|
this._status = this._connection.getResponseCode()
|
||||||
this._statusText = this._connection.getResponseMessage()
|
this._statusText = this._connection.getResponseMessage()
|
||||||
if (this._status >= 0 && this._status < 300) {
|
if (this._status >= 0 && this._status < 300) {
|
||||||
@@ -224,8 +238,8 @@ export class XMLHttpRequest {
|
|||||||
} else {
|
} else {
|
||||||
this._responseText = this.readOutput(this._connection.getErrorStream())
|
this._responseText = this.readOutput(this._connection.getErrorStream())
|
||||||
}
|
}
|
||||||
this.setResponseHeaders(this._connection.getHeaderFields())
|
this.setResponseHeaders()
|
||||||
this.onloadend && this.onloadend()
|
this.onloadend?.()
|
||||||
} catch (ex: any) {
|
} catch (ex: any) {
|
||||||
if (ex instanceof SocketTimeoutException && this.ontimeout) {
|
if (ex instanceof SocketTimeoutException && this.ontimeout) {
|
||||||
return this.ontimeout(ex)
|
return this.ontimeout(ex)
|
||||||
@@ -239,15 +253,15 @@ export class XMLHttpRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private setResponseHeaders(header: any) {
|
private setResponseHeaders() {
|
||||||
header.forEach((key: string | number, value: string | any[]) => {
|
this._connection.getHeaderFields().forEach((key: string | number, value: any[]) => {
|
||||||
this._responseHeaders[key + ''] = value[value.length - 1] + ''
|
this._responseHeaders[key + ''] = Java.from(value)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private setReadyState(state: ReadyState) {
|
private setReadyState(state: ReadyState) {
|
||||||
this._readyState = state
|
this._readyState = state
|
||||||
this.onreadystatechange && this.onreadystatechange()
|
this.onreadystatechange?.()
|
||||||
}
|
}
|
||||||
|
|
||||||
private readOutput(input: any) {
|
private readOutput(input: any) {
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
../../.npmignore
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ccms/protocol",
|
"name": "@ccms/protocol",
|
||||||
"version": "0.23.0",
|
"version": "0.28.0-beta.8",
|
||||||
"description": "MiaoScript protocol package",
|
"description": "MiaoScript protocol package",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"miaoscript",
|
"miaoscript",
|
||||||
@@ -13,15 +13,15 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"types": "dist/index.d.ts",
|
"types": "dist/index.d.ts",
|
||||||
|
"files": [
|
||||||
|
"dist/**/*.js",
|
||||||
|
"dist/**/*.ts",
|
||||||
|
"dist/**/*.map"
|
||||||
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"clean": "rimraf dist",
|
"clean": "rimraf dist",
|
||||||
"watch": "tsc --watch",
|
"watch": "tsc --watch",
|
||||||
"build": "yarn clean && tsc",
|
"build": "pnpm clean && tsc",
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1"
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"reflect-metadata": "^0.1.13",
|
|
||||||
"rimraf": "^3.0.2",
|
|
||||||
"typescript": "^4.6.3"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user