Delete stuff
This commit is contained in:
parent
142cc34060
commit
4993aacfd6
@ -1,18 +1,20 @@
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
import picocli.CommandLine.Option;
|
||||
import picocli.CommandLine.Parameters;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import picocli.CommandLine;
|
||||
import picocli.CommandLine.RunLast;
|
||||
import picocli.CommandLine.Command;
|
||||
import picocli.CommandLine.HelpCommand;
|
||||
import picocli.CommandLine.Option;
|
||||
import picocli.CommandLine.Parameters;
|
||||
import picocli.CommandLine.RunLast;
|
||||
|
||||
import java.nio.file.Path;
|
||||
@Command(name = "mlg", subcommands = {
|
||||
HelpCommand.class})
|
||||
|
||||
public class CommandLineMain implements Runnable{
|
||||
@Option(names = {"-v", "--verbose"}, description = "Be verbose.")
|
||||
public class CommandLineMain implements Runnable {
|
||||
@Option(names = { "-v", "--verbose" }, description = "Be verbose.")
|
||||
private boolean verbose = false;
|
||||
|
||||
@Parameters(index = "0", description = "X-coordinate")
|
||||
@ -33,11 +35,10 @@ public class CommandLineMain implements Runnable{
|
||||
@Option(names = {"--y-offset", "-yoff"}, description = "set the Z offset to generate land around")
|
||||
private int zOffset = 0;
|
||||
|
||||
|
||||
|
||||
public CommandLineMain(){
|
||||
public CommandLineMain() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
CommandLine.usage(this, System.err);
|
||||
|
@ -19,205 +19,14 @@
|
||||
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author morlok8k
|
||||
*/
|
||||
@Deprecated
|
||||
public class FileRead {
|
||||
|
||||
/**
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
|
||||
private static Log log = LogFactory.getLog(Main.class);
|
||||
|
||||
public static ArrayList<Vector3i> readArrayListCoordLog(final String file) {
|
||||
|
||||
|
||||
final ArrayList<Vector3i> Return = new ArrayList<>();
|
||||
|
||||
try {
|
||||
final BufferedReader in = new BufferedReader(new FileReader(new File(file)));
|
||||
String line = "";
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
|
||||
line = line.trim();
|
||||
|
||||
int end = line.indexOf('#'); // comments, ignored lines
|
||||
boolean ignoreLine = false;
|
||||
Vector3i c;
|
||||
|
||||
if (end == -1) { // If we have no hash sign, then we read till the end of the line
|
||||
end = line.length();
|
||||
}
|
||||
|
||||
if (end == 0) { //hash is first char, meaning entire line is a comment
|
||||
ignoreLine = true;
|
||||
}
|
||||
|
||||
if (!(ignoreLine)) {
|
||||
c = parseString(line.substring(0, end));
|
||||
Return.add(c);
|
||||
} else {
|
||||
if (line.startsWith("##Size:")) { // Potential Resume data.
|
||||
int xx = 0;
|
||||
int zz = 0;
|
||||
|
||||
xx = line.indexOf('X');
|
||||
zz = line.indexOf('Z');
|
||||
|
||||
var.resumeX = Integer.parseInt(line.substring(xx + 1, zz));
|
||||
var.resumeZ = Integer.parseInt(line.substring(zz + 1));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
in.close();
|
||||
|
||||
} catch (final FileNotFoundException ex) {
|
||||
log.info("Could not find " + file + ".");
|
||||
return Return;
|
||||
} catch (final IOException ex) {
|
||||
log.error("Could not read " + file + ".");
|
||||
return Return;
|
||||
}
|
||||
|
||||
return Return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void readConf() {
|
||||
//TODO: element comment
|
||||
//String errorMsg = "";
|
||||
|
||||
try {
|
||||
final File config = new File(var.MinecraftLandGeneratorConf);
|
||||
final BufferedReader in = new BufferedReader(new FileReader(config));
|
||||
String line = "";
|
||||
String property = "";
|
||||
String value = "";
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
int pos = line.indexOf('=');
|
||||
|
||||
int end = line.lastIndexOf('#'); // comments, ignored lines
|
||||
|
||||
if (end == -1) { // If we have no hash sign, then we read till the end of the line
|
||||
end = line.length();
|
||||
|
||||
}
|
||||
if (end <= (pos + 1)) { // If hash is before the '=', we may have an issue... it should be fine, cause we check for issues next, but lets make sure.
|
||||
end = line.length();
|
||||
pos = -1;
|
||||
}
|
||||
|
||||
if (end == 0) { //hash is first char, meaning entire line is a comment
|
||||
end = line.length();
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
if (pos != -1) {
|
||||
if (line.length() == 0) {
|
||||
property = "";
|
||||
value = "";
|
||||
} else {
|
||||
property = line.substring(0, pos).toLowerCase();
|
||||
value = line.substring(pos + 1, end);
|
||||
}
|
||||
|
||||
if (property.equals("serverpath")) {
|
||||
var.serverPath = value;
|
||||
} else if (property.equals("java")) {
|
||||
var.javaLine = value;
|
||||
} else if (property.equals("done_text")) {
|
||||
var.doneText = value;
|
||||
} else if (property.equals("preparing_text")) {
|
||||
var.preparingText = value;
|
||||
} else if (property.equals("preparing_level")) {
|
||||
var.preparingLevel = value;
|
||||
} else if (property.equals("level-0")) {
|
||||
var.level_0 = value;
|
||||
} else if (property.equals("level-1")) {
|
||||
var.level_1 = value;
|
||||
} else if (property.equals("level-2")) {
|
||||
var.level_2 = value;
|
||||
} else if (property.equals("level-3")) {
|
||||
var.level_3 = value;
|
||||
} else if (property.equals("level-4")) {
|
||||
var.level_4 = value;
|
||||
} else if (property.equals("level-5")) {
|
||||
var.level_5 = value;
|
||||
} else if (property.equals("level-6")) {
|
||||
var.level_6 = value;
|
||||
} else if (property.equals("level-7")) {
|
||||
var.level_7 = value;
|
||||
} else if (property.equals("level-8")) {
|
||||
var.level_8 = value;
|
||||
} else if (property.equals("level-9")) {
|
||||
var.level_9 = value;
|
||||
} else if (property.equals("waitsave")) {
|
||||
if (value.toLowerCase().equals("true")) {
|
||||
var.waitSave = true;
|
||||
} else {
|
||||
var.waitSave = false;
|
||||
}
|
||||
} else if (property.equals("weblaunch")) {
|
||||
if (value.toLowerCase().equals("true")) {
|
||||
var.webLaunch = true;
|
||||
} else {
|
||||
var.webLaunch = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
|
||||
if (var.testing) {
|
||||
log.debug("Test Output: Reading of Config File ");
|
||||
log.debug(" serverPath: " + var.serverPath);
|
||||
log.debug(" javaLine: " + var.javaLine);
|
||||
log.debug(" doneText: " + var.doneText);
|
||||
log.debug(" preparingText: " + var.preparingText);
|
||||
log.debug("preparingLevel: " + var.preparingLevel);
|
||||
log.debug(" level_0: " + var.level_0);
|
||||
log.debug(" level_1: " + var.level_1);
|
||||
log.debug(" level_2: " + var.level_2);
|
||||
log.debug(" level_3: " + var.level_3);
|
||||
log.debug(" level_4: " + var.level_4);
|
||||
log.debug(" level_5: " + var.level_5);
|
||||
log.debug(" level_6: " + var.level_6);
|
||||
log.debug(" level_7: " + var.level_7);
|
||||
log.debug(" level_8: " + var.level_8);
|
||||
log.debug(" level_9: " + var.level_9);
|
||||
log.debug(" waitSave: " + var.waitSave);
|
||||
log.debug(" webLaunch: " + var.webLaunch);
|
||||
}
|
||||
} catch (final FileNotFoundException ex) {
|
||||
log.error("Could not find "
|
||||
+ var.MinecraftLandGeneratorConf
|
||||
+ ". It is recommended that you run the application with the -conf option to create it.");
|
||||
return;
|
||||
} catch (final IOException ex) {
|
||||
log.error("Could not read " + var.MinecraftLandGeneratorConf + ".");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3i parseString(String StringOfCoords) {
|
||||
StringOfCoords = StringOfCoords.trim();
|
||||
|
||||
@ -231,13 +40,15 @@ public class FileRead {
|
||||
end = StringOfCoords.indexOf(")");
|
||||
String[] coordshort = StringOfCoords.substring(start, end).split(",");
|
||||
if ((start != -1) && (end != -1)) {
|
||||
return new Vector3i(Integer.valueOf(coordshort[0]), 64, Integer.valueOf(coordshort[2]));
|
||||
return new Vector3i(Integer.valueOf(coordshort[0]), 64,
|
||||
Integer.valueOf(coordshort[2]));
|
||||
} else {
|
||||
return new Vector3i(0, 0, 0);
|
||||
}
|
||||
} else {
|
||||
|
||||
return new Vector3i(Integer.valueOf(coordlong[0]), Integer.valueOf(coordlong[1]), Integer.valueOf(coordlong[2]));
|
||||
return new Vector3i(Integer.valueOf(coordlong[0]), Integer.valueOf(coordlong[1]),
|
||||
Integer.valueOf(coordlong[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,6 @@
|
||||
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
import java.awt.EventQueue;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@ -32,12 +31,10 @@ import java.util.Iterator;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import morlok8k.MinecraftLandGenerator.GUI.MLG_GUI;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
|
||||
/**
|
||||
* @author Corrodias, Morlok8k, pr0f1x
|
||||
*/
|
||||
@ -52,91 +49,12 @@ public class Main {
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* the command line arguments
|
||||
* the command line arguments
|
||||
*/
|
||||
private static Log log = LogFactory.getLog(Main.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
var.startTime = System.currentTimeMillis();
|
||||
|
||||
var.originalArgs = args; // we may potentially remove some args later, but we keep a record of the original for the log file.
|
||||
|
||||
// This is really just here for debugging...
|
||||
// I plan on adding more asserts later, but for now, this will do.
|
||||
// to enable this, run:
|
||||
// java -enableassertions -jar MinecraftLandGenerator.jar
|
||||
assert var.assertsEnabled = true; // Intentional side-effect!!! (This may cause a Warning, which is safe to ignore: "Possible accidental assignment in place of a comparison. A condition expression should not be reduced to an assignment")
|
||||
if (var.assertsEnabled) {
|
||||
log.info("assertsEnabled: " + var.assertsEnabled);
|
||||
var.verbose = true;
|
||||
log.info("Verbose mode forced!");
|
||||
var.testing = true;
|
||||
log.info("Debug mode forced!");
|
||||
var.dontWait = true;
|
||||
log.info("-nowait mode forced!");
|
||||
log.info("");
|
||||
}
|
||||
|
||||
boolean GUI = false; // GUI needs to be true to run in graphical mode
|
||||
boolean NOGUI = false; // NOGUI is a flag that finds reasons to not use a graphical mode.
|
||||
|
||||
if (args.length != 0) { // if args are present, then we assume we want NOGUI
|
||||
NOGUI = true; // if no args are present, we will attempt GUI
|
||||
}
|
||||
|
||||
String[] argsNOGUI = new String[args.length];
|
||||
argsNOGUI = args;
|
||||
argsNOGUI = StringArrayParse.Parse(argsNOGUI, "nogui"); //parse out "nogui"
|
||||
if (!(args.equals(argsNOGUI))) { //do the freshly parsed args match the original?
|
||||
args = argsNOGUI; //use the freshly parsed args for everything else now...
|
||||
NOGUI = true;
|
||||
}
|
||||
|
||||
//MLG_GUI Choosing code...
|
||||
if ((!NOGUI) && (!java.awt.GraphicsEnvironment.isHeadless())) {
|
||||
GUI = true;
|
||||
if (var.testing) {
|
||||
log.info("MLG_GUI: This is a graphical enviroment.");
|
||||
}
|
||||
|
||||
//////
|
||||
GUI = false; // forcing GUI to be false for now, because I don't have the MLG_GUI code ready yet!
|
||||
//////
|
||||
|
||||
} else {
|
||||
GUI = false; // No GUI for us today...
|
||||
if (var.testing) {
|
||||
log.info("MLG_GUI: Command Line Only!");
|
||||
}
|
||||
}
|
||||
|
||||
if (GUI) { //GUI
|
||||
// Launch MLG_GUI
|
||||
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
|
||||
@SuppressWarnings("static-access")
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
try {
|
||||
final MLG_GUI window = new MLG_GUI();
|
||||
window.frmMLG_GUI.setVisible(true);
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
} else { //No GUI
|
||||
// Finally, Lets Start MLG!
|
||||
|
||||
var.UsingGUI = false;
|
||||
var.args = args;
|
||||
Main.runCLI();
|
||||
}
|
||||
|
||||
Main.runCLI();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -281,7 +199,8 @@ public class Main {
|
||||
log.info("Centering land generation on [" + var.xOffset + ", " + var.zOffset
|
||||
+ "] due to switches.");
|
||||
} else {
|
||||
log.info("Centering land generation on [" + var.xOffset + ", " + var.zOffset + "]\n");
|
||||
log.info("Centering land generation on [" + var.xOffset + ", " + var.zOffset
|
||||
+ "]\n");
|
||||
}
|
||||
|
||||
double xLoops, zLoops;
|
||||
@ -329,7 +248,7 @@ public class Main {
|
||||
if (xLoops > 3) {
|
||||
xLoops = xLoops + 1;
|
||||
}
|
||||
|
||||
|
||||
if (zLoops > 3) {
|
||||
zLoops = zLoops + 1;
|
||||
}
|
||||
@ -340,7 +259,8 @@ public class Main {
|
||||
log.info("Estimated Total Spawn Points: " + totalIterations);
|
||||
|
||||
if (totalIterations > Integer.MAX_VALUE) {
|
||||
log.error("TOO BIG! Please reduce the world size. World Size can't be larger than 17609200 x 17609200"); //or 17794560 using -i384
|
||||
log.error(
|
||||
"TOO BIG! Please reduce the world size. World Size can't be larger than 17609200 x 17609200"); //or 17794560 using -i384
|
||||
backupLevel.delete();
|
||||
log.info("Removed backup file.");
|
||||
System.exit(0);
|
||||
@ -357,7 +277,8 @@ public class Main {
|
||||
launchList = new ArrayList<>((int) totalIterations);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
log.error("TOO BIG! Your computer can't handle such a large map. The size is dependant on 32/64 bit and Memory.");
|
||||
log.error(
|
||||
"TOO BIG! Your computer can't handle such a large map. The size is dependant on 32/64 bit and Memory.");
|
||||
backupLevel.delete();
|
||||
log.info("Removed backup file.");
|
||||
System.exit(0);
|
||||
@ -392,22 +313,20 @@ public class Main {
|
||||
{ // Middle of Loop
|
||||
|
||||
if (currentIteration % 10000000 == 0) { //for long calculations, we output an update every 10,000,000 points
|
||||
String percentDone =
|
||||
Double.toString((((double) currentIteration) / totalIterations) * 100);
|
||||
String percentDone = Double.toString(
|
||||
(((double) currentIteration) / totalIterations) * 100);
|
||||
final int percentIndex =
|
||||
((percentDone.indexOf(".") + 3) > percentDone.length())
|
||||
? percentDone.length() : (percentDone.indexOf(".") + 3); //fix index on numbers like 12.3
|
||||
percentDone =
|
||||
percentDone.substring(0, (percentDone.indexOf(".") == -1
|
||||
? percentDone.length() : percentIndex)); //Trim output, unless whole number
|
||||
percentDone = percentDone.substring(0, (percentDone.indexOf(".") == -1
|
||||
? percentDone.length() : percentIndex)); //Trim output, unless whole number
|
||||
log.info("Calculated: " + currentIteration + "/" + totalIterations
|
||||
+ " spawn points. (" + percentDone + "% Done)");
|
||||
}
|
||||
|
||||
// add Coordinates to arraylist here
|
||||
final Vector3i tempCoords =
|
||||
new Vector3i((int) currentX + var.xOffset, 64, (int) currentZ
|
||||
+ var.zOffset);
|
||||
final Vector3i tempCoords = new Vector3i((int) currentX + var.xOffset, 64,
|
||||
(int) currentZ + var.zOffset);
|
||||
launchList.add(tempCoords);
|
||||
|
||||
// Write the current Coordinates to log file!
|
||||
@ -421,8 +340,8 @@ public class Main {
|
||||
} // End of the Middle of Loop
|
||||
|
||||
if (curZloops == 1) { // We are at the North edge. We have special code for the North edge, so we need to change currentZ to be normal again.
|
||||
currentZ =
|
||||
(long) ((Math.ceil((((0 - zRangeAdj) / 2) / var.increment))) * var.increment);
|
||||
currentZ = (long) ((Math.ceil((((0 - zRangeAdj) / 2) / var.increment)))
|
||||
* var.increment);
|
||||
}
|
||||
if (southEdgeReached) {
|
||||
currentZ = (long) zRangeAdj; // We reached the South edge, so we make sure that we exit the "for loop", bypassing the "1152 bug"
|
||||
@ -431,8 +350,8 @@ public class Main {
|
||||
} // End Z
|
||||
curZloops = 0;
|
||||
if (curXloops == 1) { // We are at the West edge. We have special code for the West edge, so we need to change currentX to be normal again.
|
||||
currentX =
|
||||
(long) ((Math.ceil((((0 - xRangeAdj) / 2) / var.increment))) * var.increment);
|
||||
currentX = (long) ((Math.ceil((((0 - xRangeAdj) / 2) / var.increment)))
|
||||
* var.increment);
|
||||
}
|
||||
if (eastEdgeReached) {
|
||||
currentX = (long) xRangeAdj; // We reached the East edge, so we make sure that we exit the "for loop", bypassing the "1152 bug"
|
||||
@ -472,13 +391,10 @@ public class Main {
|
||||
|
||||
String percentDone =
|
||||
Double.toString((((double) currentIteration - 1) / totalIterations) * 100);
|
||||
final int percentIndex =
|
||||
((percentDone.indexOf(".") + 3) > percentDone.length()) ? percentDone
|
||||
.length() : (percentDone.indexOf(".") + 3); //fix index on numbers like 12.3
|
||||
percentDone =
|
||||
percentDone.substring(0,
|
||||
(percentDone.indexOf(".") == -1 ? percentDone.length()
|
||||
: percentIndex)); //Trim output, unless whole number
|
||||
final int percentIndex = ((percentDone.indexOf(".") + 3) > percentDone.length())
|
||||
? percentDone.length() : (percentDone.indexOf(".") + 3); //fix index on numbers like 12.3
|
||||
percentDone = percentDone.substring(0,
|
||||
(percentDone.indexOf(".") == -1 ? percentDone.length() : percentIndex)); //Trim output, unless whole number
|
||||
|
||||
log.info("Setting spawn to [X,Y,Z]: " + xyz + " (" + currentIteration + " of "
|
||||
+ totalIterations + ") " + percentDone + "% Done"); // Time Remaining estimate
|
||||
@ -489,7 +405,8 @@ public class Main {
|
||||
differenceTime =
|
||||
(timeTracking - generationStartTimeTracking) / (currentIteration + 1); // Updated. we now count all runs, instead of the last 4.
|
||||
differenceTime *= 1 + (totalIterations - currentIteration); // this should provide a more accurate result.
|
||||
log.info("Estimated time remaining: " + String.format("%02d:%02d", (differenceTime / 1000) / 60, (differenceTime / 1000) % 60)); // I've noticed it gets pretty accurate after about 8 launches!
|
||||
log.info("Estimated time remaining: " + String.format("%02d:%02d",
|
||||
(differenceTime / 1000) / 60, (differenceTime / 1000) % 60)); // I've noticed it gets pretty accurate after about 8 launches!
|
||||
|
||||
// Set the spawn point
|
||||
SpawnPoint.setSpawn(serverLevel, xyz);
|
||||
@ -526,10 +443,10 @@ public class Main {
|
||||
Misc.copyFile(backupLevel, serverLevel);
|
||||
backupLevel.delete();
|
||||
log.info("Restored original level.dat.");
|
||||
long completeIn =var.startTime - System.currentTimeMillis();
|
||||
log.info("Generation complete in: "
|
||||
+ String.format("%02d:%02d", (completeIn / 1000) / 60, (completeIn / 1000) % 60));
|
||||
// Time.waitTenSec(false);
|
||||
long completeIn = var.startTime - System.currentTimeMillis();
|
||||
log.info("Generation complete in: " + String.format("%02d:%02d",
|
||||
(completeIn / 1000) / 60, (completeIn / 1000) % 60));
|
||||
// Time.waitTenSec(false);
|
||||
|
||||
if (var.webLaunch) { //if webLaunch is already false, don't check for these things
|
||||
if (java.awt.GraphicsEnvironment.isHeadless()) {
|
||||
|
@ -1,64 +0,0 @@
|
||||
/*
|
||||
#######################################################################
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# Version 2, December 2004 #
|
||||
# #
|
||||
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> #
|
||||
# #
|
||||
# Everyone is permitted to copy and distribute verbatim or modified #
|
||||
# copies of this license document, and changing it is allowed as long #
|
||||
# as the name is changed. #
|
||||
# #
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION #
|
||||
# #
|
||||
# 0. You just DO WHAT THE FUCK YOU WANT TO. #
|
||||
# #
|
||||
#######################################################################
|
||||
*/
|
||||
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author morlok8k
|
||||
*/
|
||||
public class SelfAware {
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String JVMinfo() {
|
||||
|
||||
String Return = "";
|
||||
|
||||
final RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
|
||||
final List<String> aList = RuntimemxBean.getInputArguments();
|
||||
|
||||
for (int i = 0; i < aList.size(); i++) {
|
||||
Return = Return + (aList.get(i)) + " ";
|
||||
}
|
||||
|
||||
Return = Return.trim();
|
||||
|
||||
Return =
|
||||
"Launch info: Java: " + System.getProperty("java.vm.name") + " "
|
||||
+ System.getProperty("java.version") + " OS: "
|
||||
+ System.getProperty("os.name") + " " + System.getProperty("os.version")
|
||||
+ " " + System.getProperty("os.arch") + " "
|
||||
+ System.getProperty("sun.desktop") + var.newLine + "# JVM: " + " JAR: "
|
||||
+ System.getProperty("sun.java.command") + " ARGS: ";
|
||||
|
||||
for (int i = 0; i < var.originalArgs.length; i++) {
|
||||
Return = Return + (var.originalArgs[i]) + " ";
|
||||
}
|
||||
|
||||
Return = Return.trim();
|
||||
return Return;
|
||||
}
|
||||
}
|
@ -7,13 +7,13 @@
|
||||
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -21,306 +21,41 @@ import java.io.OutputStream;
|
||||
*/
|
||||
public class Server {
|
||||
|
||||
/**
|
||||
* Starts the process in the given ProcessBuilder, monitors its output for a "[INFO] Done!" message, and sends it a "stop\r\n" message. One message is printed to the console before launching and
|
||||
* one is printed to the console when the Done! message is detected. If "verbose" is true, the process's output will also be printed to the console.
|
||||
*
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @author Corrodias, Morlok8k
|
||||
*/
|
||||
private static Log log = LogFactory.getLog(Main.class);
|
||||
|
||||
protected static boolean runMinecraft() throws IOException {
|
||||
/**
|
||||
* Starts the process in the given ProcessBuilder, monitors its output for a "Done" message, and sends it a "stop" message.
|
||||
* If "verbose" is true, the process's output will also be printed to the console.
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
* @author Corrodias, Morlok8k, piegames
|
||||
*/
|
||||
protected static void runMinecraft() throws IOException, InterruptedException {
|
||||
log.info("Starting server.");
|
||||
final Process process = var.minecraft.start();
|
||||
|
||||
if (var.verbose) {
|
||||
log.info("Starting server.");
|
||||
}
|
||||
boolean serverSuccess = true;
|
||||
boolean warning = false;
|
||||
boolean warningsWeCanIgnore = false;
|
||||
final boolean ignoreWarningsOriginal = var.ignoreWarnings;
|
||||
final BufferedReader pOut =
|
||||
new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
for (String line = pOut.readLine(); line != null; line = pOut.readLine()) {
|
||||
line = line.trim();
|
||||
if (log.isDebugEnabled()) log.debug(line);
|
||||
|
||||
// monitor output and print to console where required.
|
||||
// STOP the server when it's done.
|
||||
if (line.contains("Done")) {
|
||||
PrintStream out = new PrintStream(process.getOutputStream());
|
||||
|
||||
if (var.alternate) { // Alternate - a replication (slightly stripped down) of MLG 1.3.0's code. simplest code possible.
|
||||
log.info("Alternate Launch");
|
||||
final Process process = var.minecraft.start();
|
||||
|
||||
final byte[] saveAll = { 's', 'a', 'v', 'e', '-', 'a', 'l', 'l', '\r', '\n' };
|
||||
final byte[] stop = { 's', 't', 'o', 'p', '\r', '\n' };
|
||||
|
||||
// monitor output and print to console where required.
|
||||
// STOP the server when it's done.
|
||||
final BufferedReader pOut =
|
||||
new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
while ((line = pOut.readLine()) != null) { // readLine() returns null when the process exits
|
||||
|
||||
line = line.trim();
|
||||
|
||||
System.out.println(line);
|
||||
if (line.contains(var.doneText)) { // EDITED By Morlok8k for Minecraft 1.3+ Beta
|
||||
final OutputStream outputStream = process.getOutputStream();
|
||||
|
||||
log.info("Stopping server... (Please Wait...)");
|
||||
outputStream.write(saveAll);
|
||||
outputStream.flush();
|
||||
outputStream.write(stop);
|
||||
outputStream.flush();
|
||||
|
||||
}
|
||||
log.info("Stopping server... ");
|
||||
out.println("save-all");
|
||||
out.flush();
|
||||
out.println("stop");
|
||||
out.flush();
|
||||
}
|
||||
// End while loop
|
||||
|
||||
} else { // start minecraft server normally!
|
||||
final Process process = var.minecraft.start();
|
||||
if (var.verbose) {
|
||||
log.info("Started Server.");
|
||||
}
|
||||
final BufferedReader pOut =
|
||||
new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
if (var.verbose) {
|
||||
log.info("Accessing Server Output...");
|
||||
}
|
||||
|
||||
String line = null;
|
||||
String shortLine = null;
|
||||
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!
|
||||
// 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
|
||||
|
||||
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
|
||||
|
||||
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.
|
||||
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.
|
||||
} else {
|
||||
shortLine = line.substring(posBracket + 2);
|
||||
}
|
||||
|
||||
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.
|
||||
} // added this check to remove warning, as i didn't want to suppress all null warnings for runMinecraft
|
||||
|
||||
} else {
|
||||
shortLine = line;
|
||||
}
|
||||
|
||||
if (var.verbose) {
|
||||
log.info(shortLine);
|
||||
//} else if (line.toLowerCase().contains("saving")) { //this was just clutter
|
||||
// Main.outS(shortLine);
|
||||
} else if (line.contains(var.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(".");
|
||||
//} else {
|
||||
outTmp = outTmp2;
|
||||
|
||||
if (prepTextFirst) {
|
||||
log.info(var.MLG + outTmp + "...");
|
||||
prepTextFirst = false;
|
||||
} else {
|
||||
//Main.outP(" " + outTmp + "...");
|
||||
log.info("\r" + var.MLG + outTmp + "..."); //here we use \r to go back to the previous line, and rewrite it
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
} else if (line.contains(var.preparingLevel)) {
|
||||
prepTextFirst = true;
|
||||
|
||||
if (convertedMapFormattingFlag == true) {
|
||||
log.info(var.newLine);
|
||||
convertedMapFormattingFlag = false;
|
||||
}
|
||||
|
||||
if (line.contains("level 0")) { // "Preparing start region for level 0"
|
||||
log.info(var.MLG + var.worldName + ": " + var.level_0 + ":" + var.newLine);
|
||||
} else if (line.contains("level 1")) { // "Preparing start region for level 1"
|
||||
log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_1 + ":"
|
||||
+ var.newLine);
|
||||
} else if (line.contains("level 2")) { // "Preparing start region for level 2"
|
||||
log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_2 + ":"
|
||||
+ var.newLine);
|
||||
} else if (line.contains("level 3")) { // "Preparing start region for level 3"
|
||||
log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_3 + ":"
|
||||
+ var.newLine);
|
||||
} else if (line.contains("level 4")) { // "Preparing start region for level 4"
|
||||
log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_4 + ":"
|
||||
+ var.newLine);
|
||||
} else if (line.contains("level 5")) { // "Preparing start region for level 5"
|
||||
log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_5 + ":"
|
||||
+ var.newLine);
|
||||
} else if (line.contains("level 6")) { // "Preparing start region for level 6"
|
||||
log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_6 + ":"
|
||||
+ var.newLine);
|
||||
} else if (line.contains("level 7")) { // "Preparing start region for level 7"
|
||||
log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_7 + ":"
|
||||
+ var.newLine);
|
||||
} else if (line.contains("level 8")) { // "Preparing start region for level 8"
|
||||
log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_8 + ":"
|
||||
+ var.newLine);
|
||||
} else if (line.contains("level 9")) { // "Preparing start region for level 9"
|
||||
log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_9 + ":"
|
||||
+ var.newLine);
|
||||
} else {
|
||||
log.info(var.newLine + var.MLG + shortLine + var.newLine);
|
||||
}
|
||||
} else if (line.contains("server version") || line.contains("Converting map!")) { //TODO: add to .conf
|
||||
log.info(shortLine);
|
||||
|
||||
if (line.contains("server version") && var.MC_Server_Version.isEmpty()) {
|
||||
// if server version, save string to variable, for use in arraylist save file.
|
||||
var.MC_Server_Version = shortLine;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (line.contains(var.doneText)) { // now this is configurable!
|
||||
|
||||
log.info(var.newLine);
|
||||
log.info(line.substring(line.lastIndexOf("]") + 2, line.indexOf("!")));
|
||||
if (var.waitSave) {
|
||||
log.info("Waiting 30 seconds to save...");
|
||||
|
||||
int count = 1;
|
||||
while (count <= 30) {
|
||||
log.info(".");
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
count += 1;
|
||||
}
|
||||
log.info("");
|
||||
}
|
||||
log.info("Saving server data...");
|
||||
outputStream.write(saveAll);
|
||||
outputStream.flush();
|
||||
|
||||
log.info("Stopping server... (Please Wait...)");
|
||||
// OutputStream outputStream = process.getOutputStream();
|
||||
outputStream.write(stop);
|
||||
outputStream.flush();
|
||||
// outputStream.close();
|
||||
|
||||
if (var.waitSave) {
|
||||
log.info("Waiting 10 seconds to save.");
|
||||
int count = 1;
|
||||
while (count <= 10) {
|
||||
log.info(".");
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
count += 1;
|
||||
}
|
||||
log.info("");
|
||||
}
|
||||
}
|
||||
|
||||
//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?
|
||||
var.ignoreWarnings = true;
|
||||
} else if (line.contains("[WARNING] To start the server with more ram")) {
|
||||
if (var.verbose == false) { // If verbose is true, we already displayed it.
|
||||
log.info(line);
|
||||
}
|
||||
warningsWeCanIgnore = true; //we can safely ignore this...
|
||||
var.ignoreWarnings = true;
|
||||
} else if (line.contains("Error occurred during initialization of VM")
|
||||
|| line.contains("Could not reserve enough space for object heap")) {
|
||||
if (var.verbose == false) { // If verbose is true, we already displayed it.
|
||||
log.info("[Java Error] " + line);
|
||||
}
|
||||
warning = true;
|
||||
}
|
||||
|
||||
if (var.ignoreWarnings == false) {
|
||||
if (line.contains("[WARNING]")) { // If we have a warning, stop...
|
||||
log.info("");
|
||||
log.info("Warning found: Stopping " + var.PROG_NAME);
|
||||
if (var.verbose == false) { // If verbose is true, we already displayed it.
|
||||
log.info(line);
|
||||
}
|
||||
log.info("");
|
||||
log.info("Forcing Save...");
|
||||
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.flush();
|
||||
outputStream.write(stop);
|
||||
outputStream.flush();
|
||||
// outputStream.close();
|
||||
warning = true;
|
||||
// System.exit(1);
|
||||
}
|
||||
if (line.contains("[SEVERE]")) { // If we have a severe error, stop...
|
||||
log.info("");
|
||||
log.info("Severe error found: Stopping server.");
|
||||
if (var.verbose == false) { // If verbose is true, we already displayed it.
|
||||
log.info(line);
|
||||
}
|
||||
log.info("");
|
||||
log.info("Forcing Save...");
|
||||
outputStream.write(saveAll);
|
||||
outputStream.flush();
|
||||
// OutputStream outputStream = process.getOutputStream();
|
||||
outputStream.write(stop);
|
||||
outputStream.flush();
|
||||
outputStream.write(stop); // sometimes we need to do stop twice...
|
||||
outputStream.flush();
|
||||
// outputStream.close();
|
||||
warning = true;
|
||||
// System.exit(1);
|
||||
// Quit!
|
||||
}
|
||||
}
|
||||
|
||||
if (warningsWeCanIgnore) {
|
||||
var.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();
|
||||
}
|
||||
|
||||
// while loop has finished now.
|
||||
return serverSuccess;
|
||||
/* The process should have stopped by now. */
|
||||
int exit = process.waitFor();
|
||||
if (exit != 0)
|
||||
log.warn("Process stopped with non-zero exit code (" + exit + ")");
|
||||
else log.info("Stopped server");
|
||||
}
|
||||
}
|
||||
|
@ -19,14 +19,14 @@
|
||||
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author morlok8k
|
||||
@ -58,9 +58,8 @@ public class Setup {
|
||||
|
||||
//---------- Verify server.properties
|
||||
try {
|
||||
serverPropertiesFile =
|
||||
new BufferedReader(new FileReader(new File(var.serverPath + var.fileSeparator
|
||||
+ "server.properties")));
|
||||
serverPropertiesFile = new BufferedReader(new FileReader(
|
||||
new File(var.serverPath + var.fileSeparator + "server.properties")));
|
||||
} catch (IOException e) {
|
||||
log.error("Could not open the server.properties file.");
|
||||
return true;
|
||||
@ -116,7 +115,8 @@ public class Setup {
|
||||
|
||||
if (levelDat.exists() && levelDat.isFile()) {
|
||||
if (backupLevel.exists()) {
|
||||
log.error("There is a level_backup.dat file left over from a previous attempt that failed.");
|
||||
log.error(
|
||||
"There is a level_backup.dat file left over from a previous attempt that failed.");
|
||||
log.info("Resuming...");
|
||||
|
||||
//use resume data
|
||||
@ -141,16 +141,14 @@ public class Setup {
|
||||
} else {
|
||||
/*FileNotFoundException fileException =
|
||||
new FileNotFoundException("The currently configured world does not exist.");*/
|
||||
log.error("The currently configured world does not exist! Launching the server once to create it...");
|
||||
log.error(
|
||||
"The currently configured world does not exist! Launching the server once to create it...");
|
||||
try {
|
||||
var.minecraft = new ProcessBuilder(var.javaLine.split("\\s")); // is this always going to work? i don't know. (most likely yes)
|
||||
var.minecraft.directory(new File(var.serverPath));
|
||||
var.minecraft.redirectErrorStream(true);
|
||||
if (!(Server.runMinecraft())) {
|
||||
log.error("Huh oh! Something went wrong with the server! Exiting...");
|
||||
System.exit(1); // we got a warning or severe error
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Server.runMinecraft();
|
||||
} catch (IOException | InterruptedException e) {
|
||||
return true;
|
||||
}
|
||||
log.error("World created! Starting world generation...");
|
||||
|
@ -19,16 +19,15 @@
|
||||
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -40,26 +39,6 @@ import java.util.Date;
|
||||
public class Startup {
|
||||
private static Log log = LogFactory.getLog(Main.class);
|
||||
|
||||
public static void initialStart() {
|
||||
|
||||
// Lets get the date, and our BuildID
|
||||
var.date = new Date();
|
||||
Update.readBuildID();
|
||||
|
||||
// The following displays no matter what happens, so we needed this date stuff to happen first.
|
||||
|
||||
log.info(var.PROG_NAME + " version " + var.VERSION);
|
||||
log.info("BuildID: (" + var.MLG_Last_Modified_Date.getTime() + ")"); // instead of dateformatting the buildid, we return the raw Long number.
|
||||
// thus different timezones wont display a different buildID
|
||||
log.info("This version was last modified on "
|
||||
+ var.dateFormat.format(var.MLG_Last_Modified_Date));
|
||||
log.info("");
|
||||
log.info("Uses a Minecraft server to generate square land of a specified size.");
|
||||
log.info("");
|
||||
log.info("");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* CLI only: Reads arguments from command line
|
||||
@ -269,7 +248,8 @@ public class Startup {
|
||||
var.zOffset = Integer.valueOf(var.args[i + 2].substring(2));
|
||||
log.info("Notice: Z Offset: " + var.zOffset);
|
||||
if (nextSwitch.startsWith("-y")) {
|
||||
log.info("Notice: MLG now uses Z instead of Y. Please use the -z switch instead");
|
||||
log.info(
|
||||
"Notice: MLG now uses Z instead of Y. Please use the -z switch instead");
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -284,47 +264,4 @@ public class Startup {
|
||||
|
||||
return false; // success!
|
||||
}
|
||||
|
||||
public static boolean confFile() {
|
||||
FileRead.readConf();
|
||||
|
||||
boolean oldConf = false; // This next section checks to see if we have a old configuration file (or none!)
|
||||
|
||||
if ((var.serverPath == null) || (var.javaLine == null)) { // MLG 1.2 Check for a valid .conf file.
|
||||
log.error(var.MinecraftLandGeneratorConf
|
||||
+ " does not contain all required properties. Making New File!"); // Please recreate it by running this application with -conf.
|
||||
|
||||
// return;
|
||||
|
||||
// We no longer quit. We generate a new one with defaults.
|
||||
|
||||
var.javaLine = var.defaultJavaLine;
|
||||
var.serverPath = ".";
|
||||
oldConf = true;
|
||||
}
|
||||
|
||||
if (var.doneText == null) { // MLG 1.4.0
|
||||
oldConf = true;
|
||||
} else if (var.preparingText == null) { // MLG 1.4.0
|
||||
oldConf = true;
|
||||
} else if (var.preparingLevel == null) { // MLG 1.4.5 / 1.5.0
|
||||
oldConf = true;
|
||||
} else if (var.level_1 == null) { // MLG 1.4.5 / 1.5.0
|
||||
oldConf = true;
|
||||
} else if (var.level_0 == null) { // MLG 1.5.1 / 1.6.0
|
||||
oldConf = true;
|
||||
}
|
||||
|
||||
if (oldConf) {
|
||||
log.error("Old Version of " + var.MinecraftLandGeneratorConf + " found. Updating...");
|
||||
|
||||
FileWrite.saveConf(false); //old conf
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false; // success!
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user