feat: add plugin self method
This commit is contained in:
		@@ -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'
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -51,7 +51,7 @@ export class PluginEventManager {
 | 
				
			|||||||
        listener.off = off
 | 
					        listener.off = off
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private unregistryListener(pluginInstance: plugin.Plugin, listener: any = pluginInstance) {
 | 
					    public unregistryListener(pluginInstance: plugin.Plugin, listener: any = pluginInstance) {
 | 
				
			||||||
        if (listener && listener.off) {
 | 
					        if (listener && listener.off) {
 | 
				
			||||||
            listener.off()
 | 
					            listener.off()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -11,6 +13,12 @@ export namespace interfaces {
 | 
				
			|||||||
        public logger: MiaoScriptConsole
 | 
					        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,10 +36,42 @@ export namespace interfaces {
 | 
				
			|||||||
            return dataFolder.getAbsolutePath()
 | 
					            return dataFolder.getAbsolutePath()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        public registryCommand(executor: any) { }
 | 
					        /**
 | 
				
			||||||
        public unregistryCommand(executor: any) { }
 | 
					         * 注册命令
 | 
				
			||||||
        public registryListener(listener: any) { }
 | 
					         * @param executor 命令执行器
 | 
				
			||||||
        public unregistryListener(listener: any) { }
 | 
					         */
 | 
				
			||||||
 | 
					        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() { }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user