Clean up again

This commit is contained in:
huangyuhui
2017-01-27 22:41:34 +08:00
parent 809d7378e2
commit 972c4758b1
120 changed files with 353 additions and 1725 deletions

View File

@@ -18,8 +18,6 @@
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 javax.swing.UnsupportedLookAndFeelException;
@@ -60,13 +58,7 @@ public class Main {
new MainWindow().setVisible(true);
} catch (Throwable t) {
HMCLog.err("There's something wrong when running server holder.", t);
LogWindow.INSTANCE.clean();
LogWindow.INSTANCE.warning("开服器崩溃了QAQ");
StringWriter trace = new StringWriter();
t.printStackTrace(new PrintWriter(trace));
LogWindow.INSTANCE.warning(trace.toString());
LogWindow.INSTANCE.setVisible(true);
LogWindow.INSTANCE.showAsCrashWindow(false);
System.exit(-1);
}

View File

@@ -122,7 +122,7 @@ public class ForgeInstaller {
File packFile = new File(gameDir, "libraries" + File.separator + library.formatted + ".pack.xz");
if (packFile.exists() && packFile.isFile())
try {
unpackLibrary(lib.getParentFile(), IOUtils.readFully(FileUtils.openInputStream(packFile)).toByteArray());
unpackLibrary(lib.getParentFile(), IOUtils.toByteArray(FileUtils.openInputStream(packFile)));
if (!checksumValid(lib, Arrays.asList(library.checksums)))
badLibs.add(library.name);
} catch (IOException e) {
@@ -139,7 +139,7 @@ public class ForgeInstaller {
if (output.exists())
output.delete();
byte[] decompressed = IOUtils.readFully(new XZInputStream(new ByteArrayInputStream(data))).toByteArray();
byte[] decompressed = IOUtils.toByteArray(new XZInputStream(new ByteArrayInputStream(data)));
String end = new String(decompressed, decompressed.length - 4, 4);
if (!end.equals("SIGN")) {
@@ -165,7 +165,7 @@ public class ForgeInstaller {
private static boolean checksumValid(File libPath, List<String> checksums) {
try {
byte[] fileData = IOUtils.readFully(FileUtils.openInputStream(libPath)).toByteArray();
byte[] fileData = IOUtils.toByteArray(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);
@@ -184,7 +184,7 @@ public class ForgeInstaller {
try (JarInputStream jar = new JarInputStream(new ByteArrayInputStream(data))) {
JarEntry entry = jar.getNextJarEntry();
while (entry != null) {
byte[] eData = IOUtils.readFully(jar).toByteArray();
byte[] eData = IOUtils.toByteArray(jar);
if (entry.getName().equals("checksums.sha1"))
hashes = new String(eData, Charset.forName("UTF-8")).split("\n");

View File

@@ -24,7 +24,6 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
@@ -47,6 +46,7 @@ import org.jackhuang.hellominecraft.svrmgr.util.WaitForThread;
import org.jackhuang.hellominecraft.svrmgr.util.Utilities;
import org.jackhuang.hellominecraft.util.Event;
import org.jackhuang.hellominecraft.util.EventHandler;
import org.jackhuang.hellominecraft.util.code.Charsets;
import org.jackhuang.hellominecraft.util.func.Consumer;
/**
@@ -54,7 +54,7 @@ import org.jackhuang.hellominecraft.util.func.Consumer;
* @author huangyuhui
*/
public class Server implements Event<Integer>, MonitorThread.MonitorThreadListener,
ActionListener {
ActionListener {
private static Server instance;
private static boolean disactived = false;
@@ -125,17 +125,13 @@ public class Server implements Event<Integer>, MonitorThread.MonitorThreadListen
pb.directory(new File(SettingsManager.settings.mainjar).getParentFile());
try {
disactiveMods(SettingsManager.settings.inactiveExtMods,
SettingsManager.settings.inactiveCoreMods,
SettingsManager.settings.inactivePlugins);
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()));
}
bw = new BufferedWriter(new OutputStreamWriter(server.getOutputStream(), Charsets.toCharset()));
isRunning = true;
startedEvent.execute(null);
sendStatus("*** 启动服务端中 ***");
@@ -244,7 +240,7 @@ public class Server implements Event<Integer>, MonitorThread.MonitorThreadListen
}
private static void disactiveMods(ArrayList<String> inactiveExtMods,
ArrayList<String> inactiveCoreMods, ArrayList<String> inactivePlugins) {
ArrayList<String> inactiveCoreMods, ArrayList<String> inactivePlugins) {
disactiveModsByType(inactiveExtMods, "mods");
disactiveModsByType(inactiveCoreMods, "coremods");
disactiveModsByType(inactivePlugins, "plugins");
@@ -267,7 +263,7 @@ public class Server implements Event<Integer>, MonitorThread.MonitorThreadListen
String name = file.getName();
if ((!paramArrayOfString.contains(name))
|| ((!name.toLowerCase().endsWith(".zip")) && (!name.toLowerCase().endsWith(".jar"))))
|| ((!name.toLowerCase().endsWith(".zip")) && (!name.toLowerCase().endsWith(".jar"))))
continue;
String newName = name + "X";

View File

@@ -90,7 +90,7 @@ public abstract class PlayerList<T extends BasePlayer> {
op = null;
if (txt.exists())
try {
initByText(FileUtils.readIgnoreFileNotFound(txt));
initByText(FileUtils.read(txt));
if (op != null)
player.addAll(op);
} catch (IOException e) {
@@ -100,7 +100,7 @@ public abstract class PlayerList<T extends BasePlayer> {
}
public void saveAsText(File file) throws IOException {
FileUtils.write(file, StrUtils.parseParams("", op, System.getProperty("line.separator")));
FileUtils.write(file, StrUtils.parseParams("", op.toArray(), System.getProperty("line.separator")));
}
public void saveAsJson(File file) throws IOException {

View File

@@ -26,6 +26,7 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import org.jackhuang.hellominecraft.util.logging.HMCLog;
import org.jackhuang.hellominecraft.util.system.FileUtils;
import org.jackhuang.hellominecraft.util.system.IOUtils;
/**
@@ -58,7 +59,7 @@ public class ServerProperties {
public String getProperty(String key, String defaultValue) {
try {
is = new FileInputStream(new File(path, "server.properties"));
is = FileUtils.openInputStream(new File(path, "server.properties"));
p = new Properties();
p.load(is);
return p.getProperty(key, defaultValue);
@@ -84,12 +85,12 @@ public class ServerProperties {
public void setProperty(String key, String value) {
try {
is = new FileInputStream(new File(path, "server.properties"));
is = FileUtils.openInputStream(new File(path, "server.properties"));
p = new Properties();
p.load(is);
p.setProperty(key, value);
SimpleDateFormat f = new SimpleDateFormat("E M d HH:mm:ss z y");
p.store(new FileOutputStream(new File(path, "server.properties")),
p.store(FileUtils.openOutputStream(new File(path, "server.properties")),
"Minecraft server properties\n" + f.format(new Date()));
} catch (IOException ex) {
HMCLog.warn("Failed to set property in server.properties", ex);

View File

@@ -86,7 +86,7 @@ import org.jackhuang.hellominecraft.svrmgr.util.IPGet;
import org.jackhuang.hellominecraft.svrmgr.util.Utilities;
import org.jackhuang.hellominecraft.util.ui.SwingUtils;
import org.jackhuang.hellominecraft.svrmgr.util.version.MinecraftRemoteVersion;
import org.jackhuang.hellominecraft.lookandfeel.comp.ConstomButton;
import org.jackhuang.hellominecraft.lookandfeel.ConstomButton;
import org.jackhuang.hellominecraft.util.Event;
import org.jackhuang.hellominecraft.util.StrUtils;

View File

@@ -21,8 +21,8 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import org.jackhuang.hellominecraft.util.code.Charsets;
import org.jackhuang.hellominecraft.util.logging.HMCLog;
/**
@@ -42,11 +42,7 @@ public class MonitorThread extends Thread {
public MonitorThread(InputStream is) {
this.listeners = new ArrayList<>(5);
try {
br = new BufferedReader(new InputStreamReader(is, System.getProperty("sun.jnu.encoding", "gbk")));
} catch (UnsupportedEncodingException ex) {
br = new BufferedReader(new InputStreamReader(is));
}
br = new BufferedReader(new InputStreamReader(is, Charsets.toCharset(System.getProperty("sun.jnu.encoding", "gbk"))));
}
public void addListener(MonitorThreadListener l) {