@@ -10,14 +10,13 @@ import { getPluginMetadatas, getPluginCommandMetadata, getPluginListenerMetadata
 | 
			
		||||
export function plugin(metadata: interfaces.PluginMetadata) {
 | 
			
		||||
    return function (target: any) {
 | 
			
		||||
        metadata.target = target;
 | 
			
		||||
        metadata.source = metadata.source + '';
 | 
			
		||||
        decorate(injectable(), target);
 | 
			
		||||
        Reflect.defineMetadata(METADATA_KEY.plugin, metadata, target);
 | 
			
		||||
        const previousMetadata: Map<string, interfaces.PluginMetadata> = getPluginMetadatas();
 | 
			
		||||
        previousMetadata.set(metadata.name, metadata);
 | 
			
		||||
        Reflect.defineMetadata(METADATA_KEY.plugin, previousMetadata, Reflect);
 | 
			
		||||
        const previousSources: Map<string, interfaces.PluginMetadata> = getPluginSources();
 | 
			
		||||
        previousSources.set(metadata.source, metadata);
 | 
			
		||||
        previousSources.set(metadata.source.toString(), metadata);
 | 
			
		||||
        Reflect.defineMetadata(METADATA_KEY.souece, previousSources, Reflect);
 | 
			
		||||
    };
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,5 @@
 | 
			
		||||
import { server, MiaoScriptConsole, event } from "@ccms/api";
 | 
			
		||||
import { injectable, inject } from "@ccms/container";
 | 
			
		||||
import { injectable, inject, postConstruct } from "@ccms/container";
 | 
			
		||||
import { getPluginMetadata } from "./utils";
 | 
			
		||||
 | 
			
		||||
export namespace interfaces {
 | 
			
		||||
@@ -7,11 +7,17 @@ export namespace interfaces {
 | 
			
		||||
    export abstract class Plugin {
 | 
			
		||||
        public description: PluginMetadata;
 | 
			
		||||
        public logger: Console;
 | 
			
		||||
        @inject(server.Console)
 | 
			
		||||
        private Console: MiaoScriptConsole;
 | 
			
		||||
 | 
			
		||||
        constructor(@inject(server.Console) Console: MiaoScriptConsole) {
 | 
			
		||||
        constructor() {
 | 
			
		||||
            this.description = getPluginMetadata(this)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        @postConstruct()
 | 
			
		||||
        private initialize() {
 | 
			
		||||
            // @ts-ignore
 | 
			
		||||
            this.logger = new Console(this.description.prefix || this.description.name)
 | 
			
		||||
            this.logger = new this.Console(this.description.prefix || this.description.name)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public load() { }
 | 
			
		||||
 
 | 
			
		||||
@@ -35,7 +35,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
 | 
			
		||||
            this.pluginMap = new Map()
 | 
			
		||||
            console.i18n('ms.plugin.event.map', { count: this.EventManager.mapEventName().toFixed(0), type: this.serverType });
 | 
			
		||||
            this.initialized = true;
 | 
			
		||||
            this.plugnMappings = getPluginSources()
 | 
			
		||||
            this.plugnMappings = getPluginSources();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -62,9 +62,13 @@ export class PluginManagerImpl implements plugin.PluginManager {
 | 
			
		||||
        this.execPluginStage(plugin, stage)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 从文件加载插件
 | 
			
		||||
     * @param file java.io.File
 | 
			
		||||
     */
 | 
			
		||||
    loadFromFile(file: string): interfaces.Plugin {
 | 
			
		||||
        this.loadPlugin(file)
 | 
			
		||||
        let plugin = this.buildPlugin(this.plugnMappings.get(file))
 | 
			
		||||
        let plugin = this.buildPlugin(this.plugnMappings.get(file.toString()))
 | 
			
		||||
        this.load(plugin)
 | 
			
		||||
        this.enable(plugin)
 | 
			
		||||
        return plugin;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,8 @@
 | 
			
		||||
import { interfaces } from './interfaces'
 | 
			
		||||
import { METADATA_KEY } from './constants'
 | 
			
		||||
 | 
			
		||||
const pluginSourceCache = new Map<string, interfaces.PluginMetadata>();
 | 
			
		||||
 | 
			
		||||
function getPlugins() {
 | 
			
		||||
    return [...getPluginMetadatas().values()].map((target) => target.target);
 | 
			
		||||
}
 | 
			
		||||
@@ -13,7 +15,7 @@ function getPluginSources() {
 | 
			
		||||
    let pluginSources: Map<string, interfaces.PluginMetadata> = Reflect.getMetadata(
 | 
			
		||||
        METADATA_KEY.souece,
 | 
			
		||||
        Reflect
 | 
			
		||||
    ) || new Map<string, interfaces.PluginMetadata>();
 | 
			
		||||
    ) || pluginSourceCache;
 | 
			
		||||
    return pluginSources;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user