From bc27eda220dab8c58347bdc769cc75d07de04fcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B1=BC=E5=89=8D=E4=B8=89=E7=99=BE?= <169084442+fishdry1000@users.noreply.github.com> Date: Sun, 25 Oct 2026 16:40:47 +0800 Subject: [PATCH] =?UTF-8?q?chore(event):=20=E7=A7=BB=E9=99=A4=E8=BF=87?= =?UTF-8?q?=E6=97=B6=E4=B8=94=E8=BF=9C=E5=8F=A4=E7=9A=84=E8=BF=9B=E7=A8=8B?= =?UTF-8?q?=E9=80=80=E5=87=BA=E4=BA=8B=E4=BB=B6=EF=BC=8C=E5=B9=B6=E5=B0=86?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E9=80=9F=E5=BA=A6=E4=BA=8B=E4=BB=B6=E4=B8=8E?= =?UTF-8?q?=E5=85=A8=E5=B1=80=20EventBus=20=E8=A7=A3=E8=80=A6=20(#7063)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hmcl/event/JVMLaunchFailedEvent.java | 56 ------------------- .../event/ProcessExitedAbnormallyEvent.java | 56 ------------------- .../hmcl/event/ProcessStoppedEvent.java | 47 ---------------- .../org/jackhuang/hmcl/launch/ExitWaiter.java | 9 --- .../org/jackhuang/hmcl/task/FetchTask.java | 3 +- 5 files changed, 1 insertion(+), 170 deletions(-) delete mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/event/JVMLaunchFailedEvent.java delete mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/event/ProcessExitedAbnormallyEvent.java delete mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/event/ProcessStoppedEvent.java diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/event/JVMLaunchFailedEvent.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/event/JVMLaunchFailedEvent.java deleted file mode 100644 index 4907b80286..0000000000 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/event/JVMLaunchFailedEvent.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Hello Minecraft! Launcher - * Copyright (C) 2020 huangyuhui and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.jackhuang.hmcl.event; - -import org.jackhuang.hmcl.util.ToStringBuilder; -import org.jackhuang.hmcl.util.platform.ManagedProcess; - -/** - * This event gets fired when we launch the JVM and it got crashed. - *
- * This event is fired on the {@link org.jackhuang.hmcl.event.EventBus#EVENT_BUS} - * - * @author huangyuhui - */ -public class JVMLaunchFailedEvent extends Event { - - private final ManagedProcess process; - - /** - * Constructor. - * - * @param source {@link org.jackhuang.hmcl.launch.ExitWaiter} - * @param process the crashed process. - */ - public JVMLaunchFailedEvent(Object source, ManagedProcess process) { - super(source); - this.process = process; - } - - public ManagedProcess getProcess() { - return process; - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("source", source) - .append("process", process) - .toString(); - } -} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/event/ProcessExitedAbnormallyEvent.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/event/ProcessExitedAbnormallyEvent.java deleted file mode 100644 index c0931da977..0000000000 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/event/ProcessExitedAbnormallyEvent.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Hello Minecraft! Launcher - * Copyright (C) 2020 huangyuhui and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.jackhuang.hmcl.event; - -import org.jackhuang.hmcl.util.ToStringBuilder; -import org.jackhuang.hmcl.util.platform.ManagedProcess; - -/** - * This event gets fired when a JavaProcess exited abnormally and the exit code is not zero. - * - * This event is fired on the {@link org.jackhuang.hmcl.event.EventBus#EVENT_BUS} - * - * @author huangyuhui - */ -public final class ProcessExitedAbnormallyEvent extends Event { - - private final ManagedProcess process; - - /** - * Constructor. - * - * @param source {@link org.jackhuang.hmcl.launch.ExitWaiter} - * @param process The process that exited abnormally. - */ - public ProcessExitedAbnormallyEvent(Object source, ManagedProcess process) { - super(source); - this.process = process; - } - - public ManagedProcess getProcess() { - return process; - } - - @Override - public String toString() { - return new ToStringBuilder(this) - .append("source", source) - .append("process", process) - .toString(); - } -} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/event/ProcessStoppedEvent.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/event/ProcessStoppedEvent.java deleted file mode 100644 index 328dfe45e3..0000000000 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/event/ProcessStoppedEvent.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Hello Minecraft! Launcher - * Copyright (C) 2020 huangyuhui and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.jackhuang.hmcl.event; - -import org.jackhuang.hmcl.util.platform.ManagedProcess; - -/** - * This event gets fired when minecraft process exited successfully and the exit code is 0. - *
- * This event is fired on the {@link org.jackhuang.hmcl.event.EventBus#EVENT_BUS} - * - * @author huangyuhui - */ -public class ProcessStoppedEvent extends Event { - - private final ManagedProcess process; - - /** - * Constructor. - * - * @param source {@link org.jackhuang.hmcl.launch.ExitWaiter} - * @param process minecraft process - */ - public ProcessStoppedEvent(Object source, ManagedProcess process) { - super(source); - this.process = process; - } - - public ManagedProcess getProcess() { - return process; - } -} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/ExitWaiter.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/ExitWaiter.java index 5ebcea3207..8327f0740d 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/ExitWaiter.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/launch/ExitWaiter.java @@ -17,10 +17,6 @@ */ package org.jackhuang.hmcl.launch; -import org.jackhuang.hmcl.event.EventBus; -import org.jackhuang.hmcl.event.JVMLaunchFailedEvent; -import org.jackhuang.hmcl.event.ProcessExitedAbnormallyEvent; -import org.jackhuang.hmcl.event.ProcessStoppedEvent; import org.jackhuang.hmcl.util.Log4jLevel; import org.jackhuang.hmcl.util.StringUtils; import org.jackhuang.hmcl.util.platform.ManagedProcess; @@ -67,13 +63,10 @@ final class ExitWaiter implements Runnable { "Could not create the Java Virtual Machine.", "Error occurred during initialization of VM", "A fatal exception has occurred. Program will exit.")) { - EventBus.EVENT_BUS.fireEvent(new JVMLaunchFailedEvent(this, process)); exitType = ProcessListener.ExitType.JVM_ERROR; } else if (exitCode != 0 || StringUtils.containsOne(errorLines, "Crash report saved to", "Could not save crash report to", "This crash report has been saved to:", "Unable to launch", "An exception was thrown, the game will display an error screen and halt.")) { - EventBus.EVENT_BUS.fireEvent(new ProcessExitedAbnormallyEvent(this, process)); - if (exitCode == 137 && OperatingSystem.CURRENT_OS.isLinuxOrBSD()) { exitType = ProcessListener.ExitType.SIGKILL; } else { @@ -83,8 +76,6 @@ final class ExitWaiter implements Runnable { exitType = ProcessListener.ExitType.NORMAL; } - EventBus.EVENT_BUS.fireEvent(new ProcessStoppedEvent(this, process)); - watcher.accept(exitCode, exitType); } catch (InterruptedException e) { watcher.accept(1, ProcessListener.ExitType.INTERRUPTED); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FetchTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FetchTask.java index 418440cb0b..d25d8dd1ef 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FetchTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FetchTask.java @@ -21,7 +21,6 @@ import org.glavo.url.WebURL; import org.jackhuang.hmcl.download.DownloadCandidate; import org.jackhuang.hmcl.download.DownloadCandidates; import org.jackhuang.hmcl.event.Event; -import org.jackhuang.hmcl.event.EventBus; import org.jackhuang.hmcl.event.EventManager; import org.jackhuang.hmcl.util.*; import org.jackhuang.hmcl.util.io.*; @@ -587,7 +586,7 @@ public abstract class FetchTask extends Ta private static final Timer timer = new Timer("DownloadSpeedRecorder", true); private static final AtomicLong downloadSpeed = new AtomicLong(0L); - public static final EventManager SPEED_EVENT = EventBus.EVENT_BUS.channel(SpeedEvent.class); + public static final EventManager SPEED_EVENT = new EventManager<>(); static { timer.schedule(new TimerTask() {