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;
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.util.C;
import org.jackhuang.hellominecraft.util.task.TaskWindow;
@@ -62,6 +62,6 @@ public enum DownloadType {
}
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.util.HashSet;
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.launcher.api.event.launch.DecompressLibrariesEvent;
import org.jackhuang.hellominecraft.launcher.api.event.launch.DownloadLibrariesEvent;
@@ -44,7 +44,7 @@ public class DefaultGameLauncher extends GameLauncher {
}
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;
final TaskWindow.TaskWindowFactory dw = TaskWindow.factory();
ParallelTask parallelTask = new ParallelTask();
@@ -63,7 +63,7 @@ public class DefaultGameLauncher extends GameLauncher {
flag = true;
t.setResult(flag);
});
HMCLAPI.EVENT_BUS.channel(DecompressLibrariesEvent.class).register(t -> {
HMCAPI.EVENT_BUS.channel(DecompressLibrariesEvent.class).register(t -> {
if (t.getValue() == null) {
t.setResult(false);
return;

View File

@@ -23,7 +23,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
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.DecompressLibraryJob;
import org.jackhuang.hellominecraft.launcher.api.event.launch.DownloadLibrariesEvent;
@@ -90,7 +90,7 @@ public class GameLauncher {
public void makeLaunchCommand() throws AuthenticationException, GameException, RuntimeGameException {
HMCLog.log("Building process");
HMCLog.log("Logging in...");
HMCLAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.LoggingIn));
HMCAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.LoggingIn));
IMinecraftLoader loader;
if (info != null)
result = login.login(info);
@@ -98,9 +98,9 @@ public class GameLauncher {
result = login.loginBySettings();
if (result == 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);
File file = service.version().getDecompressNativesToLocation(loader.getMinecraftVersion());
@@ -109,18 +109,18 @@ public class GameLauncher {
if (!options.isNotCheckGame()) {
HMCLog.log("Detecting libraries...");
HMCLAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.DownloadingLibraries));
if (!HMCLAPI.EVENT_BUS.fireChannelResulted(new DownloadLibrariesEvent(this, service.download().getDownloadLibraries(loader.getMinecraftVersion()))))
HMCAPI.EVENT_BUS.fireChannel(new LaunchingStateChangedEvent(this, LaunchingState.DownloadingLibraries));
if (!HMCAPI.EVENT_BUS.fireChannelResulted(new DownloadLibrariesEvent(this, service.download().getDownloadLibraries(loader.getMinecraftVersion()))))
throw new GameException("Failed to download libraries");
}
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());
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");
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());
JavaProcess jp = new JavaProcess(str, builder.start(), PROCESS_MANAGER);
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.util.ArrayList;
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.util.sys.OS;
import org.jackhuang.hellominecraft.util.sys.Platform;
@@ -108,7 +108,7 @@ public class MinecraftLibrary extends IMinecraftLibrary {
if (info == null)
return null;
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();
}

View File

@@ -25,7 +25,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
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.RefreshedVersionsEvent;
import org.jackhuang.hellominecraft.launcher.api.event.version.RefreshingVersionsEvent;
@@ -72,7 +72,7 @@ public class MinecraftVersionManager extends IMinecraftProvider {
@Override
public synchronized void refreshVersions() {
HMCLAPI.EVENT_BUS.fireChannel(new RefreshingVersionsEvent(this, service));
HMCAPI.EVENT_BUS.fireChannel(new RefreshingVersionsEvent(this, service));
try {
MCUtils.tryWriteProfile(service.baseDirectory());
@@ -142,12 +142,12 @@ public class MinecraftVersionManager extends IMinecraftProvider {
}
versions.put(id, mcVersion);
HMCLAPI.EVENT_BUS.fireChannel(new LoadedOneVersionEvent(this, id));
HMCAPI.EVENT_BUS.fireChannel(new LoadedOneVersionEvent(this, id));
} catch (Exception 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

View File

@@ -27,7 +27,7 @@ import java.util.TreeMap;
import java.util.UUID;
import org.jackhuang.hellominecraft.launcher.core.auth.IAuthenticator;
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.DownloadTypeChangedEvent;
import org.jackhuang.hellominecraft.launcher.api.event.config.ThemeChangedEvent;
@@ -92,7 +92,7 @@ public final class Config implements Cloneable {
public void setTheme(int theme) {
this.theme = theme;
HMCLAPI.EVENT_BUS.fireChannel(new ThemeChangedEvent(this, getTheme()));
HMCAPI.EVENT_BUS.fireChannel(new ThemeChangedEvent(this, getTheme()));
Settings.save();
}
@@ -182,7 +182,7 @@ public final class Config implements Cloneable {
if (logintype < 0 || logintype >= IAuthenticator.LOGINS.size())
return;
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();
}
@@ -192,7 +192,7 @@ public final class Config implements Cloneable {
public void setDownloadType(int downloadtype) {
this.downloadtype = downloadtype;
HMCLAPI.EVENT_BUS.fireChannel(new DownloadTypeChangedEvent(this, getDownloadSource()));
HMCAPI.EVENT_BUS.fireChannel(new DownloadTypeChangedEvent(this, getDownloadSource()));
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.download.DownloadType;
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.ProfileLoadingEvent;
import org.jackhuang.hellominecraft.util.sys.FileUtils;
@@ -161,12 +161,12 @@ public final class Settings {
Profile p = getLastProfile();
if (p == null)
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();
}
public static void onProfileLoading() {
HMCLAPI.EVENT_BUS.fireChannel(new ProfileLoadingEvent(SETTINGS));
HMCAPI.EVENT_BUS.fireChannel(new ProfileLoadingEvent(SETTINGS));
onProfileChanged();
}
}

View File

@@ -43,7 +43,7 @@ import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.TableModelEvent;
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.ProfileLoadingEvent;
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];
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 (!showedNoVersion && Settings.getLastProfile().service().checkingModpack) {
showedNoVersion = true;
@@ -123,9 +123,9 @@ public final class GameSettingsPanel extends RepaintPage implements DropTargetLi
cboJava.addItem(j.getLocalizedName());
isLoading = false;
HMCLAPI.EVENT_BUS.channel(ProfileLoadingEvent.class).register(onLoadingProfiles);
HMCLAPI.EVENT_BUS.channel(ProfileChangedEvent.class).register(onSelectedProfilesChanged);
HMCLAPI.EVENT_BUS.channel(RefreshedVersionsEvent.class).register(onRefreshedVersions);
HMCAPI.EVENT_BUS.channel(ProfileLoadingEvent.class).register(onLoadingProfiles);
HMCAPI.EVENT_BUS.channel(ProfileChangedEvent.class).register(onSelectedProfilesChanged);
HMCAPI.EVENT_BUS.channel(RefreshedVersionsEvent.class).register(onRefreshedVersions);
}
void initExplorationMenu() {

View File

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

View File

@@ -29,7 +29,7 @@ import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
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.ProfileChangedEvent;
import org.jackhuang.hellominecraft.launcher.api.event.config.ProfileLoadingEvent;
@@ -97,12 +97,12 @@ public class MainPagePanel extends Page {
((RepaintPage) pnlMore).setRepainter(pnlRoot);
HMCLAPI.EVENT_BUS.channel(AuthenticatorChangedEvent.class).register(onAuthChanged);
HMCLAPI.EVENT_BUS.channel(ProfileLoadingEvent.class).register(onLoadingProfiles);
HMCLAPI.EVENT_BUS.channel(ProfileChangedEvent.class).register(onSelectedProfilesChanged);
HMCLAPI.EVENT_BUS.channel(RefreshedVersionsEvent.class).register(onRefreshedVersions);
HMCLAPI.EVENT_BUS.channel(LaunchingStateChangedEvent.class).register(launchingStateChanged);
HMCLAPI.EVENT_BUS.channel(LaunchSucceededEvent.class).register(this::prepareAuths);
HMCAPI.EVENT_BUS.channel(AuthenticatorChangedEvent.class).register(onAuthChanged);
HMCAPI.EVENT_BUS.channel(ProfileLoadingEvent.class).register(onLoadingProfiles);
HMCAPI.EVENT_BUS.channel(ProfileChangedEvent.class).register(onSelectedProfilesChanged);
HMCAPI.EVENT_BUS.channel(RefreshedVersionsEvent.class).register(onRefreshedVersions);
HMCAPI.EVENT_BUS.channel(LaunchingStateChangedEvent.class).register(launchingStateChanged);
HMCAPI.EVENT_BUS.channel(LaunchSucceededEvent.class).register(this::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.Settings;
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.LaunchingState;
import org.jackhuang.hellominecraft.launcher.api.event.launch.LaunchingStateChangedEvent;
@@ -50,12 +50,12 @@ public class HMCLGameLauncher {
public HMCLGameLauncher(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) {
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;
}
@@ -85,7 +85,7 @@ public class HMCLGameLauncher {
Thread.currentThread().setName("Game Launcher");
try {
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);
GameLauncherTag tag = new GameLauncherTag();
tag.launcherVisibility = profile.getSelectedVersionSetting().getLauncherVisibility();

View File

@@ -18,7 +18,7 @@
package org.jackhuang.hellominecraft.launcher.util;
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.core.version.GameDirType;
import org.jackhuang.hellominecraft.launcher.core.version.MinecraftVersionManager;
@@ -34,7 +34,7 @@ public class HMCLGameProvider extends MinecraftVersionManager {
public HMCLGameProvider(HMCLMinecraftService p) {
super(p);
HMCLAPI.EVENT_BUS.channel(MinecraftLibraryPathEvent.class).register(t -> {
HMCAPI.EVENT_BUS.channel(MinecraftLibraryPathEvent.class).register(t -> {
if (!t.getFile().getValue().exists())
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.Map;
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.RefreshedVersionsEvent;
import org.jackhuang.hellominecraft.launcher.api.event.version.RefreshingVersionsEvent;
@@ -57,8 +57,8 @@ public class HMCLMinecraftService extends IMinecraftService {
this.p = p;
this.provider = new HMCLGameProvider(this);
provider.initializeMiencraft();
HMCLAPI.EVENT_BUS.channel(RefreshingVersionsEvent.class).register(versionSettings::clear);
HMCLAPI.EVENT_BUS.channel(RefreshedVersionsEvent.class).registerFirst(() -> {
HMCAPI.EVENT_BUS.channel(RefreshingVersionsEvent.class).register(versionSettings::clear);
HMCAPI.EVENT_BUS.channel(RefreshedVersionsEvent.class).registerFirst(() -> {
if (!checkingModpack) {
checkingModpack = true;
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.mds = new MinecraftDownloadService(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.regex.Matcher;
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.sys.IOUtils;
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.WaitForThread;
import org.jackhuang.hellominecraft.svrmgr.util.Utilities;
import org.jackhuang.hellominecraft.api.Event;
import org.jackhuang.hellominecraft.api.EventHandler;
import org.jackhuang.hellominecraft.svrmgr.api.ServerStartedEvent;
import org.jackhuang.hellominecraft.svrmgr.api.ServerStoppedEvent;
import org.jackhuang.hellominecraft.util.code.Charsets;
import org.jackhuang.hellominecraft.util.func.Consumer;
@@ -53,7 +55,7 @@ import org.jackhuang.hellominecraft.util.func.Consumer;
*
* @author huangyuhui
*/
public class Server implements Event<Integer>, MonitorThread.MonitorThreadListener,
public class Server implements Consumer<SimpleEvent<Integer>>, MonitorThread.MonitorThreadListener,
ActionListener {
private static Server instance;
@@ -77,9 +79,7 @@ public class Server implements Event<Integer>, MonitorThread.MonitorThreadListen
WaitForThread threadC;
Consumer<Pair<String, String[]>> gettingPlayerNumber;
ArrayList<MonitorThread.MonitorThreadListener> listeners;
ArrayList<Event<Integer>> listenersC;
//ArrayList<DoneListener0> listenersBegin, listenersDone;
public final EventHandler<Void> startedEvent = new EventHandler<>(this), stoppedEvent = new EventHandler<>(this);
ArrayList<Consumer<SimpleEvent<Integer>>> listenersC;
ArrayList<TimerTask> timerTasks;
ArrayList<Schedule> schedules;
BufferedWriter bw;
@@ -103,7 +103,7 @@ public class Server implements Event<Integer>, MonitorThread.MonitorThreadListen
listeners.add(l);
}
public void addListener(Event<Integer> l) {
public void addListener(Consumer<SimpleEvent<Integer>> l) {
listenersC.add(l);
}
@@ -133,7 +133,7 @@ public class Server implements Event<Integer>, MonitorThread.MonitorThreadListen
registerThreadC(server);
bw = new BufferedWriter(new OutputStreamWriter(server.getOutputStream(), Charsets.toCharset()));
isRunning = true;
startedEvent.fire(null);
HMCAPI.EVENT_BUS.fireChannel(new ServerStartedEvent(this));
sendStatus("*** 启动服务端中 ***");
} catch (IOException 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) {
threadC = new WaitForThread(p);
for (Event<Integer> l : listenersC)
for (Consumer<SimpleEvent<Integer>> l : listenersC)
threadC.event.register(l);
threadC.event.register(this);
threadC.start();
}
@Override
public boolean call(Object sender, Integer t) {
public void accept(SimpleEvent<Integer> event) {
int t = event.getValue();
if (t == 0) {
sendStatus("*** 服务端已停止 ***");
System.out.println("Server stopped successfully");
@@ -236,7 +237,6 @@ public class Server implements Event<Integer>, MonitorThread.MonitorThreadListen
}
isRestart = false;
}
return true;
}
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 \"\\?\"");
Matcher m = p.matcher(status);
if (m.find()) {
stoppedEvent.fire(null);
HMCAPI.EVENT_BUS.fireChannel(new ServerStoppedEvent(this));
timer = new Timer();
timerTasks.clear();
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.svrmgr.util.version.MinecraftRemoteVersion;
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.func.Consumer;
/**
*
* @author huangyuhui
*/
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"));
JLabel backgroundLabel;
@@ -3095,25 +3099,24 @@ public final class MainWindow extends javax.swing.JFrame
MessageBox.show("服务器未开启!");
}
class ServerBeginListener implements Event<Void> {
class ServerBeginListener implements Runnable {
@Override
public boolean call(Object sender, Void v) {
public void run() {
commandSet = new ArrayList<>();
txtMain.setText("");
btnLaunch.setEnabled(false);
btnStop.setEnabled(true);
btnShutdown.setEnabled(true);
btnCommand.setEnabled(true);
return true;
}
}
class ServerDoneListener implements Event<Void> {
class ServerDoneListener implements Runnable {
@Override
public boolean call(Object sender, Void v) {
public void run() {
getPlayerNumberTimer = new Timer();
getPlayerNumberTimer.schedule(new TimerTask() {
@@ -3122,7 +3125,6 @@ public final class MainWindow extends javax.swing.JFrame
loadPlayers();
}
}, 1000 * 60 * 10, 1000 * 60 * 10);
return true;
}
}
@@ -3153,14 +3155,14 @@ public final class MainWindow extends javax.swing.JFrame
Server.getInstance()
.addListener((MonitorThread.MonitorThreadListener) this);
Server.getInstance()
.addListener((Event<Integer>) this);
.addListener((Consumer<SimpleEvent<Integer>>) this);
Server.getInstance()
.clearSchedule();
for (Schedule s : SettingsManager.settings.schedules)
Server.getInstance().addSchedule(s);
Server.getInstance().startedEvent.register(new ServerBeginListener());
Server.getInstance().startedEvent.register(new ServerDoneListener());
HMCAPI.EVENT_BUS.channel(ServerStartedEvent.class).register(new ServerBeginListener());
HMCAPI.EVENT_BUS.channel(ServerStoppedEvent.class).register(new ServerDoneListener());
try {
Server.getInstance().run();
} catch (IOException ex) {
@@ -3956,7 +3958,7 @@ public final class MainWindow extends javax.swing.JFrame
}
@Override
public boolean call(Object sender, Integer t) {
public void accept(SimpleEvent<Integer> event) {
btnLaunch.setEnabled(true);
btnStop.setEnabled(false);
btnShutdown.setEnabled(false);
@@ -3973,7 +3975,6 @@ public final class MainWindow extends javax.swing.JFrame
getPlayerNumberTimer.cancel();
getPlayerNumberTimer = null;
}
return true;
}
private void sendCommand() {

View File

@@ -18,6 +18,7 @@
package org.jackhuang.hellominecraft.svrmgr.util;
import org.jackhuang.hellominecraft.api.EventHandler;
import org.jackhuang.hellominecraft.api.SimpleEvent;
import org.jackhuang.hellominecraft.util.log.HMCLog;
/**
@@ -26,7 +27,7 @@ import org.jackhuang.hellominecraft.util.log.HMCLog;
*/
public class WaitForThread extends Thread {
public final EventHandler<Integer> event = new EventHandler<>(this);
public final EventHandler<SimpleEvent<Integer>> event = new EventHandler<>();
Process p;
public WaitForThread(Process p) {
@@ -37,10 +38,10 @@ public class WaitForThread extends Thread {
public void run() {
try {
int exitCode = p.waitFor();
event.fire(exitCode);
event.fire(new SimpleEvent<>(this, exitCode));
} catch (InterruptedException 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
*/
public class HMCLAPI {
public class HMCAPI {
/**
* Events.

View File

@@ -23,7 +23,7 @@ import com.google.gson.JsonSyntaxException;
import java.io.IOException;
import org.jackhuang.hellominecraft.util.log.HMCLog;
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.event.OutOfDateEvent;
@@ -98,7 +98,7 @@ public final class UpdateChecker implements IUpdateChecker {
@Override
public void checkOutdate() {
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()));
}
}

View File

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