From 9acbe0acca92e6f4091f6f2fe824b3710d3907b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E9=98=94?= <1520622465@qq.com> Date: Mon, 6 Jan 2025 11:49:36 +0800 Subject: [PATCH 1/3] =?UTF-8?q?FileWatcher#=E4=BF=AE=E5=A4=8D=E5=A4=9A?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9B=91=E5=90=AC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/taboolib/common5/FileWatcher.java | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/common-legacy-api/src/main/java/taboolib/common5/FileWatcher.java b/common-legacy-api/src/main/java/taboolib/common5/FileWatcher.java index 4beb9794d..063194842 100755 --- a/common-legacy-api/src/main/java/taboolib/common5/FileWatcher.java +++ b/common-legacy-api/src/main/java/taboolib/common5/FileWatcher.java @@ -52,13 +52,24 @@ public class FileWatcher { public FileWatcher(int interval) { try { this.watchService = FileSystems.getDefault().newWatchService(); - this.executorService.scheduleAtFixedRate(() -> fileListenerMap.forEach((file, listener) -> { - try { - listener.poll(); - } catch (Throwable ex) { - ex.printStackTrace(); + this.executorService.scheduleAtFixedRate(() -> { + WatchKey key; + while ((key = watchService.poll()) != null) { + key.pollEvents().forEach(event -> { + if (event.context() instanceof Path) { + Path changedPath = (Path) event.context(); + fileListenerMap.forEach((file, listener) -> { + try { + listener.handleEvent(changedPath); + } catch (Throwable ex) { + ex.printStackTrace(); + } + }); + } + }); + key.reset(); } - }), 1000, interval, TimeUnit.MILLISECONDS); + }, 1000, interval, TimeUnit.MILLISECONDS); // 注册关闭回调 TabooLib.registerLifeCycleTask(LifeCycle.DISABLE, 0, this::release); } catch (IOException e) { @@ -142,27 +153,22 @@ static class FileListener { ); } - public void poll() { - watchKey.pollEvents().forEach(event -> { - if (event.context() instanceof Path) { - Path path = (Path) event.context(); - Path fullPath = file.getParentFile().toPath().resolve(path); - // 监听目录 - if (file.isDirectory()) { - try { - // 使用 relativize 检查路径关系,更加准确 - file.toPath().relativize(fullPath); - callback.accept(fullPath.toFile()); - } catch (IllegalArgumentException ignored) { - // 如果不是子路径,会抛出异常,直接忽略 - } - } - // 监听文件 - else if (isSameFile(fullPath, file.toPath())) { - callback.accept(fullPath.toFile()); // 使用完整路径 - } + public void handleEvent(Path changedPath) { + Path fullPath = file.getParentFile().toPath().resolve(changedPath); + // 监听目录 + if (file.isDirectory()) { + try { + // 使用 relativize 检查路径关系,更加准确 + file.toPath().relativize(fullPath); + callback.accept(fullPath.toFile()); + } catch (IllegalArgumentException ignored) { + // 如果不是子路径,会抛出异常,直接忽略 } - }); + } + // 监听文件 + else if (isSameFile(fullPath, file.toPath())) { + callback.accept(fullPath.toFile()); + } } public boolean isSameFile(Path path1, Path path2) { From a2597945a528c56b307989217755753151a993b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E9=98=94?= <1520622465@qq.com> Date: Mon, 6 Jan 2025 13:08:29 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E5=85=BC=E5=AE=B9Mohist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/taboolib/common/env/RuntimeEnvDependency.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/common-env/src/main/java/taboolib/common/env/RuntimeEnvDependency.java b/common-env/src/main/java/taboolib/common/env/RuntimeEnvDependency.java index 31662662d..28dcfb507 100644 --- a/common-env/src/main/java/taboolib/common/env/RuntimeEnvDependency.java +++ b/common-env/src/main/java/taboolib/common/env/RuntimeEnvDependency.java @@ -44,6 +44,12 @@ public class RuntimeEnvDependency { } catch (ClassNotFoundException e) { isAetherFound = false; } + // Mohist直接不用Aether + try { + Class.forName("com.mohistmc.MohistMC"); + isAetherFound = false; + }catch (ClassNotFoundException ignored){ + } } public List getDependency(@NotNull ReflexClass clazz) { From 76ca9515ffe097532610b2845b816ad25c95c878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=91?= Date: Mon, 6 Jan 2025 13:38:41 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E7=9B=98=E5=8F=A4=E4=B9=8B=E7=99=BD?= =?UTF-8?q?=E9=83=BD=E6=B2=A1=E6=9C=89=EF=BC=8C=E4=B8=91=E9=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/taboolib/common/env/RuntimeEnvDependency.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common-env/src/main/java/taboolib/common/env/RuntimeEnvDependency.java b/common-env/src/main/java/taboolib/common/env/RuntimeEnvDependency.java index 28dcfb507..45b81ba8b 100644 --- a/common-env/src/main/java/taboolib/common/env/RuntimeEnvDependency.java +++ b/common-env/src/main/java/taboolib/common/env/RuntimeEnvDependency.java @@ -44,7 +44,7 @@ public class RuntimeEnvDependency { } catch (ClassNotFoundException e) { isAetherFound = false; } - // Mohist直接不用Aether + // Mohist 直接不用 Aether try { Class.forName("com.mohistmc.MohistMC"); isAetherFound = false;