mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-01 22:00:46 +08:00
event manager
This commit is contained in:
parent
0e032cf9b7
commit
78826c5648
@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
@ -22,6 +24,7 @@ public class MiraiEventManager {
|
||||
return MiraiEventManager.instance;
|
||||
}
|
||||
|
||||
Lock hooksLock = new ReentrantLock();
|
||||
private Map<Class<? extends MiraiEvent>, List<MiraiEventConsumer<? extends MiraiEvent>>> hooks = new HashMap<>();
|
||||
|
||||
public <D extends MiraiEvent> void registerUntil(MiraiEventHook<D> hook, Predicate<D> toRemove){
|
||||
@ -37,8 +40,8 @@ public class MiraiEventManager {
|
||||
this.registerUntil(hook,(a) -> false);
|
||||
}
|
||||
|
||||
|
||||
public void boardcastEvent(MiraiEvent event){
|
||||
hooksLock.lock();
|
||||
if(hooks.containsKey(event.getClass())){
|
||||
hooks.put(event.getClass(),
|
||||
hooks.get(event.getClass())
|
||||
@ -48,6 +51,7 @@ public class MiraiEventManager {
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
hooksLock.unlock();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user