Fixed Issue #1 & Added proxy support

This commit is contained in:
huanghongxun
2015-06-24 13:45:00 +08:00
parent 7bfe7c3432
commit e5621d1a58
30 changed files with 623 additions and 578 deletions

View File

@@ -89,13 +89,13 @@ task proguard(type: proguard.gradle.ProGuardTask, dependsOn: jar) {
launch4j { launch4j {
launch4jCmd = 'D:\\Develop\\Java\\Launch4j\\launch4j.exe' launch4jCmd = 'D:\\Develop\\Java\\Launch4j\\launch4j.exe'
supportUrl = 'http://www.mcbbs.net/thread-142335-1-1.html' supportUrl = 'http://www.mcbbs.net/thread-142335-1-1.html'
jreMinVersion = '1.6.0' jreMinVersion = '1.7.0'
mainClassName = mainClass mainClassName = mainClass
icon = new File(project.buildDir, '../icon.ico').absolutePath icon = new File(project.buildDir, '../icon.ico').absolutePath
version = mavenVersion + '.0' version = mavenVersion + '.0'
downloadUrl = 'http://java.com/download' downloadUrl = 'http://java.com/download'
copyright = "Copyright(c) 2013-2014 huangyuhui." copyright = "Copyright(c) 2013-2015 huangyuhui."
jar = new File(project.buildDir, 'libs/' + mavenGroupId + '-' + mavenVersion + '.jar').absolutePath jar = new File(project.buildDir, 'libs/' + mavenGroupId + '-' + mavenVersion + '.jar').absolutePath
outfile = mavenGroupId + '-' + mavenVersion + '.exe' outfile = mavenGroupId + '-' + mavenVersion + '.exe'

Binary file not shown.

Before

Width:  |  Height:  |  Size: 573 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 309 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 657 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

View File

@@ -1,41 +0,0 @@
<launch4jConfig>
<dontWrapJar>false</dontWrapJar>
<headerType>gui</headerType>
<jar>F:\Documents\NetBeansProjects\HMCL\HMCL\build\libs\HMCL-2.1.3.jar</jar>
<outfile>F:\Documents\NetBeansProjects\HMCL\HMCL\build\libs\HMCL-2.1.3-Launch4j.exe</outfile>
<errTitle></errTitle>
<cmdLine></cmdLine>
<chdir></chdir>
<priority>normal</priority>
<downloadUrl>http://java.com/download</downloadUrl>
<supportUrl></supportUrl>
<stayAlive>false</stayAlive>
<manifest></manifest>
<icon>F:\Documents\NetBeansProjects\HMCL\HMCL\icon.ico</icon>
<jre>
<path></path>
<bundledJre64Bit>false</bundledJre64Bit>
<minVersion>1.6.0</minVersion>
<maxVersion></maxVersion>
<jdkPreference>preferJre</jdkPreference>
</jre>
<versionInfo>
<fileVersion>2.1.3.0</fileVersion>
<txtFileVersion>2.1.3.0</txtFileVersion>
<fileDescription>Hello Minecraft! Launcher</fileDescription>
<copyright>Copyright(c) 2013~2014 huangyuhui</copyright>
<productVersion>2.1.3.0</productVersion>
<txtProductVersion>2.1.3.0</txtProductVersion>
<productName>Hello Minecraft! Launcher</productName>
<companyName></companyName>
<internalName>Hello Minecraft! Launcher</internalName>
<originalFilename>HMCL-2.1.3.exe</originalFilename>
</versionInfo>
<messages>
<startupErr>启动程序时出现错误</startupErr>
<bundledJreErr>未找到内置Java</bundledJreErr>
<jreVersionErr>此程序需要Java</jreVersionErr>
<launcherErr>未找到Java</launcherErr>
<instanceAlreadyExistsMsg>已存在一个程序实例</instanceAlreadyExistsMsg>
</messages>
</launch4jConfig>

6
HMCL/proguard.pro vendored
View File

@@ -1,6 +1,6 @@
-libraryjars D:\Develop\Java\jdk1.6.0_45\jre\lib\rt.jar -libraryjars <java.home>/lib/rt.jar
-libraryjars D:\Develop\Java\jdk1.6.0_45\jre\lib\jce.jar -libraryjars <java.home>/lib/jce.jar
-libraryjars D:\Develop\Java\jdk1.6.0_45\jre\lib\jsse.jar -libraryjars <java.home>/lib/jsse.jar
-dontoptimize -dontoptimize
-dontshrink -dontshrink

View File

@@ -22,9 +22,14 @@ import java.awt.datatransfer.StringSelection;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException;
import java.text.ParseException;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import javax.swing.UIManager; import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import org.jackhuang.hellominecraft.C; import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.utils.functions.DoneListener0; import org.jackhuang.hellominecraft.utils.functions.DoneListener0;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
@@ -38,6 +43,7 @@ import org.jackhuang.hellominecraft.launcher.utils.settings.Settings;
import org.jackhuang.hellominecraft.launcher.views.MainFrame; import org.jackhuang.hellominecraft.launcher.views.MainFrame;
import org.jackhuang.hellominecraft.lookandfeel.HelloMinecraftLookAndFeel; import org.jackhuang.hellominecraft.lookandfeel.HelloMinecraftLookAndFeel;
import org.jackhuang.hellominecraft.utils.MessageBox; import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.StrUtils;
/** /**
* *
@@ -90,12 +96,24 @@ public final class Main implements DoneListener0 {
try { try {
UIManager.setLookAndFeel(new HelloMinecraftLookAndFeel()); UIManager.setLookAndFeel(new HelloMinecraftLookAndFeel());
} catch (Throwable ex) { } catch (ParseException | UnsupportedLookAndFeelException ex) {
HMCLog.warn("Failed to set look and feel...", ex); HMCLog.warn("Failed to set look and feel...", ex);
} }
Settings.UPDATE_CHECKER.start(); Settings.UPDATE_CHECKER.start();
if (StrUtils.isNotBlank(Settings.s().getProxyHost()) && StrUtils.isNotBlank(Settings.s().getProxyPort())) {
System.setProperty("http.proxyHost", Settings.s().getProxyHost());
System.setProperty("http.proxyPort", Settings.s().getProxyPort());
if (StrUtils.isNotBlank(Settings.s().getProxyUserName()) && StrUtils.isNotBlank(Settings.s().getProxyPassword()))
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(Settings.s().getProxyUserName(), Settings.s().getProxyPassword().toCharArray());
}
});
}
MainFrame.showMainFrame(Settings.isFirstLoad()); MainFrame.showMainFrame(Settings.isFirstLoad());
} }
} }
@@ -111,7 +129,7 @@ public final class Main implements DoneListener0 {
MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION)
try { try {
java.awt.Desktop.getDesktop().browse(new URI(C.URL_PUBLISH)); java.awt.Desktop.getDesktop().browse(new URI(C.URL_PUBLISH));
} catch (Throwable e) { } catch (URISyntaxException | IOException e) {
HMCLog.warn("Failed to browse uri: " + C.URL_PUBLISH, e); HMCLog.warn("Failed to browse uri: " + C.URL_PUBLISH, e);
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard(); Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();

View File

@@ -46,8 +46,7 @@ public class DefaultGameLauncher extends GameLauncher {
downloadLibrariesEvent.register((sender, t) -> { downloadLibrariesEvent.register((sender, t) -> {
final TaskWindow dw = TaskWindow.getInstance(); final TaskWindow dw = TaskWindow.getInstance();
ParallelTask parallelTask = new ParallelTask(); ParallelTask parallelTask = new ParallelTask();
for (DownloadLibraryJob o : t) { for (DownloadLibraryJob s : t) {
final DownloadLibraryJob s = (DownloadLibraryJob) o;
parallelTask.addDependsTask(new FileDownloadTask(s.url, s.path).setTag(s.name)); parallelTask.addDependsTask(new FileDownloadTask(s.url, s.path).setTag(s.name));
} }
dw.addTask(parallelTask); dw.addTask(parallelTask);

View File

@@ -26,7 +26,6 @@ import org.jackhuang.hellominecraft.utils.tinystream.CollectionUtils;
import org.jackhuang.hellominecraft.utils.Event; import org.jackhuang.hellominecraft.utils.Event;
import org.jackhuang.hellominecraft.utils.JavaProcess; import org.jackhuang.hellominecraft.utils.JavaProcess;
import org.jackhuang.hellominecraft.utils.MessageBox; import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.utils.functions.Predicate;
import org.jackhuang.hellominecraft.utils.ProcessThread; import org.jackhuang.hellominecraft.utils.ProcessThread;
import org.jackhuang.hellominecraft.utils.StrUtils; import org.jackhuang.hellominecraft.utils.StrUtils;
import org.jackhuang.hellominecraft.views.LogWindow; import org.jackhuang.hellominecraft.views.LogWindow;
@@ -37,57 +36,44 @@ import org.jackhuang.hellominecraft.views.LogWindow;
*/ */
public class LaunchFinisher implements Event<List<String>> { public class LaunchFinisher implements Event<List<String>> {
private final HashSet<Thread> al = new HashSet<Thread>(); private final HashSet<Thread> al = new HashSet<>();
@Override @Override
public boolean call(Object sender, List<String> str) { public boolean call(Object sender, List<String> str) {
final GameLauncher obj = (GameLauncher) sender; final GameLauncher obj = (GameLauncher) sender;
obj.launchEvent.register(new Event<JavaProcess>() { obj.launchEvent.register((sender1, p) -> {
@Override if (obj.getProfile().getLauncherVisibility() == 0 && !LogWindow.instance.isVisible())
public boolean call(Object sender, JavaProcess p) { System.exit(0);
if (obj.getProfile().getLauncherVisibility() == 0 && !LogWindow.instance.isVisible()) else if (obj.getProfile().getLauncherVisibility() == 2)
System.exit(0); MainFrame.instance.closeMessage();
else if (obj.getProfile().getLauncherVisibility() == 2) else {
MainFrame.instance.closeMessage(); if (LogWindow.instance.isVisible())
else { LogWindow.instance.setExit(TrueDoneListener.instance);
if (LogWindow.instance.isVisible()) MainFrame.instance.dispose();
LogWindow.instance.setExit(TrueDoneListener.instance);
MainFrame.instance.dispose();
}
Event<JavaProcess> event = new Event<JavaProcess>() {
@Override
public boolean call(Object sender, JavaProcess t) {
processThreadStopped((ProcessThread) sender, obj, t, false);
return true;
}
};
ProcessThread a = new ProcessThread(p, true, true);
a.stopEvent.register(new Event<JavaProcess>() {
@Override
public boolean call(Object sender, JavaProcess p) {
if (p.getExitCode() != 0 && p.getStdErrLines().size() > 0 && StrUtils.containsOne(p.getStdErrLines(),
Arrays.asList("Could not create the Java Virtual Machine.",
"Error occurred during initialization of VM",
"A fatal exception has occurred. Program will exit.")))
MessageBox.Show(C.i18n("launch.cannot_create_jvm"));
processThreadStopped((ProcessThread) sender, obj, p, false);
return true;
}
});
a.start();
al.add(a);
a = new ProcessThread(p, false, true);
a.stopEvent.register(event);
a.start();
al.add(a);
a = new ProcessThread(p, false, false);
a.stopEvent.register(event);
a.start();
al.add(a);
return true;
} }
Event<JavaProcess> event = (sender2, t) -> {
processThreadStopped((ProcessThread) sender2, obj, t, false);
return true;
};
ProcessThread a = new ProcessThread(p, true, true);
a.stopEvent.register((sender3, p1) -> {
if (p1.getExitCode() != 0 && p1.getStdErrLines().size() > 0 && StrUtils.containsOne(p1.getStdErrLines(), Arrays.asList("Could not create the Java Virtual Machine.",
"Error occurred during initialization of VM",
"A fatal exception has occurred. Program will exit."))) MessageBox.Show(C.i18n("launch.cannot_create_jvm"));
processThreadStopped((ProcessThread) sender3, obj, p1, false);
return true;
});
a.start();
al.add(a);
a = new ProcessThread(p, false, true);
a.stopEvent.register(event);
a.start();
al.add(a);
a = new ProcessThread(p, false, false);
a.stopEvent.register(event);
a.start();
al.add(a);
return true;
}); });
obj.launch(str); obj.launch(str);
return true; return true;
@@ -95,14 +81,7 @@ public class LaunchFinisher implements Event<List<String>> {
void processThreadStopped(ProcessThread t, GameLauncher obj, JavaProcess p, boolean forceTermintate) { void processThreadStopped(ProcessThread t, GameLauncher obj, JavaProcess p, boolean forceTermintate) {
al.remove(t); al.remove(t);
al.removeAll(CollectionUtils.sortOut(al, new Predicate<Thread>() { al.removeAll(CollectionUtils.sortOut(al, t1 -> !t1.isAlive()));
@Override
public boolean apply(Thread t) {
return !t.isAlive();
}
}));
if (al.isEmpty() || forceTermintate) { if (al.isEmpty() || forceTermintate) {
for (Thread a : al) a.interrupt(); for (Thread a : al) a.interrupt();
al.clear(); al.clear();

View File

@@ -35,7 +35,8 @@ public final class Config {
@SerializedName("username") @SerializedName("username")
private String username; private String username;
@SerializedName("clientToken") @SerializedName("clientToken")
private String clientToken; private final String clientToken;
private String proxyHost, proxyPort, proxyUserName, proxyPassword;
@SerializedName("enableShadow") @SerializedName("enableShadow")
private boolean enableShadow; private boolean enableShadow;
@SerializedName("theme") @SerializedName("theme")
@@ -160,4 +161,40 @@ public final class Config {
if(downloadtype >= DownloadType.values().length || downloadtype < 0) return null; if(downloadtype >= DownloadType.values().length || downloadtype < 0) return null;
return DownloadType.values()[downloadtype]; return DownloadType.values()[downloadtype];
} }
public String getProxyHost() {
return proxyHost == null ? "" : proxyHost;
}
public void setProxyHost(String proxyHost) {
this.proxyHost = proxyHost;
Settings.save();
}
public String getProxyPort() {
return proxyPort == null ? "" : proxyPort;
}
public void setProxyPort(String proxyPort) {
this.proxyPort = proxyPort;
Settings.save();
}
public String getProxyUserName() {
return proxyUserName == null ? "" : proxyUserName;
}
public void setProxyUserName(String proxyUserName) {
this.proxyUserName = proxyUserName;
Settings.save();
}
public String getProxyPassword() {
return proxyPassword == null ? "" : proxyPassword;
}
public void setProxyPassword(String proxyPassword) {
this.proxyPassword = proxyPassword;
Settings.save();
}
} }

View File

@@ -16,12 +16,13 @@
*/ */
package org.jackhuang.hellominecraft.launcher.utils.settings; package org.jackhuang.hellominecraft.launcher.utils.settings;
import com.google.gson.JsonSyntaxException;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.jackhuang.hellominecraft.C; import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.utils.functions.DoneListener0;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.launcher.Main; import org.jackhuang.hellominecraft.launcher.Main;
import org.jackhuang.hellominecraft.utils.tinystream.CollectionUtils; import org.jackhuang.hellominecraft.utils.tinystream.CollectionUtils;
@@ -40,7 +41,7 @@ public final class Settings {
public static final File settingsFile = new File(IOUtils.currentDir(), "hmcl.json"); public static final File settingsFile = new File(IOUtils.currentDir(), "hmcl.json");
private static boolean isFirstLoad; private static boolean isFirstLoad;
private static Config settings; private static final Config settings;
public static final UpdateChecker UPDATE_CHECKER; public static final UpdateChecker UPDATE_CHECKER;
public static Config s() { public static Config s() {
@@ -52,50 +53,39 @@ public final class Settings {
} }
static { static {
settings = initSettings();
isFirstLoad = StrUtils.isBlank(settings.getUsername());
if(!getVersions().containsKey("Default"))
getVersions().put("Default", new Profile());
UPDATE_CHECKER = new UpdateChecker(new VersionNumber(Main.firstVer, Main.secondVer, Main.thirdVer),
"hmcl", settings.isCheckUpdate(), () -> Main.invokeUpdate());
}
private static Config initSettings() {
Config c = new Config();
if (settingsFile.exists()) { if (settingsFile.exists()) {
try { try {
String str = FileUtils.readFileToString(settingsFile); String str = FileUtils.readFileToString(settingsFile);
if (str == null || str.trim().equals("")) { if (str == null || str.trim().equals("")) {
init();
HMCLog.log("Settings file is empty, use the default settings."); HMCLog.log("Settings file is empty, use the default settings.");
} else { } else {
settings = C.gsonPrettyPrinting.fromJson(str, Config.class); Config d = C.gsonPrettyPrinting.fromJson(str, Config.class);
if(d != null) c = d;
} }
HMCLog.log("Initialized settings."); HMCLog.log("Initialized settings.");
} catch (Exception e) { } catch (IOException | JsonSyntaxException e) {
HMCLog.warn("Something happened wrongly when load settings.", e); HMCLog.warn("Something happened wrongly when load settings.", e);
if (MessageBox.Show(C.i18n("settings.failed_load"), MessageBox.YES_NO_OPTION) == MessageBox.YES_OPTION) { if (MessageBox.Show(C.i18n("settings.failed_load"), MessageBox.YES_NO_OPTION) == MessageBox.NO_OPTION) {
init();
} else {
HMCLog.err("Cancelled loading settings."); HMCLog.err("Cancelled loading settings.");
System.exit(1); System.exit(1);
} }
} }
} else { } else {
HMCLog.log("No settings file here, may be first loading."); HMCLog.log("No settings file here, may be first loading.");
isFirstLoad = true; isFirstLoad = true;
init();
} }
if(settings == null) init(); return c;
isFirstLoad = StrUtils.isBlank(settings.getUsername());
if(!settings.getConfigurations().containsKey("Default")) {
settings.getConfigurations().put("Default", new Profile());
}
UPDATE_CHECKER = new UpdateChecker(new VersionNumber(Main.firstVer, Main.secondVer, Main.thirdVer), "hmcl", settings.isCheckUpdate(), new DoneListener0() {
@Override
public void onDone() {
Main.invokeUpdate();
}
});
}
public static void init() {
settings = new Config();
save();
} }
public static void save() { public static void save() {
@@ -107,13 +97,7 @@ public final class Settings {
} }
public static Profile getVersion(String name) { public static Profile getVersion(String name) {
if (settings == null) { return getVersions().get(name);
return null;
}
if (settings.getConfigurations() == null) {
return null;
}
return settings.getConfigurations().get(name);
} }
public static Map<String, Profile> getVersions() { public static Map<String, Profile> getVersions() {
@@ -121,31 +105,22 @@ public final class Settings {
} }
public static void setVersion(Profile ver) { public static void setVersion(Profile ver) {
if (ver == null) { Objects.requireNonNull(ver);
return; getVersions().put(ver.getName(), ver);
}
settings.getConfigurations().put(ver.getName(), ver);
} }
public static Collection<Profile> getProfiles() { public static Collection<Profile> getProfiles() {
return CollectionUtils.sortOut(settings.getConfigurations().values(), (t) -> t != null && t.getName() != null); return CollectionUtils.sortOut(getVersions().values(), (t) -> t != null && t.getName() != null);
} }
public static Profile getOneProfile() { public static Profile getOneProfile() {
if(settings.getConfigurations().size() == 0) {
settings.getConfigurations().put("Default", new Profile());
}
return settings.getConfigurations().firstEntry().getValue(); return settings.getConfigurations().firstEntry().getValue();
} }
public static boolean trySetVersion(Profile ver) { public static boolean trySetVersion(Profile ver) {
if (ver == null || ver.getName() == null) { if (ver == null || ver.getName() == null || getVersions().containsKey(ver.getName()))
return false; return false;
} getVersions().put(ver.getName(), ver);
if (settings.getConfigurations().containsKey(ver.getName())) {
return false;
}
settings.getConfigurations().put(ver.getName(), ver);
return true; return true;
} }
@@ -154,7 +129,6 @@ public final class Settings {
} }
public static void delVersion(String ver) { public static void delVersion(String ver) {
if (settings == null) return; getVersions().remove(ver);
settings.getConfigurations().remove(ver);
} }
} }

View File

@@ -19,22 +19,14 @@
<Group type="102" attributes="0"> <Group type="102" attributes="0">
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="jLabel4" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<Component id="chkEnableShadow" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="btnCheckUpdate" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel7" alignment="0" min="-2" max="-2" attributes="0"/> <Component id="jLabel7" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jLabel1" alignment="0" min="-2" max="-2" attributes="0"/> <Component id="jLabel1" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jLabel14" alignment="0" min="-2" max="-2" attributes="0"/> <Component id="jLabel14" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="jLabel2" alignment="0" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0"> <Group type="102" alignment="1" attributes="0">
<Component id="txtBackgroundPath" max="32767" attributes="0"/> <Component id="txtBackgroundPath" max="32767" attributes="0"/>
@@ -43,8 +35,34 @@
</Group> </Group>
<Component id="cboDownloadSource" alignment="1" max="32767" attributes="0"/> <Component id="cboDownloadSource" alignment="1" max="32767" attributes="0"/>
<Component id="cboTheme" alignment="1" max="32767" attributes="0"/> <Component id="cboTheme" alignment="1" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtProxyHost" min="-2" pref="80" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel5" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtProxyPort" min="-2" pref="80" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel6" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtProxyUsername" min="-2" pref="80" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel8" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtProxyPassword" min="-2" pref="80" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group> </Group>
</Group> </Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel4" min="-2" max="-2" attributes="0"/>
<Component id="chkEnableShadow" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="btnCheckUpdate" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
</Group> </Group>
@@ -70,11 +88,22 @@
<Component id="cboTheme" alignment="3" min="-2" pref="26" max="-2" attributes="0"/> <Component id="cboTheme" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="3" attributes="0">
<Component id="chkEnableShadow" min="-2" max="-2" attributes="0"/> <Component id="txtProxyHost" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
<Component id="btnCheckUpdate" alignment="0" min="-2" pref="26" max="-2" attributes="0"/> <Component id="jLabel2" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="jLabel3" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtProxyPort" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
<Component id="jLabel5" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtProxyUsername" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
<Component id="jLabel6" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="txtProxyPassword" alignment="3" min="-2" pref="26" max="-2" attributes="0"/>
<Component id="jLabel8" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace pref="119" max="32767" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="chkEnableShadow" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnCheckUpdate" min="-2" pref="26" max="-2" attributes="0"/>
<EmptySpace pref="71" max="32767" attributes="0"/>
<Component id="jLabel4" min="-2" max="-2" attributes="0"/> <Component id="jLabel4" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
</Group> </Group>
@@ -174,5 +203,60 @@
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="cboThemeItemStateChanged"/> <EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="cboThemeItemStateChanged"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JLabel" name="jLabel2">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="launcher.proxy" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtProxyHost">
<Events>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtProxyHostFocusLost"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel3">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="proxy.host" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtProxyPort">
<Events>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtProxyPortFocusLost"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel5">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="proxy.port" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="jLabel6">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="proxy.username" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
<Component class="javax.swing.JTextField" name="txtProxyUsername">
<Events>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtProxyUsernameFocusLost"/>
</Events>
</Component>
<Component class="javax.swing.JTextField" name="txtProxyPassword">
<Events>
<EventHandler event="focusLost" listener="java.awt.event.FocusListener" parameters="java.awt.event.FocusEvent" handler="txtProxyPasswordFocusLost"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel8">
<Properties>
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
<ResourceString bundle="org/jackhuang/hellominecraft/launcher/I18N.properties" key="proxy.password" replaceFormat="java.util.ResourceBundle.getBundle(&quot;{bundleNameSlashes}&quot;).getString(&quot;{key}&quot;)"/>
</Property>
</Properties>
</Component>
</SubComponents> </SubComponents>
</Form> </Form>

View File

@@ -39,6 +39,10 @@ public class LauncherSettingsPanel extends javax.swing.JPanel {
initComponents(); initComponents();
txtBackgroundPath.setText(Settings.s().getBgpath()); txtBackgroundPath.setText(Settings.s().getBgpath());
txtProxyHost.setText(Settings.s().getProxyHost());
txtProxyPort.setText(Settings.s().getProxyPort());
txtProxyUsername.setText(Settings.s().getProxyUserName());
txtProxyPassword.setText(Settings.s().getProxyPassword());
cboDownloadSource.setSelectedIndex(Settings.s().getDownloadType()); cboDownloadSource.setSelectedIndex(Settings.s().getDownloadType());
cboTheme.setSelectedIndex(Settings.s().getTheme()); cboTheme.setSelectedIndex(Settings.s().getTheme());
chkEnableShadow.setSelected(Settings.s().isEnableShadow()); chkEnableShadow.setSelected(Settings.s().isEnableShadow());
@@ -66,6 +70,15 @@ public class LauncherSettingsPanel extends javax.swing.JPanel {
chkEnableShadow = new javax.swing.JCheckBox(); chkEnableShadow = new javax.swing.JCheckBox();
jLabel1 = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel();
cboTheme = new javax.swing.JComboBox(); cboTheme = new javax.swing.JComboBox();
jLabel2 = new javax.swing.JLabel();
txtProxyHost = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
txtProxyPort = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
txtProxyUsername = new javax.swing.JTextField();
txtProxyPassword = new javax.swing.JTextField();
jLabel8 = new javax.swing.JLabel();
cboDownloadSource.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Mojang", "BMCLAPI(By bangbang93)" })); cboDownloadSource.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Mojang", "BMCLAPI(By bangbang93)" }));
cboDownloadSource.addItemListener(new java.awt.event.ItemListener() { cboDownloadSource.addItemListener(new java.awt.event.ItemListener() {
@@ -119,6 +132,40 @@ public class LauncherSettingsPanel extends javax.swing.JPanel {
} }
}); });
jLabel2.setText(bundle.getString("launcher.proxy")); // NOI18N
txtProxyHost.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
txtProxyHostFocusLost(evt);
}
});
jLabel3.setText(bundle.getString("proxy.host")); // NOI18N
txtProxyPort.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
txtProxyPortFocusLost(evt);
}
});
jLabel5.setText(bundle.getString("proxy.port")); // NOI18N
jLabel6.setText(bundle.getString("proxy.username")); // NOI18N
txtProxyUsername.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
txtProxyUsernameFocusLost(evt);
}
});
txtProxyPassword.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
txtProxyPasswordFocusLost(evt);
}
});
jLabel8.setText(bundle.getString("proxy.password")); // NOI18N
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout); this.setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
@@ -127,17 +174,11 @@ public class LauncherSettingsPanel extends javax.swing.JPanel {
.addContainerGap() .addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup() .addGroup(layout.createSequentialGroup()
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addComponent(chkEnableShadow)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnCheckUpdate))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel7) .addComponent(jLabel7)
.addComponent(jLabel1) .addComponent(jLabel1)
.addComponent(jLabel14)) .addComponent(jLabel14)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
@@ -145,7 +186,30 @@ public class LauncherSettingsPanel extends javax.swing.JPanel {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnSelBackgroundPath)) .addComponent(btnSelBackgroundPath))
.addComponent(cboDownloadSource, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(cboDownloadSource, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cboTheme, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) .addComponent(cboTheme, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtProxyHost, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtProxyPort, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtProxyUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel8)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtProxyPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(chkEnableShadow)
.addComponent(btnCheckUpdate))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap()) .addContainerGap())
); );
layout.setVerticalGroup( layout.setVerticalGroup(
@@ -165,10 +229,21 @@ public class LauncherSettingsPanel extends javax.swing.JPanel {
.addComponent(jLabel1) .addComponent(jLabel1)
.addComponent(cboTheme, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(cboTheme, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(chkEnableShadow) .addComponent(txtProxyHost, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnCheckUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 119, Short.MAX_VALUE) .addComponent(jLabel3)
.addComponent(txtProxyPort, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5)
.addComponent(txtProxyUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6)
.addComponent(txtProxyPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel8))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(chkEnableShadow)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCheckUpdate, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 71, Short.MAX_VALUE)
.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap()) .addContainerGap())
); );
@@ -200,8 +275,7 @@ public class LauncherSettingsPanel extends javax.swing.JPanel {
}//GEN-LAST:event_btnSelBackgroundPathActionPerformed }//GEN-LAST:event_btnSelBackgroundPathActionPerformed
private void txtBackgroundPathFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtBackgroundPathFocusLost private void txtBackgroundPathFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtBackgroundPathFocusLost
String path = txtBackgroundPath.getText(); Settings.s().setBgpath(txtBackgroundPath.getText());
Settings.s().setBgpath(path);
MainFrame.instance.loadBackground(); MainFrame.instance.loadBackground();
}//GEN-LAST:event_txtBackgroundPathFocusLost }//GEN-LAST:event_txtBackgroundPathFocusLost
@@ -219,6 +293,22 @@ public class LauncherSettingsPanel extends javax.swing.JPanel {
MainFrame.instance.reloadColor(); MainFrame.instance.reloadColor();
}//GEN-LAST:event_cboThemeItemStateChanged }//GEN-LAST:event_cboThemeItemStateChanged
private void txtProxyHostFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtProxyHostFocusLost
Settings.s().setProxyHost(txtProxyHost.getText());
}//GEN-LAST:event_txtProxyHostFocusLost
private void txtProxyPortFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtProxyPortFocusLost
Settings.s().setProxyPort(txtProxyPort.getText());
}//GEN-LAST:event_txtProxyPortFocusLost
private void txtProxyUsernameFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtProxyUsernameFocusLost
Settings.s().setProxyUserName(txtProxyUsername.getText());
}//GEN-LAST:event_txtProxyUsernameFocusLost
private void txtProxyPasswordFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtProxyPasswordFocusLost
Settings.s().setProxyPassword(txtProxyPassword.getText());
}//GEN-LAST:event_txtProxyPasswordFocusLost
// Variables declaration - do not modify//GEN-BEGIN:variables // Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCheckUpdate; private javax.swing.JButton btnCheckUpdate;
private javax.swing.JButton btnSelBackgroundPath; private javax.swing.JButton btnSelBackgroundPath;
@@ -227,8 +317,17 @@ public class LauncherSettingsPanel extends javax.swing.JPanel {
private javax.swing.JCheckBox chkEnableShadow; private javax.swing.JCheckBox chkEnableShadow;
private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JTextField txtBackgroundPath; private javax.swing.JTextField txtBackgroundPath;
private javax.swing.JTextField txtProxyHost;
private javax.swing.JTextField txtProxyPassword;
private javax.swing.JTextField txtProxyPort;
private javax.swing.JTextField txtProxyUsername;
// End of variables declaration//GEN-END:variables // End of variables declaration//GEN-END:variables
} }

View File

@@ -34,6 +34,7 @@ public final class C {
public static final String URL_PUBLISH = "http://www.mcbbs.net/thread-142335-1-1.html"; public static final String URL_PUBLISH = "http://www.mcbbs.net/thread-142335-1-1.html";
public static final String URL_TIEBA = "http://tieba.baidu.com/f?kw=hellominecraftlauncher"; public static final String URL_TIEBA = "http://tieba.baidu.com/f?kw=hellominecraftlauncher";
public static final String URL_GITHUB = "https://github.com/huanghongxun/HMCL/issues";
public static final String URL_MINECRAFTFORUM = "http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-tools/1265720-hello-minecraft-launcher-1-9-3-mc-1-7-4-auto"; public static final String URL_MINECRAFTFORUM = "http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-tools/1265720-hello-minecraft-launcher-1-9-3-mc-1-7-4-auto";
public static final String FILE_MINECRAFT_VERSIONS = "versions"; public static final String FILE_MINECRAFT_VERSIONS = "versions";

View File

@@ -41,8 +41,9 @@ public class Compressor {
/** /**
* 功能:把 sourceDir 目录下的所有文件进行 zip 格式的压缩,保存为指定 zip 文件 * 功能:把 sourceDir 目录下的所有文件进行 zip 格式的压缩,保存为指定 zip 文件
* *
* @param sourceDir * @param sourceDir 源文件夹
* @param zipFile * @param zipFile 压缩生成的zip文件路径。
* @throws java.io.IOException 压缩失败或无法读取
*/ */
public static void zip(File sourceDir, File zipFile) throws IOException { public static void zip(File sourceDir, File zipFile) throws IOException {
FileOutputStream os; FileOutputStream os;
@@ -65,7 +66,7 @@ public class Compressor {
* *
* @param source zip文件路径 * @param source zip文件路径
* @param basePath 待压缩文件根目录 * @param basePath 待压缩文件根目录
* @param zos * @param zos zip文件的os
*/ */
private static void zipFile(File source, String basePath, private static void zipFile(File source, String basePath,
ZipOutputStream zos) throws IOException { ZipOutputStream zos) throws IOException {
@@ -115,6 +116,7 @@ public class Compressor {
* @param zipFileName zip文件路径 * @param zipFileName zip文件路径
* @param extPlace 待压缩文件根目录 * @param extPlace 待压缩文件根目录
* @param without 带前缀的不解压 * @param without 带前缀的不解压
* @throws java.io.IOException 解压失败或无法写入
*/ */
public static void unzip(File zipFileName, File extPlace, String[] without) throws IOException { public static void unzip(File zipFileName, File extPlace, String[] without) throws IOException {
extPlace.mkdirs(); extPlace.mkdirs();
@@ -164,6 +166,7 @@ public class Compressor {
* *
* @param destFile zip1 * @param destFile zip1
* @param srcFile zip2 * @param srcFile zip2
* @throws java.io.IOException 无法写入或读取
*/ */
public static void merge(File destFile, File srcFile) throws IOException { public static void merge(File destFile, File srcFile) throws IOException {
try (ZipOutputStream os = new ZipOutputStream(new FileOutputStream(destFile))) { try (ZipOutputStream os = new ZipOutputStream(new FileOutputStream(destFile))) {

View File

@@ -42,12 +42,16 @@ public class Stream<T> {
protected Stream() { protected Stream() {
} }
protected static <T> Stream<T> of(List<T> a) { protected static <T> Stream<T> noneCopyOf(List<T> a) {
Stream<T> b = new Stream<>(); Stream<T> b = new Stream<>();
b.internal = a; b.internal = a;
return b; return b;
} }
protected static <T> Stream<T> of(Collection<T> a) {
return new Stream<>(a);
}
public Stream<T> forEach(Consumer<? super T> p) { public Stream<T> forEach(Consumer<? super T> p) {
for (T t : internal) p.accept(t); for (T t : internal) p.accept(t);
return this; return this;
@@ -88,15 +92,25 @@ public class Stream<T> {
} }
public boolean anyMatch(Predicate<? super T> p) { public boolean anyMatch(Predicate<? super T> p) {
return map(t -> p.apply(t)).reduce(false, (accumulator, _item) -> accumulator | _item); return map(t -> p.apply(t)).<Boolean>reduce(false, (a, b) -> a | b);
} }
public boolean allMatch(Predicate<? super T> p) { public boolean allMatch(Predicate<? super T> p) {
return map(t -> p.apply(t)).reduce(true, (accumulator, _item) -> accumulator & _item); return map(t -> p.apply(t)).<Boolean>reduce(true, (a, b) -> a & b);
} }
public T findFirst() { public T findFirst() {
return internal.isEmpty() ? null : internal.get(0); return internal.isEmpty() ? null : internal.get(0);
} }
public Stream<T> skip(int c) {
internal = internal.subList(c+1, internal.size());
return this;
}
public Stream<T> limit(int c) {
internal = internal.subList(0, c);
return this;
}
} }

View File

@@ -37,6 +37,8 @@
<Component id="btnMCBBS" min="-2" max="-2" attributes="0"/> <Component id="btnMCBBS" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="btnMCF" min="-2" max="-2" attributes="0"/> <Component id="btnMCF" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="btnGitHub" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/> <EmptySpace max="32767" attributes="0"/>
<Component id="btnTerminateGame" min="-2" max="-2" attributes="0"/> <Component id="btnTerminateGame" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
@@ -46,7 +48,7 @@
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="btnClose" min="-2" max="-2" attributes="0"/> <Component id="btnClose" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<Component id="lblCrash" alignment="0" pref="639" max="32767" attributes="0"/> <Component id="lblCrash" alignment="0" pref="674" max="32767" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
</Group> </Group>
@@ -68,6 +70,7 @@
<Component id="btnTieBa" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnTieBa" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnMCF" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnMCF" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnTerminateGame" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="btnTerminateGame" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btnGitHub" alignment="3" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
</Group> </Group>
@@ -164,5 +167,13 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnTerminateGameActionPerformed"/> <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnTerminateGameActionPerformed"/>
</Events> </Events>
</Component> </Component>
<Component class="javax.swing.JButton" name="btnGitHub">
<Properties>
<Property name="text" type="java.lang.String" value="GitHub"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnGitHubActionPerformed"/>
</Events>
</Component>
</SubComponents> </SubComponents>
</Form> </Form>

View File

@@ -73,6 +73,7 @@ public class LogWindow extends javax.swing.JFrame {
btnTieBa = new javax.swing.JButton(); btnTieBa = new javax.swing.JButton();
btnMCF = new javax.swing.JButton(); btnMCF = new javax.swing.JButton();
btnTerminateGame = new javax.swing.JButton(); btnTerminateGame = new javax.swing.JButton();
btnGitHub = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Log"); setTitle("Log");
@@ -139,6 +140,13 @@ public class LogWindow extends javax.swing.JFrame {
} }
}); });
btnGitHub.setText("GitHub");
btnGitHub.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnGitHubActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout); getContentPane().setLayout(layout);
layout.setHorizontalGroup( layout.setHorizontalGroup(
@@ -153,6 +161,8 @@ public class LogWindow extends javax.swing.JFrame {
.addComponent(btnMCBBS) .addComponent(btnMCBBS)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnMCF) .addComponent(btnMCF)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnGitHub)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnTerminateGame) .addComponent(btnTerminateGame)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
@@ -161,7 +171,7 @@ public class LogWindow extends javax.swing.JFrame {
.addComponent(btnClear) .addComponent(btnClear)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnClose)) .addComponent(btnClose))
.addComponent(lblCrash, javax.swing.GroupLayout.DEFAULT_SIZE, 639, Short.MAX_VALUE)) .addComponent(lblCrash, javax.swing.GroupLayout.DEFAULT_SIZE, 674, Short.MAX_VALUE))
.addContainerGap()) .addContainerGap())
); );
layout.setVerticalGroup( layout.setVerticalGroup(
@@ -179,7 +189,8 @@ public class LogWindow extends javax.swing.JFrame {
.addComponent(btnMCBBS) .addComponent(btnMCBBS)
.addComponent(btnTieBa) .addComponent(btnTieBa)
.addComponent(btnMCF) .addComponent(btnMCF)
.addComponent(btnTerminateGame)) .addComponent(btnTerminateGame)
.addComponent(btnGitHub))
.addContainerGap()) .addContainerGap())
); );
@@ -219,6 +230,10 @@ public class LogWindow extends javax.swing.JFrame {
terminateGameListener.onDone(); terminateGameListener.onDone();
}//GEN-LAST:event_btnTerminateGameActionPerformed }//GEN-LAST:event_btnTerminateGameActionPerformed
private void btnGitHubActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGitHubActionPerformed
Utils.openLink(C.URL_GITHUB);
}//GEN-LAST:event_btnGitHubActionPerformed
public void log(String status) { public void log(String status) {
String text = txtLog.getText(); String text = txtLog.getText();
text += status + System.getProperty("line.separator"); text += status + System.getProperty("line.separator");
@@ -286,6 +301,7 @@ public class LogWindow extends javax.swing.JFrame {
private javax.swing.JButton btnClear; private javax.swing.JButton btnClear;
private javax.swing.JButton btnClose; private javax.swing.JButton btnClose;
private javax.swing.JButton btnCopy; private javax.swing.JButton btnCopy;
private javax.swing.JButton btnGitHub;
private javax.swing.JButton btnMCBBS; private javax.swing.JButton btnMCBBS;
private javax.swing.JButton btnMCF; private javax.swing.JButton btnMCF;
private javax.swing.JButton btnTerminateGame; private javax.swing.JButton btnTerminateGame;

View File

@@ -73,6 +73,11 @@ login.type=\u767b\u5f55
login.username=\u540d\u5b57 login.username=\u540d\u5b57
login.account=\u90ae\u7bb1 login.account=\u90ae\u7bb1
proxy.username=\u8d26\u6237
proxy.password=\u5bc6\u7801
proxy.host=\u4e3b\u673a
proxy.port=\u7aef\u53e3
login.failed.connect_authentication_server=\u65e0\u6cd5\u8fde\u63a5\u8ba4\u8bc1\u670d\u52a1\u5668,\u53ef\u80fd\u662f\u7f51\u7edc\u95ee\u9898 login.failed.connect_authentication_server=\u65e0\u6cd5\u8fde\u63a5\u8ba4\u8bc1\u670d\u52a1\u5668,\u53ef\u80fd\u662f\u7f51\u7edc\u95ee\u9898
login.profile.not_logged_in=\u65e0\u6cd5\u4fee\u6539\u6e38\u620f\u8d44\u6599\u540c\u65f6\u672a\u767b\u5f55 login.profile.not_logged_in=\u65e0\u6cd5\u4fee\u6539\u6e38\u620f\u8d44\u6599\u540c\u65f6\u672a\u767b\u5f55
@@ -144,7 +149,7 @@ ui.message.making=\u751f\u6210\u4e2d
ui.message.sure_remove=\u771f\u7684\u8981\u5220\u9664\u914d\u7f6e%s\u5417\uff1f ui.message.sure_remove=\u771f\u7684\u8981\u5220\u9664\u914d\u7f6e%s\u5417\uff1f
ui.label.settings=\u9009\u9879 ui.label.settings=\u9009\u9879
ui.label.crashing=<html>Hello Minecraft! Launcher\u9047\u5230\u4e86\u65e0\u6cd5\u5904\u7406\u7684\u9519\u8bef\uff0c\u8bf7\u590d\u5236\u4e0b\u5217\u5185\u5bb9\u5e76\u901a\u8fc7mcbbs\u3001\u8d34\u5427\u6216Minecraft Forum\u53cd\u9988bug\u3002</html> ui.label.crashing=<html>Hello Minecraft! Launcher\u9047\u5230\u4e86\u65e0\u6cd5\u5904\u7406\u7684\u9519\u8bef\uff0c\u8bf7\u590d\u5236\u4e0b\u5217\u5185\u5bb9\u5e76\u901a\u8fc7mcbbs\u3001\u8d34\u5427\u3001Github\u6216Minecraft Forum\u53cd\u9988bug\u3002</html>
ui.label.crashing_out_dated=<html>Hello Minecraft! Launcher\u9047\u5230\u4e86\u65e0\u6cd5\u5904\u7406\u7684\u9519\u8bef\uff0c\u5df2\u68c0\u6d4b\u5230\u60a8\u7684\u542f\u52a8\u5668\u4e0d\u662f\u6700\u65b0\u7248\u672c\uff0c\u8bf7\u66f4\u65b0\u540e\u518d\u8bd5\uff01</html> ui.label.crashing_out_dated=<html>Hello Minecraft! Launcher\u9047\u5230\u4e86\u65e0\u6cd5\u5904\u7406\u7684\u9519\u8bef\uff0c\u5df2\u68c0\u6d4b\u5230\u60a8\u7684\u542f\u52a8\u5668\u4e0d\u662f\u6700\u65b0\u7248\u672c\uff0c\u8bf7\u66f4\u65b0\u540e\u518d\u8bd5\uff01</html>
ui.label.failed_set=\u8bbe\u7f6e\u5931\u8d25\uff1a ui.label.failed_set=\u8bbe\u7f6e\u5931\u8d25\uff1a
@@ -221,6 +226,7 @@ launcher.background_tooltip=<html>\n<body>\n\u542f\u52a8\u5668\u9ed8\u8ba4\u4f7f
launcher.update_launcher=\u68c0\u67e5\u66f4\u65b0 launcher.update_launcher=\u68c0\u67e5\u66f4\u65b0
launcher.enable_shadow=\u542f\u7528\u7a97\u53e3\u9634\u5f71(\u91cd\u542f\u542f\u52a8\u5668\u751f\u6548,\u53ef\u52a0\u5feb\u6e32\u67d3\u901f\u5ea6) launcher.enable_shadow=\u542f\u7528\u7a97\u53e3\u9634\u5f71(\u91cd\u542f\u542f\u52a8\u5668\u751f\u6548,\u53ef\u52a0\u5feb\u6e32\u67d3\u901f\u5ea6)
launcher.theme=\u4e3b\u9898 launcher.theme=\u4e3b\u9898
launcher.proxy=\u4ee3\u7406
launcher.title.game=\u6e38\u620f\u8bbe\u7f6e launcher.title.game=\u6e38\u620f\u8bbe\u7f6e
launcher.title.main=\u4e3b\u9875 launcher.title.main=\u4e3b\u9875

View File

@@ -50,7 +50,7 @@ configure(install.repositories.mavenInstaller) {
dependencies { dependencies {
compile project(":HMCLAPI") compile project(":HMCLAPI")
compile project(":MetroLookAndFeel") compile project(":MetroLookAndFeel")
compile files("../../../../repo/org/ho/jyaml/1.3/jyaml-1.3.jar") compile ('org.jyaml:jyaml:1.3')
compile ("org.tukaani:xz:1.5") compile ("org.tukaani:xz:1.5")
compile ('org.jsoup:jsoup:1.7.2') compile ('org.jsoup:jsoup:1.7.2')
} }

6
HMCSM/proguard.pro vendored
View File

@@ -1,6 +1,6 @@
-libraryjars D:\Java\jdk1.6.0_45\jre\lib\rt.jar -libraryjars <java.home>/lib/rt.jar
-libraryjars D:\Java\jdk1.6.0_45\jre\lib\jce.jar -libraryjars <java.home>/lib/jce.jar
-libraryjars D:\Java\jdk1.6.0_45\jre\lib\jsse.jar -libraryjars <java.home>/lib/jsse.jar
-dontoptimize -dontoptimize
-dontwarn -dontwarn

View File

@@ -9,8 +9,8 @@ package org.jackhuang.hellominecraft.svrmgr.installer.bukkit;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.jackhuang.hellominecraft.DoneListener1;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.functions.Consumer;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
@@ -22,18 +22,18 @@ import org.jsoup.select.Elements;
*/ */
public class BukkitFormatThread extends Thread { public class BukkitFormatThread extends Thread {
DoneListener1<List<BukkitVersion>> lis; Consumer<List<BukkitVersion>> lis;
List<BukkitVersion> formattedList; List<BukkitVersion> formattedList;
String url; String url;
public BukkitFormatThread(String url, DoneListener1<List<BukkitVersion>> lis) { public BukkitFormatThread(String url, Consumer<List<BukkitVersion>> lis) {
this.lis = lis; this.lis = lis;
this.url = url; this.url = url;
} }
public void format(String url) { public void format(String url) {
formattedList = new ArrayList<BukkitVersion>(); formattedList = new ArrayList<>();
try { try {
Document doc = Jsoup.connect(url).get(); Document doc = Jsoup.connect(url).get();
@@ -74,7 +74,7 @@ public class BukkitFormatThread extends Thread {
List<BukkitVersion> al = null; List<BukkitVersion> al = null;
format(url); format(url);
if(lis != null) if(lis != null)
lis.onDone(formattedList); lis.accept(formattedList);
} }
} }

View File

@@ -9,7 +9,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jackhuang.hellominecraft.DoneListener1; import org.jackhuang.hellominecraft.utils.functions.Consumer;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
@@ -22,10 +22,10 @@ import org.jsoup.select.Elements;
*/ */
public class ForgeFormatThread extends Thread { public class ForgeFormatThread extends Thread {
DoneListener1<Map<String, List<ForgeVersion>>> lis; Consumer<Map<String, List<ForgeVersion>>> lis;
Map<String, List<ForgeVersion>> formattedList; Map<String, List<ForgeVersion>> formattedList;
public ForgeFormatThread(DoneListener1<Map<String, List<ForgeVersion>>> lis) { public ForgeFormatThread(Consumer<Map<String, List<ForgeVersion>>> lis) {
this.lis = lis; this.lis = lis;
} }
@@ -75,14 +75,14 @@ public class ForgeFormatThread extends Thread {
} }
if(!formattedList.containsKey(v.mcver)) if(!formattedList.containsKey(v.mcver))
formattedList.put(v.mcver, new ArrayList<ForgeVersion>()); formattedList.put(v.mcver, new ArrayList<>());
formattedList.get(v.mcver).add(v); formattedList.get(v.mcver).add(v);
} }
} catch (IOException ex) { } catch (IOException ex) {
HMCLog.warn("Failed to get forge list", ex); HMCLog.warn("Failed to get forge list", ex);
ForgeVersion v = new ForgeVersion(); ForgeVersion v = new ForgeVersion();
v.mcver = v.ver = "获取失败"; v.mcver = v.ver = "获取失败";
formattedList.put(v.mcver, new ArrayList<ForgeVersion>()); formattedList.put(v.mcver, new ArrayList<>());
formattedList.get(v.mcver).add(v); formattedList.get(v.mcver).add(v);
} }
} }
@@ -91,7 +91,7 @@ public class ForgeFormatThread extends Thread {
public void run() { public void run() {
formatNew(); formatNew();
if(lis != null) if(lis != null)
lis.onDone(formattedList); lis.accept(formattedList);
} }
} }

View File

@@ -22,8 +22,6 @@ 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.utils.functions.DoneListener0;
import org.jackhuang.hellominecraft.DoneListener1;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.IOUtils; import org.jackhuang.hellominecraft.utils.IOUtils;
import org.jackhuang.hellominecraft.utils.MessageBox; import org.jackhuang.hellominecraft.utils.MessageBox;
@@ -34,12 +32,15 @@ import org.jackhuang.hellominecraft.svrmgr.settings.SettingsManager;
import org.jackhuang.hellominecraft.svrmgr.threads.MonitorThread; import org.jackhuang.hellominecraft.svrmgr.threads.MonitorThread;
import org.jackhuang.hellominecraft.svrmgr.threads.WaitForThread; import org.jackhuang.hellominecraft.svrmgr.threads.WaitForThread;
import org.jackhuang.hellominecraft.svrmgr.utils.Utilities; import org.jackhuang.hellominecraft.svrmgr.utils.Utilities;
import org.jackhuang.hellominecraft.utils.Event;
import org.jackhuang.hellominecraft.utils.EventHandler;
import org.jackhuang.hellominecraft.utils.functions.Consumer;
/** /**
* *
* @author hyh * @author hyh
*/ */
public class Server implements DoneListener1<Integer>, MonitorThread.MonitorThreadListener, public class Server implements Event<Integer>, MonitorThread.MonitorThreadListener,
ActionListener { ActionListener {
private static Server instance; private static Server instance;
@@ -61,10 +62,11 @@ public class Server implements DoneListener1<Integer>, MonitorThread.MonitorThre
Process server; Process server;
MonitorThread threadA, threadB; MonitorThread threadA, threadB;
WaitForThread threadC; WaitForThread threadC;
DoneListener1<Pair<String, String[]>> gettingPlayerNumber; Consumer<Pair<String, String[]>> gettingPlayerNumber;
ArrayList<MonitorThread.MonitorThreadListener> listeners; ArrayList<MonitorThread.MonitorThreadListener> listeners;
ArrayList<DoneListener1<Integer>> listenersC; ArrayList<Event<Integer>> listenersC;
ArrayList<DoneListener0> listenersBegin, listenersDone; //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;
@@ -78,30 +80,20 @@ public class Server implements DoneListener1<Integer>, MonitorThread.MonitorThre
this.jar = jar; this.jar = jar;
this.memory = memory; this.memory = memory;
isRestart = isDone = false; isRestart = isDone = false;
listeners = new ArrayList<MonitorThread.MonitorThreadListener>(); listeners = new ArrayList<>();
listenersC = new ArrayList<DoneListener1<Integer>>(); listenersC = new ArrayList<>();
listenersBegin = new ArrayList<DoneListener0>(); schedules = new ArrayList<>();
listenersDone = new ArrayList<DoneListener0>(); timerTasks = new ArrayList<>();
schedules = new ArrayList<Schedule>();
timerTasks = new ArrayList<TimerTask>();
} }
public void addListener(MonitorThread.MonitorThreadListener l) { public void addListener(MonitorThread.MonitorThreadListener l) {
listeners.add(l); listeners.add(l);
} }
public void addListener(DoneListener1<Integer> l) { public void addListener(Event<Integer> l) {
listenersC.add(l); listenersC.add(l);
} }
public void addServerStartedListener(DoneListener0 l) {
listenersBegin.add(l);
}
public void addServerDoneListener(DoneListener0 l) {
listenersDone.add(l);
}
public void run() throws IOException { public void run() throws IOException {
String jvmPath; String jvmPath;
if (StrUtils.isBlank(SettingsManager.settings.javaDir)) { if (StrUtils.isBlank(SettingsManager.settings.javaDir)) {
@@ -133,9 +125,7 @@ public class Server implements DoneListener1<Integer>, MonitorThread.MonitorThre
bw = new BufferedWriter(new OutputStreamWriter(server.getOutputStream())); bw = new BufferedWriter(new OutputStreamWriter(server.getOutputStream()));
} }
isRunning = true; isRunning = true;
for (DoneListener0 d : listenersBegin) { startedEvent.execute(null);
d.onDone();
}
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);
@@ -156,7 +146,7 @@ public class Server implements DoneListener1<Integer>, MonitorThread.MonitorThre
} }
} }
public void getPlayerNumber(DoneListener1<Pair<String, String[]>> d) { public void getPlayerNumber(Consumer<Pair<String, String[]>> d) {
isGettingPlayerNumber = 1; isGettingPlayerNumber = 1;
gettingPlayerNumber = d; gettingPlayerNumber = d;
sendCommand("list"); sendCommand("list");
@@ -210,15 +200,13 @@ public class Server implements DoneListener1<Integer>, MonitorThread.MonitorThre
private void registerThreadC(Process p) { private void registerThreadC(Process p) {
threadC = new WaitForThread(p); threadC = new WaitForThread(p);
for (DoneListener1<Integer> l : listenersC) { for (Event<Integer> l : listenersC) threadC.event.register(l);
threadC.addListener(l); threadC.event.register(this);
}
threadC.addListener(this);
threadC.start(); threadC.start();
} }
@Override @Override
public void onDone(Integer t) { public boolean call(Object sender, Integer t) {
if (t == 0) { if (t == 0) {
sendStatus("*** 服务端已停止 ***"); sendStatus("*** 服务端已停止 ***");
System.out.println("Server stopped successfully"); System.out.println("Server stopped successfully");
@@ -227,17 +215,9 @@ public class Server implements DoneListener1<Integer>, MonitorThread.MonitorThre
System.err.println("Server crashed(exit code: " + t + ")"); System.err.println("Server crashed(exit code: " + t + ")");
} }
isRunning = false; isRunning = false;
for (int i = 0; i < schedules.size(); i++) { for (Schedule schedule : schedules) if (schedule.timeType == Schedule.TIME_TYPE_SERVER_STOPPED) ScheduleTranslator.translate(this, schedule).run();
if (schedules.get(i).timeType == Schedule.TIME_TYPE_SERVER_STOPPED) { if (timer != null) timer.cancel();
ScheduleTranslator.translate(this, schedules.get(i)).run(); if (pastTimer != null) pastTimer.stop();
}
}
if (timer != null) {
timer.cancel();
}
if (pastTimer != null) {
pastTimer.stop();
}
restoreMods(); restoreMods();
if (isRestart) { if (isRestart) {
try { try {
@@ -248,6 +228,7 @@ public class Server implements DoneListener1<Integer>, MonitorThread.MonitorThre
} }
isRestart = false; isRestart = false;
} }
return true;
} }
private static void disactiveMods(ArrayList<String> inactiveExtMods, private static void disactiveMods(ArrayList<String> inactiveExtMods,
@@ -270,58 +251,49 @@ public class Server implements DoneListener1<Integer>, MonitorThread.MonitorThre
System.out.println("没有文件: " + paramString); System.out.println("没有文件: " + paramString);
return; return;
} }
for (int i = 0; i < files.length; i++) { for (File file : files) if (!file.isDirectory()) {
File file = files[i]; String name = file.getName();
if (!file.isDirectory()) {
String name = file.getName(); if ((!paramArrayOfString.contains(name))
|| ((!name.toLowerCase().endsWith(".zip")) && (!name.toLowerCase().endsWith(".jar")))) {
if ((!paramArrayOfString.contains(name)) continue;
|| ((!name.toLowerCase().endsWith(".zip")) && (!name.toLowerCase().endsWith(".jar")))) { }
continue;
} String newName = name + "X";
File newFile = new File(file.getParentFile(), newName);
String newName = name + "X";
File newFile = new File(file.getParentFile(), newName); if (newFile.exists()) {
newFile.delete();
if (newFile.exists()) { }
newFile.delete(); if (file.renameTo(newFile)) {
} System.out.println("已禁用: " + name + ", 新名称: " + newFile.getName());
if (file.renameTo(newFile)) { } else {
System.out.println("禁用: " + name + ", 新名称: " + newFile.getName()); System.out.println("无法禁用: " + name);
} else { }
System.out.println("无法禁用: " + name); }
}
}
}
} }
private static void restoreModsByType(String paramString) { private static void restoreModsByType(String paramString) {
System.out.println("还原被禁用的文件: " + paramString); System.out.println("还原被禁用的文件: " + paramString);
File[] files = new File(Utilities.getGameDir(), paramString).listFiles(); File[] files = new File(Utilities.getGameDir(), paramString).listFiles();
if (files == null) { if (files == null) return;
return; for (File file : files) if (!file.isDirectory()) {
} String name = file.getName();
for (int i = 0; i < files.length; i++) { String lowName = name.toLowerCase();
File file = files[i]; if ((!lowName.endsWith(".zipx")) && (!lowName.endsWith(".jarx"))) {
if (file.isDirectory()) { continue;
continue; }
} String newName = name.substring(0, name.length() - 1);
String name = file.getName();
String lowName = name.toLowerCase(); File newFile = new File(file.getParentFile(), newName);
if ((!lowName.endsWith(".zipx")) && (!lowName.endsWith(".jarx"))) { if (newFile.exists()) {
continue; file.delete();
} } else {
String newName = name.substring(0, name.length() - 1); if (!file.renameTo(newFile)) {
System.out.println("无法重命名: " + file.getName() + " 到: " + newFile.getName() + " 在: " + file.getParent());
File newFile = new File(file.getParentFile(), newName); }
if (newFile.exists()) { }
file.delete(); }
} else {
if (!file.renameTo(newFile)) {
System.out.println("无法重命名: " + file.getName() + " 到: " + newFile.getName() + " 在: " + file.getParent());
}
}
}
} }
static void restoreMods() { static void restoreMods() {
@@ -360,18 +332,16 @@ public class Server implements DoneListener1<Integer>, MonitorThread.MonitorThre
} else { } else {
s = new String[0]; s = new String[0];
} }
Pair<String, String[]> p = new Pair<String, String[]>(playerNumber, s); Pair<String, String[]> p = new Pair<>(playerNumber, s);
isGettingPlayerNumber = 0; isGettingPlayerNumber = 0;
gettingPlayerNumber.onDone(p); gettingPlayerNumber.accept(p);
return; return;
} }
if (isDone == false) { if (isDone == false) {
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()) {
for (DoneListener0 d : listenersDone) { stoppedEvent.execute(null);
d.onDone();
}
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++) {
@@ -379,9 +349,7 @@ public class Server implements DoneListener1<Integer>, MonitorThread.MonitorThre
ScheduleTranslator.translate(this, schedules.get(i)).run(); ScheduleTranslator.translate(this, schedules.get(i)).run();
continue; continue;
} }
if (schedules.get(i).timeType != Schedule.TIME_TYPE_PER) { if (schedules.get(i).timeType != Schedule.TIME_TYPE_PER) continue;
continue;
}
long mill = (long) Math.floor(schedules.get(i).per * 60 * 1000); long mill = (long) Math.floor(schedules.get(i).per * 60 * 1000);
timerTasks.add(ScheduleTranslator.translate(this, schedules.get(i))); timerTasks.add(ScheduleTranslator.translate(this, schedules.get(i)));
timer.schedule(timerTasks.get(i), mill, mill); timer.schedule(timerTasks.get(i), mill, mill);
@@ -395,11 +363,7 @@ public class Server implements DoneListener1<Integer>, MonitorThread.MonitorThre
} }
if (status.length() > 20) { if (status.length() > 20) {
if (status.substring(20).contains("[SEVERE] This crash report has been saved to: ")) { if (status.substring(20).contains("[SEVERE] This crash report has been saved to: ")) {
for (int i = 0; i < schedules.size(); i++) { for (Schedule schedule : schedules) if (schedule.timeType == Schedule.TIME_TYPE_SERVER_CRASHED) ScheduleTranslator.translate(this, schedule).run();
if (schedules.get(i).timeType == Schedule.TIME_TYPE_SERVER_CRASHED) {
ScheduleTranslator.translate(this, schedules.get(i)).run();
}
}
} }
} }
} }
@@ -409,23 +373,15 @@ public class Server implements DoneListener1<Integer>, MonitorThread.MonitorThre
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
c.setTime(new Date()); c.setTime(new Date());
if (c.get(Calendar.SECOND) != 0) { if (c.get(Calendar.SECOND) != 0) return;
return;
}
int minute = c.get(Calendar.MINUTE); int minute = c.get(Calendar.MINUTE);
for (int i = 0; i < schedules.size(); i++) { for (Schedule schedule : schedules) {
if (schedules.get(i).timeType != Schedule.TIME_TYPE_PAST_HOUR) { if (schedule.timeType != Schedule.TIME_TYPE_PAST_HOUR) continue;
continue; if (schedule.per == minute) ScheduleTranslator.translate(this, schedule).run();
} }
if (schedules.get(i).per == minute) {
ScheduleTranslator.translate(this, schedules.get(i)).run();
}
}
} }
private void sendStatus(String status) { private void sendStatus(String status) {
for (MonitorThread.MonitorThreadListener l : listeners) { for (MonitorThread.MonitorThreadListener l : listeners) l.onStatus(status);
l.onStatus(status);
}
} }
} }

View File

@@ -4,10 +4,9 @@
*/ */
package org.jackhuang.hellominecraft.svrmgr.threads; package org.jackhuang.hellominecraft.svrmgr.threads;
import java.util.ArrayList;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.jackhuang.hellominecraft.DoneListener1; import org.jackhuang.hellominecraft.utils.EventHandler;
/** /**
* *
@@ -15,30 +14,21 @@ import org.jackhuang.hellominecraft.DoneListener1;
*/ */
public class WaitForThread extends Thread { public class WaitForThread extends Thread {
public ArrayList<DoneListener1<Integer>> al; public final EventHandler<Integer> event = new EventHandler<>(this);
Process p; Process p;
public WaitForThread(Process p) { public WaitForThread(Process p) {
this.p = p; this.p = p;
al = new ArrayList<DoneListener1<Integer>>();
}
public void addListener(DoneListener1<Integer> dl) {
al.add(dl);
} }
@Override @Override
public void run() { public void run() {
try { try {
int exitCode = p.waitFor(); int exitCode = p.waitFor();
for(DoneListener1<Integer> dl : al) event.execute(exitCode);
if(dl != null)
dl.onDone(exitCode);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
Logger.getLogger(WaitForThread.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(WaitForThread.class.getName()).log(Level.SEVERE, null, ex);
for(DoneListener1<Integer> dl : al) event.execute(-1);
if(dl != null)
dl.onDone(-1);
} }
} }

View File

@@ -8,9 +8,9 @@ package org.jackhuang.hellominecraft.svrmgr.utils;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.jackhuang.hellominecraft.DoneListener1;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.utils.NetUtils; import org.jackhuang.hellominecraft.utils.NetUtils;
import org.jackhuang.hellominecraft.utils.functions.Consumer;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
@@ -21,7 +21,7 @@ import org.jsoup.select.Elements;
*/ */
public class IPGet extends Thread { public class IPGet extends Thread {
public DoneListener1<String> dl; public Consumer<String> dl;
@Override @Override
public void run() { public void run() {
@@ -37,11 +37,11 @@ public class IPGet extends Thread {
while(m.find()) { while(m.find()) {
s += m.group() + ","; s += m.group() + ",";
} }
dl.onDone(s.substring(0, s.length()-1)); dl.accept(s.substring(0, s.length()-1));
} }
} catch (Exception ex) { } catch (Exception ex) {
HMCLog.warn("Failed to get ip from ip138.", ex); HMCLog.warn("Failed to get ip from ip138.", ex);
dl.onDone("获取失败"); dl.accept("获取失败");
} }
} }

View File

@@ -34,8 +34,6 @@ import javax.swing.JPopupMenu;
import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel; import javax.swing.table.DefaultTableModel;
import org.jackhuang.hellominecraft.C; import org.jackhuang.hellominecraft.C;
import org.jackhuang.hellominecraft.utils.functions.DoneListener0;
import org.jackhuang.hellominecraft.DoneListener1;
import org.jackhuang.hellominecraft.HMCLog; import org.jackhuang.hellominecraft.HMCLog;
import org.jackhuang.hellominecraft.tasks.Task; import org.jackhuang.hellominecraft.tasks.Task;
import org.jackhuang.hellominecraft.tasks.TaskWindow; import org.jackhuang.hellominecraft.tasks.TaskWindow;
@@ -48,7 +46,6 @@ import org.jackhuang.hellominecraft.utils.MessageBox;
import org.jackhuang.hellominecraft.svrmgr.utils.ModType; import org.jackhuang.hellominecraft.svrmgr.utils.ModType;
import org.jackhuang.hellominecraft.svrmgr.utils.MonitorInfoBean; import org.jackhuang.hellominecraft.svrmgr.utils.MonitorInfoBean;
import org.jackhuang.hellominecraft.svrmgr.utils.MonitorServiceImpl; import org.jackhuang.hellominecraft.svrmgr.utils.MonitorServiceImpl;
import org.jackhuang.hellominecraft.utils.Pair;
import org.jackhuang.hellominecraft.version.MinecraftRemoteVersions; import org.jackhuang.hellominecraft.version.MinecraftRemoteVersions;
import org.jackhuang.hellominecraft.svrmgr.Main; import org.jackhuang.hellominecraft.svrmgr.Main;
import org.jackhuang.hellominecraft.svrmgr.cbplugins.BukkitPlugin; import org.jackhuang.hellominecraft.svrmgr.cbplugins.BukkitPlugin;
@@ -78,13 +75,14 @@ import org.jackhuang.hellominecraft.svrmgr.utils.Utilities;
import org.jackhuang.hellominecraft.utils.SwingUtils; import org.jackhuang.hellominecraft.utils.SwingUtils;
import org.jackhuang.hellominecraft.version.MinecraftRemoteVersion; import org.jackhuang.hellominecraft.version.MinecraftRemoteVersion;
import org.jackhuang.hellominecraft.lookandfeel.components.ConstomButton; import org.jackhuang.hellominecraft.lookandfeel.components.ConstomButton;
import org.jackhuang.hellominecraft.utils.Event;
/** /**
* *
* @author hyh * @author hyh
*/ */
public final class MainWindow extends javax.swing.JFrame public final class MainWindow extends javax.swing.JFrame
implements MonitorThread.MonitorThreadListener, DoneListener1<Integer> { implements MonitorThread.MonitorThreadListener, Event<Integer> {
ImageIcon background = new ImageIcon(getClass().getResource("/background.jpg")); ImageIcon background = new ImageIcon(getClass().getResource("/background.jpg"));
JLabel backgroundLabel; JLabel backgroundLabel;
@@ -144,11 +142,10 @@ public final class MainWindow extends javax.swing.JFrame
setTitle(Main.makeTitle()); setTitle(Main.makeTitle());
String mainjar = SettingsManager.settings.mainjar; String mainjar = SettingsManager.settings.mainjar;
if (!Utilities.isEmpty(mainjar)) { if (!Utilities.isEmpty(mainjar))
ServerProperties.init(new File(mainjar).getParent()); ServerProperties.init(new File(mainjar).getParent());
}
txtMainJar.setText(mainjar); txtMainJar.setText(mainjar);
commandSet = new ArrayList<String>(); commandSet = new ArrayList<>();
btnStop.setEnabled(false); btnStop.setEnabled(false);
btnShutdown.setEnabled(false); btnShutdown.setEnabled(false);
btnCommand.setEnabled(false); btnCommand.setEnabled(false);
@@ -480,9 +477,8 @@ public final class MainWindow extends javax.swing.JFrame
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
InputDialog id = new InputDialog(MainWindow.this, true, new String[]{"玩家", "物品ID", "数量"}); InputDialog id = new InputDialog(MainWindow.this, true, new String[]{"玩家", "物品ID", "数量"});
id.setVisible(true); id.setVisible(true);
if (id.result != null) { if (id.result != null)
Server.getInstance().sendCommand("give " + id.result[0] + " " + id.result[1] + " " + id.result[2]); Server.getInstance().sendCommand("give " + id.result[0] + " " + id.result[1] + " " + id.result[2]);
}
} }
}); });
ppmBasically.add(itm); ppmBasically.add(itm);
@@ -2896,23 +2892,21 @@ public final class MainWindow extends javax.swing.JFrame
void loadFromServerProperties() { void loadFromServerProperties() {
ServerProperties sp = ServerProperties.getInstance(); ServerProperties sp = ServerProperties.getInstance();
if (sp == null) { if (sp == null)
return; return;
}
txtServerPort.setValue(sp.getPropertyInt("server-port", 25565)); txtServerPort.setValue(sp.getPropertyInt("server-port", 25565));
txtServerName.setText(sp.getProperty("server-name")); txtServerName.setText(sp.getProperty("server-name"));
cboGameMode.setSelectedIndex(sp.getPropertyInt("gamemode", 0)); cboGameMode.setSelectedIndex(sp.getPropertyInt("gamemode", 0));
cboDifficulty.setSelectedIndex(sp.getPropertyInt("difficulty", 1)); cboDifficulty.setSelectedIndex(sp.getPropertyInt("difficulty", 1));
String wt = sp.getProperty("level-type"); String wt = sp.getProperty("level-type");
if (wt.equals("LARGEBIOMES")) { if (wt.equals("LARGEBIOMES"))
cboWorldType.setSelectedIndex(2); cboWorldType.setSelectedIndex(2);
} else if (wt.equals("FLAT")) { else if (wt.equals("FLAT"))
cboWorldType.setSelectedIndex(1); cboWorldType.setSelectedIndex(1);
} else if (wt.equals("DEFAULT")) { else if (wt.equals("DEFAULT"))
cboWorldType.setSelectedIndex(0); cboWorldType.setSelectedIndex(0);
} else { else
cboWorldType.setSelectedIndex(0); cboWorldType.setSelectedIndex(0);
}
txtMaxPlayer.setValue(sp.getPropertyInt("max-players", 20)); txtMaxPlayer.setValue(sp.getPropertyInt("max-players", 20));
chkAllowFlight.setSelected(sp.getPropertyBoolean("allow-flight", false)); chkAllowFlight.setSelected(sp.getPropertyBoolean("allow-flight", false));
chkAllowNether.setSelected(sp.getPropertyBoolean("allow-nether", true)); chkAllowNether.setSelected(sp.getPropertyBoolean("allow-nether", true));
@@ -2932,82 +2926,64 @@ public final class MainWindow extends javax.swing.JFrame
void loadFromOPs() { void loadFromOPs() {
File mainjar = new File(SettingsManager.settings.mainjar); File mainjar = new File(SettingsManager.settings.mainjar);
if (!mainjar.exists()) { if (!mainjar.exists()) return;
return;
}
File folder = mainjar.getParentFile(); File folder = mainjar.getParentFile();
op = new Op(); op = new Op();
op.initByBoth(new File(folder, "ops.txt"), new File(folder, "ops.json")); op.initByBoth(new File(folder, "ops.txt"), new File(folder, "ops.json"));
for (Op.Operator ss : op.op) { for (Op.Operator ss : op.op) lstOPModel.addElement(ss.name);
lstOPModel.addElement(ss.name);
}
lstOP.setModel(lstOPModel); lstOP.setModel(lstOPModel);
} }
void loadFromWhiteList() { void loadFromWhiteList() {
File mainjar = new File(SettingsManager.settings.mainjar); File mainjar = new File(SettingsManager.settings.mainjar);
if (!mainjar.exists()) { if (!mainjar.exists()) return;
return;
}
File folder = mainjar.getParentFile(); File folder = mainjar.getParentFile();
whitelist = new WhiteList(); whitelist = new WhiteList();
whitelist.initByBoth(new File(folder, "white-list.txt"), new File(folder, "white-list.json")); whitelist.initByBoth(new File(folder, "white-list.txt"), new File(folder, "white-list.json"));
for (WhiteList.WhiteListPlayer ss : whitelist.op) { for (WhiteList.WhiteListPlayer ss : whitelist.op) lstWhiteListModel.addElement(ss.name);
lstWhiteListModel.addElement(ss.name);
}
lstWhiteList.setModel(lstWhiteListModel); lstWhiteList.setModel(lstWhiteListModel);
} }
void loadFromBannedPlayers() { void loadFromBannedPlayers() {
File mainjar = new File(SettingsManager.settings.mainjar); File mainjar = new File(SettingsManager.settings.mainjar);
if (!mainjar.exists()) { if (!mainjar.exists()) return;
return;
}
File folder = mainjar.getParentFile(); File folder = mainjar.getParentFile();
banned = new BannedPlayers(); banned = new BannedPlayers();
banned.initByBoth(new File(folder, "banned-players.txt"), new File(folder, "banned-players.json")); banned.initByBoth(new File(folder, "banned-players.txt"), new File(folder, "banned-players.json"));
for (BannedPlayers.BannedPlayer ss : banned.op) { for (BannedPlayers.BannedPlayer ss : banned.op)
lstBannedModel.addElement(ss.name); lstBannedModel.addElement(ss.name);
}
lstBanned.setModel(lstBannedModel); lstBanned.setModel(lstBannedModel);
} }
void loadLocalMods() { void loadLocalMods() {
String path = Utilities.getPath("mods"); String path = Utilities.getPath("mods");
if (path == null) { if (path == null) return;
return;
}
ArrayList<String> sl = Utilities.findAllFile(new File(path)); ArrayList<String> sl = Utilities.findAllFile(new File(path));
DefaultTableModel model = (DefaultTableModel) lstExternalMods.getModel(); DefaultTableModel model = (DefaultTableModel) lstExternalMods.getModel();
while (model.getRowCount() > 0) { while (model.getRowCount() > 0)
model.removeRow(0); model.removeRow(0);
} for (String s : sl)
for (String s : sl) {
model.addRow(new Object[]{!SettingsManager.settings.inactiveExtMods.contains(s), s, ModType.getModTypeShowName(ModType.getModType(Utilities.addSeparator(path) + s))}); model.addRow(new Object[]{!SettingsManager.settings.inactiveExtMods.contains(s), s, ModType.getModTypeShowName(ModType.getModType(Utilities.addSeparator(path) + s))});
}
lstExternalMods.updateUI(); lstExternalMods.updateUI();
} }
void loadLocalPlugins() { void loadLocalPlugins() {
String path = Utilities.getPath("plugins"); String path = Utilities.getPath("plugins");
if (path == null) { if (path == null)
return; return;
}
ArrayList<String> sl = Utilities.findAllFile(new File(path)); ArrayList<String> sl = Utilities.findAllFile(new File(path));
DefaultTableModel model = (DefaultTableModel) lstPlugins.getModel(); DefaultTableModel model = (DefaultTableModel) lstPlugins.getModel();
while (model.getRowCount() > 0) { while (model.getRowCount() > 0)
model.removeRow(0); model.removeRow(0);
}
for (String s : sl) { for (String s : sl) {
PluginInformation p = PluginManager.getPluginYML(new File(Utilities.getGameDir() + "plugins" + File.separator + s)); PluginInformation p = PluginManager.getPluginYML(new File(Utilities.getGameDir() + "plugins" + File.separator + s));
if (p == null) { if (p == null)
model.addRow(new Object[]{!SettingsManager.settings.inactivePlugins.contains(s), s, model.addRow(new Object[]{!SettingsManager.settings.inactivePlugins.contains(s), s,
"", "", "", ""}); "", "", "", ""});
} else { else
model.addRow(new Object[]{!SettingsManager.settings.inactivePlugins.contains(s), s, model.addRow(new Object[]{!SettingsManager.settings.inactivePlugins.contains(s), s,
p.name, p.version, p.author, p.description}); p.name, p.version, p.author, p.description});
}
} }
lstPlugins.updateUI(); lstPlugins.updateUI();
@@ -3015,17 +2991,14 @@ public final class MainWindow extends javax.swing.JFrame
void loadLocalCoreMods() { void loadLocalCoreMods() {
String path = Utilities.getPath("coremods"); String path = Utilities.getPath("coremods");
if (path == null) { if (path == null)
return; return;
}
ArrayList<String> sl = Utilities.findAllFile(new File(path)); ArrayList<String> sl = Utilities.findAllFile(new File(path));
DefaultTableModel model = (DefaultTableModel) lstCoreMods.getModel(); DefaultTableModel model = (DefaultTableModel) lstCoreMods.getModel();
while (model.getRowCount() > 0) { while (model.getRowCount() > 0)
model.removeRow(0); model.removeRow(0);
} for (String s : sl)
for (String s : sl) {
model.addRow(new Object[]{!SettingsManager.settings.inactiveCoreMods.contains(s), s, ModType.getModTypeShowName(ModType.getModType(Utilities.addSeparator(path) + s))}); model.addRow(new Object[]{!SettingsManager.settings.inactiveCoreMods.contains(s), s, ModType.getModTypeShowName(ModType.getModType(Utilities.addSeparator(path) + s))});
}
lstCoreMods.updateUI(); lstCoreMods.updateUI();
} }
@@ -3033,14 +3006,12 @@ public final class MainWindow extends javax.swing.JFrame
void loadWorlds() { void loadWorlds() {
ArrayList<String> s = BackupManager.findAllWorlds(); ArrayList<String> s = BackupManager.findAllWorlds();
DefaultTableModel model = (DefaultTableModel) lstWorlds.getModel(); DefaultTableModel model = (DefaultTableModel) lstWorlds.getModel();
if (SettingsManager.settings.inactiveWorlds == null) { if (SettingsManager.settings.inactiveWorlds == null)
SettingsManager.settings.inactiveWorlds = new ArrayList<String>(); SettingsManager.settings.inactiveWorlds = new ArrayList<>();
} for (String world : s)
for (String world : s) {
model.addRow(new Object[]{ model.addRow(new Object[]{
world, Utilities.getGameDir() + world, !SettingsManager.settings.inactiveWorlds.contains(world) world, Utilities.getGameDir() + world, !SettingsManager.settings.inactiveWorlds.contains(world)
}); });
}
lstWorlds.updateUI(); lstWorlds.updateUI();
} }
@@ -3057,13 +3028,11 @@ public final class MainWindow extends javax.swing.JFrame
} }
void loadSchedules() { void loadSchedules() {
if (SettingsManager.settings.schedules == null) { if (SettingsManager.settings.schedules == null)
SettingsManager.settings.schedules = new ArrayList<Schedule>(); SettingsManager.settings.schedules = new ArrayList<>();
}
DefaultTableModel model = (DefaultTableModel) lstSchedules.getModel(); DefaultTableModel model = (DefaultTableModel) lstSchedules.getModel();
for (Schedule s : SettingsManager.settings.schedules) { for (Schedule s : SettingsManager.settings.schedules)
model.addRow(ScheduleTranslator.getRow(s)); model.addRow(ScheduleTranslator.getRow(s));
}
lstSchedules.updateUI(); lstSchedules.updateUI();
} }
@@ -3073,67 +3042,46 @@ public final class MainWindow extends javax.swing.JFrame
void loadBukkits() { void loadBukkits() {
int idx = cboBukkitType.getSelectedIndex(); int idx = cboBukkitType.getSelectedIndex();
if (idx == -1) { if (idx == -1) return;
return;
}
String url = null;
if (idx == 1) { if (idx == 1) {
BukkitFormatThread thread = new BukkitFormatThread( BukkitFormatThread thread = new BukkitFormatThread(
"http://dl.bukkit.org/downloads/craftbukkit/list/beta/", "http://dl.bukkit.org/downloads/craftbukkit/list/beta/", value -> {
new DoneListener1<List<BukkitVersion>>() { craftBukkitBeta = value;
@Override reloadBukkitList();
public void onDone(List<BukkitVersion> value) {
craftBukkitBeta = value;
reloadBukkitList();
}
}); });
thread.start(); thread.start();
} else if (idx == 0) { } else if (idx == 0) {
BukkitFormatThread thread = new BukkitFormatThread( BukkitFormatThread thread = new BukkitFormatThread(
"http://dl.bukkit.org/downloads/craftbukkit/list/rb/", "http://dl.bukkit.org/downloads/craftbukkit/list/rb/", value -> {
new DoneListener1<List<BukkitVersion>>() { craftBukkitRecommended = value;
@Override reloadBukkitList();
public void onDone(List<BukkitVersion> value) {
craftBukkitRecommended = value;
reloadBukkitList();
}
}); });
thread.start(); thread.start();
} else if (idx == 2) { } else if (idx == 2) {
BukkitFormatThread thread = new BukkitFormatThread( BukkitFormatThread thread = new BukkitFormatThread(
"http://dl.bukkit.org/downloads/craftbukkit/list/dev/", "http://dl.bukkit.org/downloads/craftbukkit/list/dev/", value -> {
new DoneListener1<List<BukkitVersion>>() { craftBukkitDev = value;
@Override reloadBukkitList();
public void onDone(List<BukkitVersion> value) {
craftBukkitDev = value;
reloadBukkitList();
}
}); });
thread.start(); thread.start();
} }
} }
void loadMCPCs() { void loadMCPCs() {
ForgeFormatThread thread = new ForgeFormatThread( ForgeFormatThread thread = new ForgeFormatThread(value -> {
new DoneListener1<Map<String, List<ForgeVersion>>>() { mcpcPackages = value;
@Override reloadMCPCList();
public void onDone(Map<String, List<ForgeVersion>> value) { });
mcpcPackages = value;
reloadMCPCList();
}
});
thread.start(); thread.start();
} }
public void reloadMCPCList() { public void reloadMCPCList() {
if (mcpcPackages == null) { if (mcpcPackages == null)
return; return;
}
int cnt = cboCauldronMinecraft.getItemCount(); int cnt = cboCauldronMinecraft.getItemCount();
cboCauldronMinecraft.removeAllItems(); cboCauldronMinecraft.removeAllItems();
for (String s : mcpcPackages.keySet()) { for (String s : mcpcPackages.keySet())
cboCauldronMinecraft.addItem(s); cboCauldronMinecraft.addItem(s);
}
String mcver = (String) cboCauldronMinecraft.getSelectedItem(); String mcver = (String) cboCauldronMinecraft.getSelectedItem();
useMCPCVersions(mcver); useMCPCVersions(mcver);
@@ -3141,9 +3089,8 @@ public final class MainWindow extends javax.swing.JFrame
public void useMCPCVersions(String ver) { public void useMCPCVersions(String ver) {
DefaultTableModel model = (DefaultTableModel) lstMCPC.getModel(); DefaultTableModel model = (DefaultTableModel) lstMCPC.getModel();
while (model.getRowCount() > 0) { while (model.getRowCount() > 0)
model.removeRow(0); model.removeRow(0);
}
for (ForgeVersion v : mcpcPackages.get(ver)) { for (ForgeVersion v : mcpcPackages.get(ver)) {
Object[] row = new Object[]{ Object[] row = new Object[]{
v.mcver, v.ver, v.releasetime v.mcver, v.ver, v.releasetime
@@ -3155,26 +3102,22 @@ public final class MainWindow extends javax.swing.JFrame
public void reloadBukkitList() { public void reloadBukkitList() {
int idx = cboBukkitType.getSelectedIndex(); int idx = cboBukkitType.getSelectedIndex();
if (idx == -1) { if (idx == -1)
return; return;
} if (idx == 1)
if (idx == 1) {
useBukkitVersions(craftBukkitBeta); useBukkitVersions(craftBukkitBeta);
} else if (idx == 0) { else if (idx == 0)
useBukkitVersions(craftBukkitRecommended); useBukkitVersions(craftBukkitRecommended);
} else if (idx == 2) { else if (idx == 2)
useBukkitVersions(craftBukkitDev); useBukkitVersions(craftBukkitDev);
}
} }
public void useBukkitVersions(List<BukkitVersion> list) { public void useBukkitVersions(List<BukkitVersion> list) {
if (list == null) { if (list == null)
return; return;
}
DefaultTableModel model = (DefaultTableModel) lstCraftbukkit.getModel(); DefaultTableModel model = (DefaultTableModel) lstCraftbukkit.getModel();
while (model.getRowCount() > 0) { while (model.getRowCount() > 0)
model.removeRow(0); model.removeRow(0);
}
for (BukkitVersion v : list) { for (BukkitVersion v : list) {
Object[] row = new Object[]{ Object[] row = new Object[]{
v.buildNumber, v.version v.buildNumber, v.version
@@ -3229,54 +3172,42 @@ public final class MainWindow extends javax.swing.JFrame
void refreshInfos() { void refreshInfos() {
ArrayList<String> al = Utilities.findAllFile(new File(Utilities.getGameDir() + "infos-HMCSM")); ArrayList<String> al = Utilities.findAllFile(new File(Utilities.getGameDir() + "infos-HMCSM"));
DefaultTableModel model = (DefaultTableModel) lstInfos.getModel(); DefaultTableModel model = (DefaultTableModel) lstInfos.getModel();
for (String s : al) { for (String s : al)
model.addRow(new Object[]{s, Utilities.trimExtension(s)}); model.addRow(new Object[]{s, Utilities.trimExtension(s)});
}
lstInfos.updateUI(); lstInfos.updateUI();
} }
void refreshReports() { void refreshReports() {
ArrayList<String> al = Utilities.findAllFile(new File(Utilities.getGameDir() + "crash-reports")); ArrayList<String> al = Utilities.findAllFile(new File(Utilities.getGameDir() + "crash-reports"));
for (String s : al) { for (String s : al) lstCrashReportsModel.addElement(s);
lstCrashReportsModel.addElement(s);
}
lstReports.setModel(lstCrashReportsModel); lstReports.setModel(lstCrashReportsModel);
} }
void getIP() { void getIP() {
IPGet get = new IPGet(); IPGet get = new IPGet();
get.dl = new DoneListener1<String>() { get.dl = a -> lblIPAddress.setText("IP: " + a);;
@Override
public void onDone(String value) {
lblIPAddress.setText("IP: " + value);
}
};
get.start(); get.start();
} }
void loadBukkitPlugins() { void loadBukkitPlugins() {
final DefaultTableModel model = (DefaultTableModel) lstBukkitPlugins.getModel(); final DefaultTableModel model = (DefaultTableModel) lstBukkitPlugins.getModel();
while (model.getRowCount() > 0) { while (model.getRowCount() > 0)
model.removeRow(0); model.removeRow(0);
}
lstBukkitPlugins.updateUI(); lstBukkitPlugins.updateUI();
Thread t = new Thread() { Thread t = new Thread() {
@Override @Override
public void run() { public void run() {
try { try {
List<BukkitPlugin> l; List<BukkitPlugin> l;
if (cboCategory.getSelectedIndex() == 0) { if (cboCategory.getSelectedIndex() == 0)
l = PluginManager.getPlugins(); l = PluginManager.getPlugins();
} else { else
l = PluginManager.getPluginsByCategory(cboCategory.getSelectedItem().toString()); l = PluginManager.getPluginsByCategory(cboCategory.getSelectedItem().toString());
}
plugins = l; plugins = l;
for (BukkitPlugin p : l) { for (BukkitPlugin p : l)
model.addRow(new Object[]{ model.addRow(new Object[]{
p.plugin_name, p.description, p.getLatestVersion(), p.getLatestBukkit() p.plugin_name, p.description, p.getLatestVersion(), p.getLatestBukkit()
}); });
}
lstBukkitPlugins.updateUI(); lstBukkitPlugins.updateUI();
} catch (Exception ex) { } catch (Exception ex) {
HMCLog.warn("Failed to get plugins", ex); HMCLog.warn("Failed to get plugins", ex);
@@ -3294,9 +3225,8 @@ public final class MainWindow extends javax.swing.JFrame
List<Category> l = PluginManager.getCategories(); List<Category> l = PluginManager.getCategories();
cboCategory.removeAllItems(); cboCategory.removeAllItems();
cboCategory.addItem("所有"); cboCategory.addItem("所有");
for (Category c : l) { for (Category c : l)
cboCategory.addItem(c.name); cboCategory.addItem(c.name);
}
} catch (Exception ex) { } catch (Exception ex) {
HMCLog.warn("Failed to load bukkit categories."); HMCLog.warn("Failed to load bukkit categories.");
} }
@@ -3320,41 +3250,36 @@ public final class MainWindow extends javax.swing.JFrame
void loadPlayers() { void loadPlayers() {
Server s = Server.getInstance(); Server s = Server.getInstance();
if (s != null && s.isRunning) { if (s != null && s.isRunning)
s.getPlayerNumber(new DoneListener1<Pair<String, String[]>>() { s.getPlayerNumber(t -> {
@Override lblPlayers.setText("在线人数" + t.key);
public void onDone(Pair<String, String[]> t) { lstPlayersModel.clear();
lblPlayers.setText("在线人数" + t.key); for (String s1 : t.value) lstPlayersModel.addElement(s1);
lstPlayersModel.clear(); lstPlayers.setModel(lstPlayersModel);
for (String s : t.value) {
lstPlayersModel.addElement(s);
}
lstPlayers.setModel(lstPlayersModel);
}
}); });
} else { else
MessageBox.Show("服务器未开启!"); MessageBox.Show("服务器未开启!");
}
} }
class ServerBeginListener implements DoneListener0 { class ServerBeginListener implements Event<Void> {
@Override @Override
public void onDone() { public boolean call(Object sender, Void v) {
commandSet = new ArrayList<String>(); 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 DoneListener0 { class ServerDoneListener implements Event<Void> {
@Override @Override
public void onDone() { public boolean call(Object sender, Void v) {
getPlayerNumberTimer = new Timer(); getPlayerNumberTimer = new Timer();
getPlayerNumberTimer.schedule(new TimerTask() { getPlayerNumberTimer.schedule(new TimerTask() {
@@ -3363,6 +3288,7 @@ public final class MainWindow extends javax.swing.JFrame
loadPlayers(); loadPlayers();
} }
}, 1000 * 60 * 10, 1000 * 60 * 10); }, 1000 * 60 * 10, 1000 * 60 * 10);
return true;
} }
} }
@@ -3372,40 +3298,35 @@ public final class MainWindow extends javax.swing.JFrame
if (!eula.exists()) { if (!eula.exists()) {
int option = JOptionPane.showConfirmDialog(null, "您是否确认新的EULA(https://account.mojang.com/documents/minecraft_eula)如果拒绝会导致无法启动Minecraft 1.7.10或更高版本的服务端。"); int option = JOptionPane.showConfirmDialog(null, "您是否确认新的EULA(https://account.mojang.com/documents/minecraft_eula)如果拒绝会导致无法启动Minecraft 1.7.10或更高版本的服务端。");
try { try {
if (option == JOptionPane.YES_OPTION) { if (option == JOptionPane.YES_OPTION)
FileUtils.write(eula, "eula=true"); FileUtils.write(eula, "eula=true");
} else if (option == JOptionPane.NO_OPTION) { else if (option == JOptionPane.NO_OPTION)
FileUtils.write(eula, "eula=false"); FileUtils.write(eula, "eula=false");
}
} catch (IOException e) { } catch (IOException e) {
MessageBox.Show("确认rula失败"); MessageBox.Show("确认rula失败");
} }
} }
File serverproperties = new File(new File(SettingsManager.settings.mainjar).getParentFile(), "server.properties"); File serverproperties = new File(new File(SettingsManager.settings.mainjar).getParentFile(), "server.properties");
if (!serverproperties.exists()) { if (!serverproperties.exists())
try { try {
FileUtils.write(serverproperties, ServerProperties.getDefault()); FileUtils.write(serverproperties, ServerProperties.getDefault());
} catch (IOException ex) { } catch (IOException ex) {
HMCLog.warn("Failed to save server.properties", ex); HMCLog.warn("Failed to save server.properties", ex);
} }
}
Server.init(SettingsManager.settings.mainjar, String.valueOf(SettingsManager.settings.maxMemory)); Server.init(SettingsManager.settings.mainjar, String.valueOf(SettingsManager.settings.maxMemory));
Server.getInstance() Server.getInstance()
.addListener((MonitorThread.MonitorThreadListener) this); .addListener((MonitorThread.MonitorThreadListener) this);
Server.getInstance() Server.getInstance()
.addListener((DoneListener1<Integer>) this); .addListener((Event<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() Server.getInstance().startedEvent.register(new ServerBeginListener());
.addServerStartedListener(new ServerBeginListener()); Server.getInstance().startedEvent.register(new ServerDoneListener());
Server.getInstance()
.addServerDoneListener(new ServerDoneListener());
try { try {
Server.getInstance().run(); Server.getInstance().run();
} catch (IOException ex) { } catch (IOException ex) {
@@ -3434,18 +3355,15 @@ public final class MainWindow extends javax.swing.JFrame
} else if (evt.getKeyCode() == KeyEvent.VK_DOWN) { } else if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
newCommandIndex++; newCommandIndex++;
type = 1; type = 1;
} else if (evt.getKeyCode() == KeyEvent.VK_ENTER) { } else if (evt.getKeyCode() == KeyEvent.VK_ENTER)
type = 2; type = 2;
}
if (type == 1) { if (type == 1) {
if (outOfCommandSet(newCommandIndex)) { if (outOfCommandSet(newCommandIndex))
return; return;
}
commandIndex = newCommandIndex; commandIndex = newCommandIndex;
txtCommand.setText(commandSet.get(commandIndex)); txtCommand.setText(commandSet.get(commandIndex));
} else if (type == 2) { } else if (type == 2)
sendCommand(); sendCommand();
}
}//GEN-LAST:event_txtCommandKeyPressed }//GEN-LAST:event_txtCommandKeyPressed
private void btnSendCommandActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSendCommandActionPerformed private void btnSendCommandActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSendCommandActionPerformed
@@ -3530,13 +3448,12 @@ public final class MainWindow extends javax.swing.JFrame
private void cboWorldTypeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboWorldTypeItemStateChanged private void cboWorldTypeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboWorldTypeItemStateChanged
int OAO = cboWorldType.getSelectedIndex(); int OAO = cboWorldType.getSelectedIndex();
String type = "DEFAULT"; String type = "DEFAULT";
if (OAO == 0) { if (OAO == 0)
type = "DEFAULT"; type = "DEFAULT";
} else if (OAO == 1) { else if (OAO == 1)
type = "FLAT"; type = "FLAT";
} else if (OAO == 2) { else if (OAO == 2)
type = "LARGEBIMOES"; type = "LARGEBIMOES";
}
ServerProperties.getInstance().setLevelType(type); ServerProperties.getInstance().setLevelType(type);
}//GEN-LAST:event_cboWorldTypeItemStateChanged }//GEN-LAST:event_cboWorldTypeItemStateChanged
@@ -3560,9 +3477,9 @@ public final class MainWindow extends javax.swing.JFrame
lstOPModel.addElement(txtOPName.getText()); lstOPModel.addElement(txtOPName.getText());
lstOP.updateUI(); lstOP.updateUI();
if (Server.isInstanceRunning()) { if (Server.isInstanceRunning())
Server.getInstance().sendCommand("op " + txtOPName.getText()); Server.getInstance().sendCommand("op " + txtOPName.getText());
} else { else {
Op.Operator operator = new Op.Operator(txtOPName.getText()); Op.Operator operator = new Op.Operator(txtOPName.getText());
op.op.add(operator); op.op.add(operator);
File dir = new File(SettingsManager.settings.mainjar).getParentFile(); File dir = new File(SettingsManager.settings.mainjar).getParentFile();
@@ -3580,9 +3497,9 @@ public final class MainWindow extends javax.swing.JFrame
lstOPModel.removeElement(lstOP.getSelectedIndex()); lstOPModel.removeElement(lstOP.getSelectedIndex());
lstOP.updateUI(); lstOP.updateUI();
if (Server.isInstanceRunning()) { if (Server.isInstanceRunning())
Server.getInstance().sendCommand("deop " + txtOPName.getText()); Server.getInstance().sendCommand("deop " + txtOPName.getText());
} else { else {
Op.Operator operator = new Op.Operator(s); Op.Operator operator = new Op.Operator(s);
op.op.remove(operator); op.op.remove(operator);
File dir = new File(SettingsManager.settings.mainjar).getParentFile(); File dir = new File(SettingsManager.settings.mainjar).getParentFile();
@@ -3599,9 +3516,9 @@ public final class MainWindow extends javax.swing.JFrame
lstWhiteListModel.addElement(txtWhiteName.getText()); lstWhiteListModel.addElement(txtWhiteName.getText());
lstWhiteList.updateUI(); lstWhiteList.updateUI();
if (Server.isInstanceRunning()) { if (Server.isInstanceRunning())
Server.getInstance().sendCommand("whitelist add " + txtWhiteName.getText()); Server.getInstance().sendCommand("whitelist add " + txtWhiteName.getText());
} else { else {
WhiteList.WhiteListPlayer player = new WhiteList.WhiteListPlayer(txtWhiteName.getText()); WhiteList.WhiteListPlayer player = new WhiteList.WhiteListPlayer(txtWhiteName.getText());
whitelist.op.add(player); whitelist.op.add(player);
File dir = new File(SettingsManager.settings.mainjar).getParentFile(); File dir = new File(SettingsManager.settings.mainjar).getParentFile();
@@ -3619,9 +3536,9 @@ public final class MainWindow extends javax.swing.JFrame
lstWhiteListModel.removeElement(lstWhiteList.getSelectedIndex()); lstWhiteListModel.removeElement(lstWhiteList.getSelectedIndex());
lstWhiteList.updateUI(); lstWhiteList.updateUI();
if (Server.isInstanceRunning()) { if (Server.isInstanceRunning())
Server.getInstance().sendCommand("whitelist remove " + txtWhiteName.getText()); Server.getInstance().sendCommand("whitelist remove " + txtWhiteName.getText());
} else { else {
WhiteList.WhiteListPlayer player = new WhiteList.WhiteListPlayer(name); WhiteList.WhiteListPlayer player = new WhiteList.WhiteListPlayer(name);
whitelist.op.remove(player); whitelist.op.remove(player);
File dir = new File(SettingsManager.settings.mainjar).getParentFile(); File dir = new File(SettingsManager.settings.mainjar).getParentFile();
@@ -3773,22 +3690,20 @@ public final class MainWindow extends javax.swing.JFrame
Vector strings = ((DefaultTableModel) lstExternalMods.getModel()).getDataVector(); Vector strings = ((DefaultTableModel) lstExternalMods.getModel()).getDataVector();
for (Object s : strings) { for (Object s : strings) {
Vector v = (Vector) s; Vector v = (Vector) s;
if (!(Boolean) v.elementAt(0)) { if (!(Boolean) v.elementAt(0))
arrayList.add((String) v.elementAt(1)); arrayList.add((String) v.elementAt(1));
}
} }
SettingsManager.settings.inactiveExtMods = arrayList; SettingsManager.settings.inactiveExtMods = arrayList;
SettingsManager.save(); SettingsManager.save();
}//GEN-LAST:event_btnSaveExtModActionPerformed }//GEN-LAST:event_btnSaveExtModActionPerformed
private void btnSavePluginsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSavePluginsActionPerformed private void btnSavePluginsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSavePluginsActionPerformed
ArrayList<String> arrayList = new ArrayList<String>(); ArrayList<String> arrayList = new ArrayList<>();
Vector strings = ((DefaultTableModel) lstCoreMods.getModel()).getDataVector(); Vector strings = ((DefaultTableModel) lstCoreMods.getModel()).getDataVector();
for (Object s : strings) { for (Object s : strings) {
Vector v = (Vector) s; Vector v = (Vector) s;
if (!(Boolean) v.elementAt(0)) { if (!(Boolean) v.elementAt(0))
arrayList.add((String) v.elementAt(1)); arrayList.add((String) v.elementAt(1));
}
} }
SettingsManager.settings.inactiveCoreMods = arrayList; SettingsManager.settings.inactiveCoreMods = arrayList;
SettingsManager.save(); SettingsManager.save();
@@ -3798,9 +3713,9 @@ public final class MainWindow extends javax.swing.JFrame
lstBannedModel.addElement(txtBanName.getText()); lstBannedModel.addElement(txtBanName.getText());
lstBanned.updateUI(); lstBanned.updateUI();
if (Server.isInstanceRunning()) { if (Server.isInstanceRunning())
Server.getInstance().sendCommand("ban " + txtBanName.getText()); Server.getInstance().sendCommand("ban " + txtBanName.getText());
} else { else {
BannedPlayers.BannedPlayer player = new BannedPlayers.BannedPlayer(txtBanName.getText()); BannedPlayers.BannedPlayer player = new BannedPlayers.BannedPlayer(txtBanName.getText());
banned.op.add(player); banned.op.add(player);
File dir = new File(SettingsManager.settings.mainjar).getParentFile(); File dir = new File(SettingsManager.settings.mainjar).getParentFile();
@@ -3818,9 +3733,9 @@ public final class MainWindow extends javax.swing.JFrame
lstBannedModel.removeElement(lstBanned.getSelectedIndex()); lstBannedModel.removeElement(lstBanned.getSelectedIndex());
lstBanned.updateUI(); lstBanned.updateUI();
if (Server.isInstanceRunning()) { if (Server.isInstanceRunning())
Server.getInstance().sendCommand("pardon " + txtBanName.getText()); Server.getInstance().sendCommand("pardon " + txtBanName.getText());
} else { else {
BannedPlayers.BannedPlayer player = new BannedPlayers.BannedPlayer(s); BannedPlayers.BannedPlayer player = new BannedPlayers.BannedPlayer(s);
banned.op.remove(player); banned.op.remove(player);
File dir = new File(SettingsManager.settings.mainjar).getParentFile(); File dir = new File(SettingsManager.settings.mainjar).getParentFile();
@@ -3905,12 +3820,10 @@ public final class MainWindow extends javax.swing.JFrame
private void btnSaveWorldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveWorldActionPerformed private void btnSaveWorldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveWorldActionPerformed
DefaultTableModel model = (DefaultTableModel) lstWorlds.getModel(); DefaultTableModel model = (DefaultTableModel) lstWorlds.getModel();
SettingsManager.settings.inactiveWorlds = new ArrayList<String>(); SettingsManager.settings.inactiveWorlds = new ArrayList<>();
for (int i = 0; i < model.getRowCount(); i++) { for (int i = 0; i < model.getRowCount(); i++)
if ((Boolean) model.getValueAt(i, 2) == false) { if ((Boolean) model.getValueAt(i, 2) == false)
SettingsManager.settings.inactiveWorlds.add((String) model.getValueAt(i, 0)); SettingsManager.settings.inactiveWorlds.add((String) model.getValueAt(i, 0));
}
}
SettingsManager.save(); SettingsManager.save();
}//GEN-LAST:event_btnSaveWorldActionPerformed }//GEN-LAST:event_btnSaveWorldActionPerformed
@@ -3931,9 +3844,8 @@ public final class MainWindow extends javax.swing.JFrame
private void btnDeleteBackupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteBackupActionPerformed private void btnDeleteBackupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteBackupActionPerformed
int index = lstBackups.getSelectedRow(); int index = lstBackups.getSelectedRow();
if (index == -1) { if (index == -1)
return; return;
}
DefaultTableModel model = (DefaultTableModel) lstBackups.getModel(); DefaultTableModel model = (DefaultTableModel) lstBackups.getModel();
Utilities.deleteAll(new File(BackupManager.backupDir() Utilities.deleteAll(new File(BackupManager.backupDir()
+ model.getValueAt(index, 0) + "+" + model.getValueAt(index, 0) + "+"
@@ -3944,9 +3856,8 @@ public final class MainWindow extends javax.swing.JFrame
private void btnRestoreBackupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRestoreBackupActionPerformed private void btnRestoreBackupActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRestoreBackupActionPerformed
int index = lstBackups.getSelectedRow(); int index = lstBackups.getSelectedRow();
if (index == -1) { if (index == -1)
return; return;
}
DefaultTableModel model = (DefaultTableModel) lstBackups.getModel(); DefaultTableModel model = (DefaultTableModel) lstBackups.getModel();
BackupManager.restoreBackup(BackupManager.backupDir() BackupManager.restoreBackup(BackupManager.backupDir()
+ model.getValueAt(index, 0) + "+" + model.getValueAt(index, 0) + "+"
@@ -3977,9 +3888,8 @@ public final class MainWindow extends javax.swing.JFrame
try { try {
DefaultTableModel model = (DefaultTableModel) lstInfos.getModel(); DefaultTableModel model = (DefaultTableModel) lstInfos.getModel();
int index = lstInfos.getSelectedRow(); int index = lstInfos.getSelectedRow();
if (index == -1) { if (index == -1)
return; return;
}
String path = Utilities.getGameDir() + "infos-HMCSM" + File.separator + model.getValueAt(index, 0); String path = Utilities.getGameDir() + "infos-HMCSM" + File.separator + model.getValueAt(index, 0);
String content = FileUtils.readFileToString(new File(path)); String content = FileUtils.readFileToString(new File(path));
txtInfo.setText(content); txtInfo.setText(content);
@@ -3990,14 +3900,13 @@ public final class MainWindow extends javax.swing.JFrame
private void btnAutoSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAutoSearchActionPerformed private void btnAutoSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAutoSearchActionPerformed
ArrayList<String> al = Utilities.findAllFile(IOUtils.currentDir()); ArrayList<String> al = Utilities.findAllFile(IOUtils.currentDir());
for (String s : al) { for (String s : al)
if (ServerChecker.isServerJar(new File(s))) { if (ServerChecker.isServerJar(new File(s))) {
String path = IOUtils.tryGetCanonicalFilePath(new File(IOUtils.currentDir(), s)); String path = IOUtils.tryGetCanonicalFilePath(new File(IOUtils.currentDir(), s));
txtMainJar.setText(path); txtMainJar.setText(path);
SettingsManager.settings.mainjar = path; SettingsManager.settings.mainjar = path;
SettingsManager.save(); SettingsManager.save();
} }
}
}//GEN-LAST:event_btnAutoSearchActionPerformed }//GEN-LAST:event_btnAutoSearchActionPerformed
private void cboCategoryItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboCategoryItemStateChanged private void cboCategoryItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboCategoryItemStateChanged
@@ -4007,9 +3916,8 @@ public final class MainWindow extends javax.swing.JFrame
private void btnShowPluginInfoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowPluginInfoActionPerformed private void btnShowPluginInfoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowPluginInfoActionPerformed
try { try {
int index = lstBukkitPlugins.getSelectedRow(); int index = lstBukkitPlugins.getSelectedRow();
if (index == -1) { if (index == -1)
return; return;
}
PluginInfo pi = PluginManager.getPluginInfo(plugins.get(index).slug); PluginInfo pi = PluginManager.getPluginInfo(plugins.get(index).slug);
PluginInfoDialog w = new PluginInfoDialog(this, true, pi); PluginInfoDialog w = new PluginInfoDialog(this, true, pi);
w.setVisible(true); w.setVisible(true);
@@ -4025,9 +3933,8 @@ public final class MainWindow extends javax.swing.JFrame
private void btnShowReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowReportActionPerformed private void btnShowReportActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnShowReportActionPerformed
try { try {
int index = lstReports.getSelectedIndex(); int index = lstReports.getSelectedIndex();
if (index == -1) { if (index == -1)
return; return;
}
String path = Utilities.getGameDir() + "crash-reports" + File.separator + lstCrashReportsModel.get(index); String path = Utilities.getGameDir() + "crash-reports" + File.separator + lstCrashReportsModel.get(index);
String content = FileUtils.readFileToString(new File(path)); String content = FileUtils.readFileToString(new File(path));
txtCrashReport.setText(content); txtCrashReport.setText(content);
@@ -4083,15 +3990,13 @@ public final class MainWindow extends javax.swing.JFrame
private void btnDownloadCraftbukkitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadCraftbukkitActionPerformed private void btnDownloadCraftbukkitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadCraftbukkitActionPerformed
int idx = lstCraftbukkit.getSelectedRow(); int idx = lstCraftbukkit.getSelectedRow();
if (idx == -1) { if (idx == -1)
return; return;
}
String ext = ""; String ext = "";
List<BukkitVersion> cb = null; List<BukkitVersion> cb = null;
int idx2 = cboBukkitType.getSelectedIndex(); int idx2 = cboBukkitType.getSelectedIndex();
if (idx2 == -1) { if (idx2 == -1)
return; return;
}
switch (idx2) { switch (idx2) {
case 0: case 0:
ext = "rb"; ext = "rb";
@@ -4101,6 +4006,8 @@ public final class MainWindow extends javax.swing.JFrame
ext = "beta"; ext = "beta";
cb = craftBukkitBeta; cb = craftBukkitBeta;
break; break;
default:
return;
} }
BukkitVersion v = cb.get(idx); BukkitVersion v = cb.get(idx);
File file = new File(IOUtils.currentDir(), "craftbukkit-" + ext + "-" + v.version + ".jar"); File file = new File(IOUtils.currentDir(), "craftbukkit-" + ext + "-" + v.version + ".jar");
@@ -4110,18 +4017,16 @@ public final class MainWindow extends javax.swing.JFrame
private void btnDownloadMCPCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadMCPCActionPerformed private void btnDownloadMCPCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDownloadMCPCActionPerformed
int idx = lstMCPC.getSelectedRow(); int idx = lstMCPC.getSelectedRow();
if (idx == -1) { if (idx == -1)
return; return;
}
ForgeVersion v = mcpcPackages.get(cboCauldronMinecraft.getSelectedItem().toString()).get(idx); ForgeVersion v = mcpcPackages.get(cboCauldronMinecraft.getSelectedItem().toString()).get(idx);
String url; String url;
File filepath = new File(IOUtils.currentDir(), "forge-installer.jar"); File filepath = new File(IOUtils.currentDir(), "forge-installer.jar");
url = v.installer[1]; url = v.installer[1];
if (!TaskWindow.getInstance().addTask(new FileDownloadTask(url, filepath).setTag("cauldron-" + v.ver)).start()) { if (!TaskWindow.getInstance().addTask(new FileDownloadTask(url, filepath).setTag("cauldron-" + v.ver)).start())
MessageBox.Show(C.I18N.getString("install.failed_download_forge")); MessageBox.Show(C.I18N.getString("install.failed_download_forge"));
} else { else
installMCPC(filepath); installMCPC(filepath);
}
}//GEN-LAST:event_btnDownloadMCPCActionPerformed }//GEN-LAST:event_btnDownloadMCPCActionPerformed
private void installMCPC(final File filepath) { private void installMCPC(final File filepath) {
@@ -4144,18 +4049,16 @@ public final class MainWindow extends javax.swing.JFrame
Vector strings = ((DefaultTableModel) lstPlugins.getModel()).getDataVector(); Vector strings = ((DefaultTableModel) lstPlugins.getModel()).getDataVector();
for (Object s : strings) { for (Object s : strings) {
Vector v = (Vector) s; Vector v = (Vector) s;
if (!(Boolean) v.elementAt(0)) { if (!(Boolean) v.elementAt(0))
arrayList.add((String) v.elementAt(1)); arrayList.add((String) v.elementAt(1));
}
} }
SettingsManager.settings.inactivePlugins = arrayList; SettingsManager.settings.inactivePlugins = arrayList;
SettingsManager.save(); SettingsManager.save();
}//GEN-LAST:event_btnSaveCoreModActionPerformed }//GEN-LAST:event_btnSaveCoreModActionPerformed
private void cboCauldronMinecraftItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboCauldronMinecraftItemStateChanged private void cboCauldronMinecraftItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboCauldronMinecraftItemStateChanged
if (cboCauldronMinecraft.getItemCount() > 0 && mcpcPackages != null && mcpcPackages.containsKey(cboCauldronMinecraft.getSelectedItem().toString())) { if (cboCauldronMinecraft.getItemCount() > 0 && mcpcPackages != null && mcpcPackages.containsKey(cboCauldronMinecraft.getSelectedItem().toString()))
useMCPCVersions(cboCauldronMinecraft.getSelectedItem().toString()); useMCPCVersions(cboCauldronMinecraft.getSelectedItem().toString());
}
}//GEN-LAST:event_cboCauldronMinecraftItemStateChanged }//GEN-LAST:event_cboCauldronMinecraftItemStateChanged
private void btnInstallMCPCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInstallMCPCActionPerformed private void btnInstallMCPCActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnInstallMCPCActionPerformed
@@ -4177,9 +4080,8 @@ public final class MainWindow extends javax.swing.JFrame
}//GEN-LAST:event_jButton11ActionPerformed }//GEN-LAST:event_jButton11ActionPerformed
private void btnCommandMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCommandMouseClicked private void btnCommandMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCommandMouseClicked
if (Server.getInstance() == null || !Server.getInstance().isRunning || !btnCommand.isEnabled()) { if (Server.getInstance() == null || !Server.getInstance().isRunning || !btnCommand.isEnabled())
return; return;
}
ppmBasically.show(evt.getComponent(), evt.getPoint().x, evt.getPoint().y); ppmBasically.show(evt.getComponent(), evt.getPoint().x, evt.getPoint().y);
}//GEN-LAST:event_btnCommandMouseClicked }//GEN-LAST:event_btnCommandMouseClicked
@@ -4192,9 +4094,8 @@ public final class MainWindow extends javax.swing.JFrame
}//GEN-LAST:event_formWindowClosed }//GEN-LAST:event_formWindowClosed
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
if (Server.getInstance() != null && Server.getInstance().isRunning) { if (Server.getInstance() != null && Server.getInstance().isRunning)
Server.getInstance().stop(); Server.getInstance().stop();
}
}//GEN-LAST:event_formWindowClosing }//GEN-LAST:event_formWindowClosing
private void txtMaxMemoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMaxMemoryFocusLost private void txtMaxMemoryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_txtMaxMemoryFocusLost
@@ -4212,7 +4113,7 @@ public final class MainWindow extends javax.swing.JFrame
} }
@Override @Override
public void onDone(Integer t) { public boolean call(Object sender, Integer t) {
btnLaunch.setEnabled(true); btnLaunch.setEnabled(true);
btnStop.setEnabled(false); btnStop.setEnabled(false);
btnShutdown.setEnabled(false); btnShutdown.setEnabled(false);
@@ -4229,30 +4130,28 @@ public final class MainWindow extends javax.swing.JFrame
getPlayerNumberTimer.cancel(); getPlayerNumberTimer.cancel();
getPlayerNumberTimer = null; getPlayerNumberTimer = null;
} }
return true;
} }
private void sendCommand() { private void sendCommand() {
String command = txtCommand.getText(); String command = txtCommand.getText();
boolean append = false; boolean append = false;
if (outOfCommandSet()) { if (outOfCommandSet())
append = true; append = true;
} else if (!command.equals(commandSet.get(commandIndex))) { else if (!command.equals(commandSet.get(commandIndex)))
append = true; append = true;
} if (Server.getInstance() != null)
if (Server.getInstance() != null) {
Server.getInstance().sendCommand(command); Server.getInstance().sendCommand(command);
} else { else
System.err.println("Server is null."); System.err.println("Server is null.");
}
System.out.println("Send command: " + command); System.out.println("Send command: " + command);
onStatus(">" + command); onStatus(">" + command);
txtCommand.setText(""); txtCommand.setText("");
if (append) { if (append) {
commandSet.add(command); commandSet.add(command);
commandIndex = commandSet.size(); commandIndex = commandSet.size();
} else { } else
commandIndex++; commandIndex++;
}
} }
MonitorThread mainThread; MonitorThread mainThread;