feat: modify sponge event mapping handle

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2019-09-22 18:01:13 +08:00
parent 38bd2f5187
commit 8f5882ff0a

View File

@ -23,6 +23,7 @@ let priorityMap = {
export class SpongeEvent extends event.Event { export class SpongeEvent extends event.Event {
@inject(plugin.PluginInstance) @inject(plugin.PluginInstance)
private pluginInstance: any; private pluginInstance: any;
private eventManager: any = Sponge.getEventManager();
constructor() { constructor() {
super('org/spongepowered/api/event'); super('org/spongepowered/api/event');
@ -37,16 +38,16 @@ export class SpongeEvent extends event.Event {
Modifier.isAbstract(clazz.getModifiers()); Modifier.isAbstract(clazz.getModifiers());
} }
class2Name(clazz: any) { class2Name(clazz: any) {
return clazz.canonicalName.substring(clazz.name.lastIndexOf(".") + 1); return clazz.name.substring(clazz.name.lastIndexOf(".") + 1);
} }
register(eventCls: any, exec: Function, priority: any = 'NORMAL', ignoreCancel: boolean = true) { register(eventCls: any, exec: Function, priority: any = 'NORMAL', ignoreCancel: boolean = true) {
var listener = new EventListener({ var listener = new EventListener({
handle: exec handle: exec
}); });
Sponge.getEventManager().registerListener(this.pluginInstance, eventCls, Order[priorityMap[priority]], listener); this.eventManager.registerListener(this.pluginInstance, eventCls, Order[priorityMap[priority]], listener);
return listener; return listener;
} }
unregister(event: any, listener: any): void { unregister(event: any, listener: any): void {
Sponge.getEventManager().unregisterListeners(listener); this.eventManager.unregisterListeners(listener);
} }
} }