feat: add command bean and event bean
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
		@@ -23,7 +23,7 @@
 | 
				
			|||||||
    },
 | 
					    },
 | 
				
			||||||
    "dependencies": {
 | 
					    "dependencies": {
 | 
				
			||||||
        "@ms/common": "^0.0.0",
 | 
					        "@ms/common": "^0.0.0",
 | 
				
			||||||
        "inversify": "^5.0.1"
 | 
					        "@ms/container": "^0.0.0"
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "devDependencies": {
 | 
					    "devDependencies": {
 | 
				
			||||||
        "reflect-metadata": "^0.1.13",
 | 
					        "reflect-metadata": "^0.1.13",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,9 @@
 | 
				
			|||||||
import { PluginInfo } from './typings/plugin';
 | 
					import { injectable } from "@ms/container";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export namespace command {
 | 
					export namespace command {
 | 
				
			||||||
 | 
					    @injectable()
 | 
				
			||||||
    export abstract class Command {
 | 
					    export abstract class Command {
 | 
				
			||||||
        on(plugin: PluginInfo, name: string, exec: { cmd: Function, tab?: Function }) {
 | 
					        on(plugin: any, name: string, exec: { cmd: Function, tab?: Function }) {
 | 
				
			||||||
            var cmd = this.create(plugin, { name: name });
 | 
					            var cmd = this.create(plugin, { name: name });
 | 
				
			||||||
            console.debug(`插件 ${plugin.description.name} 创建命令 ${name}(${cmd})...`)
 | 
					            console.debug(`插件 ${plugin.description.name} 创建命令 ${name}(${cmd})...`)
 | 
				
			||||||
            if (exec.cmd && typeof exec.cmd === "function") {
 | 
					            if (exec.cmd && typeof exec.cmd === "function") {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,11 +6,12 @@ export class MiaoScriptConsole implements Console {
 | 
				
			|||||||
    Console: NodeJS.ConsoleConstructor;
 | 
					    Console: NodeJS.ConsoleConstructor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private _name: string = '';
 | 
					    private _name: string = '';
 | 
				
			||||||
    private logger: any;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    protected logger: any;
 | 
				
			||||||
    protected prefix: string = '§6[§bMiaoScript§6]§r ';
 | 
					    protected prefix: string = '§6[§bMiaoScript§6]§r ';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor() {
 | 
					    constructor(name?: string) {
 | 
				
			||||||
 | 
					        this.name = name;
 | 
				
			||||||
        this.logger = global.logger;
 | 
					        this.logger = global.logger;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -65,7 +66,8 @@ export class MiaoScriptConsole implements Console {
 | 
				
			|||||||
        stack.forEach(function(trace) {
 | 
					        stack.forEach(function(trace) {
 | 
				
			||||||
            if (trace.className.startsWith('<')) {
 | 
					            if (trace.className.startsWith('<')) {
 | 
				
			||||||
                var fileName = trace.fileName
 | 
					                var fileName = trace.fileName
 | 
				
			||||||
                fileName = fileName.indexOf('runtime') > -1 ? fileName.split('runtime')[1] : fileName;
 | 
					                if (fileName.startsWith(root)) { fileName = fileName.split(root)[1] }
 | 
				
			||||||
 | 
					                if (fileName.startsWith('/runtime')) { fileName = fileName.split('/runtime')[1] }
 | 
				
			||||||
                cache.push(`    §e->§c ${fileName} => §4${trace.methodName}:${trace.lineNumber}`)
 | 
					                cache.push(`    §e->§c ${fileName} => §4${trace.methodName}:${trace.lineNumber}`)
 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                var className = trace.className;
 | 
					                var className = trace.className;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -4,20 +4,21 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
import '@ms/core'
 | 
					import '@ms/core'
 | 
				
			||||||
import '@ms/nashorn'
 | 
					import '@ms/nashorn'
 | 
				
			||||||
import { injectable } from 'inversify'
 | 
					import { injectable } from '@ms/container'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const Thread = Java.type("java.lang.Thread");
 | 
					const Thread = Java.type("java.lang.Thread");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@injectable()
 | 
					export namespace event {
 | 
				
			||||||
abstract class EventService {
 | 
					    @injectable()
 | 
				
			||||||
    private plugin;
 | 
					    export abstract class Event {
 | 
				
			||||||
        private mapEvent = [];
 | 
					        private mapEvent = [];
 | 
				
			||||||
        private listenerMap = [];
 | 
					        private listenerMap = [];
 | 
				
			||||||
        private baseEventDir = '';
 | 
					        private baseEventDir = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        constructor(baseEventDir: string) {
 | 
					        constructor(baseEventDir: string) {
 | 
				
			||||||
            this.baseEventDir = baseEventDir;
 | 
					            this.baseEventDir = baseEventDir;
 | 
				
			||||||
 | 
					 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /**
 | 
					        /**
 | 
				
			||||||
         * 扫描包 org.bukkit.event 下的所有事件
 | 
					         * 扫描包 org.bukkit.event 下的所有事件
 | 
				
			||||||
         * 映射简写名称 org.bukkit.event.player.PlayerLoginEvent => playerloginevent
 | 
					         * 映射简写名称 org.bukkit.event.player.PlayerLoginEvent => playerloginevent
 | 
				
			||||||
@@ -134,21 +135,16 @@ abstract class EventService {
 | 
				
			|||||||
            return off;
 | 
					            return off;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    abstract isValidEvent(clazz: any): boolean;
 | 
					        disable(plugin: any) {
 | 
				
			||||||
    abstract register(eventCls: any, exec: Function, priority, ignoreCancel);
 | 
					            var eventCache = this.listenerMap[plugin.description.name];
 | 
				
			||||||
    abstract unregister(event, listener);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
var EventHandler = Object.assign(new EventHandler(), require('event'));
 | 
					 | 
				
			||||||
// 映射事件名称
 | 
					 | 
				
			||||||
console.info(`bukkit 事件映射完毕 共计 ${EventHandler.mapEventName().toFixed(0)} 个事件!`);
 | 
					 | 
				
			||||||
module.exports = {
 | 
					 | 
				
			||||||
    on: EventHandler.listen.bind(EventHandler),
 | 
					 | 
				
			||||||
    disable: function(jsp) {
 | 
					 | 
				
			||||||
        var eventCache = EventHandler.listenerMap[jsp.description.name];
 | 
					 | 
				
			||||||
            if (eventCache) {
 | 
					            if (eventCache) {
 | 
				
			||||||
                eventCache.forEach(t => t.off());
 | 
					                eventCache.forEach(t => t.off());
 | 
				
			||||||
            delete EventHandler.listenerMap[jsp.description.name];
 | 
					                delete this.listenerMap[plugin.description.name];
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
};
 | 
					
 | 
				
			||||||
 | 
					        abstract isValidEvent(clazz: any): boolean;
 | 
				
			||||||
 | 
					        abstract register(eventCls: any, exec: Function, priority: any, ignoreCancel: boolean): any;
 | 
				
			||||||
 | 
					        abstract unregister(event: any, listener: any): void;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,6 @@
 | 
				
			|||||||
import './typings/global'
 | 
					import './typings/global'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export * from './event'
 | 
				
			||||||
 | 
					export * from './console'
 | 
				
			||||||
export * from './command'
 | 
					export * from './command'
 | 
				
			||||||
export * from './interfaces'
 | 
					export * from './interfaces'
 | 
				
			||||||
export * from './console'
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user