diff --git a/mirai-core/src/main/java/net/mamoe/mirai/MiraiMain.java b/mirai-core/src/main/java/net/mamoe/mirai/MiraiMain.java index 942fffb2a..7b3531266 100644 --- a/mirai-core/src/main/java/net/mamoe/mirai/MiraiMain.java +++ b/mirai-core/src/main/java/net/mamoe/mirai/MiraiMain.java @@ -14,31 +14,9 @@ public final class MiraiMain { Runtime.getRuntime().addShutdownHook(new Thread(() -> { server.shutdown(); })); - server.getEventManager() - .onEvent(ServerDisableEvent.class) - .setHandler(a -> { - System.out.println("?"); - }); - - server.getEventManager() - .onEventOnce(ServerDisableEvent.class) - .setHandler(a -> { - System.out.println("?"); - }); - - server.getEventManager() - .onEvent(ServerDisableEvent.class) - .setHandler(a -> { - System.out.println("?"); - }) - .setValidWhile((a) -> true); - - server.getEventManager() - .onEvent(ServerDisableEvent.class) - .setHandler(a -> { - System.out.println("?"); - }) - .setValidUntil((a) -> true); + server.getTaskManager().repeatingTask(() -> { + System.out.println(3); + },1000,5); } } diff --git a/mirai-core/src/main/java/net/mamoe/mirai/MiraiServer.java b/mirai-core/src/main/java/net/mamoe/mirai/MiraiServer.java index 56f272518..d22e93eb8 100644 --- a/mirai-core/src/main/java/net/mamoe/mirai/MiraiServer.java +++ b/mirai-core/src/main/java/net/mamoe/mirai/MiraiServer.java @@ -43,6 +43,7 @@ public class MiraiServer { this.eventManager = MiraiEventManager.getInstance(); this.taskManager = MiraiTaskManager.getInstance(); + /* try { Network.start(Network.getAvailablePort()); } catch (InterruptedException | IOException e) { @@ -50,6 +51,7 @@ public class MiraiServer { this.shutdown(); } + */ } diff --git a/mirai-core/src/main/java/net/mamoe/mirai/event/MiraiEventHook.java b/mirai-core/src/main/java/net/mamoe/mirai/event/MiraiEventHook.java index 8382c5a23..f94a48db3 100644 --- a/mirai-core/src/main/java/net/mamoe/mirai/event/MiraiEventHook.java +++ b/mirai-core/src/main/java/net/mamoe/mirai/event/MiraiEventHook.java @@ -13,13 +13,13 @@ public class MiraiEventHook { Class eventClass; @Getter - private Consumer handler; + private volatile Consumer handler; @Getter - private int priority = 0; + private volatile int priority = 0; @Getter - private boolean ignoreCancelled = true; + private volatile boolean ignoreCancelled = true; /** * return true -> this hook need to be removed diff --git a/mirai-core/src/main/java/net/mamoe/mirai/event/MiraiEventManager.java b/mirai-core/src/main/java/net/mamoe/mirai/event/MiraiEventManager.java index b19afa53d..d015cce7e 100644 --- a/mirai-core/src/main/java/net/mamoe/mirai/event/MiraiEventManager.java +++ b/mirai-core/src/main/java/net/mamoe/mirai/event/MiraiEventManager.java @@ -29,13 +29,17 @@ public class MiraiEventManager { private Map, List>> hooks = new HashMap<>(); public void registerUntil(MiraiEventHook hook, Predicate toRemove){ + hooksLock.lock(); hooks.putIfAbsent(hook.getEventClass(),new ArrayList<>()); hooks.get(hook.getEventClass()).add(hook.setValidUntil(toRemove)); + hooksLock.unlock(); } public void registerWhile(MiraiEventHook hook, Predicate toKeep){ + hooksLock.lock(); hooks.putIfAbsent(hook.getEventClass(),new ArrayList<>()); hooks.get(hook.getEventClass()).add(hook.setValidWhile(toKeep)); + hooksLock.unlock(); } public void registerOnce(MiraiEventHook hook){ @@ -74,12 +78,14 @@ public class MiraiEventManager { public void boardcastEvent(MiraiEvent event){ hooksLock.lock(); + System.out.println(hooks); if(hooks.containsKey(event.getClass())){ + System.out.println(hooks.get(event.getClass()).size()); hooks.put(event.getClass(), hooks.get(event.getClass()) .stream() .sorted(Comparator.comparingInt(MiraiEventHook::getPriority)) - .dropWhile(a -> a.accept(event)) + .filter(a -> !a.accept(event)) .collect(Collectors.toList()) ); } diff --git a/mirai-core/src/main/java/net/mamoe/mirai/task/MiraiTaskManager.java b/mirai-core/src/main/java/net/mamoe/mirai/task/MiraiTaskManager.java index 39d59663f..bdcce07e1 100644 --- a/mirai-core/src/main/java/net/mamoe/mirai/task/MiraiTaskManager.java +++ b/mirai-core/src/main/java/net/mamoe/mirai/task/MiraiTaskManager.java @@ -25,9 +25,11 @@ public class MiraiTaskManager { private MiraiTaskManager() { this.pool = new MiraiThreadPool(); + MiraiServer.getInstance().getEventManager() .onEvent(ServerDisableEvent.class) .setHandler(a -> this.pool.close()); + } /** @@ -99,7 +101,7 @@ public class MiraiTaskManager { } public void repeatingTask(Runnable runnable, long interval, int times, MiraiTaskExceptionHandler handler){ - AtomicInteger integer = new AtomicInteger(times); + AtomicInteger integer = new AtomicInteger(times-1); this.repeatingTask( runnable,interval, a -> integer.getAndDecrement() > 0, handler ); diff --git a/mirai-core/src/main/java/net/mamoe/mirai/util/_TEAEncryption.java b/mirai-core/src/main/java/net/mamoe/mirai/util/_TEAEncryption.java index 003ff1b7c..63a9cc0da 100644 --- a/mirai-core/src/main/java/net/mamoe/mirai/util/_TEAEncryption.java +++ b/mirai-core/src/main/java/net/mamoe/mirai/util/_TEAEncryption.java @@ -27,7 +27,7 @@ import java.util.Random; * * * - * @author https://juejin.im/post/5c5bdf8cf265da2dc706d532 + * @author b * @author luma * @author notXX */