feat: add plugin self method
This commit is contained in:
parent
afd3f91a3f
commit
a0866c1085
@ -1,7 +1,5 @@
|
||||
import "@ccms/nashorn"
|
||||
|
||||
export * from './web'
|
||||
export * from './amqp'
|
||||
export * from './chat'
|
||||
export * from './task'
|
||||
export * from './item'
|
||||
|
@ -32,18 +32,28 @@ export const provideSingletonNamed = (identifier: interfaces.ServiceIdentifier<a
|
||||
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
|
||||
* @param className Java全类名
|
||||
*/
|
||||
export const JavaClass = (className: string) => {
|
||||
return function (target: object, propertyKey: string, index?: number) {
|
||||
try { target[propertyKey] = Java.type(className).class; return } catch (error: any) { }
|
||||
try { target[propertyKey] = base.getClass(className); return } catch (error: any) { }
|
||||
console.warn('JavaClass', className, 'Inject target', target.constructor.name, 'propertyKey', propertyKey, 'failed!')
|
||||
_proxyGetter(target, propertyKey, () => {
|
||||
return getJavaClass(className) || 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类
|
||||
* @param className Java 全类名
|
||||
@ -51,9 +61,7 @@ export const JavaClass = (className: string) => {
|
||||
export const JSClass = (className: string) => {
|
||||
return function (target: object, propertyKey: string, index?: number) {
|
||||
_proxyGetter(target, propertyKey, () => {
|
||||
try { return Java.type(className) } catch (error: any) { }
|
||||
try { return base.getClass(className).static } catch (error: any) { }
|
||||
console.warn('JSClass', className, 'Inject target', target.constructor.name, 'propertyKey', propertyKey, 'failed!')
|
||||
return getJSClass(className) || console.warn('JSClass', className, 'Inject target', target.constructor.name, 'propertyKey', propertyKey, 'failed!')
|
||||
}, true)
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ export class PluginEventManager {
|
||||
listener.off = off
|
||||
}
|
||||
|
||||
private unregistryListener(pluginInstance: plugin.Plugin, listener: any = pluginInstance) {
|
||||
public unregistryListener(pluginInstance: plugin.Plugin, listener: any = pluginInstance) {
|
||||
if (listener && listener.off) {
|
||||
listener.off()
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
import { server, MiaoScriptConsole, event, plugin } from "@ccms/api"
|
||||
import { injectable, inject, postConstruct } from "@ccms/container"
|
||||
import { server, MiaoScriptConsole, event, plugin, task, command } from "@ccms/api"
|
||||
import { injectable, inject, postConstruct, Autowired } from "@ccms/container"
|
||||
import { getPluginMetadata } from "./utils"
|
||||
import { PluginEventManager } from "./event"
|
||||
import { PluginCommandManager } from "./command"
|
||||
|
||||
const File = Java.type('java.io.File')
|
||||
|
||||
@ -11,6 +13,12 @@ export namespace interfaces {
|
||||
public logger: MiaoScriptConsole
|
||||
@inject(server.Console)
|
||||
private Console: MiaoScriptConsole
|
||||
@Autowired()
|
||||
private taskManager: task.TaskManager
|
||||
@Autowired()
|
||||
private eventManager: PluginEventManager
|
||||
@Autowired()
|
||||
private commandManager: PluginCommandManager
|
||||
|
||||
constructor() {
|
||||
this.description = getPluginMetadata(this)
|
||||
@ -28,10 +36,42 @@ export namespace interfaces {
|
||||
return dataFolder.getAbsolutePath()
|
||||
}
|
||||
|
||||
public registryCommand(executor: any) { }
|
||||
public unregistryCommand(executor: any) { }
|
||||
public registryListener(listener: any) { }
|
||||
public unregistryListener(listener: any) { }
|
||||
/**
|
||||
* 注册命令
|
||||
* @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 enable() { }
|
||||
|
Loading…
Reference in New Issue
Block a user