another minor change - makes xx% output nicer by rewriting existing line.

This commit is contained in:
Morlok8k 2012-08-01 20:30:27 -07:00
parent d50178faeb
commit cdf14f9f4f

View File

@ -24,37 +24,37 @@ public class MLG_Server {
boolean warning = false;
boolean warningsWeCanIgnore = false;
final boolean ignoreWarningsOriginal = Main.ignoreWarnings;
// monitor output and print to console where required.
// STOP the server when it's done.
if (alternate) { // Alternate - a replication (slightly stripped down) of MLG 1.3.0's code. simplest code possible.
Main.out("Alternate Launch");
Process process = Main.minecraft.start();
byte[] stop = { 's', 't', 'o', 'p', '\r', '\n' };
// monitor output and print to console where required.
// STOP the server when it's done.
BufferedReader pOut =
new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = pOut.readLine()) != null) {
while ((line = pOut.readLine()) != null) { // readLine() returns null when the process exits
line = line.trim(); //Trim spaces off the beginning and end, if any.
System.out.println(line);
if (line.contains(Main.doneText)) { // EDITED By Morlok8k for Minecraft 1.3+ Beta
OutputStream outputStream = process.getOutputStream();
Main.out("Stopping server... (Please Wait...)");
outputStream.write(stop);
outputStream.flush();
}
}
// readLine() returns null when the process exits
// End while loop
} else { // start minecraft server normally!
Process process = Main.minecraft.start();
if (Main.verbose) {
@ -65,36 +65,25 @@ public class MLG_Server {
if (Main.verbose) {
Main.out("Accessing Server Output...");
}
String line = null;
String shortLine = null;
String outTmp = "";
String outTmp2 = null;
byte[] stop = { 's', 't', 'o', 'p', '\r', '\n' }; // Moved here, so this code wont run every loop, thus Faster!
// and no, i can't use a string here!
byte[] saveAll = { 's', 'a', 'v', 'e', '-', 'a', 'l', 'l', '\r', '\n' };
boolean prepTextFirst = true;
OutputStream outputStream = process.getOutputStream(); // moved here to remove some redundancy
/*
2012-02-29 03:50:28 [INFO] Converting map!
Scanning folders...
Total conversion count is 9
2012-02-29 03:50:29 [INFO] Converting... 8%
2012-02-29 03:50:30 [INFO] Converting... 9%
2012-02-29 03:50:31 [INFO] Converting... 10%
2012-02-29 03:50:32 [INFO] Converting... 12%
2012-02-29 03:50:33 [INFO] Converting... 13%
*/
boolean convertedMapFormattingFlag = false; // This allows MLG to track if we converted a map to a new format (such as Chunk-file -> McRegion, or McRegion -> Anvil)
// just so it gets a line ending after the % output finishes
while ((line = pOut.readLine()) != null) {
while ((line = pOut.readLine()) != null) { // readLine() returns null when the process exits
int posBracket = line.lastIndexOf("]");
if (posBracket != -1) {
shortLine = line.substring(posBracket + 2);
@ -102,86 +91,98 @@ public class MLG_Server {
} else {
shortLine = line;
}
line = line.trim();
if (Main.verbose) {
Main.outS(shortLine);
} else if (line.toLowerCase().contains("saving")) {
Main.outS(shortLine);
//} else if (line.toLowerCase().contains("saving")) { //this was just clutter
// Main.outS(shortLine);
} else if (line.contains(Main.preparingText) || line.contains("Converting...")) {
if (line.contains("Converting...")) {
convertedMapFormattingFlag = true;
}
outTmp2 = line.substring(line.length() - 3, line.length());
outTmp2 = outTmp2.trim(); //we are removing extra spaces here
if (outTmp.equals(outTmp2)) {
//instead of printing the same number, we add another dot
Main.outP(".");
//if (outTmp.equals(outTmp2)) {
//instead of printing the same number, we add another dot
//Main.outP(".");
//} else {
outTmp = outTmp2;
if (prepTextFirst) {
Main.outP(Main.MLG + outTmp + "...");
prepTextFirst = false;
} else {
outTmp = outTmp2;
if (prepTextFirst) {
Main.outP(Main.MLG + outTmp + "...");
prepTextFirst = false;
} else {
Main.outP(" " + outTmp + "...");
}
//Main.outP(" " + outTmp + "...");
Main.outP("\r" + Main.MLG + outTmp + "..."); //here we use \r to go back to the previous line, and rewrite it
}
//}
} else if (line.contains(Main.preparingLevel)) {
prepTextFirst = true;
if (convertedMapFormattingFlag == true) {
Main.outP(Main.newLine);
convertedMapFormattingFlag = false;
}
if (line.contains("level 0")) { // "Preparing start region for level 0"
Main.outP(Main.MLG + Main.worldName + ": " + Main.level_0 + ":" + Main.newLine);
Main.outP(Main.MLG + Main.worldName + ": " + Main.level_0 + ":"
+ Main.newLine);
} else if (line.contains("level 1")) { // "Preparing start region for level 1"
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_1 + ":" + Main.newLine);
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_1
+ ":" + Main.newLine);
} else if (line.contains("level 2")) { // "Preparing start region for level 2"
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_2 + ":" + Main.newLine);
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_2
+ ":" + Main.newLine);
} else if (line.contains("level 3")) { // "Preparing start region for level 3"
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_3 + ":" + Main.newLine);
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_3
+ ":" + Main.newLine);
} else if (line.contains("level 4")) { // "Preparing start region for level 4"
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_4 + ":" + Main.newLine);
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_4
+ ":" + Main.newLine);
} else if (line.contains("level 5")) { // "Preparing start region for level 5"
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_5 + ":" + Main.newLine);
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_5
+ ":" + Main.newLine);
} else if (line.contains("level 6")) { // "Preparing start region for level 6"
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_6 + ":" + Main.newLine);
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_6
+ ":" + Main.newLine);
} else if (line.contains("level 7")) { // "Preparing start region for level 7"
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_7 + ":" + Main.newLine);
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_7
+ ":" + Main.newLine);
} else if (line.contains("level 8")) { // "Preparing start region for level 8"
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_8 + ":" + Main.newLine);
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_8
+ ":" + Main.newLine);
} else if (line.contains("level 9")) { // "Preparing start region for level 9"
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_9 + ":" + Main.newLine);
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_9
+ ":" + Main.newLine);
} else {
Main.outP(Main.newLine + Main.MLG + shortLine);
}
} else if (line.contains("server version") || line.contains("Converting map!")) { //TODO: add to .conf
Main.outS(shortLine);
if (line.contains("server version") && Main.MC_Server_Version.isEmpty()) {
// if server version, save string to variable, for use in arraylist save file.
Main.MC_Server_Version = shortLine;
}
}
if (line.contains(Main.doneText)) { // now this is configurable!
Main.outP(Main.newLine);
Main.outS(line.substring(line.lastIndexOf("]") + 2, line.indexOf("!")));
if (Main.waitSave) {
Main.out("Waiting 30 seconds to save...");
int count = 1;
while (count <= 30) {
Main.outP(".");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
@ -194,19 +195,19 @@ public class MLG_Server {
Main.out("Saving server data...");
outputStream.write(saveAll);
outputStream.flush();
Main.out("Stopping server... (Please Wait...)");
// OutputStream outputStream = process.getOutputStream();
outputStream.write(stop);
outputStream.flush();
// outputStream.close();
if (Main.waitSave) {
Main.out("Waiting 10 seconds to save.");
int count = 1;
while (count <= 10) {
Main.outP(".");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
@ -217,7 +218,7 @@ public class MLG_Server {
Main.out("");
}
}
//Here we want to ignore the most common warning: "Can't keep up!"
if (line.contains("Can't keep up!")) { //TODO: add to .conf
warningsWeCanIgnore = true; //[WARNING] Can't keep up! Did the system time change, or is the server overloaded?
@ -235,7 +236,7 @@ public class MLG_Server {
}
warning = true;
}
if (Main.ignoreWarnings == false) {
if (line.contains("[WARNING]")) { // If we have a warning, stop...
Main.out("");
@ -277,23 +278,23 @@ public class MLG_Server {
// Quit!
}
}
if (warningsWeCanIgnore) {
Main.ignoreWarnings = ignoreWarningsOriginal;
}
}
if (warning == true) { // in 1.4.4 we had a issue. tried to write stop twice, but we had closed the stream already. this, and other lines should fix this.
outputStream.flush();
//outputStream.close();
//System.exit(1);
serverSuccess = false;
}
outputStream.close();
}
// readLine() returns null when the process exits
// while loop has finished now.
return serverSuccess;
}