feat: add command bean and event bean
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
05bf312076
commit
eb6a2a32db
@ -23,7 +23,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@ms/common": "^0.0.0",
|
||||
"inversify": "^5.0.1"
|
||||
"@ms/container": "^0.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"reflect-metadata": "^0.1.13",
|
||||
|
@ -1,7 +1,9 @@
|
||||
import { PluginInfo } from './typings/plugin';
|
||||
import { injectable } from "@ms/container";
|
||||
|
||||
export namespace command {
|
||||
@injectable()
|
||||
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 });
|
||||
console.debug(`插件 ${plugin.description.name} 创建命令 ${name}(${cmd})...`)
|
||||
if (exec.cmd && typeof exec.cmd === "function") {
|
||||
|
@ -6,11 +6,12 @@ export class MiaoScriptConsole implements Console {
|
||||
Console: NodeJS.ConsoleConstructor;
|
||||
|
||||
private _name: string = '';
|
||||
private logger: any;
|
||||
|
||||
protected logger: any;
|
||||
protected prefix: string = '§6[§bMiaoScript§6]§r ';
|
||||
|
||||
constructor() {
|
||||
constructor(name?: string) {
|
||||
this.name = name;
|
||||
this.logger = global.logger;
|
||||
}
|
||||
|
||||
@ -65,7 +66,8 @@ export class MiaoScriptConsole implements Console {
|
||||
stack.forEach(function(trace) {
|
||||
if (trace.className.startsWith('<')) {
|
||||
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}`)
|
||||
} else {
|
||||
var className = trace.className;
|
||||
|
@ -4,20 +4,21 @@
|
||||
*/
|
||||
import '@ms/core'
|
||||
import '@ms/nashorn'
|
||||
import { injectable } from 'inversify'
|
||||
import { injectable } from '@ms/container'
|
||||
|
||||
const Thread = Java.type("java.lang.Thread");
|
||||
|
||||
export namespace event {
|
||||
@injectable()
|
||||
abstract class EventService {
|
||||
private plugin;
|
||||
export abstract class Event {
|
||||
private mapEvent = [];
|
||||
private listenerMap = [];
|
||||
private baseEventDir = '';
|
||||
|
||||
constructor(baseEventDir: string) {
|
||||
this.baseEventDir = baseEventDir;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫描包 org.bukkit.event 下的所有事件
|
||||
* 映射简写名称 org.bukkit.event.player.PlayerLoginEvent => playerloginevent
|
||||
@ -134,21 +135,16 @@ abstract class EventService {
|
||||
return off;
|
||||
}
|
||||
|
||||
abstract isValidEvent(clazz: any): boolean;
|
||||
abstract register(eventCls: any, exec: Function, priority, ignoreCancel);
|
||||
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];
|
||||
disable(plugin: any) {
|
||||
var eventCache = this.listenerMap[plugin.description.name];
|
||||
if (eventCache) {
|
||||
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'
|
||||
|
||||
export * from './event'
|
||||
export * from './console'
|
||||
export * from './command'
|
||||
export * from './interfaces'
|
||||
export * from './console'
|
||||
|
Loading…
Reference in New Issue
Block a user