mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-03-31 18:10:26 +08:00
test for new launcher for java && forgot to add license...
This commit is contained in:
parent
c321cb5f91
commit
abb17dd05d
BIN
HMCL/HMCLauncher.exe
Normal file
BIN
HMCL/HMCLauncher.exe
Normal file
Binary file not shown.
@ -88,29 +88,30 @@ task proguard(type: proguard.gradle.ProGuardTask, dependsOn: jar) {
|
||||
|
||||
configuration 'proguard.pro'
|
||||
}
|
||||
/*
|
||||
task makeExecutable(dependsOn: jar) {
|
||||
|
||||
task makeExecutable(dependsOn: jar) << {
|
||||
ext {
|
||||
def re = jar.classifier
|
||||
injar = jar.archivePath
|
||||
jar.classifier = ''
|
||||
outjar = jar.archivePath
|
||||
jar.classifier = re
|
||||
makeExecutableinjar = jar.archivePath
|
||||
jar.classifier = ''
|
||||
makeExecutableoutjar = jar.archivePath
|
||||
jar.classifier = ''
|
||||
}
|
||||
def fos = new FileOutputStream(outjar)
|
||||
def is = new FileInputStream('')
|
||||
def read
|
||||
def loc = new File(project.buildDir, "libs/" + makeExecutableoutjar.getName().substring(0, makeExecutableoutjar.getName().length()-4)+".exe")
|
||||
def fos = new FileOutputStream(loc)
|
||||
def is = new FileInputStream(new File(project.buildDir, '../HMCLauncher.exe'))
|
||||
int read
|
||||
def bytes = new byte[8192]
|
||||
while((read = is.read(bytes)) != -1)
|
||||
fos.write(bytes, 0, read);
|
||||
is.close()
|
||||
is = new FileInputStream(injar)
|
||||
is = new FileInputStream(makeExecutableinjar)
|
||||
while((read = is.read(bytes)) != -1)
|
||||
fos.write(bytes, 0, read);
|
||||
is.close()
|
||||
fos.close()
|
||||
}*/
|
||||
|
||||
}
|
||||
/*
|
||||
launch4j {
|
||||
launch4jCmd = 'D:\\Develop\\Java\\Launch4j\\launch4j.exe'
|
||||
supportUrl = 'http://www.mcbbs.net/thread-142335-1-1.html'
|
||||
@ -125,7 +126,7 @@ launch4j {
|
||||
jar = new File(project.buildDir, 'libs/' + mavenGroupId + '-' + mavenVersion + '.jar').absolutePath
|
||||
outfile = mavenGroupId + '-' + mavenVersion + '.exe'
|
||||
messagesJreVersionError = 'This application requires a Java Runtime Environment installation, or the runtime is corrupted.\n\u6ca1\u6709\u627e\u5230\u004a\u0061\u0076\u0061\u8fd0\u884c\u65f6\uff0c\u8bf7\u4e0d\u8981\u4f7f\u7528\u7eff\u8272\u004a\u0061\u0076\u0061\uff0c\u8bf7\u4f7f\u7528\u5b89\u88c5\u7248\u7684\u004a\u0061\u0076\u0061\uff0c\u70b9\u51fb\u786e\u5b9a\u8fdb\u5165\u004a\u0061\u0076\u0061\u5b89\u88c5\u9875\u9762\u3002'
|
||||
}
|
||||
}*/
|
||||
|
||||
processResources {
|
||||
from(sourceSets.main.resources.srcDirs) {
|
||||
@ -133,5 +134,5 @@ processResources {
|
||||
}
|
||||
}
|
||||
|
||||
build.dependsOn proguard
|
||||
//build.dependsOn makeExecutable
|
||||
makeExecutable.dependsOn proguard
|
||||
build.dependsOn makeExecutable
|
@ -101,8 +101,8 @@ ui.more=\u66f4\u591a
|
||||
|
||||
crash.advice.UnsupportedClassVersionError=\u8fd9\u53ef\u80fd\u662f\u56e0\u4e3a\u60a8\u7684Java\u7248\u672c\u8fc7\u4e8e\u8001\u65e7\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u66f4\u6362\u6700\u65b0Java\u5e76\u5728\u7248\u672c\u8bbe\u7f6e\u7684Java\u8def\u5f84\u4e2d\u8bbe\u7f6e.
|
||||
crash.advice.ConcurrentModificationException=\u8fd9\u53ef\u80fd\u662f\u56e0\u4e3a\u60a8\u7684Java\u7248\u672c\u9ad8\u4e8eJava 1.8.0_11\u5bfc\u81f4\u7684,\u53ef\u4ee5\u5c1d\u8bd5\u5378\u8f7dJava8\u5b89\u88c5Java7\u3002
|
||||
crash.advice.ClassNotFoundException=Minecraft\u4e0d\u5b8c\u6574\u6216Mod\u51b2\u7a81\uff0c\u5982\u679c\u6709\u672a\u80fd\u4e0b\u8f7d\u7684\u6587\u4ef6\u8bf7\u4e0b\u8f7d\u6210\u529f\u540e\u91cd\u8bd5\u6216\u4e0b\u8f7d\u6574\u5408\u5305\u89e3\u51b3\u95ee\u9898\u3002
|
||||
crash.advice.NoSuchFieldError=Minecraft\u4e0d\u5b8c\u6574\u6216Mod\u51b2\u7a81\uff0c\u5982\u679c\u6709\u672a\u80fd\u4e0b\u8f7d\u7684\u6587\u4ef6\u8bf7\u4e0b\u8f7d\u6210\u529f\u540e\u91cd\u8bd5\u6216\u4e0b\u8f7d\u6574\u5408\u5305\u89e3\u51b3\u95ee\u9898\u3002
|
||||
crash.advice.ClassNotFoundException=Minecraft\u4e0d\u5b8c\u6574\u6216Mod\u51b2\u7a81\uff0c\u5982\u679c\u6709\u672a\u80fd\u4e0b\u8f7d\u7684\u6587\u4ef6\u8bf7\u4e0b\u8f7d\u6210\u529f\u540e\u91cd\u8bd5\u6216\u662f\u5ba2\u6237\u7aef\u635f\u574f\u8bf7\u91cd\u8bd5\u8bf7\u91cd\u65b0\u5236\u4f5c\u5ba2\u6237\u7aef\u6216\u4e0b\u8f7d\u6574\u5408\u5305\u89e3\u51b3\u95ee\u9898\u3002
|
||||
crash.advice.NoSuchFieldError=Minecraft\u4e0d\u5b8c\u6574\u6216Mod\u51b2\u7a81\uff0c\u5982\u679c\u6709\u672a\u80fd\u4e0b\u8f7d\u7684\u6587\u4ef6\u8bf7\u4e0b\u8f7d\u6210\u529f\u540e\u91cd\u8bd5\u6216\u662f\u5ba2\u6237\u7aef\u635f\u574f\u8bf7\u91cd\u8bd5\u8bf7\u91cd\u65b0\u5236\u4f5c\u5ba2\u6237\u7aef\u6216\u4e0b\u8f7d\u6574\u5408\u5305\u89e3\u51b3\u95ee\u9898\u3002
|
||||
crash.advice.LWJGLException=\u60a8\u7684\u7535\u8111\u4e0d\u6b63\u5e38\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u9a71\u52a8\u7cbe\u7075\u6216\u5176\u4ed6\u5b89\u88c5\u5668\u66f4\u65b0\u663e\u5361\u9a71\u52a8\u3002
|
||||
crash.advice.SecurityException=\u53ef\u80fd\u662f\u60a8\u4fee\u6539\u4e86minecraft.jar\u4f46\u672a\u5220\u9664META-INF\u6587\u4ef6\u5939\u7684\u539f\u56e0\u3002\u8bf7\u901a\u8fc7\u538b\u7f29\u8f6f\u4ef6\u5220\u9664jar\u4e2d\u7684META-INF\u6587\u4ef6\u5939\u3002
|
||||
crash.advice.OutOfMemoryError=\u5185\u5b58\u6ea2\u51fa\uff0c\u60a8\u8bbe\u7f6e\u7684Minecraft\u6700\u5927\u5185\u5b58\u8fc7\u5c0f\uff0c\u8bf7\u8c03\u5927\uff01
|
||||
|
@ -96,8 +96,8 @@ ui.more=\u66f4\u591a
|
||||
|
||||
crash.advice.UnsupportedClassVersionError=\u8fd9\u53ef\u80fd\u662f\u56e0\u4e3a\u60a8\u7684Java\u7248\u672c\u8fc7\u4e8e\u8001\u65e7\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u66f4\u6362\u6700\u65b0Java\u5e76\u5728\u7248\u672c\u8bbe\u7f6e\u7684Java\u8def\u5f84\u4e2d\u8bbe\u7f6e.
|
||||
crash.advice.ConcurrentModificationException=\u8fd9\u53ef\u80fd\u662f\u56e0\u4e3a\u60a8\u7684Java\u7248\u672c\u9ad8\u4e8eJava 1.8.0_11\u5bfc\u81f4\u7684,\u53ef\u4ee5\u5c1d\u8bd5\u5378\u8f7dJava8\u5b89\u88c5Java7\u3002
|
||||
crash.advice.ClassNotFoundException=Minecraft\u4e0d\u5b8c\u6574\u6216Mod\u51b2\u7a81\uff0c\u5982\u679c\u6709\u672a\u80fd\u4e0b\u8f7d\u7684\u6587\u4ef6\u8bf7\u4e0b\u8f7d\u6210\u529f\u540e\u91cd\u8bd5\u4e0b\u8f7d\u6574\u5408\u5305\u89e3\u51b3\u95ee\u9898\u3002
|
||||
crash.advice.NoSuchFieldError=Minecraft\u4e0d\u5b8c\u6574\u6216Mod\u51b2\u7a81\uff0c\u5982\u679c\u6709\u672a\u80fd\u4e0b\u8f7d\u7684\u6587\u4ef6\u8bf7\u4e0b\u8f7d\u6210\u529f\u540e\u91cd\u8bd5\u6216\u4e0b\u8f7d\u6574\u5408\u5305\u89e3\u51b3\u95ee\u9898\u3002
|
||||
crash.advice.ClassNotFoundException=Minecraft\u4e0d\u5b8c\u6574\u6216Mod\u51b2\u7a81\uff0c\u5982\u679c\u6709\u672a\u80fd\u4e0b\u8f7d\u7684\u6587\u4ef6\u8bf7\u4e0b\u8f7d\u6210\u529f\u540e\u91cd\u8bd5\u6216\u662f\u5ba2\u6237\u7aef\u635f\u574f\u8bf7\u91cd\u65b0\u5236\u4f5c\u5ba2\u6237\u7aef\u6216\u4e0b\u8f7d\u6574\u5408\u5305\u89e3\u51b3\u95ee\u9898\u3002
|
||||
crash.advice.NoSuchFieldError=Minecraft\u4e0d\u5b8c\u6574\u6216Mod\u51b2\u7a81\uff0c\u5982\u679c\u6709\u672a\u80fd\u4e0b\u8f7d\u7684\u6587\u4ef6\u8bf7\u4e0b\u8f7d\u6210\u529f\u540e\u91cd\u8bd5\u6216\u662f\u5ba2\u6237\u7aef\u635f\u574f\u8bf7\u91cd\u8bd5\u8bf7\u91cd\u65b0\u5236\u4f5c\u5ba2\u6237\u7aef\u6216\u4e0b\u8f7d\u6574\u5408\u5305\u89e3\u51b3\u95ee\u9898\u3002
|
||||
crash.advice.LWJGLException=\u60a8\u7684\u7535\u8111\u4e0d\u6b63\u5e38\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u9a71\u52a8\u7cbe\u7075\u6216\u5176\u4ed6\u5b89\u88c5\u5668\u66f4\u65b0\u663e\u5361\u9a71\u52a8\u3002
|
||||
crash.advice.SecurityException=\u53ef\u80fd\u662f\u60a8\u4fee\u6539\u4e86minecraft.jar\u4f46\u672a\u5220\u9664META-INF\u6587\u4ef6\u5939\u7684\u539f\u56e0\u3002\u8bf7\u901a\u8fc7\u538b\u7f29\u8f6f\u4ef6\u5220\u9664jar\u4e2d\u7684META-INF\u6587\u4ef6\u5939\u3002
|
||||
crash.advice.OutOfMemoryError=\u5185\u5b58\u6ea2\u51fa\uff0c\u60a8\u8bbe\u7f6e\u7684Minecraft\u6700\u5927\u5185\u5b58\u8fc7\u5c0f\uff0c\u8bf7\u8c03\u5927\uff01
|
||||
|
@ -96,8 +96,8 @@ ui.more=\u66f4\u591a
|
||||
|
||||
crash.advice.UnsupportedClassVersionError=\u9019\u53ef\u80fd\u662f\u56e0\u70ba\u60a8\u7684Java\u7248\u672c\u904e\u65bc\u8001\u820a\uff0c\u53ef\u4ee5\u5617\u8a66\u66f4\u63db\u6700\u65b0Java\u4e26\u5728\u7248\u672c\u8a2d\u5b9a\u7684Java\u8def\u5f91\u4e2d\u8a2d\u5b9a.
|
||||
crash.advice.ConcurrentModificationException=\u9019\u53ef\u80fd\u662f\u56e0\u70ba\u60a8\u7684Java\u7248\u672c\u9ad8\u65bcJava 1.8.0_11\u5c0e\u81f4\u7684,\u53ef\u4ee5\u5617\u8a66\u5378\u8f09Java8\u5b89\u88ddJava7\u3002
|
||||
crash.advice.ClassNotFoundException=Minecraft\u4e0d\u5b8c\u6574\u6216Mod\u885d\u7a81\uff0c\u5982\u679c\u6709\u672a\u80fd\u4e0b\u8f7d\u7684\u6587\u4ef6\u8bf7\u4e0b\u8f7d\u6210\u529f\u540e\u91cd\u8bd5\u6216\u4e0b\u8f09\u6574\u5408\u5305\u89e3\u6c7a\u554f\u984c\u3002
|
||||
crash.advice.NoSuchFieldError=Minecraft\u4e0d\u5b8c\u6574\u6216Mod\u885d\u7a81\uff0c\u5982\u679c\u6709\u672a\u80fd\u4e0b\u8f7d\u7684\u6587\u4ef6\u8bf7\u4e0b\u8f7d\u6210\u529f\u540e\u91cd\u8bd5\u6216\u4e0b\u8f09\u6574\u5408\u5305\u89e3\u6c7a\u554f\u984c\u3002
|
||||
crash.advice.ClassNotFoundException=Minecraft\u4e0d\u5b8c\u6574\u6216Mod\u885d\u7a81\uff0c\u5982\u679c\u6709\u672a\u80fd\u4e0b\u8f7d\u7684\u6587\u4ef6\u8bf7\u4e0b\u8f7d\u6210\u529f\u540e\u91cd\u8bd5\u6216\u662f\u5ba2\u6237\u7aef\u635f\u574f\u8bf7\u91cd\u8bd5\u8bf7\u91cd\u65b0\u5236\u4f5c\u5ba2\u6237\u7aef\u6216\u4e0b\u8f09\u6574\u5408\u5305\u89e3\u6c7a\u554f\u984c\u3002
|
||||
crash.advice.NoSuchFieldError=Minecraft\u4e0d\u5b8c\u6574\u6216Mod\u885d\u7a81\uff0c\u5982\u679c\u6709\u672a\u80fd\u4e0b\u8f7d\u7684\u6587\u4ef6\u8bf7\u4e0b\u8f7d\u6210\u529f\u540e\u91cd\u8bd5\u6216\u662f\u5ba2\u6237\u7aef\u635f\u574f\u8bf7\u91cd\u8bd5\u8bf7\u91cd\u65b0\u5236\u4f5c\u5ba2\u6237\u7aef\u6216\u4e0b\u8f09\u6574\u5408\u5305\u89e3\u6c7a\u554f\u984c\u3002
|
||||
crash.advice.LWJGLException=\u60a8\u7684\u7535\u8111\u4e0d\u6b63\u5e38\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u9a71\u52a8\u7cbe\u7075\u6216\u5176\u4ed6\u5b89\u88c5\u5668\u66f4\u65b0\u663e\u5361\u9a71\u52a8\u3002
|
||||
crash.advice.SecurityException=\u53ef\u80fd\u662f\u60a8\u4fee\u6539\u4e86minecraft.jar\u4f46\u672a\u522a\u9664META-INF\u6587\u4ef6\u593e\u7684\u539f\u56e0\u3002\u8acb\u901a\u904e\u58d3\u7e2e\u8edf\u4ef6\u522a\u9664jar\u4e2d\u7684META-INF\u6587\u4ef6\u593e\u3002
|
||||
crash.advice.OutOfMemoryError=\u5185\u5b58\u6ea2\u51fa\uff0c\u60a8\u8bbe\u7f6e\u7684Minecraft\u6700\u5927\u5185\u5b58\u8fc7\u5c0f\uff0c\u8bf7\u8c03\u5927\uff01
|
||||
|
@ -1,16 +1,27 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
|
||||
package org.jackhuang.hellominecraft.svrmgr;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.text.ParseException;
|
||||
import javax.swing.UIManager;
|
||||
import org.jackhuang.hellominecraft.utils.functions.NonConsumer;
|
||||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
import org.jackhuang.hellominecraft.HMCLog;
|
||||
import org.jackhuang.hellominecraft.views.LogWindow;
|
||||
import org.jackhuang.hellominecraft.svrmgr.settings.SettingsManager;
|
||||
@ -24,42 +35,39 @@ import org.jackhuang.hellominecraft.lookandfeel.HelloMinecraftLookAndFeel;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
|
||||
public static String launcherName = "Hello Minecraft! Server Manager";
|
||||
public static final String PUBLISH_URL = "http://www.mcbbs.net/thread-171239-1-1.html";
|
||||
public static byte firstVer = 0, secondVer = 8, thirdVer = 6;
|
||||
|
||||
public static String makeTitle() {
|
||||
return launcherName + ' ' + firstVer + '.' + secondVer + '.' + thirdVer;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
SettingsManager.load();
|
||||
try {
|
||||
javax.swing.UIManager.setLookAndFeel(new HelloMinecraftLookAndFeel());
|
||||
UIManager.getLookAndFeelDefaults().put("defaultFont", new Font("微软雅黑", Font.PLAIN, 12));
|
||||
} catch (Throwable ex) {
|
||||
HMCLog.warn("Failed to set look and feel", ex);
|
||||
}
|
||||
new UpdateChecker(new VersionNumber(firstVer, secondVer, thirdVer), "hmcsm", SettingsManager.settings.checkUpdate, new NonConsumer() {
|
||||
|
||||
@Override
|
||||
public void onDone() {
|
||||
SettingsManager.settings.checkUpdate = false;
|
||||
}
|
||||
try {
|
||||
SettingsManager.load();
|
||||
try {
|
||||
javax.swing.UIManager.setLookAndFeel(new HelloMinecraftLookAndFeel());
|
||||
UIManager.getLookAndFeelDefaults().put("defaultFont", new Font("微软雅黑", Font.PLAIN, 12));
|
||||
} catch (ParseException | UnsupportedLookAndFeelException ex) {
|
||||
HMCLog.warn("Failed to set look and feel", ex);
|
||||
}
|
||||
new UpdateChecker(new VersionNumber(firstVer, secondVer, thirdVer), "hmcsm", SettingsManager.settings.checkUpdate, () -> {
|
||||
SettingsManager.settings.checkUpdate = false;
|
||||
}).start();
|
||||
new MainWindow().setVisible(true);
|
||||
} catch(Throwable t) {
|
||||
HMCLog.err("There's something wrong when running server holder.", t);
|
||||
new MainWindow().setVisible(true);
|
||||
} catch (Throwable t) {
|
||||
HMCLog.err("There's something wrong when running server holder.", t);
|
||||
|
||||
LogWindow.instance.clean();
|
||||
LogWindow.instance.log("开服器崩溃了QAQ");
|
||||
StringWriter trace = new StringWriter();
|
||||
t.printStackTrace(new PrintWriter(trace));
|
||||
LogWindow.instance.log(trace.toString());
|
||||
LogWindow.instance.setVisible(true);
|
||||
LogWindow.instance.clean();
|
||||
LogWindow.instance.log("开服器崩溃了QAQ");
|
||||
StringWriter trace = new StringWriter();
|
||||
t.printStackTrace(new PrintWriter(trace));
|
||||
LogWindow.instance.log(trace.toString());
|
||||
LogWindow.instance.setVisible(true);
|
||||
|
||||
System.exit(-1);
|
||||
}
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.cbplugins;
|
||||
|
||||
@ -11,27 +23,26 @@ import java.util.List;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class BukkitPlugin {
|
||||
|
||||
|
||||
public String description, plugin_name, slug;
|
||||
public List<PluginVersion> versions;
|
||||
|
||||
|
||||
public String getLatestVersion() {
|
||||
if(versions != null) {
|
||||
if (versions != null) {
|
||||
PluginVersion v = versions.get(0);
|
||||
return v.version;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public String getLatestBukkit() {
|
||||
if(versions != null) {
|
||||
if (versions != null) {
|
||||
PluginVersion v = versions.get(0);
|
||||
List<String> al = v.game_versions;
|
||||
if(al != null && !al.isEmpty()) {
|
||||
if (al != null && !al.isEmpty())
|
||||
return al.get(0);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.cbplugins;
|
||||
|
||||
@ -9,6 +21,7 @@ package org.jackhuang.hellominecraft.svrmgr.cbplugins;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class Category {
|
||||
|
||||
public double count;
|
||||
public String name;
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.cbplugins;
|
||||
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.cbplugins;
|
||||
|
||||
@ -9,7 +21,7 @@ package org.jackhuang.hellominecraft.svrmgr.cbplugins;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class PluginInformation {
|
||||
|
||||
|
||||
public String name, version, author, description;
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.cbplugins;
|
||||
|
||||
@ -22,7 +34,7 @@ import org.jackhuang.hellominecraft.utils.StrUtils;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class PluginManager {
|
||||
|
||||
|
||||
public static PluginInformation getPluginYML(File f) {
|
||||
try {
|
||||
ZipFile file = new ZipFile(f);
|
||||
@ -34,14 +46,15 @@ public class PluginManager {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static List<BukkitPlugin> getPlugins() throws Exception {
|
||||
String result = NetUtils.doGet("http://api.bukget.org/3//plugins?fields=slug,plugin_name,description,versions.version,versions.game_versions");
|
||||
Gson gson = new Gson();
|
||||
List<BukkitPlugin> list = gson.fromJson(result, new TypeToken<List<BukkitPlugin>>(){}.getType());
|
||||
List<BukkitPlugin> list = gson.fromJson(result, new TypeToken<List<BukkitPlugin>>() {
|
||||
}.getType());
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
public static final String CATEGORY_ADMIN_TOOLS = "Admin Tools",
|
||||
CATEGORY_DEVELOPER_TOOLS = "Developer Tools",
|
||||
CATEGORY_FUN = "Fun",
|
||||
@ -58,28 +71,31 @@ public class PluginManager {
|
||||
CATEGORY_MISCELLANEOUS = "Miscellaneous",
|
||||
CATEGORY_WORLD_GENERATORS = "World Generators",
|
||||
CATEGORY_WEBSITE_ADMINISTRATION = "Website Administration";
|
||||
|
||||
|
||||
public static List<BukkitPlugin> getPluginsByCategory(String category) throws Exception {
|
||||
String result = NetUtils.doGet("http://api.bukget.org/3//categories/" + category + "?fields=slug,plugin_name,description,versions.version,versions.game_versions");
|
||||
Gson gson = new Gson();
|
||||
List<BukkitPlugin> list = gson.fromJson(result, new TypeToken<List<BukkitPlugin>>(){}.getType());
|
||||
List<BukkitPlugin> list = gson.fromJson(result, new TypeToken<List<BukkitPlugin>>() {
|
||||
}.getType());
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<Category> getCategories() throws Exception {
|
||||
String result = NetUtils.doGet("http://api.bukget.org/3//categories/");
|
||||
Gson gson = new Gson();
|
||||
List<Category> list = gson.fromJson(result, new TypeToken<List<Category>>(){}.getType());
|
||||
List<Category> list = gson.fromJson(result, new TypeToken<List<Category>>() {
|
||||
}.getType());
|
||||
return list;
|
||||
}
|
||||
|
||||
public static PluginInfo getPluginInfo(String slug) throws Exception {
|
||||
if(StrUtils.isNotBlank(slug)) {
|
||||
if (StrUtils.isNotBlank(slug)) {
|
||||
String result = NetUtils.doGet("http://api.bukget.org/3//plugins/bukkit/" + slug.toLowerCase());
|
||||
if(StrUtils.isNotBlank(result)) {
|
||||
if(!result.equals("null")) {
|
||||
if (StrUtils.isNotBlank(result))
|
||||
if (!result.equals("null")) {
|
||||
PluginInfo info = new Gson().fromJson(result, PluginInfo.class);
|
||||
return info;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.cbplugins;
|
||||
|
||||
@ -11,9 +23,10 @@ import java.util.List;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class PluginVersion {
|
||||
|
||||
public long date;
|
||||
public String download, link, version;
|
||||
public List<String> game_versions;
|
||||
public String filename, type;
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,19 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
|
||||
package org.jackhuang.hellominecraft.svrmgr.installer.bukkit;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -21,60 +31,60 @@ import org.jsoup.select.Elements;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class BukkitFormatThread extends Thread {
|
||||
|
||||
|
||||
Consumer<List<BukkitVersion>> lis;
|
||||
List<BukkitVersion> formattedList;
|
||||
String url;
|
||||
|
||||
|
||||
public BukkitFormatThread(String url, Consumer<List<BukkitVersion>> lis) {
|
||||
this.lis = lis;
|
||||
this.url = url;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
|
||||
public void format(String url) {
|
||||
|
||||
|
||||
formattedList = new ArrayList<>();
|
||||
|
||||
|
||||
try {
|
||||
Document doc = Jsoup.connect(url).get();
|
||||
Elements versionsTable = doc.getElementsByClass("versionsTable");
|
||||
Elements allforge = new Elements();
|
||||
for(Element table : versionsTable)
|
||||
for (Element table : versionsTable)
|
||||
allforge.addAll(table.getElementsByTag("tr"));
|
||||
for(Element e : allforge) {
|
||||
for (Element e : allforge) {
|
||||
Elements tds = e.getElementsByTag("td");
|
||||
if(tds.isEmpty()) continue;
|
||||
if (tds.isEmpty()) continue;
|
||||
BukkitVersion v = new BukkitVersion();
|
||||
Elements ths = e.getElementsByTag("th");
|
||||
v.buildNumber = v.infoLink = null;
|
||||
if(ths.size() > 0) {
|
||||
Elements a = ths.get(0).getElementsByTag("a");
|
||||
if(a.size() > 0) {
|
||||
v.buildNumber = a.get(0).text();
|
||||
v.infoLink = a.get(0).attr("href");
|
||||
}
|
||||
}
|
||||
Elements ths = e.getElementsByTag("th");
|
||||
v.buildNumber = v.infoLink = null;
|
||||
if (ths.size() > 0) {
|
||||
Elements a = ths.get(0).getElementsByTag("a");
|
||||
if (a.size() > 0) {
|
||||
v.buildNumber = a.get(0).text();
|
||||
v.infoLink = a.get(0).attr("href");
|
||||
}
|
||||
}
|
||||
v.version = tds.get(0).text();
|
||||
v.type = tds.get(1).text();
|
||||
if(tds.get(2).getElementsByTag("a").isEmpty()) continue;
|
||||
v.downloadLink = "http://dl.bukkit.org" + tds.get(2).getElementsByTag("a").get(0).attr("href");
|
||||
v.type = tds.get(1).text();
|
||||
if (tds.get(2).getElementsByTag("a").isEmpty()) continue;
|
||||
v.downloadLink = "http://dl.bukkit.org" + tds.get(2).getElementsByTag("a").get(0).attr("href");
|
||||
formattedList.add(v);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("Failed to get bukkit list", ex);
|
||||
BukkitVersion v = new BukkitVersion();
|
||||
v.type = v.version = "获取失败";
|
||||
v.buildNumber = v.infoLink = null;
|
||||
v.buildNumber = v.infoLink = null;
|
||||
formattedList.add(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
List<BukkitVersion> al = null;
|
||||
format(url);
|
||||
if(lis != null)
|
||||
if (lis != null)
|
||||
lis.accept(formattedList);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,19 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
|
||||
package org.jackhuang.hellominecraft.svrmgr.installer.bukkit;
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.installer.cauldron;
|
||||
|
||||
@ -21,30 +33,30 @@ import org.jsoup.select.Elements;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class ForgeFormatThread extends Thread {
|
||||
|
||||
|
||||
Consumer<Map<String, List<ForgeVersion>>> lis;
|
||||
Map<String, List<ForgeVersion>> formattedList;
|
||||
|
||||
|
||||
public ForgeFormatThread(Consumer<Map<String, List<ForgeVersion>>> lis) {
|
||||
this.lis = lis;
|
||||
}
|
||||
|
||||
|
||||
public void formatNew() {
|
||||
|
||||
|
||||
formattedList = new HashMap();
|
||||
|
||||
|
||||
try {
|
||||
Document doc = Jsoup.connect("http://files.minecraftforge.net/").get();
|
||||
Elements allbuilds = doc.getElementsByClass("builds");
|
||||
Elements tables = new Elements();
|
||||
for(Element build : allbuilds)
|
||||
for (Element build : allbuilds)
|
||||
tables.addAll(build.getElementsByTag("table"));
|
||||
Elements allforge = new Elements();
|
||||
for(Element table : tables)
|
||||
for (Element table : tables)
|
||||
allforge.addAll(table.getElementsByTag("tr"));
|
||||
for(Element e : allforge) {
|
||||
for (Element e : allforge) {
|
||||
Elements tds = e.getElementsByTag("td");
|
||||
if(tds.isEmpty()) continue;
|
||||
if (tds.isEmpty()) continue;
|
||||
ForgeVersion v = new ForgeVersion();
|
||||
v.ver = tds.get(0).text();
|
||||
v.mcver = tds.get(1).text();
|
||||
@ -56,42 +68,40 @@ public class ForgeFormatThread extends Thread {
|
||||
v.userdev = new String[2];
|
||||
Elements a = tds.get(3).getElementsByTag("a");
|
||||
String prev = null;
|
||||
for(Element e2 : a) {
|
||||
for (Element e2 : a) {
|
||||
String href = e2.attributes().get("href").toLowerCase();
|
||||
if(e2.text().toLowerCase().contains("changelog")) {
|
||||
if (e2.text().toLowerCase().contains("changelog"))
|
||||
v.changelog = href;
|
||||
} else if(prev != null) {
|
||||
else if (prev != null) {
|
||||
int index;
|
||||
if(href.contains("adf.ly")) index = 0;
|
||||
if (href.contains("adf.ly")) index = 0;
|
||||
else index = 1;
|
||||
if(prev.toLowerCase().contains("installer")) {
|
||||
if (prev.toLowerCase().contains("installer"))
|
||||
v.installer[index] = href;
|
||||
} else
|
||||
if(prev.toLowerCase().contains("server")) {
|
||||
else if (prev.toLowerCase().contains("server"))
|
||||
v.universal[index] = href;
|
||||
}
|
||||
}
|
||||
prev = e2.text();
|
||||
}
|
||||
|
||||
if(!formattedList.containsKey(v.mcver))
|
||||
formattedList.put(v.mcver, new ArrayList<>());
|
||||
|
||||
if (!formattedList.containsKey(v.mcver))
|
||||
formattedList.put(v.mcver, new ArrayList<>());
|
||||
formattedList.get(v.mcver).add(v);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("Failed to get forge list", ex);
|
||||
ForgeVersion v = new ForgeVersion();
|
||||
v.mcver = v.ver = "获取失败";
|
||||
formattedList.put(v.mcver, new ArrayList<>());
|
||||
formattedList.put(v.mcver, new ArrayList<>());
|
||||
formattedList.get(v.mcver).add(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
formatNew();
|
||||
if(lis != null)
|
||||
if (lis != null)
|
||||
lis.accept(formattedList);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,18 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.installer.cauldron;
|
||||
|
||||
@ -46,194 +57,182 @@ public class ForgeInstaller {
|
||||
public File forgeInstaller;
|
||||
|
||||
public ForgeInstaller(File gameDir, File forgeInstaller) throws IOException {
|
||||
this.gameDir = gameDir.getCanonicalFile();
|
||||
this.forgeInstaller = forgeInstaller;
|
||||
this.gameDir = gameDir.getCanonicalFile();
|
||||
this.forgeInstaller = forgeInstaller;
|
||||
}
|
||||
|
||||
public void install() throws Exception {
|
||||
HMCLog.log("Extracting install profiles...");
|
||||
HMCLog.log("Extracting install profiles...");
|
||||
|
||||
ZipFile zipFile = new ZipFile(forgeInstaller);
|
||||
ZipEntry entry = zipFile.getEntry("install_profile.json");
|
||||
String content = NetUtils.getStreamContent(zipFile.getInputStream(entry));
|
||||
InstallProfile profile = gson.fromJson(content, InstallProfile.class);
|
||||
ZipFile zipFile = new ZipFile(forgeInstaller);
|
||||
ZipEntry entry = zipFile.getEntry("install_profile.json");
|
||||
String content = NetUtils.getStreamContent(zipFile.getInputStream(entry));
|
||||
InstallProfile profile = gson.fromJson(content, InstallProfile.class);
|
||||
|
||||
HMCLog.log("Extracting cauldron server pack..." + profile.install.filePath);
|
||||
HMCLog.log("Extracting cauldron server pack..." + profile.install.filePath);
|
||||
|
||||
entry = zipFile.getEntry(profile.install.filePath);
|
||||
InputStream is = zipFile.getInputStream(entry);
|
||||
entry = zipFile.getEntry(profile.install.filePath);
|
||||
InputStream is = zipFile.getInputStream(entry);
|
||||
|
||||
//MinecraftLibrary forge = new MinecraftLibrary(profile.install.path);
|
||||
//forge.format();
|
||||
File file = new File(gameDir, profile.install.filePath);
|
||||
file.getParentFile().mkdirs();
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
BufferedOutputStream bos = new BufferedOutputStream(fos);
|
||||
int c;
|
||||
while ((c = is.read()) != -1) {
|
||||
bos.write((byte) c);
|
||||
}
|
||||
bos.close();
|
||||
fos.close();
|
||||
//forge.format();
|
||||
File file = new File(gameDir, profile.install.filePath);
|
||||
file.getParentFile().mkdirs();
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
BufferedOutputStream bos = new BufferedOutputStream(fos);
|
||||
int c;
|
||||
while ((c = is.read()) != -1)
|
||||
bos.write((byte) c);
|
||||
bos.close();
|
||||
fos.close();
|
||||
|
||||
File minecraftserver = new File(gameDir, "minecraft_server." + profile.install.minecraft + ".jar");
|
||||
TaskWindow tw = TaskWindow.getInstance();
|
||||
if(minecraftserver.exists() && JOptionPane.showConfirmDialog(null, "已发现官方服务端文件,是否要重新下载?") == JOptionPane.YES_OPTION) {
|
||||
File minecraftserver = new File(gameDir, "minecraft_server." + profile.install.minecraft + ".jar");
|
||||
TaskWindow tw = TaskWindow.getInstance();
|
||||
if (minecraftserver.exists() && JOptionPane.showConfirmDialog(null, "已发现官方服务端文件,是否要重新下载?") == JOptionPane.YES_OPTION) {
|
||||
tw.clean();
|
||||
if(!tw.addTask(new FileDownloadTask("https://s3.amazonaws.com/Minecraft.Download/versions/{MCVER}/minecraft_server.{MCVER}.jar".replace("{MCVER}", profile.install.minecraft),
|
||||
minecraftserver).setTag("minecraft_server")).start())
|
||||
MessageBox.Show("Minecraft官方服务端下载失败!");
|
||||
}
|
||||
if (!tw.addTask(new FileDownloadTask("https://s3.amazonaws.com/Minecraft.Download/versions/{MCVER}/minecraft_server.{MCVER}.jar".replace("{MCVER}", profile.install.minecraft),
|
||||
minecraftserver).setTag("minecraft_server")).start())
|
||||
MessageBox.Show("Minecraft官方服务端下载失败!");
|
||||
}
|
||||
tw.clean();
|
||||
for (MinecraftLibrary library : profile.versionInfo.libraries) {
|
||||
library.init();
|
||||
File lib = new File(gameDir, "libraries" + File.separator + library.formatted + ".pack.xz");
|
||||
String libURL = "https://libraries.minecraft.net/";
|
||||
if (StrUtils.isNotBlank(library.url)) {
|
||||
libURL = library.url;
|
||||
}
|
||||
tw.addTask(new FileDownloadTask(libURL + library.formatted.replace("\\", "/"), lib).setTag(library.name));
|
||||
}
|
||||
tw.start();
|
||||
if(!tw.areTasksFinished())
|
||||
MessageBox.Show("压缩库下载失败!");
|
||||
for (MinecraftLibrary library : profile.versionInfo.libraries) {
|
||||
library.init();
|
||||
File lib = new File(gameDir, "libraries" + File.separator + library.formatted + ".pack.xz");
|
||||
String libURL = "https://libraries.minecraft.net/";
|
||||
if (StrUtils.isNotBlank(library.url))
|
||||
libURL = library.url;
|
||||
tw.addTask(new FileDownloadTask(libURL + library.formatted.replace("\\", "/"), lib).setTag(library.name));
|
||||
}
|
||||
tw.start();
|
||||
if (!tw.areTasksFinished())
|
||||
MessageBox.Show("压缩库下载失败!");
|
||||
tw.clean();
|
||||
for (MinecraftLibrary library : profile.versionInfo.libraries) {
|
||||
File packxz = new File(gameDir, "libraries" + File.separator + library.formatted + ".pack.xz");
|
||||
if(packxz.exists()) return;
|
||||
File lib = new File(gameDir, "libraries" + File.separator + library.formatted);
|
||||
lib.getParentFile().mkdirs();
|
||||
String libURL = "https://libraries.minecraft.net/";
|
||||
if (StrUtils.isNotBlank(library.url)) {
|
||||
libURL = library.url;
|
||||
}
|
||||
tw.addTask(new FileDownloadTask(libURL + library.formatted.replace("\\", "/"), lib).setTag(library.name));
|
||||
}
|
||||
tw.start();
|
||||
if(!tw.areTasksFinished())
|
||||
MessageBox.Show("库下载失败!");
|
||||
tw.clean();
|
||||
ArrayList<String> badLibs = new ArrayList<String>();
|
||||
for (MinecraftLibrary library : profile.versionInfo.libraries) {
|
||||
File lib = new File(gameDir, "libraries" + File.separator + library.formatted);
|
||||
File packFile = new File(gameDir, "libraries" + File.separator + library.formatted + ".pack.xz");
|
||||
if (packFile.exists() && packFile.isFile()) {
|
||||
try {
|
||||
unpackLibrary(lib.getParentFile(), NetUtils.getBytesFromStream(FileUtils.openInputStream(packFile)));
|
||||
if(!checksumValid(lib, Arrays.asList(library.checksums)))
|
||||
badLibs.add(library.name);
|
||||
} catch (IOException e) {
|
||||
HMCLog.warn("Failed to unpack library: " + library.name);
|
||||
badLibs.add(library.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (badLibs.size() > 0) {
|
||||
MessageBox.Show("这些库在解压的时候出现了问题" + badLibs.toString());
|
||||
}
|
||||
for (MinecraftLibrary library : profile.versionInfo.libraries) {
|
||||
File packxz = new File(gameDir, "libraries" + File.separator + library.formatted + ".pack.xz");
|
||||
if (packxz.exists()) return;
|
||||
File lib = new File(gameDir, "libraries" + File.separator + library.formatted);
|
||||
lib.getParentFile().mkdirs();
|
||||
String libURL = "https://libraries.minecraft.net/";
|
||||
if (StrUtils.isNotBlank(library.url))
|
||||
libURL = library.url;
|
||||
tw.addTask(new FileDownloadTask(libURL + library.formatted.replace("\\", "/"), lib).setTag(library.name));
|
||||
}
|
||||
tw.start();
|
||||
if (!tw.areTasksFinished())
|
||||
MessageBox.Show("库下载失败!");
|
||||
tw.clean();
|
||||
ArrayList<String> badLibs = new ArrayList<String>();
|
||||
for (MinecraftLibrary library : profile.versionInfo.libraries) {
|
||||
File lib = new File(gameDir, "libraries" + File.separator + library.formatted);
|
||||
File packFile = new File(gameDir, "libraries" + File.separator + library.formatted + ".pack.xz");
|
||||
if (packFile.exists() && packFile.isFile())
|
||||
try {
|
||||
unpackLibrary(lib.getParentFile(), NetUtils.getBytesFromStream(FileUtils.openInputStream(packFile)));
|
||||
if (!checksumValid(lib, Arrays.asList(library.checksums)))
|
||||
badLibs.add(library.name);
|
||||
} catch (IOException e) {
|
||||
HMCLog.warn("Failed to unpack library: " + library.name);
|
||||
badLibs.add(library.name);
|
||||
}
|
||||
}
|
||||
if (badLibs.size() > 0)
|
||||
MessageBox.Show("这些库在解压的时候出现了问题" + badLibs.toString());
|
||||
}
|
||||
|
||||
public static void unpackLibrary(File output, byte[] data)
|
||||
throws IOException {
|
||||
if (output.exists()) {
|
||||
output.delete();
|
||||
}
|
||||
throws IOException {
|
||||
if (output.exists())
|
||||
output.delete();
|
||||
|
||||
byte[] decompressed = IOUtils.readFully(new XZInputStream(new ByteArrayInputStream(data)));
|
||||
byte[] decompressed = IOUtils.readFully(new XZInputStream(new ByteArrayInputStream(data)));
|
||||
|
||||
String end = new String(decompressed, decompressed.length - 4, 4);
|
||||
if (!end.equals("SIGN")) {
|
||||
HMCLog.warn("Unpacking failed, signature missing " + end);
|
||||
return;
|
||||
}
|
||||
String end = new String(decompressed, decompressed.length - 4, 4);
|
||||
if (!end.equals("SIGN")) {
|
||||
HMCLog.warn("Unpacking failed, signature missing " + end);
|
||||
return;
|
||||
}
|
||||
|
||||
int x = decompressed.length;
|
||||
int len = decompressed[(x - 8)] & 0xFF | (decompressed[(x - 7)] & 0xFF) << 8 | (decompressed[(x - 6)] & 0xFF) << 16 | (decompressed[(x - 5)] & 0xFF) << 24;
|
||||
int x = decompressed.length;
|
||||
int len = decompressed[(x - 8)] & 0xFF | (decompressed[(x - 7)] & 0xFF) << 8 | (decompressed[(x - 6)] & 0xFF) << 16 | (decompressed[(x - 5)] & 0xFF) << 24;
|
||||
|
||||
byte[] checksums = Arrays.copyOfRange(decompressed, decompressed.length - len - 8, decompressed.length - 8);
|
||||
byte[] checksums = Arrays.copyOfRange(decompressed, decompressed.length - len - 8, decompressed.length - 8);
|
||||
|
||||
FileOutputStream jarBytes = new FileOutputStream(output);
|
||||
JarOutputStream jos = new JarOutputStream(jarBytes);
|
||||
FileOutputStream jarBytes = new FileOutputStream(output);
|
||||
JarOutputStream jos = new JarOutputStream(jarBytes);
|
||||
|
||||
Pack200.newUnpacker().unpack(new ByteArrayInputStream(decompressed), jos);
|
||||
Pack200.newUnpacker().unpack(new ByteArrayInputStream(decompressed), jos);
|
||||
|
||||
jos.putNextEntry(new JarEntry("checksums.sha1"));
|
||||
jos.write(checksums);
|
||||
jos.closeEntry();
|
||||
jos.putNextEntry(new JarEntry("checksums.sha1"));
|
||||
jos.write(checksums);
|
||||
jos.closeEntry();
|
||||
|
||||
jos.close();
|
||||
jarBytes.close();
|
||||
jos.close();
|
||||
jarBytes.close();
|
||||
}
|
||||
|
||||
private static boolean checksumValid(File libPath, List<String> checksums) {
|
||||
try {
|
||||
byte[] fileData = NetUtils.getBytesFromStream(FileUtils.openInputStream(libPath));
|
||||
boolean valid = (checksums == null) || (checksums.isEmpty()) || (checksums.contains(DigestUtils.sha1Hex(fileData)));
|
||||
if ((!valid) && (libPath.getName().endsWith(".jar"))) {
|
||||
valid = validateJar(libPath, fileData, checksums);
|
||||
}
|
||||
return valid;
|
||||
} catch (IOException e) {
|
||||
HMCLog.warn("Failed to checksum valid: " + libPath, e);
|
||||
}
|
||||
return false;
|
||||
try {
|
||||
byte[] fileData = NetUtils.getBytesFromStream(FileUtils.openInputStream(libPath));
|
||||
boolean valid = (checksums == null) || (checksums.isEmpty()) || (checksums.contains(DigestUtils.sha1Hex(fileData)));
|
||||
if ((!valid) && (libPath.getName().endsWith(".jar")))
|
||||
valid = validateJar(libPath, fileData, checksums);
|
||||
return valid;
|
||||
} catch (IOException e) {
|
||||
HMCLog.warn("Failed to checksum valid: " + libPath, e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean validateJar(File libPath, byte[] data, List<String> checksums) throws IOException {
|
||||
System.out.println("Checking \"" + libPath.getAbsolutePath() + "\" internal checksums");
|
||||
System.out.println("Checking \"" + libPath.getAbsolutePath() + "\" internal checksums");
|
||||
|
||||
HashMap<String, String> files = new HashMap<String, String>();
|
||||
String[] hashes = null;
|
||||
JarInputStream jar = new JarInputStream(new ByteArrayInputStream(data));
|
||||
JarEntry entry = jar.getNextJarEntry();
|
||||
while (entry != null) {
|
||||
byte[] eData = IOUtils.readFully(jar);
|
||||
HashMap<String, String> files = new HashMap<String, String>();
|
||||
String[] hashes = null;
|
||||
JarInputStream jar = new JarInputStream(new ByteArrayInputStream(data));
|
||||
JarEntry entry = jar.getNextJarEntry();
|
||||
while (entry != null) {
|
||||
byte[] eData = IOUtils.readFully(jar);
|
||||
|
||||
if (entry.getName().equals("checksums.sha1")) {
|
||||
hashes = new String(eData, Charset.forName("UTF-8")).split("\n");
|
||||
}
|
||||
if (entry.getName().equals("checksums.sha1"))
|
||||
hashes = new String(eData, Charset.forName("UTF-8")).split("\n");
|
||||
|
||||
if (!entry.isDirectory()) {
|
||||
files.put(entry.getName(), DigestUtils.sha1Hex(eData));
|
||||
}
|
||||
entry = jar.getNextJarEntry();
|
||||
}
|
||||
jar.close();
|
||||
if (!entry.isDirectory())
|
||||
files.put(entry.getName(), DigestUtils.sha1Hex(eData));
|
||||
entry = jar.getNextJarEntry();
|
||||
}
|
||||
jar.close();
|
||||
|
||||
if (hashes != null) {
|
||||
boolean failed = !checksums.contains(files.get("checksums.sha1"));
|
||||
if (failed) {
|
||||
System.out.println(" checksums.sha1 failed validation");
|
||||
} else {
|
||||
System.out.println(" checksums.sha1 validated successfully");
|
||||
for (String hash : hashes) {
|
||||
if ((!hash.trim().equals("")) && (hash.contains(" "))) {
|
||||
String[] e = hash.split(" ");
|
||||
String validChecksum = e[0];
|
||||
String target = e[1];
|
||||
String checksum = (String) files.get(target);
|
||||
if (hashes != null) {
|
||||
boolean failed = !checksums.contains(files.get("checksums.sha1"));
|
||||
if (failed)
|
||||
System.out.println(" checksums.sha1 failed validation");
|
||||
else {
|
||||
System.out.println(" checksums.sha1 validated successfully");
|
||||
for (String hash : hashes)
|
||||
if ((!hash.trim().equals("")) && (hash.contains(" "))) {
|
||||
String[] e = hash.split(" ");
|
||||
String validChecksum = e[0];
|
||||
String target = e[1];
|
||||
String checksum = (String) files.get(target);
|
||||
|
||||
if ((!files.containsKey(target)) || (checksum == null)) {
|
||||
System.out.println(" " + target + " : missing");
|
||||
failed = true;
|
||||
} else {
|
||||
if (checksum.equals(validChecksum)) {
|
||||
continue;
|
||||
}
|
||||
System.out.println(" " + target + " : failed (" + checksum + ", " + validChecksum + ")");
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!failed) {
|
||||
System.out.println(" Jar contents validated successfully");
|
||||
}
|
||||
if ((!files.containsKey(target)) || (checksum == null)) {
|
||||
System.out.println(" " + target + " : missing");
|
||||
failed = true;
|
||||
} else {
|
||||
if (checksum.equals(validChecksum))
|
||||
continue;
|
||||
System.out.println(" " + target + " : failed (" + checksum + ", " + validChecksum + ")");
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!failed)
|
||||
System.out.println(" Jar contents validated successfully");
|
||||
|
||||
return !failed;
|
||||
}
|
||||
return !failed;
|
||||
}
|
||||
|
||||
System.out.println(" checksums.sha1 was not found, validation failed");
|
||||
return false;
|
||||
System.out.println(" checksums.sha1 was not found, validation failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.installer.cauldron;
|
||||
|
||||
@ -9,12 +21,13 @@ package org.jackhuang.hellominecraft.svrmgr.installer.cauldron;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class ForgeVersion {
|
||||
|
||||
public String vername, ver, mcver, releasetime, changelog;
|
||||
public String[] installer, javadoc, src, universal, userdev;
|
||||
public int typeint;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ForgeVersion{" + "vername=" + vername + ", ver=" + ver + ", mcver=" + mcver + ", releasetime=" + releasetime + ", changelog=" + changelog + ", installer=" + installer + ", javadoc=" + javadoc + ", src=" + src + ", universal=" + universal + ", userdev=" + userdev + ", typeint=" + typeint + '}';
|
||||
return "ForgeVersion{" + "vername=" + vername + ", ver=" + ver + ", mcver=" + mcver + ", releasetime=" + releasetime + ", changelog=" + changelog + ", installer=" + installer + ", javadoc=" + javadoc + ", src=" + src + ", universal=" + universal + ", userdev=" + userdev + ", typeint=" + typeint + '}';
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,19 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
|
||||
package org.jackhuang.hellominecraft.svrmgr.installer.cauldron;
|
||||
|
||||
/**
|
||||
@ -11,5 +21,6 @@ package org.jackhuang.hellominecraft.svrmgr.installer.cauldron;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class Install {
|
||||
|
||||
public String profileName, target, path, version, filePath, welcome, minecraft, mirrorList, logo;
|
||||
}
|
||||
|
@ -1,9 +1,19 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
|
||||
package org.jackhuang.hellominecraft.svrmgr.installer.cauldron;
|
||||
|
||||
/**
|
||||
@ -11,6 +21,7 @@ package org.jackhuang.hellominecraft.svrmgr.installer.cauldron;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class InstallProfile {
|
||||
|
||||
public Install install;
|
||||
public MinecraftVersion versionInfo;
|
||||
}
|
||||
|
@ -1,7 +1,18 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.installer.cauldron;
|
||||
|
||||
@ -13,17 +24,17 @@ import java.io.File;
|
||||
*/
|
||||
public class MinecraftLibrary {
|
||||
|
||||
public String url, formatted=null, name;
|
||||
public String url, formatted = null, name;
|
||||
//public boolean serverreq=true, clientreq=true;
|
||||
public String[] checksums;
|
||||
|
||||
public void init() {
|
||||
String str = name;
|
||||
String[] s = str.split(":");
|
||||
str = s[0];
|
||||
str = str.replace('.', File.separatorChar);
|
||||
str += File.separator + s[1] + File.separator + s[2]
|
||||
+ File.separator + s[1] + '-' + s[2] + ".jar";
|
||||
formatted = str;
|
||||
String str = name;
|
||||
String[] s = str.split(":");
|
||||
str = s[0];
|
||||
str = str.replace('.', File.separatorChar);
|
||||
str += File.separator + s[1] + File.separator + s[2]
|
||||
+ File.separator + s[1] + '-' + s[2] + ".jar";
|
||||
formatted = str;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,18 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.installer.cauldron;
|
||||
|
||||
@ -14,7 +25,7 @@ import java.util.List;
|
||||
public class MinecraftVersion {
|
||||
|
||||
public String minecraftArguments, mainClass, time, id, type, processArguments,
|
||||
releaseTime, assets, jar, inheritsFrom;
|
||||
releaseTime, assets, jar, inheritsFrom;
|
||||
public int minimumLauncherVersion;
|
||||
|
||||
public List<MinecraftLibrary> libraries;
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.server;
|
||||
|
||||
@ -13,9 +25,9 @@ import org.jackhuang.hellominecraft.svrmgr.settings.Schedule;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class ScheduleTranslator {
|
||||
|
||||
|
||||
public static TimerTask translate(Server ser, Schedule s) {
|
||||
switch(s.type) {
|
||||
switch (s.type) {
|
||||
case Schedule.TYPE_AUTO_SAVE:
|
||||
return new AutoSaveSchedule(s, ser);
|
||||
case Schedule.TYPE_AUTO_RESTART:
|
||||
@ -29,9 +41,9 @@ public class ScheduleTranslator {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public static String getName(Schedule s) {
|
||||
switch(s.type) {
|
||||
switch (s.type) {
|
||||
case Schedule.TYPE_AUTO_SAVE:
|
||||
return "自动保存";
|
||||
case Schedule.TYPE_AUTO_RESTART:
|
||||
@ -45,9 +57,9 @@ public class ScheduleTranslator {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
public static String getTimeTypeName(Schedule s) {
|
||||
switch(s.timeType) {
|
||||
switch (s.timeType) {
|
||||
case Schedule.TIME_TYPE_PER:
|
||||
return "每x分钟";
|
||||
case Schedule.TIME_TYPE_PAST_HOUR:
|
||||
@ -61,11 +73,11 @@ public class ScheduleTranslator {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
public static Object[] getRow(Schedule s) {
|
||||
return new Object[] {
|
||||
getName(s), getTimeTypeName(s), s.per, s.content
|
||||
};
|
||||
return new Object[]{
|
||||
getName(s), getTimeTypeName(s), s.per, s.content
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.server;
|
||||
|
||||
@ -41,21 +53,21 @@ import org.jackhuang.hellominecraft.utils.functions.Consumer;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class Server implements Event<Integer>, MonitorThread.MonitorThreadListener,
|
||||
ActionListener {
|
||||
ActionListener {
|
||||
|
||||
private static Server instance;
|
||||
private static boolean disactived = false;
|
||||
|
||||
public static Server getInstance() {
|
||||
return instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isInstanceRunning() {
|
||||
return instance != null && instance.isRunning;
|
||||
return instance != null && instance.isRunning;
|
||||
}
|
||||
|
||||
public static void init(String jar, String memory) {
|
||||
instance = new Server(jar, memory);
|
||||
instance = new Server(jar, memory);
|
||||
}
|
||||
|
||||
String jar, memory;
|
||||
@ -77,304 +89,287 @@ public class Server implements Event<Integer>, MonitorThread.MonitorThreadListen
|
||||
String playerNumber;
|
||||
|
||||
private Server(String jar, String memory) {
|
||||
this.jar = jar;
|
||||
this.memory = memory;
|
||||
isRestart = isDone = false;
|
||||
listeners = new ArrayList<>();
|
||||
listenersC = new ArrayList<>();
|
||||
schedules = new ArrayList<>();
|
||||
timerTasks = new ArrayList<>();
|
||||
this.jar = jar;
|
||||
this.memory = memory;
|
||||
isRestart = isDone = false;
|
||||
listeners = new ArrayList<>();
|
||||
listenersC = new ArrayList<>();
|
||||
schedules = new ArrayList<>();
|
||||
timerTasks = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addListener(MonitorThread.MonitorThreadListener l) {
|
||||
listeners.add(l);
|
||||
listeners.add(l);
|
||||
}
|
||||
|
||||
public void addListener(Event<Integer> l) {
|
||||
listenersC.add(l);
|
||||
listenersC.add(l);
|
||||
}
|
||||
|
||||
public void run() throws IOException {
|
||||
String jvmPath;
|
||||
if (StrUtils.isBlank(SettingsManager.settings.javaDir)) {
|
||||
jvmPath = IOUtils.getJavaDir();
|
||||
} else {
|
||||
jvmPath = SettingsManager.settings.javaDir;
|
||||
}
|
||||
String[] puts = new String[]{
|
||||
jvmPath,
|
||||
"-Xmx" + memory + "m",
|
||||
"-jar",
|
||||
SettingsManager.settings.mainjar,
|
||||
"nogui",
|
||||
"-nojline"
|
||||
};
|
||||
ProcessBuilder pb = new ProcessBuilder(puts);
|
||||
pb.directory(new File(SettingsManager.settings.mainjar).getParentFile());
|
||||
try {
|
||||
disactiveMods(SettingsManager.settings.inactiveExtMods,
|
||||
SettingsManager.settings.inactiveCoreMods,
|
||||
SettingsManager.settings.inactivePlugins);
|
||||
server = pb.start();
|
||||
registerThread(threadA, server.getInputStream());
|
||||
registerThread(threadB, server.getErrorStream());
|
||||
registerThreadC(server);
|
||||
try {
|
||||
bw = new BufferedWriter(new OutputStreamWriter(server.getOutputStream(), System.getProperty("sun.jnu.encoding", "utf-8")));
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
bw = new BufferedWriter(new OutputStreamWriter(server.getOutputStream()));
|
||||
}
|
||||
isRunning = true;
|
||||
String jvmPath;
|
||||
if (StrUtils.isBlank(SettingsManager.settings.javaDir))
|
||||
jvmPath = IOUtils.getJavaDir();
|
||||
else
|
||||
jvmPath = SettingsManager.settings.javaDir;
|
||||
String[] puts = new String[]{
|
||||
jvmPath,
|
||||
"-Xmx" + memory + "m",
|
||||
"-jar",
|
||||
SettingsManager.settings.mainjar,
|
||||
"nogui",
|
||||
"-nojline"
|
||||
};
|
||||
ProcessBuilder pb = new ProcessBuilder(puts);
|
||||
pb.directory(new File(SettingsManager.settings.mainjar).getParentFile());
|
||||
try {
|
||||
disactiveMods(SettingsManager.settings.inactiveExtMods,
|
||||
SettingsManager.settings.inactiveCoreMods,
|
||||
SettingsManager.settings.inactivePlugins);
|
||||
server = pb.start();
|
||||
registerThread(threadA, server.getInputStream());
|
||||
registerThread(threadB, server.getErrorStream());
|
||||
registerThreadC(server);
|
||||
try {
|
||||
bw = new BufferedWriter(new OutputStreamWriter(server.getOutputStream(), System.getProperty("sun.jnu.encoding", "utf-8")));
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
bw = new BufferedWriter(new OutputStreamWriter(server.getOutputStream()));
|
||||
}
|
||||
isRunning = true;
|
||||
startedEvent.execute(null);
|
||||
sendStatus("*** 启动服务端中 ***");
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
|
||||
isRunning = false;
|
||||
}
|
||||
sendStatus("*** 启动服务端中 ***");
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
|
||||
isRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void sendCommand(String cmd) {
|
||||
if (isRunning) {
|
||||
try {
|
||||
sendStatus("发送指令: " + cmd);
|
||||
bw.write(cmd);
|
||||
bw.newLine();
|
||||
bw.flush();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
if (isRunning)
|
||||
try {
|
||||
sendStatus("发送指令: " + cmd);
|
||||
bw.write(cmd);
|
||||
bw.newLine();
|
||||
bw.flush();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void getPlayerNumber(Consumer<Pair<String, String[]>> d) {
|
||||
isGettingPlayerNumber = 1;
|
||||
gettingPlayerNumber = d;
|
||||
sendCommand("list");
|
||||
isGettingPlayerNumber = 1;
|
||||
gettingPlayerNumber = d;
|
||||
sendCommand("list");
|
||||
}
|
||||
|
||||
public void restart() {
|
||||
isRestart = true;
|
||||
stop();
|
||||
isRestart = true;
|
||||
stop();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
}
|
||||
sendCommand("stop");
|
||||
if (timer != null)
|
||||
timer.cancel();
|
||||
sendCommand("stop");
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
if (timer != null) {
|
||||
timer.cancel();
|
||||
}
|
||||
server.destroy();
|
||||
if (timer != null)
|
||||
timer.cancel();
|
||||
server.destroy();
|
||||
}
|
||||
|
||||
public void clearSchedule() {
|
||||
schedules.clear();
|
||||
schedules.clear();
|
||||
}
|
||||
|
||||
public void addSchedule(Schedule s) {
|
||||
schedules.add(s);
|
||||
schedules.add(s);
|
||||
}
|
||||
|
||||
public void delSchedule(Schedule s) {
|
||||
int index = schedules.indexOf(s);
|
||||
if (index == -1) {
|
||||
return;
|
||||
}
|
||||
schedules.remove(index);
|
||||
timerTasks.get(index).cancel();
|
||||
timerTasks.remove(index);
|
||||
int index = schedules.indexOf(s);
|
||||
if (index == -1)
|
||||
return;
|
||||
schedules.remove(index);
|
||||
timerTasks.get(index).cancel();
|
||||
timerTasks.remove(index);
|
||||
}
|
||||
|
||||
private void registerThread(MonitorThread thread, InputStream is) {
|
||||
thread = new MonitorThread(is);
|
||||
for (MonitorThread.MonitorThreadListener l : listeners) {
|
||||
thread.addListener(l);
|
||||
}
|
||||
thread.addListener(this);
|
||||
thread.start();
|
||||
thread = new MonitorThread(is);
|
||||
for (MonitorThread.MonitorThreadListener l : listeners)
|
||||
thread.addListener(l);
|
||||
thread.addListener(this);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
private void registerThreadC(Process p) {
|
||||
threadC = new WaitForThread(p);
|
||||
for (Event<Integer> l : listenersC) threadC.event.register(l);
|
||||
threadC.event.register(this);
|
||||
threadC.start();
|
||||
threadC = new WaitForThread(p);
|
||||
for (Event<Integer> l : listenersC) threadC.event.register(l);
|
||||
threadC.event.register(this);
|
||||
threadC.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean call(Object sender, Integer t) {
|
||||
if (t == 0) {
|
||||
sendStatus("*** 服务端已停止 ***");
|
||||
System.out.println("Server stopped successfully");
|
||||
} else {
|
||||
sendStatus("*** 服务端崩溃了!(错误码:" + t + ") ***");
|
||||
System.err.println("Server crashed(exit code: " + t + ")");
|
||||
}
|
||||
isRunning = false;
|
||||
if (t == 0) {
|
||||
sendStatus("*** 服务端已停止 ***");
|
||||
System.out.println("Server stopped successfully");
|
||||
} else {
|
||||
sendStatus("*** 服务端崩溃了!(错误码:" + t + ") ***");
|
||||
System.err.println("Server crashed(exit code: " + t + ")");
|
||||
}
|
||||
isRunning = false;
|
||||
for (Schedule schedule : schedules) if (schedule.timeType == Schedule.TIME_TYPE_SERVER_STOPPED) ScheduleTranslator.translate(this, schedule).run();
|
||||
if (timer != null) timer.cancel();
|
||||
if (pastTimer != null) pastTimer.stop();
|
||||
restoreMods();
|
||||
if (isRestart) {
|
||||
try {
|
||||
run();
|
||||
} catch (IOException ex) {
|
||||
MessageBox.Show("重启失败!");
|
||||
HMCLog.warn("Failed to launch!", ex);
|
||||
}
|
||||
isRestart = false;
|
||||
}
|
||||
if (timer != null) timer.cancel();
|
||||
if (pastTimer != null) pastTimer.stop();
|
||||
restoreMods();
|
||||
if (isRestart) {
|
||||
try {
|
||||
run();
|
||||
} catch (IOException ex) {
|
||||
MessageBox.Show("重启失败!");
|
||||
HMCLog.warn("Failed to launch!", ex);
|
||||
}
|
||||
isRestart = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void disactiveMods(ArrayList<String> inactiveExtMods,
|
||||
ArrayList<String> inactiveCoreMods, ArrayList<String> inactivePlugins) {
|
||||
disactiveModsByType(inactiveExtMods, "mods");
|
||||
disactiveModsByType(inactiveCoreMods, "coremods");
|
||||
disactiveModsByType(inactivePlugins, "plugins");
|
||||
disactived = true;
|
||||
ArrayList<String> inactiveCoreMods, ArrayList<String> inactivePlugins) {
|
||||
disactiveModsByType(inactiveExtMods, "mods");
|
||||
disactiveModsByType(inactiveCoreMods, "coremods");
|
||||
disactiveModsByType(inactivePlugins, "plugins");
|
||||
disactived = true;
|
||||
}
|
||||
|
||||
private static void disactiveModsByType(ArrayList<String> paramArrayOfString, String paramString) {
|
||||
restoreModsByType(paramString);
|
||||
restoreModsByType(paramString);
|
||||
|
||||
System.out.println("禁用不活动的文件: " + paramString);
|
||||
if ((paramArrayOfString == null) || (paramArrayOfString.size() <= 0)) {
|
||||
return;
|
||||
}
|
||||
File[] files = new File(Utilities.getGameDir(), paramString).listFiles();
|
||||
if (files == null) {
|
||||
System.out.println("没有文件: " + paramString);
|
||||
return;
|
||||
}
|
||||
for (File file : files) if (!file.isDirectory()) {
|
||||
String name = file.getName();
|
||||
|
||||
if ((!paramArrayOfString.contains(name))
|
||||
|| ((!name.toLowerCase().endsWith(".zip")) && (!name.toLowerCase().endsWith(".jar")))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
String newName = name + "X";
|
||||
File newFile = new File(file.getParentFile(), newName);
|
||||
|
||||
if (newFile.exists()) {
|
||||
newFile.delete();
|
||||
}
|
||||
if (file.renameTo(newFile)) {
|
||||
System.out.println("已禁用: " + name + ", 新名称: " + newFile.getName());
|
||||
} else {
|
||||
System.out.println("无法禁用: " + name);
|
||||
}
|
||||
System.out.println("禁用不活动的文件: " + paramString);
|
||||
if ((paramArrayOfString == null) || (paramArrayOfString.size() <= 0))
|
||||
return;
|
||||
File[] files = new File(Utilities.getGameDir(), paramString).listFiles();
|
||||
if (files == null) {
|
||||
System.out.println("没有文件: " + paramString);
|
||||
return;
|
||||
}
|
||||
for (File file : files) if (!file.isDirectory()) {
|
||||
String name = file.getName();
|
||||
|
||||
if ((!paramArrayOfString.contains(name))
|
||||
|| ((!name.toLowerCase().endsWith(".zip")) && (!name.toLowerCase().endsWith(".jar"))))
|
||||
continue;
|
||||
|
||||
String newName = name + "X";
|
||||
File newFile = new File(file.getParentFile(), newName);
|
||||
|
||||
if (newFile.exists())
|
||||
newFile.delete();
|
||||
if (file.renameTo(newFile))
|
||||
System.out.println("已禁用: " + name + ", 新名称: " + newFile.getName());
|
||||
else
|
||||
System.out.println("无法禁用: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
private static void restoreModsByType(String paramString) {
|
||||
System.out.println("还原被禁用的文件: " + paramString);
|
||||
File[] files = new File(Utilities.getGameDir(), paramString).listFiles();
|
||||
if (files == null) return;
|
||||
System.out.println("还原被禁用的文件: " + paramString);
|
||||
File[] files = new File(Utilities.getGameDir(), paramString).listFiles();
|
||||
if (files == null) return;
|
||||
for (File file : files) if (!file.isDirectory()) {
|
||||
String name = file.getName();
|
||||
String lowName = name.toLowerCase();
|
||||
if ((!lowName.endsWith(".zipx")) && (!lowName.endsWith(".jarx"))) {
|
||||
continue;
|
||||
String name = file.getName();
|
||||
String lowName = name.toLowerCase();
|
||||
if ((!lowName.endsWith(".zipx")) && (!lowName.endsWith(".jarx")))
|
||||
continue;
|
||||
String newName = name.substring(0, name.length() - 1);
|
||||
|
||||
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());
|
||||
}
|
||||
String newName = name.substring(0, name.length() - 1);
|
||||
|
||||
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() {
|
||||
if (disactived) {
|
||||
restoreModsByType("mods");
|
||||
restoreModsByType("coremods");
|
||||
restoreModsByType("plugins");
|
||||
disactived = false;
|
||||
}
|
||||
if (disactived) {
|
||||
restoreModsByType("mods");
|
||||
restoreModsByType("coremods");
|
||||
restoreModsByType("plugins");
|
||||
disactived = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatus(String status) {
|
||||
System.out.println(status);
|
||||
if (isGettingPlayerNumber == 1) {
|
||||
Pattern p = Pattern.compile("There are [0-9]*/[0-9]* players online");
|
||||
Matcher m = p.matcher(status);
|
||||
if (!m.find()) {
|
||||
return;
|
||||
}
|
||||
String s = m.group(0);
|
||||
s = s.substring(10, s.length() - 15);
|
||||
playerNumber = s;
|
||||
isGettingPlayerNumber = 2;
|
||||
return;
|
||||
} else if (isGettingPlayerNumber == 2) {
|
||||
try {
|
||||
status = status.substring(status.lastIndexOf("]")+1);
|
||||
status = status.substring(status.indexOf(":")+1);
|
||||
} catch(Exception e) {
|
||||
HMCLog.warn("Failed to substring status.", e);
|
||||
}
|
||||
String[] s;
|
||||
if(StrUtils.isNotBlank(status)) {
|
||||
s = status.trim().split(", ");
|
||||
} else {
|
||||
s = new String[0];
|
||||
}
|
||||
Pair<String, String[]> p = new Pair<>(playerNumber, s);
|
||||
isGettingPlayerNumber = 0;
|
||||
gettingPlayerNumber.accept(p);
|
||||
return;
|
||||
}
|
||||
if (isDone == false) {
|
||||
Pattern p = Pattern.compile("\\[INFO\\] Done \\([0-9]*\\.[0-9]*s\\)! For help, type \"help\" or \"\\?\"");
|
||||
Matcher m = p.matcher(status);
|
||||
if (m.find()) {
|
||||
stoppedEvent.execute(null);
|
||||
timer = new Timer();
|
||||
timerTasks.clear();
|
||||
for (int i = 0; i < schedules.size(); i++) {
|
||||
if (schedules.get(i).timeType == Schedule.TIME_TYPE_SERVER_STARTED) {
|
||||
ScheduleTranslator.translate(this, schedules.get(i)).run();
|
||||
continue;
|
||||
}
|
||||
if (schedules.get(i).timeType != Schedule.TIME_TYPE_PER) continue;
|
||||
long mill = (long) Math.floor(schedules.get(i).per * 60 * 1000);
|
||||
timerTasks.add(ScheduleTranslator.translate(this, schedules.get(i)));
|
||||
timer.schedule(timerTasks.get(i), mill, mill);
|
||||
}
|
||||
pastTimer = new javax.swing.Timer(1000, this);
|
||||
pastTimer.start();
|
||||
System.out.println("Server started!");
|
||||
sendStatus("*** 服务端已启动完成 ***");
|
||||
isDone = true;
|
||||
}
|
||||
}
|
||||
if (status.length() > 20) {
|
||||
if (status.substring(20).contains("[SEVERE] This crash report has been saved to: ")) {
|
||||
System.out.println(status);
|
||||
if (isGettingPlayerNumber == 1) {
|
||||
Pattern p = Pattern.compile("There are [0-9]*/[0-9]* players online");
|
||||
Matcher m = p.matcher(status);
|
||||
if (!m.find())
|
||||
return;
|
||||
String s = m.group(0);
|
||||
s = s.substring(10, s.length() - 15);
|
||||
playerNumber = s;
|
||||
isGettingPlayerNumber = 2;
|
||||
return;
|
||||
} else if (isGettingPlayerNumber == 2) {
|
||||
try {
|
||||
status = status.substring(status.lastIndexOf("]") + 1);
|
||||
status = status.substring(status.indexOf(":") + 1);
|
||||
} catch (Exception e) {
|
||||
HMCLog.warn("Failed to substring status.", e);
|
||||
}
|
||||
String[] s;
|
||||
if (StrUtils.isNotBlank(status))
|
||||
s = status.trim().split(", ");
|
||||
else
|
||||
s = new String[0];
|
||||
Pair<String, String[]> p = new Pair<>(playerNumber, s);
|
||||
isGettingPlayerNumber = 0;
|
||||
gettingPlayerNumber.accept(p);
|
||||
return;
|
||||
}
|
||||
if (isDone == false) {
|
||||
Pattern p = Pattern.compile("\\[INFO\\] Done \\([0-9]*\\.[0-9]*s\\)! For help, type \"help\" or \"\\?\"");
|
||||
Matcher m = p.matcher(status);
|
||||
if (m.find()) {
|
||||
stoppedEvent.execute(null);
|
||||
timer = new Timer();
|
||||
timerTasks.clear();
|
||||
for (int i = 0; i < schedules.size(); i++) {
|
||||
if (schedules.get(i).timeType == Schedule.TIME_TYPE_SERVER_STARTED) {
|
||||
ScheduleTranslator.translate(this, schedules.get(i)).run();
|
||||
continue;
|
||||
}
|
||||
if (schedules.get(i).timeType != Schedule.TIME_TYPE_PER) continue;
|
||||
long mill = (long) Math.floor(schedules.get(i).per * 60 * 1000);
|
||||
timerTasks.add(ScheduleTranslator.translate(this, schedules.get(i)));
|
||||
timer.schedule(timerTasks.get(i), mill, mill);
|
||||
}
|
||||
pastTimer = new javax.swing.Timer(1000, this);
|
||||
pastTimer.start();
|
||||
System.out.println("Server started!");
|
||||
sendStatus("*** 服务端已启动完成 ***");
|
||||
isDone = true;
|
||||
}
|
||||
}
|
||||
if (status.length() > 20)
|
||||
if (status.substring(20).contains("[SEVERE] This crash report has been saved to: "))
|
||||
for (Schedule schedule : schedules) if (schedule.timeType == Schedule.TIME_TYPE_SERVER_CRASHED) ScheduleTranslator.translate(this, schedule).run();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GregorianCalendar c = new GregorianCalendar();
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
c.setTime(new Date());
|
||||
if (c.get(Calendar.SECOND) != 0) return;
|
||||
int minute = c.get(Calendar.MINUTE);
|
||||
c.setTime(new Date());
|
||||
if (c.get(Calendar.SECOND) != 0) return;
|
||||
int minute = c.get(Calendar.MINUTE);
|
||||
for (Schedule schedule : schedules) {
|
||||
if (schedule.timeType != Schedule.TIME_TYPE_PAST_HOUR) continue;
|
||||
if (schedule.per == minute) ScheduleTranslator.translate(this, schedule).run();
|
||||
@ -382,6 +377,6 @@ public class Server implements Event<Integer>, MonitorThread.MonitorThreadListen
|
||||
}
|
||||
|
||||
private void sendStatus(String status) {
|
||||
for (MonitorThread.MonitorThreadListener l : listeners) l.onStatus(status);
|
||||
for (MonitorThread.MonitorThreadListener l : listeners) l.onStatus(status);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.server;
|
||||
|
||||
@ -14,22 +26,20 @@ import org.jackhuang.hellominecraft.HMCLog;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class ServerChecker {
|
||||
|
||||
|
||||
public static boolean isServerJar(File f) {
|
||||
ZipFile file;
|
||||
try {
|
||||
file = new ZipFile(f);
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("", ex);
|
||||
HMCLog.warn("", ex);
|
||||
return false;
|
||||
}
|
||||
if(file.getEntry("org/bukkit/craftbukkit/Main.class") != null) {
|
||||
if (file.getEntry("org/bukkit/craftbukkit/Main.class") != null)
|
||||
return true;
|
||||
}
|
||||
if(file.getEntry("net/minecraft/server/MinecraftServer.class") != null) {
|
||||
if (file.getEntry("net/minecraft/server/MinecraftServer.class") != null)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.server.backups;
|
||||
|
||||
@ -19,85 +31,83 @@ import org.jackhuang.hellominecraft.svrmgr.utils.Utilities;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class BackupManager {
|
||||
|
||||
|
||||
public static String backupDir() {
|
||||
return Utilities.getGameDir() + "backups-HMCSM" + File.separator;
|
||||
return Utilities.getGameDir() + "backups-HMCSM" + File.separator;
|
||||
}
|
||||
|
||||
|
||||
public static ArrayList<String> getBackupList() {
|
||||
String gameDir = backupDir();
|
||||
return Utilities.findAllFile(new File(gameDir));
|
||||
}
|
||||
|
||||
|
||||
public static void addWorldBackup(final String folder) {
|
||||
new File(backupDir()).mkdirs();
|
||||
Thread t = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
||||
Compressor.zip(Utilities.getGameDir() + folder + File.separator,
|
||||
backupDir() + "world+" + f.format(new Date()) + "+" + folder + ".zip");
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("Failed to compress world pack.", ex);
|
||||
}
|
||||
try {
|
||||
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
||||
Compressor.zip(Utilities.getGameDir() + folder + File.separator,
|
||||
backupDir() + "world+" + f.format(new Date()) + "+" + folder + ".zip");
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("Failed to compress world pack.", ex);
|
||||
}
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
}
|
||||
|
||||
|
||||
public static ArrayList<String> findAllWorlds() {
|
||||
String gameDir = Utilities.getGameDir();
|
||||
ArrayList<String> folders = Utilities.findAllDir(new File(gameDir));
|
||||
ArrayList<String> result = new ArrayList<String>();
|
||||
for(String folder : folders) {
|
||||
for (String folder : folders) {
|
||||
String worldPath = gameDir + folder + File.separator;
|
||||
ArrayList<String> files = Utilities.findAllFile(new File(worldPath));
|
||||
if(files.contains("level.dat")) {
|
||||
if (files.contains("level.dat"))
|
||||
result.add(folder);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static void restoreBackup(String backupFile) {
|
||||
try {
|
||||
File file = new File(backupFile);
|
||||
String name = Utilities.trimExtension(file.getName());
|
||||
String[] info = name.split("\\+");
|
||||
String folder = info[2];
|
||||
File world = new File(Utilities.getGameDir() + folder + File.separator);
|
||||
Utilities.deleteAll(world);
|
||||
world.mkdirs();
|
||||
Compressor.unzip(backupFile, world.getAbsolutePath());
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("Failed to decompress world pack.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void backupAllWorlds() {
|
||||
ArrayList<String> al = findAllWorlds();
|
||||
for(String world : al) {
|
||||
if(!SettingsManager.settings.inactiveWorlds.contains(world))
|
||||
addWorldBackup(world);
|
||||
try {
|
||||
File file = new File(backupFile);
|
||||
String name = Utilities.trimExtension(file.getName());
|
||||
String[] info = name.split("\\+");
|
||||
String folder = info[2];
|
||||
File world = new File(Utilities.getGameDir() + folder + File.separator);
|
||||
Utilities.deleteAll(world);
|
||||
world.mkdirs();
|
||||
Compressor.unzip(backupFile, world.getAbsolutePath());
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("Failed to decompress world pack.", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void backupAllWorlds() {
|
||||
ArrayList<String> al = findAllWorlds();
|
||||
for (String world : al)
|
||||
if (!SettingsManager.settings.inactiveWorlds.contains(world))
|
||||
addWorldBackup(world);
|
||||
}
|
||||
|
||||
public static void backupAllPlugins() {
|
||||
new File(backupDir()).mkdirs();
|
||||
Thread t = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
||||
Compressor.zip(Utilities.getGameDir() + "plugins" + File.separator,
|
||||
backupDir() + "plugin+" + f.format(new Date()) + "+plugins.zip");
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("Failed to compress world pack with plugins.", ex);
|
||||
}
|
||||
try {
|
||||
SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
|
||||
Compressor.zip(Utilities.getGameDir() + "plugins" + File.separator,
|
||||
backupDir() + "plugin+" + f.format(new Date()) + "+plugins.zip");
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("Failed to compress world pack with plugins.", ex);
|
||||
}
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.server.download;
|
||||
|
||||
@ -9,5 +21,6 @@ package org.jackhuang.hellominecraft.svrmgr.server.download;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class ServerDownloadPackage {
|
||||
|
||||
public String mcversion, version, forgeversion, majorversion, file;
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.server.schedules;
|
||||
|
||||
@ -14,10 +26,10 @@ import org.jackhuang.hellominecraft.svrmgr.settings.Schedule;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class AutoBackupSchedule extends TimerTask {
|
||||
|
||||
|
||||
Schedule main;
|
||||
Server server;
|
||||
|
||||
|
||||
public AutoBackupSchedule(Schedule s, Server s2) {
|
||||
main = s;
|
||||
server = s2;
|
||||
@ -29,5 +41,5 @@ public class AutoBackupSchedule extends TimerTask {
|
||||
Server.getInstance().sendCommand("say 自动备份完毕");
|
||||
BackupManager.backupAllWorlds();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.server.schedules;
|
||||
|
||||
@ -13,10 +25,10 @@ import org.jackhuang.hellominecraft.svrmgr.settings.Schedule;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class AutoBroadcastSchedule extends TimerTask {
|
||||
|
||||
|
||||
Schedule main;
|
||||
Server server;
|
||||
|
||||
|
||||
public AutoBroadcastSchedule(Schedule s, Server s2) {
|
||||
main = s;
|
||||
server = s2;
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.server.schedules;
|
||||
|
||||
@ -15,9 +27,10 @@ import org.jackhuang.hellominecraft.svrmgr.settings.Schedule;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class AutoExecuteSchedule extends TimerTask {
|
||||
|
||||
Schedule main;
|
||||
Server server;
|
||||
|
||||
|
||||
public AutoExecuteSchedule(Schedule s, Server s2) {
|
||||
main = s;
|
||||
server = s2;
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.server.schedules;
|
||||
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.server.schedules;
|
||||
|
||||
@ -13,10 +25,10 @@ import org.jackhuang.hellominecraft.svrmgr.settings.Schedule;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class AutoSaveSchedule extends TimerTask {
|
||||
|
||||
|
||||
Schedule main;
|
||||
Server server;
|
||||
|
||||
|
||||
public AutoSaveSchedule(Schedule s, Server s2) {
|
||||
main = s;
|
||||
server = s2;
|
||||
@ -27,5 +39,5 @@ public class AutoSaveSchedule extends TimerTask {
|
||||
System.out.println("auto save");
|
||||
server.sendCommand("save-all");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.server.schedules;
|
||||
|
||||
@ -13,9 +25,10 @@ import org.jackhuang.hellominecraft.svrmgr.settings.Schedule;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public abstract class AutoSchedule extends TimerTask {
|
||||
|
||||
Schedule main;
|
||||
Server server;
|
||||
|
||||
|
||||
public AutoSchedule(Schedule s, Server s2) {
|
||||
main = s;
|
||||
server = s2;
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.server.schedules;
|
||||
|
||||
|
@ -1,9 +1,19 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
|
||||
package org.jackhuang.hellominecraft.svrmgr.settings;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -17,20 +27,20 @@ public class BannedPlayers extends PlayerList<BannedPlayers.BannedPlayer> {
|
||||
|
||||
@Override
|
||||
protected BannedPlayer newPlayer(String name) {
|
||||
return new BannedPlayer(name);
|
||||
return new BannedPlayer(name);
|
||||
}
|
||||
|
||||
|
||||
public static class BannedPlayer extends PlayerList.BasePlayer {
|
||||
|
||||
public String source, expires, reason, created;
|
||||
|
||||
public BannedPlayer(String name) {
|
||||
super(name);
|
||||
|
||||
created = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss +0800").format(new Date());
|
||||
source = "Server";
|
||||
expires = "forever";
|
||||
reason = "你已经被服务器封禁";
|
||||
}
|
||||
public String source, expires, reason, created;
|
||||
|
||||
public BannedPlayer(String name) {
|
||||
super(name);
|
||||
|
||||
created = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss +0800").format(new Date());
|
||||
source = "Server";
|
||||
expires = "forever";
|
||||
reason = "你已经被服务器封禁";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,18 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.settings;
|
||||
|
||||
@ -13,16 +24,16 @@ public class Op extends PlayerList<Op.Operator> {
|
||||
|
||||
@Override
|
||||
protected Op.Operator newPlayer(String name) {
|
||||
return new Op.Operator(name);
|
||||
return new Op.Operator(name);
|
||||
}
|
||||
|
||||
public static class Operator extends PlayerList.BasePlayer {
|
||||
|
||||
public int level;
|
||||
public int level;
|
||||
|
||||
public Operator(String name) {
|
||||
super(name);
|
||||
level = 4;
|
||||
}
|
||||
public Operator(String name) {
|
||||
super(name);
|
||||
level = 4;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,18 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.settings;
|
||||
|
||||
@ -24,31 +35,31 @@ public abstract class PlayerList<T extends BasePlayer> {
|
||||
|
||||
public static class BasePlayer {
|
||||
|
||||
public String uuid, name;
|
||||
public String uuid, name;
|
||||
|
||||
public BasePlayer(String name) {
|
||||
uuid = UUID.randomUUID().toString();
|
||||
this.name = name;
|
||||
}
|
||||
public BasePlayer(String name) {
|
||||
uuid = UUID.randomUUID().toString();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof PlayerList.BasePlayer) {
|
||||
BasePlayer player = (BasePlayer) obj;
|
||||
return player.name.equals(name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof PlayerList.BasePlayer) {
|
||||
BasePlayer player = (BasePlayer) obj;
|
||||
return player.name.equals(name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.name.hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.name.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -57,57 +68,55 @@ public abstract class PlayerList<T extends BasePlayer> {
|
||||
protected abstract T newPlayer(String name);
|
||||
|
||||
public void initByText(String s) {
|
||||
String[] lines = s.split("\n");
|
||||
op = new HashSet<T>();
|
||||
for (String l : lines) {
|
||||
if(l.startsWith("#")) continue;
|
||||
T player = newPlayer(l);
|
||||
if (StrUtils.isBlank(l)) {
|
||||
continue;
|
||||
}
|
||||
op.add(player);
|
||||
}
|
||||
String[] lines = s.split("\n");
|
||||
op = new HashSet<T>();
|
||||
for (String l : lines) {
|
||||
if (l.startsWith("#")) continue;
|
||||
T player = newPlayer(l);
|
||||
if (StrUtils.isBlank(l))
|
||||
continue;
|
||||
op.add(player);
|
||||
}
|
||||
}
|
||||
|
||||
public void initByJson(String s) {
|
||||
op = new Gson().<HashSet<T>>fromJson(s, HashSet.class);
|
||||
op = new Gson().<HashSet<T>>fromJson(s, HashSet.class);
|
||||
}
|
||||
|
||||
public void initByBoth(File txt, File json) {
|
||||
HashSet<T> player = new HashSet<T>();
|
||||
/*op = null;
|
||||
if(json.exists()) {
|
||||
try {
|
||||
initByJson(FileUtils.readFileToStringIgnoreFileNotFound(json));
|
||||
if(op != null)
|
||||
player.addAll(op);
|
||||
} catch(IOException e) {
|
||||
HMCLLog.warn("Failed to load playerlist by json", e);
|
||||
}
|
||||
}*/
|
||||
op = null;
|
||||
if(txt.exists()) {
|
||||
try {
|
||||
initByText(FileUtils.readFileToStringIgnoreFileNotFound(txt));
|
||||
if(op != null)
|
||||
player.addAll(op);
|
||||
} catch(IOException e) {
|
||||
HMCLog.warn("Failed to load playerlist by txt", e);
|
||||
}
|
||||
}
|
||||
op = player;
|
||||
HashSet<T> player = new HashSet<T>();
|
||||
/*op = null;
|
||||
if(json.exists()) {
|
||||
try {
|
||||
initByJson(FileUtils.readFileToStringIgnoreFileNotFound(json));
|
||||
if(op != null)
|
||||
player.addAll(op);
|
||||
} catch(IOException e) {
|
||||
HMCLLog.warn("Failed to load playerlist by json", e);
|
||||
}
|
||||
}*/
|
||||
op = null;
|
||||
if (txt.exists())
|
||||
try {
|
||||
initByText(FileUtils.readFileToStringIgnoreFileNotFound(txt));
|
||||
if (op != null)
|
||||
player.addAll(op);
|
||||
} catch (IOException e) {
|
||||
HMCLog.warn("Failed to load playerlist by txt", e);
|
||||
}
|
||||
op = player;
|
||||
}
|
||||
|
||||
public void saveAsText(File file) throws IOException {
|
||||
FileUtils.write(file, StrUtils.parseParams("", op, System.getProperty("line.separator")));
|
||||
FileUtils.write(file, StrUtils.parseParams("", op, System.getProperty("line.separator")));
|
||||
}
|
||||
|
||||
public void saveAsJson(File file) throws IOException {
|
||||
FileUtils.write(file, new Gson().toJson(op));
|
||||
FileUtils.write(file, new Gson().toJson(op));
|
||||
}
|
||||
|
||||
public void saveAsBoth(File txt, File json) throws IOException {
|
||||
saveAsText(txt);
|
||||
saveAsJson(json);
|
||||
saveAsText(txt);
|
||||
saveAsJson(json);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.settings;
|
||||
|
||||
@ -9,24 +21,22 @@ package org.jackhuang.hellominecraft.svrmgr.settings;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class Schedule {
|
||||
public static final int
|
||||
TYPE_AUTO_SAVE = 0,
|
||||
|
||||
public static final int TYPE_AUTO_SAVE = 0,
|
||||
TYPE_AUTO_RESTART = 1,
|
||||
TYPE_AUTO_BACKUP = 2,
|
||||
TYPE_AUTO_BROADCAST = 3,
|
||||
TYPE_AUTO_SEND_COMMAND = 4,
|
||||
TYPE_AUTO_EXECUTE = 5;
|
||||
public static final int
|
||||
TYPE2_AUTO_BACKUP_PLUGINS = 1,
|
||||
public static final int TYPE2_AUTO_BACKUP_PLUGINS = 1,
|
||||
TYPE2_AUTH_BACKUP_CONFIG = 2,
|
||||
TYPE3_AUTH_BACKUP_WORLD = 3;
|
||||
public static final int
|
||||
TIME_TYPE_PER = 0,
|
||||
public static final int TIME_TYPE_PER = 0,
|
||||
TIME_TYPE_PAST_HOUR = 1,
|
||||
TIME_TYPE_SERVER_STARTED = 2,
|
||||
TIME_TYPE_SERVER_STOPPED = 3,
|
||||
TIME_TYPE_SERVER_CRASHED = 4;
|
||||
|
||||
|
||||
public int type, type2, timeType;
|
||||
public String content;
|
||||
public double per;
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.settings;
|
||||
|
||||
@ -19,17 +31,17 @@ import org.jackhuang.hellominecraft.HMCLog;
|
||||
* @author jack
|
||||
*/
|
||||
public class ServerProperties {
|
||||
|
||||
|
||||
public static ServerProperties getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
private static ServerProperties instance;
|
||||
|
||||
|
||||
public static void init(String path) {
|
||||
instance = new ServerProperties(path);
|
||||
}
|
||||
|
||||
|
||||
String path;
|
||||
InputStream is;
|
||||
Properties p;
|
||||
@ -37,11 +49,11 @@ public class ServerProperties {
|
||||
public ServerProperties(String path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
|
||||
public String getProperty(String key) {
|
||||
return getProperty(key, "");
|
||||
}
|
||||
|
||||
|
||||
public String getProperty(String key, String defaultValue) {
|
||||
try {
|
||||
is = new FileInputStream(new File(path, "server.properties"));
|
||||
@ -53,26 +65,26 @@ public class ServerProperties {
|
||||
return "";
|
||||
} finally {
|
||||
try {
|
||||
if(is != null)
|
||||
if (is != null)
|
||||
is.close();
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("Failed to close InputStream for server.properties", ex);
|
||||
HMCLog.warn("Failed to close InputStream for server.properties", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int getPropertyInt(String key, int defaultValue) {
|
||||
try {
|
||||
return Integer.parseInt(getProperty(key, String.valueOf(defaultValue)));
|
||||
} catch(NumberFormatException e) {
|
||||
} catch (NumberFormatException e) {
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean getPropertyBoolean(String key, boolean defaultValue) {
|
||||
return getProperty(key, String.valueOf(defaultValue)).equals("true");
|
||||
}
|
||||
|
||||
|
||||
public void setProperty(String key, String value) {
|
||||
try {
|
||||
is = new FileInputStream(new File(path, "server.properties"));
|
||||
@ -86,168 +98,168 @@ public class ServerProperties {
|
||||
HMCLog.warn("Failed to set property in server.properties", ex);
|
||||
} finally {
|
||||
try {
|
||||
if(is != null)
|
||||
if (is != null)
|
||||
is.close();
|
||||
} catch (IOException ex) {
|
||||
HMCLog.warn("Failed to close OutputStream for server.properties", ex);
|
||||
HMCLog.warn("Failed to close OutputStream for server.properties", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setProperty(String key, boolean value) {
|
||||
setProperty(key, value ? "true" : "false");
|
||||
}
|
||||
|
||||
|
||||
public void setProperty(String key, int value) {
|
||||
setProperty(key, String.valueOf(value));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setGeneratorSettings(String string) {
|
||||
setProperty("generator-settings", string);
|
||||
}
|
||||
|
||||
|
||||
public void setAllowNether(boolean bool) {
|
||||
setProperty("allow-nether", bool);
|
||||
}
|
||||
|
||||
|
||||
public void setLevelName(String string) {
|
||||
setProperty("level-name", string);
|
||||
}
|
||||
|
||||
|
||||
public void setEnableQuery(boolean bool) {
|
||||
setProperty("enable-query", bool);
|
||||
}
|
||||
|
||||
|
||||
public void setAllowFlight(boolean bool) {
|
||||
setProperty("allow-flight", bool);
|
||||
}
|
||||
|
||||
|
||||
public void setServerPort(int integer) {
|
||||
setProperty("server-port", integer);
|
||||
}
|
||||
|
||||
|
||||
public void setLevelType(String string) {
|
||||
setProperty("level-type", string);
|
||||
}
|
||||
|
||||
|
||||
public void setEnableRcon(boolean bool) {
|
||||
setProperty("enable-rcon", bool);
|
||||
}
|
||||
|
||||
|
||||
public void setForceGameMode(boolean bool) {
|
||||
setProperty("force-gamemode", bool);
|
||||
}
|
||||
|
||||
|
||||
public void setLevelSeed(String string) {
|
||||
setProperty("level-seed", string);
|
||||
}
|
||||
|
||||
|
||||
public void setServerIP(String string) {
|
||||
setProperty("server-ip", string);
|
||||
}
|
||||
|
||||
|
||||
public void setMaxBuildHeight(int integer) {
|
||||
setProperty("max-build-height", integer);
|
||||
}
|
||||
|
||||
|
||||
public void setSpawnNPCs(boolean bool) {
|
||||
setProperty("spawn-npcs", bool);
|
||||
}
|
||||
|
||||
|
||||
public void setWhiteList(boolean bool) {
|
||||
setProperty("white-list", bool);
|
||||
}
|
||||
|
||||
|
||||
public void setSpawnAnimals(boolean bool) {
|
||||
setProperty("spawn-animals", bool);
|
||||
}
|
||||
|
||||
|
||||
public void setTexturePack(String string) {
|
||||
setProperty("texture-pack", string);
|
||||
}
|
||||
|
||||
|
||||
public void setSnooperEnabled(boolean bool) {
|
||||
setProperty("snooper-enabled", bool);
|
||||
}
|
||||
|
||||
|
||||
public void setHardCore(boolean bool) {
|
||||
setProperty("hardcore", bool);
|
||||
}
|
||||
|
||||
|
||||
public void setOnlineMode(boolean bool) {
|
||||
setProperty("online-mode", bool);
|
||||
}
|
||||
|
||||
|
||||
public void setPVP(boolean bool) {
|
||||
setProperty("pvp", bool);
|
||||
}
|
||||
|
||||
|
||||
public void setDifficulty(int integer) {
|
||||
setProperty("difficulty", integer);
|
||||
}
|
||||
|
||||
|
||||
public void setServerName(String string) {
|
||||
setProperty("server-name", string);
|
||||
}
|
||||
|
||||
|
||||
public void setGameMode(int integer) {
|
||||
setProperty("gamemode", integer);
|
||||
}
|
||||
|
||||
|
||||
public void setMaxPlayers(int integer) {
|
||||
setProperty("max-players", integer);
|
||||
}
|
||||
|
||||
|
||||
public void setSpawnMonsters(boolean bool) {
|
||||
setProperty("spawn-monsters", bool);
|
||||
}
|
||||
|
||||
|
||||
public void setViewDistence(int integer) {
|
||||
setProperty("view-distance", integer);
|
||||
}
|
||||
|
||||
|
||||
public void setGenerateStructures(boolean bool) {
|
||||
setProperty("generate-structures", bool);
|
||||
}
|
||||
|
||||
|
||||
public void setMotd(String string) {
|
||||
setProperty("motd", string);
|
||||
}
|
||||
|
||||
|
||||
public static String getDefault() {
|
||||
return "generator-settings=\n" +
|
||||
"op-permission-level=4\n" +
|
||||
"allow-nether=true\n" +
|
||||
"level-name=world\n" +
|
||||
"enable-query=false\n" +
|
||||
"allow-flight=false\n" +
|
||||
"announce-player-achievements=true\n" +
|
||||
"server-port=25565\n" +
|
||||
"level-type=DEFAULT\n" +
|
||||
"enable-rcon=false\n" +
|
||||
"force-gamemode=false\n" +
|
||||
"level-seed=\n" +
|
||||
"server-ip=\n" +
|
||||
"max-build-height=256\n" +
|
||||
"spawn-npcs=true\n" +
|
||||
"white-list=false\n" +
|
||||
"spawn-animals=true\n" +
|
||||
"hardcore=false\n" +
|
||||
"snooper-enabled=true\n" +
|
||||
"online-mode=false\n" +
|
||||
"resource-pack=\n" +
|
||||
"pvp=true\n" +
|
||||
"difficulty=1\n" +
|
||||
"server-name=Unknown Server\n" +
|
||||
"enable-command-block=false\n" +
|
||||
"gamemode=0\n" +
|
||||
"player-idle-timeout=0\n" +
|
||||
"max-players=20\n" +
|
||||
"spawn-monsters=true\n" +
|
||||
"generate-structures=true\n" +
|
||||
"view-distance=10\n" +
|
||||
"spawn-protection=16\n" +
|
||||
"motd=A Minecraft Server";
|
||||
return "generator-settings=\n"
|
||||
+ "op-permission-level=4\n"
|
||||
+ "allow-nether=true\n"
|
||||
+ "level-name=world\n"
|
||||
+ "enable-query=false\n"
|
||||
+ "allow-flight=false\n"
|
||||
+ "announce-player-achievements=true\n"
|
||||
+ "server-port=25565\n"
|
||||
+ "level-type=DEFAULT\n"
|
||||
+ "enable-rcon=false\n"
|
||||
+ "force-gamemode=false\n"
|
||||
+ "level-seed=\n"
|
||||
+ "server-ip=\n"
|
||||
+ "max-build-height=256\n"
|
||||
+ "spawn-npcs=true\n"
|
||||
+ "white-list=false\n"
|
||||
+ "spawn-animals=true\n"
|
||||
+ "hardcore=false\n"
|
||||
+ "snooper-enabled=true\n"
|
||||
+ "online-mode=false\n"
|
||||
+ "resource-pack=\n"
|
||||
+ "pvp=true\n"
|
||||
+ "difficulty=1\n"
|
||||
+ "server-name=Unknown Server\n"
|
||||
+ "enable-command-block=false\n"
|
||||
+ "gamemode=0\n"
|
||||
+ "player-idle-timeout=0\n"
|
||||
+ "max-players=20\n"
|
||||
+ "spawn-monsters=true\n"
|
||||
+ "generate-structures=true\n"
|
||||
+ "view-distance=10\n"
|
||||
+ "spawn-protection=16\n"
|
||||
+ "motd=A Minecraft Server";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.settings;
|
||||
|
||||
@ -11,23 +23,23 @@ import java.util.ArrayList;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class Settings {
|
||||
|
||||
|
||||
public boolean checkUpdate;
|
||||
public String maxMemory;
|
||||
public String mainjar, bgPath, javaDir, javaArgs;
|
||||
public ArrayList<String> inactiveExtMods, inactiveCoreMods, inactivePlugins,
|
||||
inactiveWorlds;
|
||||
public ArrayList<Schedule> schedules;
|
||||
|
||||
|
||||
public Settings() {
|
||||
maxMemory = "1024";
|
||||
checkUpdate = true;
|
||||
schedules = new ArrayList<Schedule>();
|
||||
schedules = new ArrayList<>();
|
||||
mainjar = bgPath = javaDir = javaArgs = "";
|
||||
inactiveExtMods = new ArrayList<String>();
|
||||
inactiveCoreMods = new ArrayList<String>();
|
||||
inactivePlugins = new ArrayList<String>();
|
||||
inactiveWorlds = new ArrayList<String>();
|
||||
inactiveExtMods = new ArrayList<>();
|
||||
inactiveCoreMods = new ArrayList<>();
|
||||
inactivePlugins = new ArrayList<>();
|
||||
inactiveWorlds = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.settings;
|
||||
|
||||
@ -26,37 +38,36 @@ public class SettingsManager {
|
||||
static Gson gson;
|
||||
|
||||
public static void load() {
|
||||
gson = new Gson();
|
||||
File file = new File(IOUtils.currentDir(), "hmcsm.json");
|
||||
if (file.exists()) {
|
||||
try {
|
||||
String str = FileUtils.readFileToString(file);
|
||||
if (str == null || str.trim().equals("")) {
|
||||
init();
|
||||
} else {
|
||||
settings = gson.fromJson(str, Settings.class);
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
init();
|
||||
}
|
||||
} else {
|
||||
settings = new Settings();
|
||||
save();
|
||||
}
|
||||
gson = new Gson();
|
||||
File file = new File(IOUtils.currentDir(), "hmcsm.json");
|
||||
if (file.exists())
|
||||
try {
|
||||
String str = FileUtils.readFileToString(file);
|
||||
if (str == null || str.trim().equals(""))
|
||||
init();
|
||||
else
|
||||
settings = gson.fromJson(str, Settings.class);
|
||||
} catch (IOException ex) {
|
||||
init();
|
||||
}
|
||||
else {
|
||||
settings = new Settings();
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
settings = new Settings();
|
||||
isFirstLoad = true;
|
||||
save();
|
||||
settings = new Settings();
|
||||
isFirstLoad = true;
|
||||
save();
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
File f = new File(IOUtils.currentDir(), "hmcsm.json");
|
||||
try {
|
||||
FileUtils.write(f, gson.toJson(settings));
|
||||
} catch (IOException ex) {
|
||||
HMCLog.err("Failed to save settings.", ex);
|
||||
}
|
||||
File f = new File(IOUtils.currentDir(), "hmcsm.json");
|
||||
try {
|
||||
FileUtils.write(f, gson.toJson(settings));
|
||||
} catch (IOException ex) {
|
||||
HMCLog.err("Failed to save settings.", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,19 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
|
||||
package org.jackhuang.hellominecraft.svrmgr.settings;
|
||||
|
||||
/**
|
||||
@ -14,15 +24,15 @@ public class WhiteList extends PlayerList<WhiteList.WhiteListPlayer> {
|
||||
|
||||
@Override
|
||||
protected WhiteList.WhiteListPlayer newPlayer(String name) {
|
||||
return new WhiteList.WhiteListPlayer(name);
|
||||
return new WhiteList.WhiteListPlayer(name);
|
||||
}
|
||||
|
||||
|
||||
public static class WhiteListPlayer extends PlayerList.BasePlayer {
|
||||
|
||||
public WhiteListPlayer(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public WhiteListPlayer(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.threads;
|
||||
|
||||
@ -27,7 +39,7 @@ public class MonitorThread extends Thread {
|
||||
ArrayList<MonitorThreadListener> listeners;
|
||||
|
||||
public MonitorThread(InputStream is) {
|
||||
this.listeners = new ArrayList<MonitorThreadListener>(5);
|
||||
this.listeners = new ArrayList<>(5);
|
||||
try {
|
||||
br = new BufferedReader(new InputStreamReader(is, System.getProperty("sun.jnu.encoding", "gbk")));
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.threads;
|
||||
|
||||
@ -13,14 +25,14 @@ import org.jackhuang.hellominecraft.utils.EventHandler;
|
||||
* @author jack
|
||||
*/
|
||||
public class WaitForThread extends Thread {
|
||||
|
||||
|
||||
public final EventHandler<Integer> event = new EventHandler<>(this);
|
||||
Process p;
|
||||
|
||||
|
||||
public WaitForThread(Process p) {
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@ -31,5 +43,5 @@ public class WaitForThread extends Thread {
|
||||
event.execute(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.utils;
|
||||
|
||||
@ -12,7 +24,7 @@ import org.jackhuang.hellominecraft.utils.system.MessageBox;
|
||||
* @author jack
|
||||
*/
|
||||
public class FolderOpener {
|
||||
|
||||
|
||||
public static void open(String s) {
|
||||
try {
|
||||
File f = new File(s);
|
||||
@ -22,24 +34,29 @@ public class FolderOpener {
|
||||
MessageBox.Show("无法打开资源管理器: " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void openResourcePacks(String gameDir) {
|
||||
open(gameDir + "resourcepacks");
|
||||
}
|
||||
|
||||
public static void openTextutrePacks(String gameDir) {
|
||||
open(gameDir + "texturepacks");
|
||||
}
|
||||
|
||||
public static void openMods() {
|
||||
open(Utilities.try2GetPath("mods"));
|
||||
}
|
||||
|
||||
public static void openCoreMods() {
|
||||
open(Utilities.try2GetPath("coremods"));
|
||||
}
|
||||
|
||||
public static void openPlugins() {
|
||||
open(Utilities.try2GetPath("plugins"));
|
||||
}
|
||||
|
||||
public static void openConfig() {
|
||||
open(Utilities.try2GetPath("config"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.utils;
|
||||
|
||||
|
@ -1,9 +1,19 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
|
||||
package org.jackhuang.hellominecraft.svrmgr.utils;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
@ -25,24 +35,23 @@ public class IPGet extends Thread {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Document d = Jsoup.connect("http://www.ip138.com").get();
|
||||
Elements iframe = d.getElementsByTag("iframe");
|
||||
if(iframe.size() > 0) {
|
||||
String url = iframe.get(0).attr("src");
|
||||
String s = NetUtils.doGet(url, "GBK");
|
||||
Pattern p = Pattern.compile("\\[(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])){3}\\]");
|
||||
Matcher m = p.matcher(s);
|
||||
s = "";
|
||||
while(m.find()) {
|
||||
s += m.group() + ",";
|
||||
}
|
||||
dl.accept(s.substring(0, s.length()-1));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
HMCLog.warn("Failed to get ip from ip138.", ex);
|
||||
dl.accept("获取失败");
|
||||
}
|
||||
try {
|
||||
Document d = Jsoup.connect("http://www.ip138.com").get();
|
||||
Elements iframe = d.getElementsByTag("iframe");
|
||||
if (iframe.size() > 0) {
|
||||
String url = iframe.get(0).attr("src");
|
||||
String s = NetUtils.doGet(url, "GBK");
|
||||
Pattern p = Pattern.compile("\\[(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])){3}\\]");
|
||||
Matcher m = p.matcher(s);
|
||||
s = "";
|
||||
while (m.find())
|
||||
s += m.group() + ",";
|
||||
dl.accept(s.substring(0, s.length() - 1));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
HMCLog.warn("Failed to get ip from ip138.", ex);
|
||||
dl.accept("获取失败");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.utils;
|
||||
|
||||
@ -13,6 +25,7 @@ import java.util.zip.ZipFile;
|
||||
|
||||
/**
|
||||
* 判断mod类型
|
||||
*
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class ModType {
|
||||
@ -22,7 +35,7 @@ public class ModType {
|
||||
public static final int Forge = 2;
|
||||
public static final int ModLoader = 3;
|
||||
public static final int Unknown = 4;
|
||||
|
||||
|
||||
public static int getModType(String path) {
|
||||
return getModType(new File(path));
|
||||
}
|
||||
@ -35,42 +48,41 @@ public class ModType {
|
||||
zipFile = new ZipFile(path);
|
||||
String gbkPath;
|
||||
java.util.Enumeration e = zipFile.entries();
|
||||
while (e.hasMoreElements())
|
||||
{
|
||||
while (e.hasMoreElements()) {
|
||||
ZipEntry zipEnt = (ZipEntry) e.nextElement();
|
||||
if(zipEnt.isDirectory()) continue;
|
||||
if (zipEnt.isDirectory()) continue;
|
||||
gbkPath = zipEnt.getName();
|
||||
if("mcmod.info".equals(gbkPath))
|
||||
if ("mcmod.info".equals(gbkPath))
|
||||
return ForgeMod;
|
||||
else if("mcpmod.info".equals(gbkPath))
|
||||
else if ("mcpmod.info".equals(gbkPath))
|
||||
return Forge;
|
||||
else if("ModLoader.class".equals(gbkPath))
|
||||
else if ("ModLoader.class".equals(gbkPath))
|
||||
isModLoader = true;
|
||||
else if(gbkPath.trim().startsWith("mod_"))
|
||||
else if (gbkPath.trim().startsWith("mod_"))
|
||||
return ModLoaderMod;
|
||||
}
|
||||
}
|
||||
} catch(Exception e) {
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
} finally {
|
||||
try {
|
||||
if(zipFile != null)
|
||||
if (zipFile != null)
|
||||
zipFile.close();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(ModType.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (Throwable t) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
if(isModLoader)
|
||||
if (isModLoader)
|
||||
return ModLoaderMod;
|
||||
else
|
||||
return Unknown;
|
||||
}
|
||||
|
||||
|
||||
public static String getModTypeShowName(int type) {
|
||||
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/jackhuang/hellominecraftlauncher/I18N"); // NOI18N
|
||||
switch(type) {
|
||||
switch (type) {
|
||||
case ForgeMod:
|
||||
return bundle.getString("ForgeMod");
|
||||
case Forge:
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.utils;
|
||||
|
||||
@ -118,4 +130,4 @@ public class MonitorInfoBean {
|
||||
public void setCpuRatio(double cpuRatio) {
|
||||
this.cpuRatio = cpuRatio;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.utils;
|
||||
|
||||
@ -56,11 +68,10 @@ public class MonitorServiceImpl implements IMonitorService {
|
||||
for (parentThread = Thread.currentThread().getThreadGroup(); parentThread.getParent() != null; parentThread = parentThread.getParent());
|
||||
int totalThread = parentThread.activeCount();
|
||||
double cpuRatio = 0;
|
||||
if (osName.toLowerCase().startsWith("windows")) {
|
||||
if (osName.toLowerCase().startsWith("windows"))
|
||||
cpuRatio = this.getCpuRatioForWindows();
|
||||
} else {
|
||||
else
|
||||
cpuRatio = getCpuRateForLinux();
|
||||
}
|
||||
// 构造返回对象
|
||||
MonitorInfoBean infoBean = new MonitorInfoBean();
|
||||
infoBean.setFreeMemory(freeMemory);
|
||||
@ -135,15 +146,12 @@ public class MonitorServiceImpl implements IMonitorService {
|
||||
private static void freeResource(InputStream is, InputStreamReader isr,
|
||||
BufferedReader br) {
|
||||
try {
|
||||
if (is != null) {
|
||||
if (is != null)
|
||||
is.close();
|
||||
}
|
||||
if (isr != null) {
|
||||
if (isr != null)
|
||||
isr.close();
|
||||
}
|
||||
if (br != null) {
|
||||
if (br != null)
|
||||
br.close();
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
System.out.println(ioe.getMessage());
|
||||
}
|
||||
@ -166,9 +174,8 @@ public class MonitorServiceImpl implements IMonitorService {
|
||||
long idletime = c1[0] - c0[0];
|
||||
long busytime = c1[1] - c0[1];
|
||||
return (double) PERCENT * (busytime) / (busytime + idletime);
|
||||
} else {
|
||||
} else
|
||||
return 0.0;
|
||||
}
|
||||
} catch (IOException | InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
return 0.0;
|
||||
@ -189,9 +196,8 @@ public class MonitorServiceImpl implements IMonitorService {
|
||||
InputStreamReader ir = new InputStreamReader(proc.getInputStream());
|
||||
LineNumberReader input = new LineNumberReader(ir);
|
||||
String line = input.readLine();
|
||||
if (line == null || line.length() < FAULTLENGTH) {
|
||||
if (line == null || line.length() < FAULTLENGTH)
|
||||
return null;
|
||||
}
|
||||
int capidx = line.indexOf("Caption");
|
||||
int cmdidx = line.indexOf("CommandLine");
|
||||
int rocidx = line.indexOf("ReadOperationCount");
|
||||
@ -202,33 +208,27 @@ public class MonitorServiceImpl implements IMonitorService {
|
||||
long kneltime = 0;
|
||||
long usertime = 0;
|
||||
while ((line = input.readLine()) != null) {
|
||||
if (line.length() < wocidx) {
|
||||
if (line.length() < wocidx)
|
||||
continue;
|
||||
}
|
||||
// 字段出现顺序:Caption,CommandLine,KernelModeTime,ReadOperationCount,
|
||||
// ThreadCount,UserModeTime,WriteOperation
|
||||
String caption = StrUtils.substring(line, capidx, cmdidx - 1).trim();
|
||||
String cmd = StrUtils.substring(line, cmdidx, kmtidx - 1).trim();
|
||||
if (cmd.contains("wmic.exe")) {
|
||||
if (cmd.contains("wmic.exe"))
|
||||
continue;
|
||||
}
|
||||
String s1 = StrUtils.substring(line, kmtidx, rocidx - 1).trim();
|
||||
String s2 = StrUtils.substring(line, umtidx, wocidx - 1).trim();
|
||||
if (caption.equals("System Idle Process") || caption.equals("System")) {
|
||||
if (s1.length() > 0) {
|
||||
if (s1.length() > 0)
|
||||
idletime += Long.parseLong(s1);
|
||||
}
|
||||
if (s2.length() > 0) {
|
||||
if (s2.length() > 0)
|
||||
idletime += Long.parseLong(s2);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (s1.length() > 0) {
|
||||
if (s1.length() > 0)
|
||||
kneltime += Long.parseLong(s1);
|
||||
}
|
||||
if (s2.length() > 0) {
|
||||
if (s2.length() > 0)
|
||||
usertime += Long.parseLong(s2);
|
||||
}
|
||||
}
|
||||
retn[0] = idletime;
|
||||
retn[1] = kneltime + usertime;
|
||||
@ -265,4 +265,4 @@ public class MonitorServiceImpl implements IMonitorService {
|
||||
System.out.println("已使用的物理内存=" + monitorInfo.getUsedMemory() + "kb");
|
||||
System.out.println("线程总数=" + monitorInfo.getTotalThread() + "kb");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.utils;
|
||||
|
||||
@ -51,7 +63,7 @@ public class Utilities {
|
||||
}
|
||||
|
||||
public static ArrayList<String> findAllFile(File f) {
|
||||
ArrayList<String> arr = new ArrayList<String>();
|
||||
ArrayList<String> arr = new ArrayList<>();
|
||||
if (!f.exists()) {
|
||||
return arr;
|
||||
}
|
||||
@ -68,7 +80,7 @@ public class Utilities {
|
||||
}
|
||||
|
||||
public static ArrayList<String> findAllDir(File f) {
|
||||
ArrayList<String> arr = new ArrayList<String>();
|
||||
ArrayList<String> arr = new ArrayList<>();
|
||||
if (f.isDirectory()) {
|
||||
File[] f1 = f.listFiles();
|
||||
int len = f1.length;
|
||||
@ -104,10 +116,7 @@ public class Utilities {
|
||||
|
||||
public static boolean is16Folder(String path) {
|
||||
path = Utilities.addSeparator(path);
|
||||
if (new File(path + "versions").exists()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return new File(path + "versions").exists();
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String s) {
|
||||
@ -184,11 +193,11 @@ public class Utilities {
|
||||
dp.browse(uri);
|
||||
isBrowsed = true;
|
||||
}
|
||||
} catch (java.lang.NullPointerException e) {
|
||||
} catch (java.lang.NullPointerException | java.io.IOException e) {
|
||||
//此为uri为空时抛出异常
|
||||
} catch (java.io.IOException e) {
|
||||
//此为无法获取系统默认浏览器
|
||||
}
|
||||
|
||||
}
|
||||
return isBrowsed;
|
||||
}
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.views;
|
||||
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.views;
|
||||
|
||||
@ -19,7 +31,7 @@ import javax.swing.JTextField;
|
||||
* @author huangyuhui
|
||||
*/
|
||||
public class InputDialog extends javax.swing.JDialog {
|
||||
|
||||
|
||||
ArrayList<JTextField> textFields;
|
||||
ArrayList<JPanel> panels;
|
||||
public String[] result;
|
||||
@ -30,31 +42,26 @@ public class InputDialog extends javax.swing.JDialog {
|
||||
public InputDialog(java.awt.Frame parent, boolean modal, String[] messages) {
|
||||
super(parent, modal);
|
||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||
|
||||
textFields = new ArrayList<JTextField>();
|
||||
panels = new ArrayList<JPanel>();
|
||||
|
||||
textFields = new ArrayList<>();
|
||||
panels = new ArrayList<>();
|
||||
jButton1 = new javax.swing.JButton();
|
||||
jButton1.setText("确认");
|
||||
jButton1.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
result = new String[textFields.size()];
|
||||
for(int i = 0; i < textFields.size(); i++)
|
||||
result[i] = textFields.get(i).getText();
|
||||
InputDialog.this.dispose();
|
||||
}
|
||||
jButton1.addActionListener((ActionEvent e) -> {
|
||||
result = new String[textFields.size()];
|
||||
for (int i = 0; i < textFields.size(); i++)
|
||||
result[i] = textFields.get(i).getText();
|
||||
InputDialog.this.dispose();
|
||||
});
|
||||
for(String s : messages) {
|
||||
for (String s : messages)
|
||||
makeNewField(s);
|
||||
}
|
||||
makeLayout();
|
||||
Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
setLocation((scrSize.width - this.getWidth()) / 2,
|
||||
(scrSize.height - this.getHeight()) / 2);
|
||||
}
|
||||
|
||||
void makeNewField(String message) {
|
||||
|
||||
final void makeNewField(String message) {
|
||||
JLabel label = new JLabel();
|
||||
label.setText(message);
|
||||
JTextField textField = new JTextField();
|
||||
@ -64,55 +71,55 @@ public class InputDialog extends javax.swing.JDialog {
|
||||
javax.swing.GroupLayout jPanelLayout = new javax.swing.GroupLayout(panel);
|
||||
panel.setLayout(jPanelLayout);
|
||||
jPanelLayout.setHorizontalGroup(
|
||||
jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanelLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanelLayout.createSequentialGroup()
|
||||
.addComponent(label)
|
||||
.addGap(0, 0, Short.MAX_VALUE))
|
||||
.addComponent(textField))
|
||||
.addContainerGap())
|
||||
jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanelLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanelLayout.createSequentialGroup()
|
||||
.addComponent(label)
|
||||
.addGap(0, 0, Short.MAX_VALUE))
|
||||
.addComponent(textField))
|
||||
.addContainerGap())
|
||||
);
|
||||
jPanelLayout.setVerticalGroup(
|
||||
jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanelLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(label)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(textField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
jPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(jPanelLayout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addComponent(label)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(textField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
);
|
||||
textFields.add(textField);
|
||||
panels.add(panel);
|
||||
}
|
||||
|
||||
void makeLayout() {
|
||||
|
||||
final void makeLayout() {
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||
getContentPane().setLayout(layout);
|
||||
GroupLayout.ParallelGroup g = layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING);
|
||||
for(JPanel p : panels)
|
||||
for (JPanel p : panels)
|
||||
g.addComponent(p, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE);
|
||||
g.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addGap(0, 0, Short.MAX_VALUE)
|
||||
.addComponent(jButton1));
|
||||
.addGap(0, 0, Short.MAX_VALUE)
|
||||
.addComponent(jButton1));
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(g)
|
||||
.addContainerGap())
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(g)
|
||||
.addContainerGap())
|
||||
);
|
||||
GroupLayout.SequentialGroup g2 = layout.createSequentialGroup()
|
||||
.addContainerGap();
|
||||
for(JPanel p : panels)
|
||||
for (JPanel p : panels)
|
||||
g2 = g2.addComponent(p, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED);
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED);
|
||||
g2 = g2.addComponent(jButton1)
|
||||
.addContainerGap();
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(g2)
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(g2)
|
||||
);
|
||||
|
||||
pack();
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.views;
|
||||
|
||||
|
@ -1,6 +1,18 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
* Copyright 2013 huangyuhui <huanghongxun2008@126.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program.
|
||||
*/
|
||||
package org.jackhuang.hellominecraft.svrmgr.views;
|
||||
|
||||
@ -36,12 +48,11 @@ public class PluginInfoDialog extends javax.swing.JDialog {
|
||||
lblWebsite.setText(pi.link);
|
||||
//SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
DefaultTableModel model = (DefaultTableModel) lstPluginInfo.getModel();
|
||||
for (PluginVersion v : pi.versions) {
|
||||
for (PluginVersion v : pi.versions)
|
||||
model.addRow(new Object[]{
|
||||
v.date, v.version, v.filename, StrUtils.parseParams("", v.game_versions.toArray(), ", "),
|
||||
v.type
|
||||
});
|
||||
}
|
||||
lstPluginInfo.updateUI();
|
||||
}
|
||||
|
||||
@ -216,14 +227,13 @@ public class PluginInfoDialog extends javax.swing.JDialog {
|
||||
|
||||
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
|
||||
int index = lstPluginInfo.getSelectedRow();
|
||||
if (index == -1) {
|
||||
if (index == -1)
|
||||
return;
|
||||
}
|
||||
String url = pi.versions.get(index).download;
|
||||
TaskWindow.getInstance()
|
||||
.addTask(new FileDownloadTask(url, new File(Utilities.getGameDir() + "plugins"
|
||||
+ File.separator + pi.versions.get(index).filename)))
|
||||
.start();
|
||||
.addTask(new FileDownloadTask(url, new File(Utilities.getGameDir() + "plugins"
|
||||
+ File.separator + pi.versions.get(index).filename)))
|
||||
.start();
|
||||
}//GEN-LAST:event_jButton1ActionPerformed
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
|
Loading…
x
Reference in New Issue
Block a user