why does the ui crash

This commit is contained in:
huangyuhui 2015-12-27 10:59:03 +08:00
parent b1c6c3549f
commit 07357db42d
536 changed files with 1562 additions and 776 deletions

1
.gitignore vendored Normal file → Executable file
View File

@ -22,5 +22,6 @@ hs_err_pid*
HMCLAPI/build/ HMCLAPI/build/
HMCL/build/ HMCL/build/
HMCL/src/main/org/jackhuang/hellominecraft/launcher/servers/
HMCSM/build/ HMCSM/build/
MetroLookAndFeel/build/ MetroLookAndFeel/build/

26
.gitignore~ Executable file
View File

@ -0,0 +1,26 @@
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
.gradle
.nb-gradle
*.bat
*.log
.mine*
*.json
*.hmd
HMCLAPI/build/
HMCL/build/
HMCSM/build/
MetroLookAndFeel/build/

0
.nb-gradle-properties Normal file → Executable file
View File

0
HMCL/HMCLauncher.exe Normal file → Executable file
View File

0
HMCL/build.gradle Normal file → Executable file
View File

0
HMCL/icon.ico Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 4.2 KiB

0
HMCL/obfuscate_2.3.3.map Normal file → Executable file
View File

0
HMCL/obfuscate_2.3.4.map Normal file → Executable file
View File

0
HMCL/proguard.pro vendored Normal file → Executable file
View File

0
HMCL/src/main/icon.icns Normal file → Executable file
View File

View File

View File

@ -33,6 +33,7 @@ import javax.swing.ImageIcon;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException; import javax.swing.UnsupportedLookAndFeelException;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.api.PluginManager;
import org.jackhuang.hellominecraft.launcher.launch.GameLauncher; import org.jackhuang.hellominecraft.launcher.launch.GameLauncher;
import org.jackhuang.hellominecraft.launcher.utils.CrashReporter; import org.jackhuang.hellominecraft.launcher.utils.CrashReporter;
import org.jackhuang.hellominecraft.logging.Configuration; import org.jackhuang.hellominecraft.logging.Configuration;
@ -86,7 +87,7 @@ public final class Main implements Runnable {
} }
public static final String LAUNCHER_NAME = "Hello Minecraft! Launcher"; public static final String LAUNCHER_NAME = "Hello Minecraft! Launcher";
public static final byte VERSION_FIRST = 2, VERSION_SECOND = 3, VERSION_THIRD = 1, VERSION_FORTH = 6; public static final byte VERSION_FIRST = 2, VERSION_SECOND = 3, VERSION_THIRD = 5, VERSION_FORTH = 7;
public static final int MINIMUM_LAUNCHER_VERSION = 16; public static final int MINIMUM_LAUNCHER_VERSION = 16;
//public static Proxy PROXY; //public static Proxy PROXY;
@ -109,10 +110,13 @@ public final class Main implements Runnable {
} }
public static final Main INSTANCE = new Main(); public static final Main INSTANCE = new Main();
public static HelloMinecraftLookAndFeel LOOK_AND_FEEL;
@SuppressWarnings({"CallToPrintStackTrace", "UseSpecificCatch"}) @SuppressWarnings({"CallToPrintStackTrace", "UseSpecificCatch"})
public static void main(String[] args) { public static void main(String[] args) {
{ {
//PluginManager.getServerPlugin();
if (IUpgrader.NOW_UPGRADER.parseArguments(new VersionNumber(VERSION_FIRST, VERSION_SECOND, VERSION_THIRD), args)) if (IUpgrader.NOW_UPGRADER.parseArguments(new VersionNumber(VERSION_FIRST, VERSION_SECOND, VERSION_THIRD), args))
return; return;
@ -136,7 +140,8 @@ public final class Main implements Runnable {
LogWindow.INSTANCE.setTerminateGame(GameLauncher.PROCESS_MANAGER::stopAllProcesses); LogWindow.INSTANCE.setTerminateGame(GameLauncher.PROCESS_MANAGER::stopAllProcesses);
try { try {
UIManager.setLookAndFeel(new HelloMinecraftLookAndFeel()); LOOK_AND_FEEL = new HelloMinecraftLookAndFeel(Settings.getInstance().getTheme().settings);
UIManager.setLookAndFeel(LOOK_AND_FEEL);
} catch (ParseException | UnsupportedLookAndFeelException ex) { } catch (ParseException | UnsupportedLookAndFeelException ex) {
HMCLog.warn("Failed to set look and feel...", ex); HMCLog.warn("Failed to set look and feel...", ex);
} }
@ -159,7 +164,7 @@ public final class Main implements Runnable {
} }
try { try {
MainFrame.showMainFrame(Settings.isFirstLoading()); PluginManager.NOW_PLUGIN.showUI();
} catch (Throwable t) { } catch (Throwable t) {
new CrashReporter(false).uncaughtException(Thread.currentThread(), t); new CrashReporter(false).uncaughtException(Thread.currentThread(), t);
System.exit(1); System.exit(1);

View File

@ -0,0 +1,62 @@
/*
* 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.launcher.api;
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.settings.Profile;
import org.jackhuang.hellominecraft.launcher.utils.auth.AuthenticationException;
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.utils.functions.Consumer;
/**
*
* @author huangyuhui
*/
public interface IPlugin {
/**
* You can modify the application actions by this method.
*
* @param profile info to the Minecraft Loader
* @return For example, you can implement IMinecraftProvider to support
* MultiMC
*/
IMinecraftProvider provideMinecraftProvider(Profile profile);
/**
* Register authenticators by calling IAuthenticator.LOGINS.add.
*
* @param apply call apply.accept(your authenticator)
*/
void onRegisterAuthenticators(Consumer<IAuthenticator> apply);
/**
* Open your customized UI.
*/
void showUI();
/**
* Add your server ip or modify the access token.
*
* @param result What you want.
*/
void onProcessingLoginResult(UserProfileProvider result) throws AuthenticationException;
void onInitializingProfile(Profile p);
}

View File

@ -0,0 +1,43 @@
/*
* 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.launcher.api;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.launch.DefaultPlugin;
/**
*
* @author huangyuhui
*/
public class PluginManager {
public static IPlugin NOW_PLUGIN = new DefaultPlugin();
public static void getServerPlugin() {
try {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
Class c = cl.loadClass("org.jackhuang.hellominecraft.launcher.servers.ServerPlugin");
IPlugin p = (IPlugin) c.newInstance();
NOW_PLUGIN = p;
} catch (ClassNotFoundException ignore) {
} catch (Exception e) {
HMCLog.err("Failed to new instance");
}
}
}

View File

@ -0,0 +1,77 @@
/*
* 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.launcher.launch;
import org.jackhuang.hellominecraft.launcher.api.IPlugin;
import org.jackhuang.hellominecraft.launcher.settings.Profile;
import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.utils.auth.OfflineAuthenticator;
import org.jackhuang.hellominecraft.launcher.utils.auth.SkinmeAuthenticator;
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.utils.auth.YggdrasilAuthenticator;
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersionManager;
import org.jackhuang.hellominecraft.launcher.views.MainFrame;
import org.jackhuang.hellominecraft.utils.functions.Consumer;
/**
*
* @author huangyuhui
*/
public class DefaultPlugin implements IPlugin {
protected static YggdrasilAuthenticator YGGDRASIL_LOGIN;
protected static OfflineAuthenticator OFFLINE_LOGIN;
protected static SkinmeAuthenticator SKINME_LOGIN;
@Override
public IMinecraftProvider provideMinecraftProvider(Profile profile) {
return new MinecraftVersionManager(profile);
}
@Override
public void onRegisterAuthenticators(Consumer<IAuthenticator> apply) {
String clientToken = Settings.getInstance().getClientToken();
OFFLINE_LOGIN = new OfflineAuthenticator(clientToken);
YGGDRASIL_LOGIN = new YggdrasilAuthenticator(clientToken);
YGGDRASIL_LOGIN.onLoadSettings(Settings.getInstance().getYggdrasilConfig());
SKINME_LOGIN = new SkinmeAuthenticator(clientToken);
Runtime.getRuntime().addShutdownHook(new Thread(()
-> Settings.getInstance().setYggdrasilConfig(YGGDRASIL_LOGIN.onSaveSettings())
));
apply.accept(OFFLINE_LOGIN);
apply.accept(YGGDRASIL_LOGIN);
apply.accept(SKINME_LOGIN);
}
@Override
public void showUI() {
MainFrame.showMainFrame(Settings.isFirstLoading());
}
@Override
public void onProcessingLoginResult(UserProfileProvider result) {
}
@Override
public void onInitializingProfile(Profile p) {
}
}

View File

@ -26,6 +26,7 @@ import java.io.UnsupportedEncodingException;
import java.util.List; import java.util.List;
import org.jackhuang.hellominecraft.C; import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.api.PluginManager;
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator; import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.utils.auth.LoginInfo; import org.jackhuang.hellominecraft.launcher.utils.auth.LoginInfo;
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider; import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
@ -73,7 +74,9 @@ public class GameLauncher {
result = login.login(info); result = login.login(info);
else else
result = login.loginBySettings(); result = login.loginBySettings();
if (result == null) throw new AuthenticationException("Result can not be null."); if (result == null)
throw new IllegalStateException("Result can not be null.");
PluginManager.NOW_PLUGIN.onProcessingLoginResult(result);
} catch (Throwable e) { } catch (Throwable e) {
String error = C.i18n("login.failed") + e.getMessage(); String error = C.i18n("login.failed") + e.getMessage();
HMCLog.warn("Login failed by method: " + login.getName(), e); HMCLog.warn("Login failed by method: " + login.getName(), e);
@ -115,7 +118,8 @@ public class GameLauncher {
*/ */
public void launch(List str) { public void launch(List str) {
try { try {
provider.onLaunch(); if (!provider.onLaunch())
return;
if (StrUtils.isNotBlank(getProfile().getPrecalledCommand())) { if (StrUtils.isNotBlank(getProfile().getPrecalledCommand())) {
Process p = Runtime.getRuntime().exec(getProfile().getPrecalledCommand()); Process p = Runtime.getRuntime().exec(getProfile().getPrecalledCommand());
try { try {
@ -128,7 +132,7 @@ public class GameLauncher {
HMCLog.log("Starting process"); HMCLog.log("Starting process");
ProcessBuilder builder = new ProcessBuilder(str); ProcessBuilder builder = new ProcessBuilder(str);
if (get == null || get.getSelectedMinecraftVersion() == null || StrUtils.isBlank(get.getCanonicalGameDir())) if (get == null || get.getSelectedMinecraftVersion() == null || StrUtils.isBlank(get.getCanonicalGameDir()))
throw new NullPointerException("Fucking bug!"); throw new Error("Fucking bug!");
builder.directory(provider.getRunDirectory(get.getSelectedMinecraftVersion().id)) builder.directory(provider.getRunDirectory(get.getSelectedMinecraftVersion().id))
.environment().put("APPDATA", get.getCanonicalGameDir()); .environment().put("APPDATA", get.getCanonicalGameDir());
JavaProcess jp = new JavaProcess(str, builder.start(), PROCESS_MANAGER); JavaProcess jp = new JavaProcess(str, builder.start(), PROCESS_MANAGER);

View File

@ -189,7 +189,9 @@ public abstract class IMinecraftProvider {
/** /**
* When GameLauncher launches the game, this function will be called. * When GameLauncher launches the game, this function will be called.
*
* @return if false, will break the launch process.
*/ */
public abstract void onLaunch(); public abstract boolean onLaunch();
} }

View File

@ -1,58 +0,0 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui
*
* 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.launcher.launch;
import java.util.List;
import org.jackhuang.hellominecraft.launcher.settings.LauncherVisibility;
import org.jackhuang.hellominecraft.launcher.views.MainFrame;
import org.jackhuang.hellominecraft.utils.Event;
import org.jackhuang.hellominecraft.utils.system.JavaProcessMonitor;
import org.jackhuang.hellominecraft.views.LogWindow;
/**
*
* @author huangyuhui
*/
public class LaunchFinisher implements Event<List<String>> {
@Override
public boolean call(Object sender, List<String> str) {
final GameLauncher obj = (GameLauncher) sender;
obj.launchEvent.register((sender1, p) -> {
if (obj.getProfile().getLauncherVisibility() == LauncherVisibility.CLOSE && !LogWindow.INSTANCE.isVisible())
System.exit(0);
else if (obj.getProfile().getLauncherVisibility() == LauncherVisibility.KEEP)
MainFrame.INSTANCE.closeMessage();
else {
if (LogWindow.INSTANCE.isVisible())
LogWindow.INSTANCE.setExit(() -> true);
MainFrame.INSTANCE.dispose();
}
JavaProcessMonitor jpm = new JavaProcessMonitor(p);
jpm.stoppedEvent.register((sender3, t) -> {
if (obj.getProfile().getLauncherVisibility() != LauncherVisibility.KEEP && !LogWindow.INSTANCE.isVisible())
System.exit(0);
return true;
});
jpm.start();
return true;
});
obj.launch(str);
return true;
}
}

View File

@ -1,51 +0,0 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui
*
* 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.launcher.launch;
import java.io.IOException;
import java.util.List;
import javax.swing.JOptionPane;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.views.MainFrame;
import org.jackhuang.hellominecraft.utils.Event;
import org.jackhuang.hellominecraft.utils.MessageBox;
/**
*
* @author huangyuhui
*/
public class LaunchScriptFinisher implements Event<List<String>> {
@Override
public boolean call(Object sender, List str) {
boolean flag = false;
try {
String s = JOptionPane.showInputDialog(C.i18n("mainwindow.enter_script_name"));
if (s != null)
MessageBox.Show(C.i18n("mainwindow.make_launch_succeed") + " " + ((GameLauncher) sender).makeLauncher(s, str).getAbsolutePath());
flag = true;
} catch (IOException ex) {
MessageBox.Show(C.i18n("mainwindow.make_launch_script_failed"));
HMCLog.err("Failed to create script file.", ex);
}
MainFrame.INSTANCE.closeMessage();
return flag;
}
}

View File

@ -0,0 +1,91 @@
/*
* 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.launcher.servers;
import org.jackhuang.hellominecraft.launcher.api.IPlugin;
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.servers.mfcraft.CheckModsMinecraftProvider;
import org.jackhuang.hellominecraft.launcher.servers.mfcraft.MFCraftAuthenticator;
import org.jackhuang.hellominecraft.launcher.servers.mfcraft.Servers;
import org.jackhuang.hellominecraft.launcher.settings.Profile;
import org.jackhuang.hellominecraft.launcher.settings.Settings;
import org.jackhuang.hellominecraft.launcher.utils.auth.AuthenticationException;
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.utils.auth.YggdrasilAuthenticator;
import org.jackhuang.hellominecraft.launcher.version.ServerInfo;
import org.jackhuang.hellominecraft.launcher.views.MainFrame;
import org.jackhuang.hellominecraft.launcher.views.ServerListView;
import org.jackhuang.hellominecraft.utils.functions.Consumer;
import org.jackhuang.hellominecraft.views.Selector;
/**
*
* @author huangyuhui
*/
public class ServerPlugin implements IPlugin {
protected static YggdrasilAuthenticator YGGDRASIL_LOGIN;
protected static MFCraftAuthenticator MFCRAFT_LOGIN;
@Override
public IMinecraftProvider provideMinecraftProvider(Profile profile) {
return new CheckModsMinecraftProvider(profile);
}
@Override
public void onRegisterAuthenticators(Consumer<IAuthenticator> apply) {
String clientToken = Settings.getInstance().getClientToken();
MFCRAFT_LOGIN = new MFCraftAuthenticator(clientToken);
YGGDRASIL_LOGIN = new YggdrasilAuthenticator(clientToken);
YGGDRASIL_LOGIN.onLoadSettings(Settings.getInstance().getYggdrasilConfig());
apply.accept(MFCRAFT_LOGIN);
apply.accept(YGGDRASIL_LOGIN);
}
@Override
public void showUI() {
MainFrame.showMainFrame(Settings.isFirstLoading());
}
public static ServerInfo lastServerInfo;
@Override
public void onProcessingLoginResult(UserProfileProvider result) throws AuthenticationException {
Servers s = Servers.getInstance();
String[] sel = new String[s.areas.size()];
for (int i = 0; i < sel.length; i++)
sel[i] = s.areas.get(i).name;
Selector selector = new Selector(null, sel, "选择你要登录的服务器大区");
int ind = selector.getChoice();
for (ServerInfo si : s.areas.get(ind).servers)
si.downloadIcon();
ServerListView slv = new ServerListView(s.areas.get(ind).servers.toArray(new ServerInfo[0]));
int c = slv.getChoice();
if (c == -1)
throw new AuthenticationException("未选择服务器");
lastServerInfo = s.areas.get(ind).servers.get(ind);
result.setServer(lastServerInfo);
}
@Override
public void onInitializingProfile(Profile p) {
p.initialize(1);
}
}

View File

@ -0,0 +1,51 @@
/*
* 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.launcher.servers.mfcraft;
import java.io.IOException;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.servers.ServerPlugin;
import org.jackhuang.hellominecraft.launcher.settings.Profile;
import org.jackhuang.hellominecraft.launcher.version.MinecraftModService;
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersionManager;
import org.jackhuang.hellominecraft.utils.ArrayUtils;
/**
*
* @author huangyuhui
*/
public class CheckModsMinecraftProvider extends MinecraftVersionManager {
public CheckModsMinecraftProvider(Profile p) {
super(p);
}
@Override
public boolean onLaunch() {
try {
super.onLaunch();
String[] md5s = ((MinecraftModService) getModService()).checkMd5s();
String[] md5 = ServerPlugin.lastServerInfo.md5;
return ArrayUtils.equals(md5s, md5);
} catch (IOException ex) {
HMCLog.err("Failed to check md5");
return false;
}
}
}

View File

@ -0,0 +1,76 @@
/*
* 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.launcher.servers.mfcraft;
import com.google.gson.JsonSyntaxException;
import java.io.IOException;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.launcher.utils.auth.AuthenticationException;
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
import org.jackhuang.hellominecraft.launcher.utils.auth.LoginInfo;
import static org.jackhuang.hellominecraft.launcher.utils.auth.OfflineAuthenticator.getUUIDFromUserName;
import org.jackhuang.hellominecraft.launcher.utils.auth.UserProfileProvider;
import org.jackhuang.hellominecraft.launcher.version.ServerInfo;
import org.jackhuang.hellominecraft.utils.NetUtils;
/**
*
* @author huangyuhui
*/
public class MFCraftAuthenticator extends IAuthenticator {
public MFCraftAuthenticator(String clientToken) {
super(clientToken);
}
@Override
public UserProfileProvider login(LoginInfo info) throws AuthenticationException {
try {
UserProfileProvider result = new UserProfileProvider();
String url = String.format("http://zh.mfcraft.cn/index.php?c=user_public&a=clientlogin&user=%s&pass=%s", info.username, info.password);
String response = NetUtils.get(url);
if (response.contains("error"))
throw new AuthenticationException(C.i18n("login.wrong_password"));
result.setUserName(info.username);
String uuid = getUUIDFromUserName(info.username);
result.setSession(uuid);
result.setUserId(uuid);
result.setAccessToken(uuid);
result.setUserType("Legacy");
return result;
} catch (IOException | JsonSyntaxException ex) {
throw new AuthenticationException(C.i18n("login.failed.connect_authentication_server"), ex);
}
}
@Override
public String getName() {
return "MFCraft";
}
@Override
public UserProfileProvider loginBySettings() throws AuthenticationException {
return null;
}
@Override
public void logout() {
}
}

View File

@ -0,0 +1,31 @@
/*
* 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.launcher.servers.mfcraft;
import java.util.ArrayList;
import org.jackhuang.hellominecraft.launcher.version.ServerInfo;
/**
*
* @author huangyuhui
*/
public class ServerArea {
public String name;
public ArrayList<ServerInfo> servers;
}

View File

@ -0,0 +1,50 @@
/*
* 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.launcher.servers.mfcraft;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.NetUtils;
/**
*
* @author huangyuhui
*/
public class Servers {
public static Servers instance;
public static Servers getInstance() {
if (instance == null) {
String servers = null;
try {
servers = NetUtils.get("http://zh.mfcraft.cn/View/servers.php");
instance = C.gson.fromJson(servers, Servers.class);
} catch (IOException ex) {
HMCLog.err("Failed to get servers");
}
}
return instance;
}
public ArrayList<ServerArea> areas;
}

View File

@ -24,6 +24,9 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.UUID; import java.util.UUID;
import org.jackhuang.hellominecraft.launcher.utils.auth.IAuthenticator;
import org.jackhuang.hellominecraft.lookandfeel.Theme;
import org.jackhuang.hellominecraft.utils.EventHandler;
import org.jackhuang.hellominecraft.utils.system.JdkVersion; import org.jackhuang.hellominecraft.utils.system.JdkVersion;
/** /**
@ -55,12 +58,15 @@ public final class Config {
return java == null ? java = new ArrayList<>() : java; return java == null ? java = new ArrayList<>() : java;
} }
public int getTheme() { public transient final EventHandler<Theme> themeChangedEvent = new EventHandler<>(this);
return theme;
public Theme getTheme() {
return Theme.values()[theme];
} }
public void setTheme(int theme) { public void setTheme(int theme) {
this.theme = theme; this.theme = theme;
themeChangedEvent.execute(getTheme());
Settings.save(); Settings.save();
} }
@ -90,6 +96,7 @@ public final class Config {
this.bgpath = bgpath; this.bgpath = bgpath;
Settings.save(); Settings.save();
} }
public boolean isEnableAnimation() { public boolean isEnableAnimation() {
return enableAnimation; return enableAnimation;
} }
@ -112,7 +119,13 @@ public final class Config {
return clientToken; return clientToken;
} }
public IAuthenticator getAuthenticator() {
return IAuthenticator.LOGINS.get(getLoginType());
}
public int getLoginType() { public int getLoginType() {
if (logintype < 0 || logintype >= IAuthenticator.LOGINS.size())
logintype = 0;
return logintype; return logintype;
} }
@ -162,8 +175,9 @@ public final class Config {
clientToken = UUID.randomUUID().toString(); clientToken = UUID.randomUUID().toString();
username = ""; username = "";
logintype = downloadtype = 0; logintype = downloadtype = 0;
enableShadow = false; enableAnimation = true; enableShadow = false;
theme = 0; enableAnimation = true;
theme = 4;
} }
public DownloadType getDownloadSource() { public DownloadType getDownloadSource() {

View File

@ -18,6 +18,7 @@
package org.jackhuang.hellominecraft.launcher.settings; package org.jackhuang.hellominecraft.launcher.settings;
import java.io.File; import java.io.File;
import org.jackhuang.hellominecraft.launcher.api.PluginManager;
import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider; import org.jackhuang.hellominecraft.launcher.launch.IMinecraftProvider;
import org.jackhuang.hellominecraft.utils.system.IOUtils; import org.jackhuang.hellominecraft.utils.system.IOUtils;
import org.jackhuang.hellominecraft.launcher.utils.MCUtils; import org.jackhuang.hellominecraft.launcher.utils.MCUtils;
@ -27,7 +28,7 @@ import org.jackhuang.hellominecraft.launcher.version.GameDirType;
import org.jackhuang.hellominecraft.utils.StrUtils; import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.utils.Utils; import org.jackhuang.hellominecraft.utils.Utils;
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion; import org.jackhuang.hellominecraft.launcher.version.MinecraftVersion;
import org.jackhuang.hellominecraft.launcher.version.MinecraftVersionManager; import org.jackhuang.hellominecraft.utils.EventHandler;
import org.jackhuang.hellominecraft.utils.system.Java; import org.jackhuang.hellominecraft.utils.system.Java;
import org.jackhuang.hellominecraft.utils.system.OS; import org.jackhuang.hellominecraft.utils.system.OS;
@ -65,9 +66,14 @@ public final class Profile {
gameDir = MCUtils.getInitGameDir().getPath(); gameDir = MCUtils.getInitGameDir().getPath();
debug = fullscreen = canceledWrapper = false; debug = fullscreen = canceledWrapper = false;
launcherVisibility = gameDirType = 0; launcherVisibility = gameDirType = 0;
PluginManager.NOW_PLUGIN.onInitializingProfile(this);
javaDir = java = minecraftArgs = serverIp = precalledCommand = ""; javaDir = java = minecraftArgs = serverIp = precalledCommand = "";
} }
public void initialize(int gameDirType) {
this.gameDirType = gameDirType;
}
public Profile(Profile v) { public Profile(Profile v) {
this(); this();
if (v == null) if (v == null)
@ -94,7 +100,7 @@ public final class Profile {
public IMinecraftProvider getMinecraftProvider() { public IMinecraftProvider getMinecraftProvider() {
if (minecraftProvider == null) { if (minecraftProvider == null) {
minecraftProvider = new MinecraftVersionManager(this); minecraftProvider = PluginManager.NOW_PLUGIN.provideMinecraftProvider(this);
minecraftProvider.initializeMiencraft(); minecraftProvider.initializeMiencraft();
} }
return minecraftProvider; return minecraftProvider;
@ -120,9 +126,12 @@ public final class Profile {
return v; return v;
} }
public transient final EventHandler<String> selectedVersionChangedEvent = new EventHandler<>(this);
public void setSelectedMinecraftVersion(String selectedMinecraftVersion) { public void setSelectedMinecraftVersion(String selectedMinecraftVersion) {
this.selectedMinecraftVersion = selectedMinecraftVersion; this.selectedMinecraftVersion = selectedMinecraftVersion;
Settings.save(); Settings.save();
selectedVersionChangedEvent.execute(selectedMinecraftVersion);
} }
public String getGameDir() { public String getGameDir() {
@ -363,6 +372,7 @@ public final class Profile {
} }
transient final InstallerService is = new InstallerService(this); transient final InstallerService is = new InstallerService(this);
public InstallerService getInstallerService() { public InstallerService getInstallerService() {
return is; return is;
} }

View File

@ -19,7 +19,7 @@ package org.jackhuang.hellominecraft.launcher.utils.auth;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.jackhuang.hellominecraft.launcher.settings.Settings; import org.jackhuang.hellominecraft.launcher.api.PluginManager;
/** /**
* Login interface * Login interface
@ -28,23 +28,10 @@ import org.jackhuang.hellominecraft.launcher.settings.Settings;
*/ */
public abstract class IAuthenticator { public abstract class IAuthenticator {
public static final YggdrasilAuthenticator YGGDRASIL_LOGIN; public static final List<IAuthenticator> LOGINS = new ArrayList<>();
public static final OfflineAuthenticator OFFLINE_LOGIN;
public static final SkinmeAuthenticator SKINME_LOGIN;
public static final List<IAuthenticator> LOGINS;
static { static {
String clientToken = Settings.getInstance().getClientToken(); PluginManager.NOW_PLUGIN.onRegisterAuthenticators(LOGINS::add);
LOGINS = new ArrayList<>();
LOGINS.add(OFFLINE_LOGIN = new OfflineAuthenticator(clientToken));
LOGINS.add(YGGDRASIL_LOGIN = new YggdrasilAuthenticator(clientToken));
LOGINS.add(SKINME_LOGIN = new SkinmeAuthenticator(clientToken));
YGGDRASIL_LOGIN.onLoadSettings(Settings.getInstance().getYggdrasilConfig());
Runtime.getRuntime().addShutdownHook(new Thread(()
-> Settings.getInstance().setYggdrasilConfig(YGGDRASIL_LOGIN.onSaveSettings())
));
} }
protected String clientToken; protected String clientToken;
@ -59,7 +46,8 @@ public abstract class IAuthenticator {
* @param info username & password * @param info username & password
* *
* @return login result * @return login result
* @throws org.jackhuang.hellominecraft.launcher.utils.auth.AuthenticationException * @throws
* org.jackhuang.hellominecraft.launcher.utils.auth.AuthenticationException
*/ */
public abstract UserProfileProvider login(LoginInfo info) throws AuthenticationException; public abstract UserProfileProvider login(LoginInfo info) throws AuthenticationException;
@ -72,10 +60,10 @@ public abstract class IAuthenticator {
/** /**
* Has password? * Has password?
* *
* @return Need to hide password box? * @return has password?
*/ */
public boolean hasPassword() { public boolean hasPassword() {
return false; return true;
} }
public boolean isLoggedIn() { public boolean isLoggedIn() {

View File

@ -56,7 +56,7 @@ public final class OfflineAuthenticator extends IAuthenticator {
@Override @Override
public boolean hasPassword() { public boolean hasPassword() {
return true; return false;
} }
@Override @Override

View File

@ -59,14 +59,6 @@ public final class UserProfileProvider {
this.accessToken = accessToken; this.accessToken = accessToken;
} }
public String getErrorReason() {
return error;
}
public void setErrorReason(String error) {
this.error = error;
}
public String getUserProperties() { public String getUserProperties() {
return userProperties; return userProperties;
} }
@ -111,7 +103,6 @@ public final class UserProfileProvider {
private String userId = ""; private String userId = "";
private String session = ""; private String session = "";
private String accessToken = ""; private String accessToken = "";
private String error = "";
private String userProperties = "{}"; private String userProperties = "{}";
private String userPropertyMap = "{}"; private String userPropertyMap = "{}";
private String otherInfo = ""; private String otherInfo = "";

Some files were not shown because too many files have changed in this diff Show More