This commit is contained in:
liujiahua123123 2019-08-08 23:10:02 +08:00
parent dbd94bfdff
commit 73cbb5b2d1
2 changed files with 13 additions and 0 deletions

View File

@ -1,6 +1,9 @@
package net.mamoe.mirai;
import net.mamoe.mirai.event.MiraiEventHook;
import net.mamoe.mirai.event.events.server.ServerDisableEvent;
/**
* @author Him188moe @ Mirai Project
*/
@ -11,5 +14,9 @@ public final class MiraiMain {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
server.shutdown();
}));
server.getEventManager().register(
new MiraiEventHook<>(ServerDisableEvent.class)
.setHandler(a -> System.out.println("close"))
);
}
}

View File

@ -41,6 +41,12 @@ public class MiraiEventManager {
this.registerUntil(hook,(a) -> false);
}
public <D extends MiraiEvent> MiraiEventHook<D> onEvent(Class<D> event){
MiraiEventHook<D> hook = new MiraiEventHook<>(event);
this.register(hook);
return hook;
}
public void boardcastEvent(MiraiEvent event){
hooksLock.lock();
if(hooks.containsKey(event.getClass())){