another minor change - makes xx% output nicer by rewriting existing line.
This commit is contained in:
parent
d50178faeb
commit
cdf14f9f4f
@ -24,37 +24,37 @@ public class MLG_Server {
|
|||||||
boolean warning = false;
|
boolean warning = false;
|
||||||
boolean warningsWeCanIgnore = false;
|
boolean warningsWeCanIgnore = false;
|
||||||
final boolean ignoreWarningsOriginal = Main.ignoreWarnings;
|
final boolean ignoreWarningsOriginal = Main.ignoreWarnings;
|
||||||
|
|
||||||
// monitor output and print to console where required.
|
// monitor output and print to console where required.
|
||||||
// STOP the server when it's done.
|
// 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.
|
if (alternate) { // Alternate - a replication (slightly stripped down) of MLG 1.3.0's code. simplest code possible.
|
||||||
Main.out("Alternate Launch");
|
Main.out("Alternate Launch");
|
||||||
Process process = Main.minecraft.start();
|
Process process = Main.minecraft.start();
|
||||||
|
|
||||||
byte[] stop = { 's', 't', 'o', 'p', '\r', '\n' };
|
byte[] stop = { 's', 't', 'o', 'p', '\r', '\n' };
|
||||||
|
|
||||||
// monitor output and print to console where required.
|
// monitor output and print to console where required.
|
||||||
// STOP the server when it's done.
|
// STOP the server when it's done.
|
||||||
BufferedReader pOut =
|
BufferedReader pOut =
|
||||||
new BufferedReader(new InputStreamReader(process.getInputStream()));
|
new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
String line;
|
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.
|
line = line.trim(); //Trim spaces off the beginning and end, if any.
|
||||||
|
|
||||||
System.out.println(line);
|
System.out.println(line);
|
||||||
if (line.contains(Main.doneText)) { // EDITED By Morlok8k for Minecraft 1.3+ Beta
|
if (line.contains(Main.doneText)) { // EDITED By Morlok8k for Minecraft 1.3+ Beta
|
||||||
OutputStream outputStream = process.getOutputStream();
|
OutputStream outputStream = process.getOutputStream();
|
||||||
|
|
||||||
Main.out("Stopping server... (Please Wait...)");
|
Main.out("Stopping server... (Please Wait...)");
|
||||||
outputStream.write(stop);
|
outputStream.write(stop);
|
||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// readLine() returns null when the process exits
|
// End while loop
|
||||||
|
|
||||||
} else { // start minecraft server normally!
|
} else { // start minecraft server normally!
|
||||||
Process process = Main.minecraft.start();
|
Process process = Main.minecraft.start();
|
||||||
if (Main.verbose) {
|
if (Main.verbose) {
|
||||||
@ -65,36 +65,25 @@ public class MLG_Server {
|
|||||||
if (Main.verbose) {
|
if (Main.verbose) {
|
||||||
Main.out("Accessing Server Output...");
|
Main.out("Accessing Server Output...");
|
||||||
}
|
}
|
||||||
|
|
||||||
String line = null;
|
String line = null;
|
||||||
String shortLine = null;
|
String shortLine = null;
|
||||||
String outTmp = "";
|
String outTmp = "";
|
||||||
String outTmp2 = null;
|
String outTmp2 = null;
|
||||||
|
|
||||||
byte[] stop = { 's', 't', 'o', 'p', '\r', '\n' }; // Moved here, so this code wont run every loop, thus Faster!
|
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!
|
// and no, i can't use a string here!
|
||||||
|
|
||||||
byte[] saveAll = { 's', 'a', 'v', 'e', '-', 'a', 'l', 'l', '\r', '\n' };
|
byte[] saveAll = { 's', 'a', 'v', 'e', '-', 'a', 'l', 'l', '\r', '\n' };
|
||||||
|
|
||||||
boolean prepTextFirst = true;
|
boolean prepTextFirst = true;
|
||||||
|
|
||||||
OutputStream outputStream = process.getOutputStream(); // moved here to remove some redundancy
|
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)
|
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
|
// 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("]");
|
int posBracket = line.lastIndexOf("]");
|
||||||
if (posBracket != -1) {
|
if (posBracket != -1) {
|
||||||
shortLine = line.substring(posBracket + 2);
|
shortLine = line.substring(posBracket + 2);
|
||||||
@ -102,86 +91,98 @@ public class MLG_Server {
|
|||||||
} else {
|
} else {
|
||||||
shortLine = line;
|
shortLine = line;
|
||||||
}
|
}
|
||||||
|
|
||||||
line = line.trim();
|
line = line.trim();
|
||||||
|
|
||||||
if (Main.verbose) {
|
if (Main.verbose) {
|
||||||
Main.outS(shortLine);
|
Main.outS(shortLine);
|
||||||
} else if (line.toLowerCase().contains("saving")) {
|
//} else if (line.toLowerCase().contains("saving")) { //this was just clutter
|
||||||
Main.outS(shortLine);
|
// Main.outS(shortLine);
|
||||||
} else if (line.contains(Main.preparingText) || line.contains("Converting...")) {
|
} else if (line.contains(Main.preparingText) || line.contains("Converting...")) {
|
||||||
if (line.contains("Converting...")) {
|
if (line.contains("Converting...")) {
|
||||||
convertedMapFormattingFlag = true;
|
convertedMapFormattingFlag = true;
|
||||||
}
|
}
|
||||||
outTmp2 = line.substring(line.length() - 3, line.length());
|
outTmp2 = line.substring(line.length() - 3, line.length());
|
||||||
outTmp2 = outTmp2.trim(); //we are removing extra spaces here
|
outTmp2 = outTmp2.trim(); //we are removing extra spaces here
|
||||||
if (outTmp.equals(outTmp2)) {
|
|
||||||
//instead of printing the same number, we add another dot
|
//if (outTmp.equals(outTmp2)) {
|
||||||
Main.outP(".");
|
//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 {
|
} else {
|
||||||
outTmp = outTmp2;
|
//Main.outP(" " + outTmp + "...");
|
||||||
|
Main.outP("\r" + Main.MLG + outTmp + "..."); //here we use \r to go back to the previous line, and rewrite it
|
||||||
if (prepTextFirst) {
|
|
||||||
Main.outP(Main.MLG + outTmp + "...");
|
|
||||||
prepTextFirst = false;
|
|
||||||
} else {
|
|
||||||
Main.outP(" " + outTmp + "...");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//}
|
||||||
|
|
||||||
} else if (line.contains(Main.preparingLevel)) {
|
} else if (line.contains(Main.preparingLevel)) {
|
||||||
prepTextFirst = true;
|
prepTextFirst = true;
|
||||||
|
|
||||||
if (convertedMapFormattingFlag == true) {
|
if (convertedMapFormattingFlag == true) {
|
||||||
Main.outP(Main.newLine);
|
Main.outP(Main.newLine);
|
||||||
convertedMapFormattingFlag = false;
|
convertedMapFormattingFlag = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.contains("level 0")) { // "Preparing start region for level 0"
|
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"
|
} 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"
|
} 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"
|
} 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"
|
} 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"
|
} 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"
|
} 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"
|
} 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"
|
} 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"
|
} 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 {
|
} else {
|
||||||
Main.outP(Main.newLine + Main.MLG + shortLine);
|
Main.outP(Main.newLine + Main.MLG + shortLine);
|
||||||
}
|
}
|
||||||
} else if (line.contains("server version") || line.contains("Converting map!")) { //TODO: add to .conf
|
} else if (line.contains("server version") || line.contains("Converting map!")) { //TODO: add to .conf
|
||||||
Main.outS(shortLine);
|
Main.outS(shortLine);
|
||||||
|
|
||||||
if (line.contains("server version") && Main.MC_Server_Version.isEmpty()) {
|
if (line.contains("server version") && Main.MC_Server_Version.isEmpty()) {
|
||||||
// if server version, save string to variable, for use in arraylist save file.
|
// if server version, save string to variable, for use in arraylist save file.
|
||||||
Main.MC_Server_Version = shortLine;
|
Main.MC_Server_Version = shortLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.contains(Main.doneText)) { // now this is configurable!
|
if (line.contains(Main.doneText)) { // now this is configurable!
|
||||||
|
|
||||||
Main.outP(Main.newLine);
|
Main.outP(Main.newLine);
|
||||||
Main.outS(line.substring(line.lastIndexOf("]") + 2, line.indexOf("!")));
|
Main.outS(line.substring(line.lastIndexOf("]") + 2, line.indexOf("!")));
|
||||||
if (Main.waitSave) {
|
if (Main.waitSave) {
|
||||||
Main.out("Waiting 30 seconds to save...");
|
Main.out("Waiting 30 seconds to save...");
|
||||||
|
|
||||||
int count = 1;
|
int count = 1;
|
||||||
while (count <= 30) {
|
while (count <= 30) {
|
||||||
Main.outP(".");
|
Main.outP(".");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@ -194,19 +195,19 @@ public class MLG_Server {
|
|||||||
Main.out("Saving server data...");
|
Main.out("Saving server data...");
|
||||||
outputStream.write(saveAll);
|
outputStream.write(saveAll);
|
||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
|
|
||||||
Main.out("Stopping server... (Please Wait...)");
|
Main.out("Stopping server... (Please Wait...)");
|
||||||
// OutputStream outputStream = process.getOutputStream();
|
// OutputStream outputStream = process.getOutputStream();
|
||||||
outputStream.write(stop);
|
outputStream.write(stop);
|
||||||
outputStream.flush();
|
outputStream.flush();
|
||||||
// outputStream.close();
|
// outputStream.close();
|
||||||
|
|
||||||
if (Main.waitSave) {
|
if (Main.waitSave) {
|
||||||
Main.out("Waiting 10 seconds to save.");
|
Main.out("Waiting 10 seconds to save.");
|
||||||
int count = 1;
|
int count = 1;
|
||||||
while (count <= 10) {
|
while (count <= 10) {
|
||||||
Main.outP(".");
|
Main.outP(".");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@ -217,7 +218,7 @@ public class MLG_Server {
|
|||||||
Main.out("");
|
Main.out("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Here we want to ignore the most common warning: "Can't keep up!"
|
//Here we want to ignore the most common warning: "Can't keep up!"
|
||||||
if (line.contains("Can't keep up!")) { //TODO: add to .conf
|
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?
|
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;
|
warning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Main.ignoreWarnings == false) {
|
if (Main.ignoreWarnings == false) {
|
||||||
if (line.contains("[WARNING]")) { // If we have a warning, stop...
|
if (line.contains("[WARNING]")) { // If we have a warning, stop...
|
||||||
Main.out("");
|
Main.out("");
|
||||||
@ -277,23 +278,23 @@ public class MLG_Server {
|
|||||||
// Quit!
|
// Quit!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (warningsWeCanIgnore) {
|
if (warningsWeCanIgnore) {
|
||||||
Main.ignoreWarnings = ignoreWarningsOriginal;
|
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.
|
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.flush();
|
||||||
//outputStream.close();
|
//outputStream.close();
|
||||||
//System.exit(1);
|
//System.exit(1);
|
||||||
serverSuccess = false;
|
serverSuccess = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// readLine() returns null when the process exits
|
// while loop has finished now.
|
||||||
return serverSuccess;
|
return serverSuccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user