Fixed compile errors in HMCSM

This commit is contained in:
huangyuhui
2017-02-13 13:20:52 +08:00
parent 20be2f76c6
commit 7418ef21ac
22 changed files with 280 additions and 214 deletions

View File

@@ -17,7 +17,7 @@
*/ */
package org.jackhuang.hellominecraft.launcher.core.download; package org.jackhuang.hellominecraft.launcher.core.download;
import org.jackhuang.hellominecraft.api.HMCLAPI; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.launcher.api.event.config.DownloadTypeChangedEvent; import org.jackhuang.hellominecraft.launcher.api.event.config.DownloadTypeChangedEvent;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.util.task.TaskWindow; import org.jackhuang.hellominecraft.util.task.TaskWindow;
@@ -62,6 +62,6 @@ public enum DownloadType {
} }
static { static {
HMCLAPI.EVENT_BUS.channel(DownloadTypeChangedEvent.class).register(t -> setSuggestedDownloadType(t.getValue())); HMCAPI.EVENT_BUS.channel(DownloadTypeChangedEvent.class).register(t -> setSuggestedDownloadType(t.getValue()));
} }
} }

View File

@@ -20,7 +20,7 @@ package org.jackhuang.hellominecraft.launcher.core.launch;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import org.jackhuang.hellominecraft.api.HMCLAPI; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.api.ResultedSimpleEvent; import org.jackhuang.hellominecraft.api.ResultedSimpleEvent;
import org.jackhuang.hellominecraft.launcher.api.event.launch.DecompressLibrariesEvent; import org.jackhuang.hellominecraft.launcher.api.event.launch.DecompressLibrariesEvent;
import org.jackhuang.hellominecraft.launcher.api.event.launch.DownloadLibrariesEvent; import org.jackhuang.hellominecraft.launcher.api.event.launch.DownloadLibrariesEvent;
@@ -44,7 +44,7 @@ public class DefaultGameLauncher extends GameLauncher {
} }
private void register() { private void register() {
HMCLAPI.EVENT_BUS.channel(DownloadLibrariesEvent.class).register(t -> { HMCAPI.EVENT_BUS.channel(DownloadLibrariesEvent.class).register(t -> {
ResultedSimpleEvent<List<DownloadLibraryJob>> event = (ResultedSimpleEvent) t; ResultedSimpleEvent<List<DownloadLibraryJob>> event = (ResultedSimpleEvent) t;
final TaskWindow.TaskWindowFactory dw = TaskWindow.factory(); final TaskWindow.TaskWindowFactory dw = TaskWindow.factory();
ParallelTask parallelTask = new ParallelTask(); ParallelTask parallelTask = new ParallelTask();
@@ -63,7 +63,7 @@ public class DefaultGameLauncher extends GameLauncher {
flag = true; flag = true;
t.setResult(flag); t.setResult(flag);
}); });
HMCLAPI.EVENT_BUS.channel(DecompressLibrariesEvent.class).register(t -> { HMCAPI.EVENT_BUS.channel(DecompressLibrariesEvent.class).register(t -> {
if (t.getValue() == null) { if (t.getValue() == null) {
t.setResult(false); t.setResult(false);
return; return;

View File

@@ -23,7 +23,7 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.util.List; import java.util.List;
import org.jackhuang.hellominecraft.api.HMCLAPI; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.launcher.api.event.launch.DecompressLibrariesEvent; import org.jackhuang.hellominecraft.launcher.api.event.launch.DecompressLibrariesEvent;
import org.jackhuang.hellominecraft.launcher.api.event.launch.DecompressLibraryJob; import org.jackhuang.hellominecraft.launcher.api.event.launch.DecompressLibraryJob;
import org.jackhuang.hellominecraft.launcher.api.event.launch.DownloadLibrariesEvent; import org.jackhuang.hellominecraft.launcher.api.event.launch.DownloadLibrariesEvent;
@@ -90,7 +90,7 @@ public class GameLauncher {
public void makeLaunchCommand() throws AuthenticationException, GameException, RuntimeGameException { public void makeLaunchCommand() throws AuthenticationException, GameException, RuntimeGameException {
HMCLog.log("Building process"); HMCLog.log("Building process");
HMCLog.log("Logging in..."); HMCLog.log("Logging in...");
HMCLAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.LoggingIn)); HMCAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.LoggingIn));
IMinecraftLoader loader; IMinecraftLoader loader;
if (info != null) if (info != null)
result = login.login(info); result = login.login(info);
@@ -98,9 +98,9 @@ public class GameLauncher {
result = login.loginBySettings(); result = login.loginBySettings();
if (result == null) if (result == null)
throw new AuthenticationException("Result can not be null."); throw new AuthenticationException("Result can not be null.");
HMCLAPI.EVENT_BUS.fireChannel(new ProcessingLoginResultEvent(this, result)); HMCAPI.EVENT_BUS.fireChannel(new ProcessingLoginResultEvent(this, result));
HMCLAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.GeneratingLaunchingCodes)); HMCAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.GeneratingLaunchingCodes));
loader = service.launch(options, result); loader = service.launch(options, result);
File file = service.version().getDecompressNativesToLocation(loader.getMinecraftVersion()); File file = service.version().getDecompressNativesToLocation(loader.getMinecraftVersion());
@@ -109,18 +109,18 @@ public class GameLauncher {
if (!options.isNotCheckGame()) { if (!options.isNotCheckGame()) {
HMCLog.log("Detecting libraries..."); HMCLog.log("Detecting libraries...");
HMCLAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.DownloadingLibraries)); HMCAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.DownloadingLibraries));
if (!HMCLAPI.EVENT_BUS.fireChannelResulted(new DownloadLibrariesEvent(this, service.download().getDownloadLibraries(loader.getMinecraftVersion())))) if (!HMCAPI.EVENT_BUS.fireChannelResulted(new DownloadLibrariesEvent(this, service.download().getDownloadLibraries(loader.getMinecraftVersion()))))
throw new GameException("Failed to download libraries"); throw new GameException("Failed to download libraries");
} }
HMCLog.log("Unpacking natives..."); HMCLog.log("Unpacking natives...");
HMCLAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.DecompressingNatives)); HMCAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.DecompressingNatives));
DecompressLibraryJob job = service.version().getDecompressLibraries(loader.getMinecraftVersion()); DecompressLibraryJob job = service.version().getDecompressLibraries(loader.getMinecraftVersion());
if (!HMCLAPI.EVENT_BUS.fireChannelResulted(new DecompressLibrariesEvent(this, job))) if (!HMCAPI.EVENT_BUS.fireChannelResulted(new DecompressLibrariesEvent(this, job)))
throw new GameException("Failed to decompress natives"); throw new GameException("Failed to decompress natives");
HMCLAPI.EVENT_BUS.fireChannel(new LaunchSucceededEvent(this, loader.makeLaunchingCommand())); HMCAPI.EVENT_BUS.fireChannel(new LaunchSucceededEvent(this, loader.makeLaunchingCommand()));
} }
/** /**
@@ -150,7 +150,7 @@ public class GameLauncher {
.environment().put("APPDATA", service.baseDirectory().getAbsolutePath()); .environment().put("APPDATA", service.baseDirectory().getAbsolutePath());
JavaProcess jp = new JavaProcess(str, builder.start(), PROCESS_MANAGER); JavaProcess jp = new JavaProcess(str, builder.start(), PROCESS_MANAGER);
HMCLog.log("Have started the process"); HMCLog.log("Have started the process");
HMCLAPI.EVENT_BUS.fireChannel(new LaunchEvent(this, jp)); HMCAPI.EVENT_BUS.fireChannel(new LaunchEvent(this, jp));
} }
/** /**

View File

@@ -21,7 +21,7 @@ import com.google.gson.annotations.SerializedName;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import org.jackhuang.hellominecraft.api.HMCLAPI; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.launcher.api.event.version.MinecraftLibraryPathEvent; import org.jackhuang.hellominecraft.launcher.api.event.version.MinecraftLibraryPathEvent;
import org.jackhuang.hellominecraft.util.sys.OS; import org.jackhuang.hellominecraft.util.sys.OS;
import org.jackhuang.hellominecraft.util.sys.Platform; import org.jackhuang.hellominecraft.util.sys.Platform;
@@ -108,7 +108,7 @@ public class MinecraftLibrary extends IMinecraftLibrary {
if (info == null) if (info == null)
return null; return null;
MinecraftLibraryPathEvent event = new MinecraftLibraryPathEvent(this, "libraries/" + info.path, new Wrapper<>(new File(gameDir, "libraries/" + info.path))); MinecraftLibraryPathEvent event = new MinecraftLibraryPathEvent(this, "libraries/" + info.path, new Wrapper<>(new File(gameDir, "libraries/" + info.path)));
HMCLAPI.EVENT_BUS.fireChannel(event); HMCAPI.EVENT_BUS.fireChannel(event);
return event.getFile().getValue(); return event.getFile().getValue();
} }

View File

@@ -25,7 +25,7 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import org.jackhuang.hellominecraft.api.HMCLAPI; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.launcher.api.event.version.LoadedOneVersionEvent; import org.jackhuang.hellominecraft.launcher.api.event.version.LoadedOneVersionEvent;
import org.jackhuang.hellominecraft.launcher.api.event.version.RefreshedVersionsEvent; import org.jackhuang.hellominecraft.launcher.api.event.version.RefreshedVersionsEvent;
import org.jackhuang.hellominecraft.launcher.api.event.version.RefreshingVersionsEvent; import org.jackhuang.hellominecraft.launcher.api.event.version.RefreshingVersionsEvent;
@@ -72,7 +72,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override @Override
public synchronized void refreshVersions() { public synchronized void refreshVersions() {
HMCLAPI.EVENT_BUS.fireChannel(new RefreshingVersionsEvent(this, service)); HMCAPI.EVENT_BUS.fireChannel(new RefreshingVersionsEvent(this, service));
try { try {
MCUtils.tryWriteProfile(service.baseDirectory()); MCUtils.tryWriteProfile(service.baseDirectory());
@@ -142,12 +142,12 @@ public class MinecraftVersionManager extends IMinecraftProvider {
} }
versions.put(id, mcVersion); versions.put(id, mcVersion);
HMCLAPI.EVENT_BUS.fireChannel(new LoadedOneVersionEvent(this, id)); HMCAPI.EVENT_BUS.fireChannel(new LoadedOneVersionEvent(this, id));
} catch (Exception e) { } catch (Exception e) {
HMCLog.warn("Ignoring: " + dir + ", the json of this Minecraft is malformed.", e); HMCLog.warn("Ignoring: " + dir + ", the json of this Minecraft is malformed.", e);
} }
} }
HMCLAPI.EVENT_BUS.fireChannel(new RefreshedVersionsEvent(this, service)); HMCAPI.EVENT_BUS.fireChannel(new RefreshedVersionsEvent(this, service));
} }
@Override @Override

View File

@@ -27,7 +27,7 @@ import java.util.TreeMap;
import java.util.UUID; import java.util.UUID;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator; import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
import org.jackhuang.hellominecraft.lookandfeel.Theme; import org.jackhuang.hellominecraft.lookandfeel.Theme;
import org.jackhuang.hellominecraft.api.HMCLAPI; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.launcher.api.event.config.AuthenticatorChangedEvent; import org.jackhuang.hellominecraft.launcher.api.event.config.AuthenticatorChangedEvent;
import org.jackhuang.hellominecraft.launcher.api.event.config.DownloadTypeChangedEvent; import org.jackhuang.hellominecraft.launcher.api.event.config.DownloadTypeChangedEvent;
import org.jackhuang.hellominecraft.launcher.api.event.config.ThemeChangedEvent; import org.jackhuang.hellominecraft.launcher.api.event.config.ThemeChangedEvent;
@@ -92,7 +92,7 @@ public final class Config implements Cloneable {
public void setTheme(int theme) { public void setTheme(int theme) {
this.theme = theme; this.theme = theme;
HMCLAPI.EVENT_BUS.fireChannel(new ThemeChangedEvent(this, getTheme())); HMCAPI.EVENT_BUS.fireChannel(new ThemeChangedEvent(this, getTheme()));
Settings.save(); Settings.save();
} }
@@ -182,7 +182,7 @@ public final class Config implements Cloneable {
if (logintype < 0 || logintype >= IAuthenticator.LOGINS.size()) if (logintype < 0 || logintype >= IAuthenticator.LOGINS.size())
return; return;
this.logintype = logintype; this.logintype = logintype;
HMCLAPI.EVENT_BUS.fireChannel(new AuthenticatorChangedEvent(this, IAuthenticator.LOGINS.get(logintype))); HMCAPI.EVENT_BUS.fireChannel(new AuthenticatorChangedEvent(this, IAuthenticator.LOGINS.get(logintype)));
Settings.save(); Settings.save();
} }
@@ -192,7 +192,7 @@ public final class Config implements Cloneable {
public void setDownloadType(int downloadtype) { public void setDownloadType(int downloadtype) {
this.downloadtype = downloadtype; this.downloadtype = downloadtype;
HMCLAPI.EVENT_BUS.fireChannel(new DownloadTypeChangedEvent(this, getDownloadSource())); HMCAPI.EVENT_BUS.fireChannel(new DownloadTypeChangedEvent(this, getDownloadSource()));
Settings.save(); Settings.save();
} }

View File

@@ -28,7 +28,7 @@ import org.jackhuang.hellominecraft.launcher.Main;
import org.jackhuang.hellominecraft.launcher.core.MCUtils; import org.jackhuang.hellominecraft.launcher.core.MCUtils;
import org.jackhuang.hellominecraft.launcher.core.download.DownloadType; import org.jackhuang.hellominecraft.launcher.core.download.DownloadType;
import org.jackhuang.hellominecraft.util.CollectionUtils; import org.jackhuang.hellominecraft.util.CollectionUtils;
import org.jackhuang.hellominecraft.api.HMCLAPI; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.launcher.api.event.config.ProfileChangedEvent; import org.jackhuang.hellominecraft.launcher.api.event.config.ProfileChangedEvent;
import org.jackhuang.hellominecraft.launcher.api.event.config.ProfileLoadingEvent; import org.jackhuang.hellominecraft.launcher.api.event.config.ProfileLoadingEvent;
import org.jackhuang.hellominecraft.util.sys.FileUtils; import org.jackhuang.hellominecraft.util.sys.FileUtils;
@@ -161,12 +161,12 @@ public final class Settings {
Profile p = getLastProfile(); Profile p = getLastProfile();
if (p == null) if (p == null)
throw new Error("No profiles here, it should not happen"); throw new Error("No profiles here, it should not happen");
HMCLAPI.EVENT_BUS.fireChannel(new ProfileChangedEvent(SETTINGS, p.getName())); HMCAPI.EVENT_BUS.fireChannel(new ProfileChangedEvent(SETTINGS, p.getName()));
p.onSelected(); p.onSelected();
} }
public static void onProfileLoading() { public static void onProfileLoading() {
HMCLAPI.EVENT_BUS.fireChannel(new ProfileLoadingEvent(SETTINGS)); HMCAPI.EVENT_BUS.fireChannel(new ProfileLoadingEvent(SETTINGS));
onProfileChanged(); onProfileChanged();
} }
} }

View File

@@ -43,7 +43,7 @@ import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener; import javax.swing.event.ChangeListener;
import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelEvent;
import javax.swing.table.DefaultTableModel; import javax.swing.table.DefaultTableModel;
import org.jackhuang.hellominecraft.api.HMCLAPI; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.launcher.api.event.config.ProfileChangedEvent; import org.jackhuang.hellominecraft.launcher.api.event.config.ProfileChangedEvent;
import org.jackhuang.hellominecraft.launcher.api.event.config.ProfileLoadingEvent; import org.jackhuang.hellominecraft.launcher.api.event.config.ProfileLoadingEvent;
import org.jackhuang.hellominecraft.launcher.api.event.version.RefreshedVersionsEvent; import org.jackhuang.hellominecraft.launcher.api.event.version.RefreshedVersionsEvent;
@@ -86,7 +86,7 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
final InstallerPanel installerPanels[] = new InstallerPanel[InstallerType.values().length]; final InstallerPanel installerPanels[] = new InstallerPanel[InstallerType.values().length];
public GameSettingsPanel() { public GameSettingsPanel() {
HMCLAPI.EVENT_BUS.channel(RefreshedVersionsEvent.class).register(t -> { HMCAPI.EVENT_BUS.channel(RefreshedVersionsEvent.class).register(t -> {
if (Settings.getLastProfile().service() == t.getValue() && t.getValue().version().getVersions().isEmpty()) if (Settings.getLastProfile().service() == t.getValue() && t.getValue().version().getVersions().isEmpty())
if (!showedNoVersion && Settings.getLastProfile().service().checkingModpack) { if (!showedNoVersion && Settings.getLastProfile().service().checkingModpack) {
showedNoVersion = true; showedNoVersion = true;
@@ -123,9 +123,9 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
cboJava.addItem(j.getLocalizedName()); cboJava.addItem(j.getLocalizedName());
isLoading = false; isLoading = false;
HMCLAPI.EVENT_BUS.channel(ProfileLoadingEvent.class).register(onLoadingProfiles); HMCAPI.EVENT_BUS.channel(ProfileLoadingEvent.class).register(onLoadingProfiles);
HMCLAPI.EVENT_BUS.channel(ProfileChangedEvent.class).register(onSelectedProfilesChanged); HMCAPI.EVENT_BUS.channel(ProfileChangedEvent.class).register(onSelectedProfilesChanged);
HMCLAPI.EVENT_BUS.channel(RefreshedVersionsEvent.class).register(onRefreshedVersions); HMCAPI.EVENT_BUS.channel(RefreshedVersionsEvent.class).register(onRefreshedVersions);
} }
void initExplorationMenu() { void initExplorationMenu() {

View File

@@ -20,7 +20,7 @@ package org.jackhuang.hellominecraft.launcher.ui;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import org.jackhuang.hellominecraft.api.HMCLAPI; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.api.event.process.JVMLaunchFailedEvent; import org.jackhuang.hellominecraft.api.event.process.JVMLaunchFailedEvent;
import org.jackhuang.hellominecraft.api.event.process.JavaProcessExitedAbnormallyEvent; import org.jackhuang.hellominecraft.api.event.process.JavaProcessExitedAbnormallyEvent;
import org.jackhuang.hellominecraft.api.event.process.JavaProcessStoppedEvent; import org.jackhuang.hellominecraft.api.event.process.JavaProcessStoppedEvent;
@@ -49,8 +49,8 @@ import org.jackhuang.hellominecraft.util.net.WebFrame;
public class LaunchingUIDaemon { public class LaunchingUIDaemon {
public LaunchingUIDaemon() { public LaunchingUIDaemon() {
HMCLAPI.EVENT_BUS.channel(LaunchingStateChangedEvent.class).register(LAUNCHING_STATE_CHANGED); HMCAPI.EVENT_BUS.channel(LaunchingStateChangedEvent.class).register(LAUNCHING_STATE_CHANGED);
HMCLAPI.EVENT_BUS.channel(LaunchEvent.class).register(p -> { HMCAPI.EVENT_BUS.channel(LaunchEvent.class).register(p -> {
GameLauncher obj = (GameLauncher) p.getSource(); GameLauncher obj = (GameLauncher) p.getSource();
HMCLGameLauncher.GameLauncherTag tag = (HMCLGameLauncher.GameLauncherTag) obj.getTag(); HMCLGameLauncher.GameLauncherTag tag = (HMCLGameLauncher.GameLauncherTag) obj.getTag();
if (tag.launcherVisibility == LauncherVisibility.CLOSE && !LogWindow.INSTANCE.isVisible()) { if (tag.launcherVisibility == LauncherVisibility.CLOSE && !LogWindow.INSTANCE.isVisible()) {
@@ -69,15 +69,15 @@ public class LaunchingUIDaemon {
monitor.setTag(tag.launcherVisibility); monitor.setTag(tag.launcherVisibility);
monitor.start(); monitor.start();
}); });
HMCLAPI.EVENT_BUS.channel(LaunchSucceededEvent.class).register(p -> { HMCAPI.EVENT_BUS.channel(LaunchSucceededEvent.class).register(p -> {
int state = ((HMCLGameLauncher.GameLauncherTag) ((GameLauncher) p.getSource()).getTag()).state; int state = ((HMCLGameLauncher.GameLauncherTag) ((GameLauncher) p.getSource()).getTag()).state;
if (state == 1) if (state == 1)
LAUNCH_FINISHER.accept(p); LAUNCH_FINISHER.accept(p);
else if (state == 2) else if (state == 2)
LAUNCH_SCRIPT_FINISHER.accept(p); LAUNCH_SCRIPT_FINISHER.accept(p);
}); });
HMCLAPI.EVENT_BUS.channel(JavaProcessStoppedEvent.class).register(event -> checkExit((LauncherVisibility) ((JavaProcessMonitor) event.getSource()).getTag())); HMCAPI.EVENT_BUS.channel(JavaProcessStoppedEvent.class).register(event -> checkExit((LauncherVisibility) ((JavaProcessMonitor) event.getSource()).getTag()));
HMCLAPI.EVENT_BUS.channel(JavaProcessExitedAbnormallyEvent.class).register(event -> { HMCAPI.EVENT_BUS.channel(JavaProcessExitedAbnormallyEvent.class).register(event -> {
int exitCode = event.getValue().getExitCode(); int exitCode = event.getValue().getExitCode();
HMCLog.err("The game exited abnormally, exit code: " + exitCode); HMCLog.err("The game exited abnormally, exit code: " + exitCode);
String[] logs = event.getValue().getStdOutLines().toArray(new String[0]); String[] logs = event.getValue().getStdOutLines().toArray(new String[0]);
@@ -98,7 +98,7 @@ public class LaunchingUIDaemon {
f.setVisible(true); f.setVisible(true);
checkExit((LauncherVisibility) ((JavaProcessMonitor) event.getSource()).getTag()); checkExit((LauncherVisibility) ((JavaProcessMonitor) event.getSource()).getTag());
}); });
HMCLAPI.EVENT_BUS.channel(JVMLaunchFailedEvent.class).register(event -> { HMCAPI.EVENT_BUS.channel(JVMLaunchFailedEvent.class).register(event -> {
int exitCode = event.getValue().getExitCode(); int exitCode = event.getValue().getExitCode();
HMCLog.err("Cannot create jvm, exit code: " + exitCode); HMCLog.err("Cannot create jvm, exit code: " + exitCode);
WebFrame f = new WebFrame(event.getValue().getStdOutLines().toArray(new String[0])); WebFrame f = new WebFrame(event.getValue().getStdOutLines().toArray(new String[0]));

View File

@@ -51,7 +51,7 @@ import javax.swing.JComponent;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import org.jackhuang.hellominecraft.api.HMCLAPI; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.launcher.Main; import org.jackhuang.hellominecraft.launcher.Main;
import org.jackhuang.hellominecraft.launcher.api.PluginManager; import org.jackhuang.hellominecraft.launcher.api.PluginManager;
import org.jackhuang.hellominecraft.launcher.api.event.config.ThemeChangedEvent; import org.jackhuang.hellominecraft.launcher.api.event.config.ThemeChangedEvent;
@@ -159,7 +159,7 @@ public final class MainFrame extends DraggableFrame implements IRepaint {
} }
((JPanel) getContentPane()).setOpaque(true); ((JPanel) getContentPane()).setOpaque(true);
HMCLAPI.EVENT_BUS.channel(ThemeChangedEvent.class).register(x -> reloadColor(x.getValue())); HMCAPI.EVENT_BUS.channel(ThemeChangedEvent.class).register(x -> reloadColor(x.getValue()));
SwingUtilities.invokeLater(() -> selectTab("main")); SwingUtilities.invokeLater(() -> selectTab("main"));
} }

View File

@@ -29,7 +29,7 @@ import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileNameExtensionFilter;
import org.jackhuang.hellominecraft.api.HMCLAPI; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.launcher.api.event.config.AuthenticatorChangedEvent; import org.jackhuang.hellominecraft.launcher.api.event.config.AuthenticatorChangedEvent;
import org.jackhuang.hellominecraft.launcher.api.event.config.ProfileChangedEvent; import org.jackhuang.hellominecraft.launcher.api.event.config.ProfileChangedEvent;
import org.jackhuang.hellominecraft.launcher.api.event.config.ProfileLoadingEvent; import org.jackhuang.hellominecraft.launcher.api.event.config.ProfileLoadingEvent;
@@ -97,12 +97,12 @@ public class MainPagePanel extends Page {
((RepaintPage) pnlMore).setRepainter(pnlRoot); ((RepaintPage) pnlMore).setRepainter(pnlRoot);
HMCLAPI.EVENT_BUS.channel(AuthenticatorChangedEvent.class).register(onAuthChanged); HMCAPI.EVENT_BUS.channel(AuthenticatorChangedEvent.class).register(onAuthChanged);
HMCLAPI.EVENT_BUS.channel(ProfileLoadingEvent.class).register(onLoadingProfiles); HMCAPI.EVENT_BUS.channel(ProfileLoadingEvent.class).register(onLoadingProfiles);
HMCLAPI.EVENT_BUS.channel(ProfileChangedEvent.class).register(onSelectedProfilesChanged); HMCAPI.EVENT_BUS.channel(ProfileChangedEvent.class).register(onSelectedProfilesChanged);
HMCLAPI.EVENT_BUS.channel(RefreshedVersionsEvent.class).register(onRefreshedVersions); HMCAPI.EVENT_BUS.channel(RefreshedVersionsEvent.class).register(onRefreshedVersions);
HMCLAPI.EVENT_BUS.channel(LaunchingStateChangedEvent.class).register(launchingStateChanged); HMCAPI.EVENT_BUS.channel(LaunchingStateChangedEvent.class).register(launchingStateChanged);
HMCLAPI.EVENT_BUS.channel(LaunchSucceededEvent.class).register(this::prepareAuths); HMCAPI.EVENT_BUS.channel(LaunchSucceededEvent.class).register(this::prepareAuths);
prepareAuths(); prepareAuths();
} }

View File

@@ -28,7 +28,7 @@ import org.jackhuang.hellominecraft.launcher.core.launch.LaunchOptions;
import org.jackhuang.hellominecraft.launcher.setting.Profile; import org.jackhuang.hellominecraft.launcher.setting.Profile;
import org.jackhuang.hellominecraft.launcher.setting.Settings; import org.jackhuang.hellominecraft.launcher.setting.Settings;
import org.jackhuang.hellominecraft.util.C; import org.jackhuang.hellominecraft.util.C;
import org.jackhuang.hellominecraft.api.HMCLAPI; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.launcher.api.event.launch.LaunchSucceededEvent; import org.jackhuang.hellominecraft.launcher.api.event.launch.LaunchSucceededEvent;
import org.jackhuang.hellominecraft.launcher.api.event.launch.LaunchingState; import org.jackhuang.hellominecraft.launcher.api.event.launch.LaunchingState;
import org.jackhuang.hellominecraft.launcher.api.event.launch.LaunchingStateChangedEvent; import org.jackhuang.hellominecraft.launcher.api.event.launch.LaunchingStateChangedEvent;
@@ -50,12 +50,12 @@ public class HMCLGameLauncher {
public HMCLGameLauncher(Profile p) { public HMCLGameLauncher(Profile p) {
this.profile = p; this.profile = p;
HMCLAPI.EVENT_BUS.channel(LaunchSucceededEvent.class).register(() -> setLaunching(false)); HMCAPI.EVENT_BUS.channel(LaunchSucceededEvent.class).register(() -> setLaunching(false));
} }
void setLaunching(boolean isLaunching) { void setLaunching(boolean isLaunching) {
if (isLaunching != this.isLaunching) if (isLaunching != this.isLaunching)
HMCLAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, isLaunching ? LaunchingState.Starting : LaunchingState.Done)); HMCAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, isLaunching ? LaunchingState.Starting : LaunchingState.Done));
this.isLaunching = isLaunching; this.isLaunching = isLaunching;
} }
@@ -85,7 +85,7 @@ public class HMCLGameLauncher {
Thread.currentThread().setName("Game Launcher"); Thread.currentThread().setName("Game Launcher");
try { try {
LaunchOptions options = profile.getSelectedVersionSetting().createLaunchOptions(profile.getCanonicalGameDirFile()); LaunchOptions options = profile.getSelectedVersionSetting().createLaunchOptions(profile.getCanonicalGameDirFile());
HMCLAPI.EVENT_BUS.fireChannel(new ProcessingLaunchOptionsEvent(this, options)); HMCAPI.EVENT_BUS.fireChannel(new ProcessingLaunchOptionsEvent(this, options));
DefaultGameLauncher gl = new DefaultGameLauncher(options, profile.service(), li, l); DefaultGameLauncher gl = new DefaultGameLauncher(options, profile.service(), li, l);
GameLauncherTag tag = new GameLauncherTag(); GameLauncherTag tag = new GameLauncherTag();
tag.launcherVisibility = profile.getSelectedVersionSetting().getLauncherVisibility(); tag.launcherVisibility = profile.getSelectedVersionSetting().getLauncherVisibility();

View File

@@ -18,7 +18,7 @@
package org.jackhuang.hellominecraft.launcher.util; package org.jackhuang.hellominecraft.launcher.util;
import java.io.File; import java.io.File;
import org.jackhuang.hellominecraft.api.HMCLAPI; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.launcher.api.event.version.MinecraftLibraryPathEvent; import org.jackhuang.hellominecraft.launcher.api.event.version.MinecraftLibraryPathEvent;
import org.jackhuang.hellominecraft.launcher.core.version.GameDirType; import org.jackhuang.hellominecraft.launcher.core.version.GameDirType;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersionManager; import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersionManager;
@@ -34,7 +34,7 @@ public class HMCLGameProvider extends MinecraftVersionManager {
public HMCLGameProvider(HMCLMinecraftService p) { public HMCLGameProvider(HMCLMinecraftService p) {
super(p); super(p);
HMCLAPI.EVENT_BUS.channel(MinecraftLibraryPathEvent.class).register(t -> { HMCAPI.EVENT_BUS.channel(MinecraftLibraryPathEvent.class).register(t -> {
if (!t.getFile().getValue().exists()) if (!t.getFile().getValue().exists())
t.getFile().setValue(new File(Settings.getInstance().getCommonpath(), t.getLocation())); t.getFile().setValue(new File(Settings.getInstance().getCommonpath(), t.getLocation()));
}); });

View File

@@ -22,7 +22,7 @@ import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import org.jackhuang.hellominecraft.api.HMCLAPI; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.launcher.api.event.version.LoadedOneVersionEvent; import org.jackhuang.hellominecraft.launcher.api.event.version.LoadedOneVersionEvent;
import org.jackhuang.hellominecraft.launcher.api.event.version.RefreshedVersionsEvent; import org.jackhuang.hellominecraft.launcher.api.event.version.RefreshedVersionsEvent;
import org.jackhuang.hellominecraft.launcher.api.event.version.RefreshingVersionsEvent; import org.jackhuang.hellominecraft.launcher.api.event.version.RefreshingVersionsEvent;
@@ -57,8 +57,8 @@ public class HMCLMinecraftService extends IMinecraftService {
this.p = p; this.p = p;
this.provider = new HMCLGameProvider(this); this.provider = new HMCLGameProvider(this);
provider.initializeMiencraft(); provider.initializeMiencraft();
HMCLAPI.EVENT_BUS.channel(RefreshingVersionsEvent.class).register(versionSettings::clear); HMCAPI.EVENT_BUS.channel(RefreshingVersionsEvent.class).register(versionSettings::clear);
HMCLAPI.EVENT_BUS.channel(RefreshedVersionsEvent.class).registerFirst(() -> { HMCAPI.EVENT_BUS.channel(RefreshedVersionsEvent.class).registerFirst(() -> {
if (!checkingModpack) { if (!checkingModpack) {
checkingModpack = true; checkingModpack = true;
if (version().getVersionCount() == 0) { if (version().getVersionCount() == 0) {
@@ -72,7 +72,7 @@ public class HMCLMinecraftService extends IMinecraftService {
} }
} }
}); });
HMCLAPI.EVENT_BUS.channel(LoadedOneVersionEvent.class).register(e -> loadVersionSetting(e.getValue())); HMCAPI.EVENT_BUS.channel(LoadedOneVersionEvent.class).register(e -> loadVersionSetting(e.getValue()));
this.mms = new MinecraftModService(this); this.mms = new MinecraftModService(this);
this.mds = new MinecraftDownloadService(this); this.mds = new MinecraftDownloadService(this);
this.mas = new HMCLAssetService(this); this.mas = new HMCLAssetService(this);

View File

@@ -0,0 +1,32 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.svrmgr.api;
import java.util.EventObject;
/**
*
* @author huang
*/
public class ServerStartedEvent extends EventObject {
public ServerStartedEvent(Object source) {
super(source);
}
}

View File

@@ -0,0 +1,32 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* 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 {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.svrmgr.api;
import java.util.EventObject;
/**
*
* @author huang
*/
public class ServerStoppedEvent extends EventObject {
public ServerStoppedEvent(Object source) {
super(source);
}
}

View File

@@ -34,6 +34,8 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.api.SimpleEvent;
import org.jackhuang.hellominecraft.util.log.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import org.jackhuang.hellominecraft.util.sys.IOUtils; import org.jackhuang.hellominecraft.util.sys.IOUtils;
import org.jackhuang.hellominecraft.util.MessageBox; import org.jackhuang.hellominecraft.util.MessageBox;
@@ -44,8 +46,8 @@ import org.jackhuang.hellominecraft.svrmgr.setting.SettingsManager;
import org.jackhuang.hellominecraft.svrmgr.util.MonitorThread; import org.jackhuang.hellominecraft.svrmgr.util.MonitorThread;
import org.jackhuang.hellominecraft.svrmgr.util.WaitForThread; import org.jackhuang.hellominecraft.svrmgr.util.WaitForThread;
import org.jackhuang.hellominecraft.svrmgr.util.Utilities; import org.jackhuang.hellominecraft.svrmgr.util.Utilities;
import org.jackhuang.hellominecraft.api.Event; import org.jackhuang.hellominecraft.svrmgr.api.ServerStartedEvent;
import org.jackhuang.hellominecraft.api.EventHandler; import org.jackhuang.hellominecraft.svrmgr.api.ServerStoppedEvent;
import org.jackhuang.hellominecraft.util.code.Charsets; import org.jackhuang.hellominecraft.util.code.Charsets;
import org.jackhuang.hellominecraft.util.func.Consumer; import org.jackhuang.hellominecraft.util.func.Consumer;
@@ -53,7 +55,7 @@ import org.jackhuang.hellominecraft.util.func.Consumer;
* *
* @author huangyuhui * @author huangyuhui
*/ */
public class Server implements Event<Integer>, MonitorThread.MonitorThreadListener, public class Server implements Consumer<SimpleEvent<Integer>>, MonitorThread.MonitorThreadListener,
ActionListener { ActionListener {
private static Server instance; private static Server instance;
@@ -77,9 +79,7 @@ public class Server implements Event<Integer>, MonitorThread.MonitorThreadListen
WaitForThread threadC; WaitForThread threadC;
Consumer<Pair<String, String[]>> gettingPlayerNumber; Consumer<Pair<String, String[]>> gettingPlayerNumber;
ArrayList<MonitorThread.MonitorThreadListener> listeners; ArrayList<MonitorThread.MonitorThreadListener> listeners;
ArrayList<Event<Integer>> listenersC; ArrayList<Consumer<SimpleEvent<Integer>>> listenersC;
//ArrayList<DoneListener0> listenersBegin, listenersDone;
public final EventHandler<Void> startedEvent = new EventHandler<>(this), stoppedEvent = new EventHandler<>(this);
ArrayList<TimerTask> timerTasks; ArrayList<TimerTask> timerTasks;
ArrayList<Schedule> schedules; ArrayList<Schedule> schedules;
BufferedWriter bw; BufferedWriter bw;
@@ -103,7 +103,7 @@ public class Server implements Event<Integer>, MonitorThread.MonitorThreadListen
listeners.add(l); listeners.add(l);
} }
public void addListener(Event<Integer> l) { public void addListener(Consumer<SimpleEvent<Integer>> l) {
listenersC.add(l); listenersC.add(l);
} }
@@ -133,7 +133,7 @@ public class Server implements Event<Integer>, MonitorThread.MonitorThreadListen
registerThreadC(server); registerThreadC(server);
bw = new BufferedWriter(new OutputStreamWriter(server.getOutputStream(), Charsets.toCharset())); bw = new BufferedWriter(new OutputStreamWriter(server.getOutputStream(), Charsets.toCharset()));
isRunning = true; isRunning = true;
startedEvent.fire(null); HMCAPI.EVENT_BUS.fireChannel(new ServerStartedEvent(this));
sendStatus("*** 启动服务端中 ***"); sendStatus("*** 启动服务端中 ***");
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
@@ -203,14 +203,15 @@ public class Server implements Event<Integer>, MonitorThread.MonitorThreadListen
private void registerThreadC(Process p) { private void registerThreadC(Process p) {
threadC = new WaitForThread(p); threadC = new WaitForThread(p);
for (Event<Integer> l : listenersC) for (Consumer<SimpleEvent<Integer>> l : listenersC)
threadC.event.register(l); threadC.event.register(l);
threadC.event.register(this); threadC.event.register(this);
threadC.start(); threadC.start();
} }
@Override @Override
public boolean call(Object sender, Integer t) { public void accept(SimpleEvent<Integer> event) {
int t = event.getValue();
if (t == 0) { if (t == 0) {
sendStatus("*** 服务端已停止 ***"); sendStatus("*** 服务端已停止 ***");
System.out.println("Server stopped successfully"); System.out.println("Server stopped successfully");
@@ -236,7 +237,6 @@ public class Server implements Event<Integer>, MonitorThread.MonitorThreadListen
} }
isRestart = false; isRestart = false;
} }
return true;
} }
private static void disactiveMods(ArrayList<String> inactiveExtMods, private static void disactiveMods(ArrayList<String> inactiveExtMods,
@@ -342,7 +342,7 @@ public class Server implements Event<Integer>, MonitorThread.MonitorThreadListen
Pattern p = Pattern.compile("\\[INFO\\] Done \\([0-9]*\\.[0-9]*s\\)! For help, type \"help\" or \"\\?\""); Pattern p = Pattern.compile("\\[INFO\\] Done \\([0-9]*\\.[0-9]*s\\)! For help, type \"help\" or \"\\?\"");
Matcher m = p.matcher(status); Matcher m = p.matcher(status);
if (m.find()) { if (m.find()) {
stoppedEvent.fire(null); HMCAPI.EVENT_BUS.fireChannel(new ServerStoppedEvent(this));
timer = new Timer(); timer = new Timer();
timerTasks.clear(); timerTasks.clear();
for (int i = 0; i < schedules.size(); i++) { for (int i = 0; i < schedules.size(); i++) {

View File

@@ -87,15 +87,19 @@ import org.jackhuang.hellominecraft.svrmgr.util.Utilities;
import org.jackhuang.hellominecraft.util.ui.SwingUtils; import org.jackhuang.hellominecraft.util.ui.SwingUtils;
import org.jackhuang.hellominecraft.svrmgr.util.version.MinecraftRemoteVersion; import org.jackhuang.hellominecraft.svrmgr.util.version.MinecraftRemoteVersion;
import org.jackhuang.hellominecraft.lookandfeel.ConstomButton; import org.jackhuang.hellominecraft.lookandfeel.ConstomButton;
import org.jackhuang.hellominecraft.api.Event; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.api.SimpleEvent;
import org.jackhuang.hellominecraft.svrmgr.api.ServerStartedEvent;
import org.jackhuang.hellominecraft.svrmgr.api.ServerStoppedEvent;
import org.jackhuang.hellominecraft.util.StrUtils; import org.jackhuang.hellominecraft.util.StrUtils;
import org.jackhuang.hellominecraft.util.func.Consumer;
/** /**
* *
* @author huangyuhui * @author huangyuhui
*/ */
public final class MainWindow extends javax.swing.JFrame public final class MainWindow extends javax.swing.JFrame
implements MonitorThread.MonitorThreadListener, Event<Integer> { implements MonitorThread.MonitorThreadListener, Consumer<SimpleEvent<Integer>> {
ImageIcon background = new ImageIcon(getClass().getResource("/background.jpg")); ImageIcon background = new ImageIcon(getClass().getResource("/background.jpg"));
JLabel backgroundLabel; JLabel backgroundLabel;
@@ -3095,25 +3099,24 @@ public final class MainWindow extends javax.swing.JFrame
MessageBox.show("服务器未开启!"); MessageBox.show("服务器未开启!");
} }
class ServerBeginListener implements Event<Void> { class ServerBeginListener implements Runnable {
@Override @Override
public boolean call(Object sender, Void v) { public void run() {
commandSet = new ArrayList<>(); commandSet = new ArrayList<>();
txtMain.setText(""); txtMain.setText("");
btnLaunch.setEnabled(false); btnLaunch.setEnabled(false);
btnStop.setEnabled(true); btnStop.setEnabled(true);
btnShutdown.setEnabled(true); btnShutdown.setEnabled(true);
btnCommand.setEnabled(true); btnCommand.setEnabled(true);
return true;
} }
} }
class ServerDoneListener implements Event<Void> { class ServerDoneListener implements Runnable {
@Override @Override
public boolean call(Object sender, Void v) { public void run() {
getPlayerNumberTimer = new Timer(); getPlayerNumberTimer = new Timer();
getPlayerNumberTimer.schedule(new TimerTask() { getPlayerNumberTimer.schedule(new TimerTask() {
@@ -3122,7 +3125,6 @@ public final class MainWindow extends javax.swing.JFrame
loadPlayers(); loadPlayers();
} }
}, 1000 * 60 * 10, 1000 * 60 * 10); }, 1000 * 60 * 10, 1000 * 60 * 10);
return true;
} }
} }
@@ -3153,14 +3155,14 @@ public final class MainWindow extends javax.swing.JFrame
Server.getInstance() Server.getInstance()
.addListener((MonitorThread.MonitorThreadListener) this); .addListener((MonitorThread.MonitorThreadListener) this);
Server.getInstance() Server.getInstance()
.addListener((Event<Integer>) this); .addListener((Consumer<SimpleEvent<Integer>>) this);
Server.getInstance() Server.getInstance()
.clearSchedule(); .clearSchedule();
for (Schedule s : SettingsManager.settings.schedules) for (Schedule s : SettingsManager.settings.schedules)
Server.getInstance().addSchedule(s); Server.getInstance().addSchedule(s);
Server.getInstance().startedEvent.register(new ServerBeginListener()); HMCAPI.EVENT_BUS.channel(ServerStartedEvent.class).register(new ServerBeginListener());
Server.getInstance().startedEvent.register(new ServerDoneListener()); HMCAPI.EVENT_BUS.channel(ServerStoppedEvent.class).register(new ServerDoneListener());
try { try {
Server.getInstance().run(); Server.getInstance().run();
} catch (IOException ex) { } catch (IOException ex) {
@@ -3956,7 +3958,7 @@ public final class MainWindow extends javax.swing.JFrame
} }
@Override @Override
public boolean call(Object sender, Integer t) { public void accept(SimpleEvent<Integer> event) {
btnLaunch.setEnabled(true); btnLaunch.setEnabled(true);
btnStop.setEnabled(false); btnStop.setEnabled(false);
btnShutdown.setEnabled(false); btnShutdown.setEnabled(false);
@@ -3973,7 +3975,6 @@ public final class MainWindow extends javax.swing.JFrame
getPlayerNumberTimer.cancel(); getPlayerNumberTimer.cancel();
getPlayerNumberTimer = null; getPlayerNumberTimer = null;
} }
return true;
} }
private void sendCommand() { private void sendCommand() {

View File

@@ -18,6 +18,7 @@
package org.jackhuang.hellominecraft.svrmgr.util; package org.jackhuang.hellominecraft.svrmgr.util;
import org.jackhuang.hellominecraft.api.EventHandler; import org.jackhuang.hellominecraft.api.EventHandler;
import org.jackhuang.hellominecraft.api.SimpleEvent;
import org.jackhuang.hellominecraft.util.log.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
/** /**
@@ -26,7 +27,7 @@ import org.jackhuang.hellominecraft.util.log.HMCLog;
*/ */
public class WaitForThread extends Thread { public class WaitForThread extends Thread {
public final EventHandler<Integer> event = new EventHandler<>(this); public final EventHandler<SimpleEvent<Integer>> event = new EventHandler<>();
Process p; Process p;
public WaitForThread(Process p) { public WaitForThread(Process p) {
@@ -37,10 +38,10 @@ public class WaitForThread extends Thread {
public void run() { public void run() {
try { try {
int exitCode = p.waitFor(); int exitCode = p.waitFor();
event.fire(exitCode); event.fire(new SimpleEvent<>(this, exitCode));
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
HMCLog.err("Game has been interrupted.", ex); HMCLog.err("Game has been interrupted.", ex);
event.fire(-1); event.fire(new SimpleEvent<>(this, -1));
} }
} }

View File

@@ -21,7 +21,7 @@ package org.jackhuang.hellominecraft.api;
* *
* @author huang * @author huang
*/ */
public class HMCLAPI { public class HMCAPI {
/** /**
* Events. * Events.

View File

@@ -23,7 +23,7 @@ import com.google.gson.JsonSyntaxException;
import java.io.IOException; import java.io.IOException;
import org.jackhuang.hellominecraft.util.log.HMCLog; import org.jackhuang.hellominecraft.util.log.HMCLog;
import java.util.Map; import java.util.Map;
import org.jackhuang.hellominecraft.api.HMCLAPI; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.api.SimpleEvent; import org.jackhuang.hellominecraft.api.SimpleEvent;
import org.jackhuang.hellominecraft.api.event.OutOfDateEvent; import org.jackhuang.hellominecraft.api.event.OutOfDateEvent;
@@ -98,7 +98,7 @@ public final class UpdateChecker implements IUpdateChecker {
@Override @Override
public void checkOutdate() { public void checkOutdate() {
if (outOfDate) if (outOfDate)
if (HMCLAPI.EVENT_BUS.fireChannelResulted(new OutOfDateEvent(this, getNewVersion()))) if (HMCAPI.EVENT_BUS.fireChannelResulted(new OutOfDateEvent(this, getNewVersion())))
upgrade.fire(new SimpleEvent<>(this, getNewVersion())); upgrade.fire(new SimpleEvent<>(this, getNewVersion()));
} }
} }

View File

@@ -21,7 +21,7 @@ import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import org.jackhuang.hellominecraft.util.CollectionUtils; import org.jackhuang.hellominecraft.util.CollectionUtils;
import org.jackhuang.hellominecraft.api.EventHandler; import org.jackhuang.hellominecraft.api.EventHandler;
import org.jackhuang.hellominecraft.api.HMCLAPI; import org.jackhuang.hellominecraft.api.HMCAPI;
import org.jackhuang.hellominecraft.api.event.process.JVMLaunchFailedEvent; import org.jackhuang.hellominecraft.api.event.process.JVMLaunchFailedEvent;
import org.jackhuang.hellominecraft.api.event.process.JavaProcessExitedAbnormallyEvent; import org.jackhuang.hellominecraft.api.event.process.JavaProcessExitedAbnormallyEvent;
import org.jackhuang.hellominecraft.api.event.process.JavaProcessStartingEvent; import org.jackhuang.hellominecraft.api.event.process.JavaProcessStartingEvent;
@@ -59,21 +59,21 @@ public class JavaProcessMonitor {
public void start() { public void start() {
HMCLAPI.EVENT_BUS.fireChannel(new JavaProcessStartingEvent(this, p)); HMCAPI.EVENT_BUS.fireChannel(new JavaProcessStartingEvent(this, p));
ProcessThread a = new ProcessThread(p); ProcessThread a = new ProcessThread(p);
a.stopEvent.register(event -> { a.stopEvent.register(event -> {
HMCLog.log("Process exit code: " + p.getExitCode()); HMCLog.log("Process exit code: " + p.getExitCode());
if (p.getExitCode() != 0 || StrUtils.containsOne(p.getStdOutLines(), if (p.getExitCode() != 0 || StrUtils.containsOne(p.getStdOutLines(),
Arrays.asList("Unable to launch"), Arrays.asList("Unable to launch"),
x -> Level.guessLevel(x, Level.INFO).lessOrEqual(Level.ERROR))) x -> Level.guessLevel(x, Level.INFO).lessOrEqual(Level.ERROR)))
HMCLAPI.EVENT_BUS.fireChannel(new JavaProcessExitedAbnormallyEvent(JavaProcessMonitor.this, p)); HMCAPI.EVENT_BUS.fireChannel(new JavaProcessExitedAbnormallyEvent(JavaProcessMonitor.this, p));
if (p.getExitCode() != 0 && StrUtils.containsOne(p.getStdOutLines(), if (p.getExitCode() != 0 && StrUtils.containsOne(p.getStdOutLines(),
Arrays.asList("Could not create the Java Virtual Machine.", Arrays.asList("Could not create the Java Virtual Machine.",
"Error occurred during initialization of VM", "Error occurred during initialization of VM",
"A fatal exception has occurred. Program will exit.", "A fatal exception has occurred. Program will exit.",
"Unable to launch"), "Unable to launch"),
x -> Level.guessLevel(x, Level.INFO).lessOrEqual(Level.ERROR))) x -> Level.guessLevel(x, Level.INFO).lessOrEqual(Level.ERROR)))
HMCLAPI.EVENT_BUS.fireChannel(new JVMLaunchFailedEvent(JavaProcessMonitor.this, p)); HMCAPI.EVENT_BUS.fireChannel(new JVMLaunchFailedEvent(JavaProcessMonitor.this, p));
processThreadStopped((ProcessThread) event.getSource(), false); processThreadStopped((ProcessThread) event.getSource(), false);
}); });
a.start(); a.start();
@@ -86,7 +86,7 @@ public class JavaProcessMonitor {
for (Thread a : al) for (Thread a : al)
a.interrupt(); a.interrupt();
al.clear(); al.clear();
HMCLAPI.EVENT_BUS.fireChannel(new JavaProcessStoppedEvent(this, p)); HMCAPI.EVENT_BUS.fireChannel(new JavaProcessStoppedEvent(this, p));
} }
} }
} }