Merge 71ef49ed11e8b2d0a7b0ceb7fce56f46799dd60d into 5121ab6f0113905232601b8efbeb9d170d189251
This commit is contained in:
commit
f64ea444e3
@ -170,6 +170,8 @@ public class FileRead {
|
||||
} else {
|
||||
var.waitSave = false;
|
||||
}
|
||||
} else if (property.equals("postShutdownDelay")) {
|
||||
var.postShutdownDelay = value.toLowerCase().equals("true") ? true : false;
|
||||
} else if (property.equals("weblaunch")) {
|
||||
if (value.toLowerCase().equals("true")) {
|
||||
var.webLaunch = true;
|
||||
|
@ -102,6 +102,8 @@ public class FileWrite {
|
||||
+ var.newLine
|
||||
+ "#Optional: Wait a few seconds after saving." + var.newLine
|
||||
+ "WaitSave=false" + var.newLine
|
||||
+ "#Optional: Wait a few seconds after server shutdown for OS memory housekeeping."
|
||||
+ "postShutdownDelay=false"
|
||||
+ "webLaunch=true";
|
||||
//@formatter:on
|
||||
|
||||
|
@ -32,13 +32,20 @@ public class Server {
|
||||
if (var.verbose) {
|
||||
Out.out("Starting server.");
|
||||
}
|
||||
int startCount = 0;
|
||||
|
||||
boolean serverSuccess = true;
|
||||
boolean warning = false;
|
||||
boolean warningsWeCanIgnore = false;
|
||||
boolean serverDoneReceived = false;
|
||||
final boolean ignoreWarningsOriginal = var.ignoreWarnings;
|
||||
|
||||
// monitor output and print to console where required.
|
||||
// STOP the server when it's done.
|
||||
while (serverSuccess && !serverDoneReceived) {
|
||||
if (++startCount > 1)
|
||||
Out.outP("Restarting server, try #" + startCount
|
||||
+ ": did not receive \"" + var.doneText + "\"\n");
|
||||
|
||||
if (var.alternate) { // Alternate - a replication (slightly stripped down) of MLG 1.3.0's code. simplest code possible.
|
||||
Out.out("Alternate Launch");
|
||||
@ -52,7 +59,8 @@ public class Server {
|
||||
final BufferedReader pOut =
|
||||
new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
while ((line = pOut.readLine()) != null) { // readLine() returns null when the process exits
|
||||
while ((line = pOut.readLine())
|
||||
!= null) { // readLine() returns null when the process exits
|
||||
|
||||
line = line.trim();
|
||||
|
||||
@ -60,6 +68,8 @@ public class Server {
|
||||
if (line.contains(var.doneText)) { // EDITED By Morlok8k for Minecraft 1.3+ Beta
|
||||
final OutputStream outputStream = process.getOutputStream();
|
||||
|
||||
serverDoneReceived = true;
|
||||
|
||||
Out.out("Stopping server... (Please Wait...)");
|
||||
outputStream.write(saveAll);
|
||||
outputStream.flush();
|
||||
@ -86,22 +96,26 @@ public class Server {
|
||||
String outTmp = "";
|
||||
String outTmp2 = null;
|
||||
|
||||
final byte[] stop = { 's', 't', 'o', 'p', '\r', '\n' }; // Moved here, so this code wont run every loop, thus Faster!
|
||||
final 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!
|
||||
|
||||
final byte[] saveAll = {'s', 'a', 'v', 'e', '-', 'a', 'l', 'l', '\r', '\n'};
|
||||
|
||||
boolean prepTextFirst = true;
|
||||
|
||||
final OutputStream outputStream = process.getOutputStream(); // moved here to remove some redundancy
|
||||
final OutputStream outputStream = process
|
||||
.getOutputStream(); // moved here to remove some redundancy
|
||||
|
||||
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) { // readLine() returns null when the process exits
|
||||
while ((line = pOut.readLine())
|
||||
!= null) { // readLine() returns null when the process exits
|
||||
|
||||
line = line.trim();
|
||||
|
||||
final int posBracket = line.indexOf("]"); //changed from .lastIndexOf to .indexOf, in case we have a custom server that outputs something with an "]". we want the first one anyways.
|
||||
final int posBracket = line.indexOf(
|
||||
"]"); //changed from .lastIndexOf to .indexOf, in case we have a custom server that outputs something with an "]". we want the first one anyways.
|
||||
if (posBracket != -1) {
|
||||
if ((posBracket + 2) >= line.length()) {
|
||||
shortLine = line; //On error messages with 1.7 based servers, there is a "]" at the end of the line. caused a crash here.
|
||||
@ -110,7 +124,8 @@ public class Server {
|
||||
}
|
||||
|
||||
if (shortLine != null) {
|
||||
shortLine = shortLine.trim(); // new version of Eclipse was giving a warning that it could be null here - it can't, since "shortLine" is based on "line" which is never null at this point.
|
||||
shortLine = shortLine
|
||||
.trim(); // new version of Eclipse was giving a warning that it could be null here - it can't, since "shortLine" is based on "line" which is never null at this point.
|
||||
} // added this check to remove warning, as i didn't want to suppress all null warnings for runMinecraft
|
||||
|
||||
} else {
|
||||
@ -139,7 +154,8 @@ public class Server {
|
||||
prepTextFirst = false;
|
||||
} else {
|
||||
//Main.outP(" " + outTmp + "...");
|
||||
Out.outP("\r" + var.MLG + outTmp + "..."); //here we use \r to go back to the previous line, and rewrite it
|
||||
Out.outP("\r" + var.MLG + outTmp
|
||||
+ "..."); //here we use \r to go back to the previous line, and rewrite it
|
||||
}
|
||||
|
||||
//}
|
||||
@ -153,38 +169,58 @@ public class Server {
|
||||
}
|
||||
|
||||
if (line.contains("level 0")) { // "Preparing start region for level 0"
|
||||
Out.outP(var.MLG + var.worldName + ": " + var.level_0 + ":" + var.newLine);
|
||||
} else if (line.contains("level 1")) { // "Preparing start region for level 1"
|
||||
Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_1 + ":"
|
||||
Out.outP(
|
||||
var.MLG + var.worldName + ": " + var.level_0 + ":" + var.newLine);
|
||||
} else if (line
|
||||
.contains("level 1")) { // "Preparing start region for level 1"
|
||||
Out.outP(
|
||||
var.newLine + var.MLG + var.worldName + ": " + var.level_1 + ":"
|
||||
+ var.newLine);
|
||||
} else if (line.contains("level 2")) { // "Preparing start region for level 2"
|
||||
Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_2 + ":"
|
||||
} else if (line
|
||||
.contains("level 2")) { // "Preparing start region for level 2"
|
||||
Out.outP(
|
||||
var.newLine + var.MLG + var.worldName + ": " + var.level_2 + ":"
|
||||
+ var.newLine);
|
||||
} else if (line.contains("level 3")) { // "Preparing start region for level 3"
|
||||
Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_3 + ":"
|
||||
} else if (line
|
||||
.contains("level 3")) { // "Preparing start region for level 3"
|
||||
Out.outP(
|
||||
var.newLine + var.MLG + var.worldName + ": " + var.level_3 + ":"
|
||||
+ var.newLine);
|
||||
} else if (line.contains("level 4")) { // "Preparing start region for level 4"
|
||||
Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_4 + ":"
|
||||
} else if (line
|
||||
.contains("level 4")) { // "Preparing start region for level 4"
|
||||
Out.outP(
|
||||
var.newLine + var.MLG + var.worldName + ": " + var.level_4 + ":"
|
||||
+ var.newLine);
|
||||
} else if (line.contains("level 5")) { // "Preparing start region for level 5"
|
||||
Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_5 + ":"
|
||||
} else if (line
|
||||
.contains("level 5")) { // "Preparing start region for level 5"
|
||||
Out.outP(
|
||||
var.newLine + var.MLG + var.worldName + ": " + var.level_5 + ":"
|
||||
+ var.newLine);
|
||||
} else if (line.contains("level 6")) { // "Preparing start region for level 6"
|
||||
Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_6 + ":"
|
||||
} else if (line
|
||||
.contains("level 6")) { // "Preparing start region for level 6"
|
||||
Out.outP(
|
||||
var.newLine + var.MLG + var.worldName + ": " + var.level_6 + ":"
|
||||
+ var.newLine);
|
||||
} else if (line.contains("level 7")) { // "Preparing start region for level 7"
|
||||
Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_7 + ":"
|
||||
} else if (line
|
||||
.contains("level 7")) { // "Preparing start region for level 7"
|
||||
Out.outP(
|
||||
var.newLine + var.MLG + var.worldName + ": " + var.level_7 + ":"
|
||||
+ var.newLine);
|
||||
} else if (line.contains("level 8")) { // "Preparing start region for level 8"
|
||||
Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_8 + ":"
|
||||
} else if (line
|
||||
.contains("level 8")) { // "Preparing start region for level 8"
|
||||
Out.outP(
|
||||
var.newLine + var.MLG + var.worldName + ": " + var.level_8 + ":"
|
||||
+ var.newLine);
|
||||
} else if (line.contains("level 9")) { // "Preparing start region for level 9"
|
||||
Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_9 + ":"
|
||||
} else if (line
|
||||
.contains("level 9")) { // "Preparing start region for level 9"
|
||||
Out.outP(
|
||||
var.newLine + var.MLG + var.worldName + ": " + var.level_9 + ":"
|
||||
+ var.newLine);
|
||||
} else {
|
||||
Out.outP(var.newLine + var.MLG + shortLine + var.newLine);
|
||||
}
|
||||
} 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
|
||||
Out.outS(shortLine);
|
||||
|
||||
if (line.contains("server version") && var.MC_Server_Version.isEmpty()) {
|
||||
@ -196,6 +232,8 @@ public class Server {
|
||||
|
||||
if (line.contains(var.doneText)) { // now this is configurable!
|
||||
|
||||
serverDoneReceived = true;
|
||||
|
||||
Out.outP(var.newLine);
|
||||
Out.outS(line.substring(line.lastIndexOf("]") + 2, line.indexOf("!")));
|
||||
if (var.waitSave) {
|
||||
@ -263,7 +301,8 @@ public class Server {
|
||||
if (line.contains("[WARNING]")) { // If we have a warning, stop...
|
||||
Out.out("");
|
||||
Out.out("Warning found: Stopping " + var.PROG_NAME);
|
||||
if (var.verbose == false) { // If verbose is true, we already displayed it.
|
||||
if (var.verbose
|
||||
== false) { // If verbose is true, we already displayed it.
|
||||
Out.outS(line);
|
||||
}
|
||||
Out.out("");
|
||||
@ -271,7 +310,8 @@ public class Server {
|
||||
outputStream.write(saveAll);
|
||||
outputStream.flush();
|
||||
// OutputStream outputStream = process.getOutputStream();
|
||||
outputStream.write(stop); // if the warning was a fail to bind to port, we may need to write stop twice!
|
||||
outputStream.write(
|
||||
stop); // if the warning was a fail to bind to port, we may need to write stop twice!
|
||||
outputStream.flush();
|
||||
outputStream.write(stop);
|
||||
outputStream.flush();
|
||||
@ -282,7 +322,8 @@ public class Server {
|
||||
if (line.contains("[SEVERE]")) { // If we have a severe error, stop...
|
||||
Out.out("");
|
||||
Out.out("Severe error found: Stopping server.");
|
||||
if (var.verbose == false) { // If verbose is true, we already displayed it.
|
||||
if (var.verbose
|
||||
== false) { // If verbose is true, we already displayed it.
|
||||
Out.outS(line);
|
||||
}
|
||||
Out.out("");
|
||||
@ -306,7 +347,8 @@ public class Server {
|
||||
}
|
||||
}
|
||||
|
||||
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.close();
|
||||
//System.exit(1);
|
||||
@ -317,6 +359,17 @@ public class Server {
|
||||
}
|
||||
|
||||
// while loop has finished now.
|
||||
return serverSuccess;
|
||||
// tfw while loop so big you need a comment to see where it ended ~V
|
||||
|
||||
// workaround for Windows not instantly freeing virtmem after exit
|
||||
|
||||
// TODO: Seems broken (not triggering)
|
||||
if (var.postShutdownDelay) {
|
||||
try {
|
||||
Thread.sleep(2500);
|
||||
} catch (InterruptedException ex) { }
|
||||
}
|
||||
}
|
||||
return serverSuccess && serverDoneReceived;
|
||||
}
|
||||
}
|
||||
|
@ -47,10 +47,10 @@ public class var {
|
||||
public static final String PROG_NAME = "Minecraft Land Generator";
|
||||
|
||||
/** Version Number! */
|
||||
public static final String VERSION = "1.7.7";
|
||||
public static final String VERSION = "1.7.8";
|
||||
|
||||
/** Authors */
|
||||
public static final String AUTHORS = "Corrodias, Morlok8k, pr0f1x, jaseg, Gallion";
|
||||
public static final String AUTHORS = "Corrodias, Morlok8k, pr0f1x, jaseg, Gallion, VADemon";
|
||||
|
||||
/** Website */
|
||||
public static final String WEBSITE = "https://sites.google.com/site/minecraftlandgenerator/";
|
||||
@ -185,6 +185,9 @@ public class var {
|
||||
/** Beta 1.9 glitch workaround. (not needed unless using beta 1.9) */
|
||||
public static boolean waitSave = false;
|
||||
|
||||
/** Delay shutdown to give OS time to free memory from current application **/
|
||||
public static boolean postShutdownDelay = false;
|
||||
|
||||
/** Ignores Warnings from the server. Used for compatibility and special cases */
|
||||
public static boolean ignoreWarnings = false;
|
||||
|
||||
|
Reference in New Issue
Block a user