Compare commits

...

7 Commits

Author SHA1 Message Date
MiaoWoo d4da57d7aa v0.27.4 2023-07-19 17:19:56 +08:00
MiaoWoo 3f1de332fd feat: optimze plugin system 2023-07-19 17:16:50 +08:00
MiaoWoo 25a8f35f28 v0.27.3-beta.0 2023-02-24 22:54:57 +08:00
MiaoWoo fc31824aa4 v0.27.2-beta.0 2023-02-20 17:10:50 +08:00
MiaoWoo bb154474b1 v0.27.1-beta.0 2023-02-18 17:33:51 +08:00
MiaoWoo a5d831aa0b v0.27.0 2023-02-18 16:46:44 +08:00
MiaoWoo e61b0aeb17 v0.27.0-beta.0 2023-02-18 16:12:50 +08:00
39 changed files with 6034 additions and 131 deletions

3
.gitignore vendored
View File

@ -1,8 +1,9 @@
.rollup.cache
.yarn*
.vscode .vscode
.theia .theia
node_modules node_modules
dist dist
package-lock.json package-lock.json
yarn.lock
packages/nashorn/docs packages/nashorn/docs
!packages/types/dist !packages/types/dist

View File

@ -23,3 +23,4 @@ wallaby.js
type_definitions type_definitions
tsconfig.tsbuildinfo tsconfig.tsbuildinfo
*.tsbuildinfo *.tsbuildinfo
.rollup.cache

View File

@ -1,16 +1,15 @@
{ {
"version": "0.26.0", "version": "0.27.4",
"useWorkspaces": true, "npmClient": "yarn",
"npmClient": "yarn", "packages": [
"packages": [ "packages/*"
"packages/*" ],
], "command": {
"command": { "run": {
"run": { "stream": true
"stream": true
}
},
"publishConfig": {
"access": "public"
} }
},
"publishConfig": {
"access": "public"
}
} }

View File

@ -10,18 +10,19 @@
"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": "yarn upgrade-interactive",
"np": "./script/push.sh", "np": "./script/push.sh",
"lsp": "npm login -scope=@ccms", "lsp": "npm login -scope=@ccms",
"lp": "lerna publish --verify-access --force-publish", "lp": "lerna publish --verify-access --force-publish",
"lpb": "lerna publish --preid beta --dist-tag beta --verify-access --force-publish", "lpb": "lerna publish --preid beta --dist-tag beta --verify-access --force-publish",
"lpc": "lerna publish --canary --preid beta --pre-dist-tag beta --verify-access --force-publish", "lpc": "lerna publish --canary --preid beta --pre-dist-tag beta --verify-access --force-publish",
"lpf": "lerna publish from-package --yes" "lpf": "lerna publish from-package --yes",
"sync": "./script/sync.sh"
}, },
"workspaces": [ "workspaces": [
"packages/*" "packages/*"
], ],
"devDependencies": { "devDependencies": {
"lerna": "^6.4.1" "lerna": "^7.1.4"
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/amqp", "name": "@ccms/amqp",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript amqp package", "description": "MiaoScript amqp package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -19,12 +19,12 @@
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.26.0", "@ccms/api": "^0.27.4",
"@ccms/common": "^0.26.0", "@ccms/common": "^0.27.4",
"@ccms/container": "^0.26.0" "@ccms/container": "^0.27.4"
}, },
"devDependencies": { "devDependencies": {
"@ccms/nashorn": "^0.26.0", "@ccms/nashorn": "^0.27.4",
"@javatypes/amqp-client": "^0.0.3", "@javatypes/amqp-client": "^0.0.3",
"@javatypes/spring-amqp": "^0.0.3", "@javatypes/spring-amqp": "^0.0.3",
"@javatypes/spring-rabbit": "^0.0.3", "@javatypes/spring-rabbit": "^0.0.3",

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/api", "name": "@ccms/api",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript api package", "description": "MiaoScript api package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -19,9 +19,9 @@
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"dependencies": { "dependencies": {
"@ccms/common": "^0.26.0", "@ccms/common": "^0.27.4",
"@ccms/container": "^0.26.0", "@ccms/container": "^0.27.4",
"@ccms/polyfill": "^0.26.0", "@ccms/polyfill": "^0.27.4",
"base64-js": "^1.5.1", "base64-js": "^1.5.1",
"source-map-builder": "^0.0.7" "source-map-builder": "^0.0.7"
}, },

View File

@ -25,7 +25,7 @@ export namespace event {
public EventPriority = EventPriority; public EventPriority = EventPriority;
private mapEvent = []; private mapEvent = [];
private listenerMap = []; private pluginEventMap = [];
private cacheSlowEventKey = {}; private cacheSlowEventKey = {};
protected baseEventDir = ''; protected baseEventDir = '';
@ -140,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.createExecute(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)
@ -159,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,
@ -176,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: () => any) => off()) eventCache.forEach((off: () => any) => off())
delete this.listenerMap[plugin.description.name] delete this.pluginEventMap[plugin.description.name]
} }
} }

View File

@ -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)
}
/** /**
* *
* *
@ -498,10 +504,4 @@ export namespace particle {
} }
} }
} }
@injectable()
export abstract class ParticleSpawner {
abstract spawn(location: any, particle: Particle)
abstract spawnToPlayer(player: any, location: any, particle: Particle)
}
} }

View File

@ -0,0 +1,5 @@
export namespace service {
export class ServiceManager {
}
}

View File

@ -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 {
@ -79,7 +81,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 +90,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,20 +139,35 @@ 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) this.emit('error', error)
console.ex(ex) if (!error.processed) {
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)
}
/** /**
* *
* @param args * @param args

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/bukkit", "name": "@ccms/bukkit",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript bukkit package", "description": "MiaoScript bukkit package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -25,8 +25,8 @@
"typescript": "^4.9.5" "typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.26.0", "@ccms/api": "^0.27.4",
"@ccms/common": "^0.26.0", "@ccms/common": "^0.27.4",
"@ccms/container": "^0.26.0" "@ccms/container": "^0.27.4"
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/bungee", "name": "@ccms/bungee",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript bungee package", "description": "MiaoScript bungee package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -25,8 +25,8 @@
"typescript": "^4.9.5" "typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.26.0", "@ccms/api": "^0.27.4",
"@ccms/common": "^0.26.0", "@ccms/common": "^0.27.4",
"@ccms/container": "^0.26.0" "@ccms/container": "^0.27.4"
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/common", "name": "@ccms/common",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript common package", "description": "MiaoScript common package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -19,7 +19,7 @@
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"devDependencies": { "devDependencies": {
"@ccms/nashorn": "^0.26.0", "@ccms/nashorn": "^0.27.4",
"@javatypes/jdk": "^0.0.3", "@javatypes/jdk": "^0.0.3",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2", "rimraf": "^4.1.2",

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/compile", "name": "@ccms/compile",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript compile package", "description": "MiaoScript compile package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/container", "name": "@ccms/container",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript container package", "description": "MiaoScript container package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -19,7 +19,7 @@
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"devDependencies": { "devDependencies": {
"@ccms/nashorn": "^0.26.0", "@ccms/nashorn": "^0.27.4",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2", "rimraf": "^4.1.2",
"typescript": "^4.9.5" "typescript": "^4.9.5"

View File

@ -154,8 +154,9 @@ 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)
return undefined return undefined
}) })
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/core", "name": "@ccms/core",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript core package", "description": "MiaoScript core package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -24,8 +24,8 @@
"typescript": "^4.9.5" "typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.26.0", "@ccms/api": "^0.27.4",
"@ccms/container": "^0.26.0" "@ccms/container": "^0.27.4"
}, },
"gitHead": "781524f83e52cad26d7c480513e3c525df867121" "gitHead": "781524f83e52cad26d7c480513e3c525df867121"
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/database", "name": "@ccms/database",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript database package", "description": "MiaoScript database package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -25,7 +25,7 @@
"typescript": "^4.9.5" "typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.26.0", "@ccms/api": "^0.27.4",
"@ccms/container": "^0.26.0" "@ccms/container": "^0.27.4"
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/i18n", "name": "@ccms/i18n",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript i18n package", "description": "MiaoScript i18n package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -19,7 +19,7 @@
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"devDependencies": { "devDependencies": {
"@ccms/nashorn": "^0.26.0", "@ccms/nashorn": "^0.27.4",
"@types/js-yaml": "^4.0.5", "@types/js-yaml": "^4.0.5",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2", "rimraf": "^4.1.2",

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/keyvalue", "name": "@ccms/keyvalue",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript keyvalue package", "description": "MiaoScript keyvalue package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -19,12 +19,12 @@
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.26.0", "@ccms/api": "^0.27.4",
"@ccms/common": "^0.26.0", "@ccms/common": "^0.27.4",
"@ccms/container": "^0.26.0" "@ccms/container": "^0.27.4"
}, },
"devDependencies": { "devDependencies": {
"@ccms/nashorn": "^0.26.0", "@ccms/nashorn": "^0.27.4",
"@javatypes/amqp-client": "^0.0.3", "@javatypes/amqp-client": "^0.0.3",
"@javatypes/spring-amqp": "^0.0.3", "@javatypes/spring-amqp": "^0.0.3",
"@javatypes/spring-rabbit": "^0.0.3", "@javatypes/spring-rabbit": "^0.0.3",

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/molang", "name": "@ccms/molang",
"version": "0.26.0", "version": "0.27.4",
"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",

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/nashorn", "name": "@ccms/nashorn",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript nashorn package", "description": "MiaoScript nashorn package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/nodejs", "name": "@ccms/nodejs",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript nodejs package", "description": "MiaoScript nodejs package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -19,7 +19,7 @@
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"devDependencies": { "devDependencies": {
"@ccms/nashorn": "^0.26.0", "@ccms/nashorn": "^0.27.4",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2", "rimraf": "^4.1.2",
"tslib": "^2.5.0", "tslib": "^2.5.0",

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/nukkit", "name": "@ccms/nukkit",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript nukkit package", "description": "MiaoScript nukkit package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -25,8 +25,8 @@
"typescript": "^4.9.5" "typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.26.0", "@ccms/api": "^0.27.4",
"@ccms/common": "^0.26.0", "@ccms/common": "^0.27.4",
"@ccms/container": "^0.26.0" "@ccms/container": "^0.27.4"
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/plugin", "name": "@ccms/plugin",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript plugin package", "description": "MiaoScript plugin package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -26,10 +26,10 @@
"typescript": "^4.9.5" "typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.26.0", "@ccms/api": "^0.27.4",
"@ccms/common": "^0.26.0", "@ccms/common": "^0.27.4",
"@ccms/container": "^0.26.0", "@ccms/container": "^0.27.4",
"@ccms/i18n": "^0.26.0", "@ccms/i18n": "^0.27.4",
"@ccms/verify": "^0.25.1", "@ccms/verify": "^0.25.1",
"crypto-js": "^4.1.1", "crypto-js": "^4.1.1",
"js-yaml": "^4.1.0" "js-yaml": "^4.1.0"

View File

@ -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") {
@ -82,7 +82,7 @@ export class PluginCommandManager {
} }
} }
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,7 +95,7 @@ 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.debug(`[${pluginInstance.description.name}] command ${cmd.name} is not registry tabCompleter`) } if (!cmdCompleter) { console.debug(`[${pluginInstance.description.name}] command ${cmd.name} is not registry tabCompleter`) }

View File

@ -11,6 +11,8 @@ export class PluginEventManager {
@Autowired() @Autowired()
private nativePluginChecker: server.NativePluginChecker 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))
process.on('plugin.after.disable', this.unregistryListener.bind(this)) process.on('plugin.after.disable', this.unregistryListener.bind(this))
@ -20,8 +22,9 @@ export class PluginEventManager {
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)) {
@ -35,13 +38,25 @@ export class PluginEventManager {
} }
// 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((off: () => any) => off())
}
listener.off = off
} }
private unregistryListener(pluginInstance: plugin.Plugin) { private unregistryListener(pluginInstance: plugin.Plugin, listener: any = pluginInstance) {
this.eventManager.disable(pluginInstance) if (listener && listener.off) {
listener.off()
}
if (pluginInstance) {
this.eventManager.disable(pluginInstance)
}
} }
} }

View File

@ -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,

View File

@ -8,7 +8,7 @@ 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
@ -28,6 +28,11 @@ export namespace interfaces {
return dataFolder.getAbsolutePath() return dataFolder.getAbsolutePath()
} }
public registryCommand(executor: any) { }
public unregistryCommand(executor: any) { }
public registryListener(listener: any) { }
public unregistryListener(listener: any) { }
public load() { } public load() { }
public enable() { } public enable() { }
public disable() { } public disable() { }

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/polyfill", "name": "@ccms/polyfill",
"version": "0.26.0", "version": "0.27.4",
"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",
@ -14,12 +14,12 @@
"test": "echo \"Error: run tests from root\" && exit 1" "test": "echo \"Error: run tests from root\" && exit 1"
}, },
"dependencies": { "dependencies": {
"@ccms/i18n": "^0.26.0", "@ccms/i18n": "^0.27.4",
"@ccms/nodejs": "^0.26.0", "@ccms/nodejs": "^0.27.4",
"core-js": "^3.27.2" "core-js": "^3.27.2"
}, },
"devDependencies": { "devDependencies": {
"@ccms/nashorn": "^0.26.0", "@ccms/nashorn": "^0.27.4",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2", "rimraf": "^4.1.2",
"typescript": "^4.9.5" "typescript": "^4.9.5"

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/protocol", "name": "@ccms/protocol",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript protocol package", "description": "MiaoScript protocol package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/qrcode", "name": "@ccms/qrcode",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript qrcode package", "description": "MiaoScript qrcode package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/sponge", "name": "@ccms/sponge",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript sponge package", "description": "MiaoScript sponge package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -25,8 +25,8 @@
"typescript": "^4.9.5" "typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.26.0", "@ccms/api": "^0.27.4",
"@ccms/common": "^0.26.0", "@ccms/common": "^0.27.4",
"@ccms/container": "^0.26.0" "@ccms/container": "^0.27.4"
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/spring", "name": "@ccms/spring",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript spring package", "description": "MiaoScript spring package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -24,9 +24,9 @@
"typescript": "^4.9.5" "typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.26.0", "@ccms/api": "^0.27.4",
"@ccms/common": "^0.26.0", "@ccms/common": "^0.27.4",
"@ccms/container": "^0.26.0", "@ccms/container": "^0.27.4",
"@ccms/database": "^0.26.0" "@ccms/database": "^0.27.4"
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/web", "name": "@ccms/web",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript web package", "description": "MiaoScript web package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -29,7 +29,7 @@
"typescript": "^4.9.5" "typescript": "^4.9.5"
}, },
"dependencies": { "dependencies": {
"@ccms/api": "^0.26.0", "@ccms/api": "^0.27.4",
"@ccms/container": "^0.26.0" "@ccms/container": "^0.27.4"
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@ccms/websocket", "name": "@ccms/websocket",
"version": "0.26.0", "version": "0.27.4",
"description": "MiaoScript websocket package", "description": "MiaoScript websocket package",
"keywords": [ "keywords": [
"miaoscript", "miaoscript",
@ -24,7 +24,7 @@
"parseuri": "^0.0.6" "parseuri": "^0.0.6"
}, },
"devDependencies": { "devDependencies": {
"@ccms/nashorn": "^0.26.0", "@ccms/nashorn": "^0.27.4",
"@javatypes/tomcat-websocket-api": "^0.0.3", "@javatypes/tomcat-websocket-api": "^0.0.3",
"reflect-metadata": "^0.1.13", "reflect-metadata": "^0.1.13",
"rimraf": "^4.1.2", "rimraf": "^4.1.2",

View File

@ -1,3 +1,5 @@
#!/bin/bash
for package in `ls packages`; do for package in `ls packages`; do
echo $package echo $package
pushd packages/$package pushd packages/$package

3
script/sync.sh Executable file
View File

@ -0,0 +1,3 @@
for PACKAGE in `ls packages`;do
echo "${PACKAGE} $(curl -s "https://registry-direct.npmmirror.com/@ccms/${PACKAGE}/sync?sync_upstream=true" -X 'PUT')"
done

5848
yarn.lock Normal file

File diff suppressed because it is too large Load Diff