1.7.0 test7

This commit is contained in:
Morlok8k 2012-07-09 15:31:39 -07:00
parent 71b4bef098
commit 3b59258a6e
5 changed files with 159 additions and 70 deletions

View File

@ -15,14 +15,14 @@ public class MLG_WorldVerify {
*/ */
static void verifyWorld() { static void verifyWorld() {
//TODO: element comment //TODO: element comment
// verify that we ended up with a good server path, either from the file or from an argument. // verify that we ended up with a good server path, either from the file or from an argument.
File file = new File(Main.serverPath); File file = new File(Main.serverPath);
if (!file.exists() || !file.isDirectory()) { if (!file.exists() || !file.isDirectory()) {
Main.err("The server directory is invalid: " + Main.serverPath); Main.err("The server directory is invalid: " + Main.serverPath);
return; return;
} }
try { try {
// read the name of the current world from the server.properties file // read the name of the current world from the server.properties file
BufferedReader props = BufferedReader props =
@ -32,25 +32,25 @@ public class MLG_WorldVerify {
while ((line = props.readLine()) != null) { while ((line = props.readLine()) != null) {
String property = ""; String property = "";
String value = ""; String value = "";
int pos = line.indexOf('='); int pos = line.indexOf('=');
int end = line.lastIndexOf('#'); // comments, ignored lines 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 if (end == -1) { // If we have no hash sign, then we read till the end of the line
end = line.length(); 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. 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(); end = line.length();
pos = -1; pos = -1;
} }
if (end == 0) { //hash is first char, meaning entire line is a comment if (end == 0) { //hash is first char, meaning entire line is a comment
end = line.length(); end = line.length();
pos = 0; pos = 0;
} }
if (pos != -1) { if (pos != -1) {
if (line.length() == 0) { if (line.length() == 0) {
property = ""; property = "";
@ -59,14 +59,14 @@ public class MLG_WorldVerify {
property = line.substring(0, pos).toLowerCase(); property = line.substring(0, pos).toLowerCase();
value = line.substring(pos + 1); value = line.substring(pos + 1);
} }
if (property.equals("level-name")) { if (property.equals("level-name")) {
Main.worldPath = Main.serverPath + Main.fileSeparator + value; Main.worldPath = Main.serverPath + Main.fileSeparator + value;
Main.worldName = value; Main.worldName = value;
} }
if (Main.useRCON) { if (Main.useRCON) {
if (property.equals("enable-rcon")) { if (property.equals("enable-rcon")) {
if (value.contains("true")) { if (value.contains("true")) {
Main.rcon_Enabled = true; Main.rcon_Enabled = true;
Main.out("RCON is set to be Enabled on the server."); Main.out("RCON is set to be Enabled on the server.");
@ -91,13 +91,13 @@ public class MLG_WorldVerify {
IP = "0.0.0.0"; IP = "0.0.0.0";
} }
Main.rcon_IPaddress = IP; Main.rcon_IPaddress = IP;
} }
} }
} }
} }
} catch (FileNotFoundException ex) { } catch (FileNotFoundException ex) {
Main.err("Could not open " + Main.serverPath + Main.fileSeparator + "server.properties"); Main.err("Could not open " + Main.serverPath + Main.fileSeparator + "server.properties");
return; return;
@ -105,13 +105,13 @@ public class MLG_WorldVerify {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
return; return;
} }
File level = new File(Main.worldPath + Main.fileSeparator + "level.dat"); File level = new File(Main.worldPath + Main.fileSeparator + "level.dat");
if (!level.exists() || !level.isFile()) { if (!level.exists() || !level.isFile()) {
Main.err("The currently-configured world does not exist. Please launch the server once, first."); Main.err("The currently-configured world does not exist.");
return; return;
} }
} }
} }

View File

@ -39,10 +39,10 @@ public class Main {
// //
// //
// Public Vars: // Public Vars:
public static boolean testing = false; // display more output when debugging public static boolean testing = false; // display more output when debugging
public static final String PROG_NAME = "Minecraft Land Generator"; // Program Name public static final String PROG_NAME = "Minecraft Land Generator"; // Program Name
public static final String VERSION = "1.6.99 (1.7.0 test3)"; // Version Number! public static final String VERSION = "1.7.0 test7"; // Version Number!
public static final String AUTHORS = "Corrodias, Morlok8k, pr0f1x"; // Authors public static final String AUTHORS = "Corrodias, Morlok8k, pr0f1x"; // Authors
public static final String fileSeparator = System.getProperty("file.separator"); public static final String fileSeparator = System.getProperty("file.separator");
@ -120,6 +120,9 @@ public class Main {
public static final String github_MLG_BuildID_URL = github_URL + buildIDFile; public static final String github_MLG_BuildID_URL = github_URL + buildIDFile;
public static final String github_MLG_jar_URL = github_URL + MLG_JarFile; public static final String github_MLG_jar_URL = github_URL + MLG_JarFile;
public static int resumeX = 0; //resume data, if needed.
public static int resumeZ = 0;
// //
// //
//Private Vars: //Private Vars:
@ -142,7 +145,7 @@ public class Main {
public static boolean useRCON = false; //use RCON to communicate with server. ***Experimental*** public static boolean useRCON = false; //use RCON to communicate with server. ***Experimental***
public static boolean rcon_Enabled = false; //is server is set to use RCON? public static boolean rcon_Enabled = false; //is server is set to use RCON?
public static String rcon_IPaddress = "0.0.0.0"; //default is 0.0.0.0 public static String rcon_IPaddress = "0.0.0.0"; //default is 0.0.0.0
public static String rcon_Port = "25575"; //default is 25575, we are just initializing here. public static String rcon_Port = "25575"; //default is 25575, we are just initializing here.
public static String rcon_Password = "test"; //default is "", but a password must be entered. public static String rcon_Password = "test"; //default is "", but a password must be entered.
////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////
@ -443,6 +446,16 @@ public class Main {
try { try {
xRange = Integer.parseInt(args[0]); xRange = Integer.parseInt(args[0]);
zRange = Integer.parseInt(args[1]); zRange = Integer.parseInt(args[1]);
if ((xRange < 1000) && (xRange != 0)) {
xRange = 1000; //if less than 1000, (and not 0) set to 1000 (Calculations don't work well on very small maps)
err("X size too small - Changing X to 1000");
}
if ((zRange < 1000) && (zRange != 0)) {
zRange = 1000;
err("Z size too small - Changing Z to 1000");
}
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
err("Invalid X or Z argument."); err("Invalid X or Z argument.");
err("Please Enter the size of world you want. Example: X:1000 Z:1000"); err("Please Enter the size of world you want. Example: X:1000 Z:1000");
@ -511,14 +524,33 @@ public class Main {
{ {
File backupLevel = new File(worldPath + fileSeparator + "level_backup.dat"); File backupLevel = new File(worldPath + fileSeparator + "level_backup.dat");
if (backupLevel.exists()) { if (backupLevel.exists()) {
err("There is a level_backup.dat file left over from a previous attempt that failed. You should go determine whether to keep the current level.dat" //err("There is a level_backup.dat file left over from a previous attempt that failed. You should go determine whether to keep the current level.dat"
+ " or restore the backup."); // + " or restore the backup.");
err("You most likely will want to restore the backup!"); //err("You most likely will want to restore the backup!");
MLG_Time.waitTenSec(false); //MLG_Time.waitTenSec(false);
//TODO: use resume data err("There is a level_backup.dat file left over from a previous attempt that failed.");
out("Resuming...");
//use resume data
File serverLevel = new File(worldPath + fileSeparator + "level.dat");
try {
MLG_Misc.copyFile(backupLevel, serverLevel);
} catch (IOException e) {
e.printStackTrace();
}
backupLevel.delete();
//return;
MLG_FileRead.readArrayListCoordLog(worldPath + fileSeparator
+ "MinecraftLandGenerator.log"); // we read the .log just for any resume data, if any.
System.gc(); //run the garbage collector - hopefully free up some memory!
xRange = resumeX;
zRange = resumeZ;
return;
} }
} }
@ -543,20 +575,25 @@ public class Main {
long generationStartTimeTracking = System.currentTimeMillis(); //Start of time remaining calculations. long generationStartTimeTracking = System.currentTimeMillis(); //Start of time remaining calculations.
MLG_Server.runMinecraft(alternate); boolean serverLaunch = MLG_Server.runMinecraft(alternate);
if (!(serverLaunch)) {
System.exit(1); // we got a warning or severe error
}
if ((xRange == 0) & (zRange == 0)) { //If the server is launched with an X and a Z of zero, then we just shutdown MLG after the initial launch. if ((xRange == 0) & (zRange == 0)) { //If the server is launched with an X and a Z of zero, then we just shutdown MLG after the initial launch.
return; return;
} }
xRange = (int) (Math.ceil(((double) xRange) / ((double) 16))) * 16; //say xRange was entered as 1000. this changes it to be 1008, a multiple of 16. (the size of a chunk)
zRange = (int) (Math.ceil(((double) zRange) / ((double) 16))) * 16; //say zRange was entered as 2000. there is no change, as it already is a multiple of 16.
MLG_FileWrite.AppendTxtFile( MLG_FileWrite.AppendTxtFile(
worldPath + fileSeparator + "MinecraftLandGenerator.log", worldPath + fileSeparator + "MinecraftLandGenerator.log",
"# " + PROG_NAME + " " + VERSION + " - " + MLG_SelfAware.JVMinfo() + newLine "# " + PROG_NAME + " " + VERSION + " - " + MLG_SelfAware.JVMinfo() + newLine
+ "# " + MC_Server_Version + newLine + "# Started: " + "# " + MC_Server_Version + newLine + "# Started: "
+ dateFormat.format(generationStartTimeTracking) + newLine); + dateFormat.format(generationStartTimeTracking) + newLine
+ "##Size: X" + xRange + "Z" + zRange + newLine);
xRange = (int) (Math.ceil(((double) xRange) / ((double) 16))) * 16; //say xRange was entered as 1000. this changes it to be 1008, a multiple of 16. (the size of a chunk)
zRange = (int) (Math.ceil(((double) zRange) / ((double) 16))) * 16; //say zRange was entered as 2000. there is no change, as it already is a multiple of 16.
out(""); out("");
@ -593,6 +630,10 @@ public class Main {
out(""); out("");
double xLoops, zLoops; double xLoops, zLoops;
int curXloops = 0;
int curZloops = 0;
int xRangeAdj = 0;
int zRangeAdj = 0;
// have main loop make an arraylist of spawnpoints // have main loop make an arraylist of spawnpoints
// read from a file if MLG has run before on this world. save to arraylist // read from a file if MLG has run before on this world. save to arraylist
@ -601,28 +642,28 @@ public class Main {
// X // X
xLoops = ((double) xRange / (double) increment); //How many loops do we need? xLoops = ((double) xRange / (double) increment); //How many loops do we need?
xLoops = Math.ceil(xLoops); //round up to find out! xLoops = Math.ceil(xLoops); //round up to find out!
xRangeAdj = (int) (xLoops * increment);
xLoops = xLoops + 1;
// Z // Z
zLoops = ((double) zRange / (double) increment); //How many loops do we need? zLoops = ((double) zRange / (double) increment); //How many loops do we need?
zLoops = Math.ceil(zLoops); //round up to find out! zLoops = Math.ceil(zLoops); //round up to find out!
zRangeAdj = (int) (zLoops * increment);
zLoops = zLoops + 1;
out("Calculating Spawn Points..."); out("Calculating Spawn Points...");
int totalIterations = (int) (xLoops * zLoops); int totalIterations = (int) (xLoops * zLoops);
int currentIteration = 0; int currentIteration = 0;
int curXloops = 0;
int curZloops = 0;
long differenceTime = System.currentTimeMillis(); long differenceTime = System.currentTimeMillis();
Long timeTracking = 0L; Long timeTracking = 0L;
ArrayList<Coordinates> launchList = new ArrayList<Coordinates>(totalIterations); ArrayList<Coordinates> launchList = new ArrayList<Coordinates>(totalIterations);
for (int currentX = (int) ((Math.ceil((((0 - xRange) / 2) / increment))) * increment); currentX <= (xRange / 2); currentX += for (int currentX = 0; currentX <= (xRangeAdj / 2); currentX += increment) {
increment) {
curXloops++; curXloops++;
if (curXloops == 1) { if (curXloops == 1) {
currentX = (((0 - xRange) / 2) + (increment / 2) + 16); currentX = (((0 - xRange) / 2) + (increment / 2) + 16);
@ -630,9 +671,7 @@ public class Main {
currentX = (xRange / 2) - (increment / 2); currentX = (xRange / 2) - (increment / 2);
} }
for (int currentZ = for (int currentZ = 0; currentZ <= (zRangeAdj / 2); currentZ += increment) {
(int) ((Math.ceil((((0 - zRange) / 2) / increment))) * increment); currentZ <= (zRange / 2); currentZ +=
increment) {
currentIteration++; currentIteration++;
curZloops++; curZloops++;
@ -642,20 +681,25 @@ public class Main {
currentZ = (zRange / 2) - (increment / 2); currentZ = (zRange / 2) - (increment / 2);
} }
// add coords to arraylist here {
Coordinates tempCoords = // add Coordinates to arraylist here
new Coordinates(currentX + xOffset, 64, currentZ + zOffset); Coordinates tempCoords =
launchList.add(tempCoords); new Coordinates(currentX + xOffset, 64, currentZ + zOffset);
launchList.add(tempCoords);
//TODO: remove this before release:
System.out.println(tempCoords);
}
if (curZloops == 1) { if (curZloops == 1) {
currentZ = currentZ =
(int) ((Math.ceil((((0 - zRange) / 2) / increment))) * increment); (int) ((Math.ceil((((0 - zRangeAdj) / 2) / increment))) * increment);
} }
} }
curZloops = 0; curZloops = 0;
if (curXloops == 1) { if (curXloops == 1) {
currentX = (int) ((Math.ceil((((0 - xRange) / 2) / increment))) * increment); currentX = (int) ((Math.ceil((((0 - xRangeAdj) / 2) / increment))) * increment);
} }
} }
@ -668,11 +712,6 @@ public class Main {
MLG_ArrayList.arrayListRemove(launchList, removeList); MLG_ArrayList.arrayListRemove(launchList, removeList);
} }
int numRemoved = totalIterations - launchList.size();
if (numRemoved > 0) {
out("Reduced number of server launches by: " + numRemoved);
}
removeList.clear(); // we are done with this now. removeList.clear(); // we are done with this now.
System.gc(); //run the garbage collector - hopefully free up some memory! System.gc(); //run the garbage collector - hopefully free up some memory!
@ -738,12 +777,12 @@ public class Main {
MLG_Misc.copyFile(backupLevel, serverLevel); MLG_Misc.copyFile(backupLevel, serverLevel);
backupLevel.delete(); backupLevel.delete();
out("Restored original level.dat."); out("Restored original level.dat.");
//finishedImage(); //disabled, because I didn't care for it - it didn't flow well with MLG
out("Generation complete in: " out("Generation complete in: "
+ MLG_Time.displayTime(startTime, System.currentTimeMillis())); + MLG_Time.displayTime(startTime, System.currentTimeMillis()));
MLG_Time.waitTenSec(false); MLG_Time.waitTenSec(false);
} catch (IOException ex) { } catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(Main.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
} }
} }

View File

@ -94,31 +94,58 @@ public class Coordinates {
int x = 0, y = 0, z = 0; int x = 0, y = 0, z = 0;
//TODO: add validity checks: //TODO: add validity checks:
//TODO: add short version... (Y = 0) //TODO: add short version... (Y = 64)
int start = 0, end = 0, firstComma = 0, secComma = 0; int start = 0, end = 0, firstComma = 0, secComma = 0;
String sX = "", sY = "", sZ = ""; String sX = "", sY = "", sZ = "";
boolean shortMode = false, notCoords = false;
start = StringOfCoords.indexOf("["); start = StringOfCoords.indexOf("[");
end = StringOfCoords.indexOf("]"); end = StringOfCoords.indexOf("]");
StringOfCoords = StringOfCoords.substring(start, end); if ((start == -1) || (end == -1)) {
start = StringOfCoords.indexOf("(");
end = StringOfCoords.indexOf(")");
firstComma = StringOfCoords.indexOf(","); if ((start != -1) || (end != -1)) {
secComma = StringOfCoords.lastIndexOf(","); shortMode = true;
} else {
notCoords = true;
}
}
//System.out.println(start + " " + end + " " + firstComma + " " + secComma); if (notCoords) { return new Coordinates(0, 0, 0); }
sX = StringOfCoords.substring(start + 1, firstComma); if (shortMode) {
sY = StringOfCoords.substring(firstComma + 1, secComma);
sZ = StringOfCoords.substring(secComma + 1, end);
//System.out.println(sX + " " + sY + " " + sZ); StringOfCoords = StringOfCoords.substring(start, end);
x = Integer.parseInt(sX); firstComma = StringOfCoords.indexOf(",");
y = Integer.parseInt(sY);
z = Integer.parseInt(sZ); sX = StringOfCoords.substring(start + 1, firstComma);
sY = "64";
sZ = StringOfCoords.substring(firstComma + 1, end);
} else {
StringOfCoords = StringOfCoords.substring(start, end);
firstComma = StringOfCoords.indexOf(",");
secComma = StringOfCoords.lastIndexOf(",");
sX = StringOfCoords.substring(start + 1, firstComma);
sY = StringOfCoords.substring(firstComma + 1, secComma);
sZ = StringOfCoords.substring(secComma + 1, end);
}
try {
x = Integer.parseInt(sX);
y = Integer.parseInt(sY);
z = Integer.parseInt(sZ);
} catch (NumberFormatException e) {
return new Coordinates(0, 0, 0);
}
return new Coordinates(x, y, z); return new Coordinates(x, y, z);
} }

View File

@ -20,6 +20,9 @@ public class MLG_FileRead {
String line = ""; String line = "";
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
line = line.trim();
int end = line.indexOf('#'); // comments, ignored lines int end = line.indexOf('#'); // comments, ignored lines
boolean ignoreLine = false; boolean ignoreLine = false;
Coordinates c = new Coordinates(); Coordinates c = new Coordinates();
@ -35,10 +38,19 @@ public class MLG_FileRead {
if (!(ignoreLine)) { if (!(ignoreLine)) {
c = Coordinates.parseString(line.substring(0, end)); c = Coordinates.parseString(line.substring(0, end));
Return.add(c); Return.add(c);
} /* else { } else {
// other future stuff may go here. if (line.startsWith("##Size:")) { // Potential Resume data.
int xx = 0;
int zz = 0;
xx = line.indexOf('X');
zz = line.indexOf('Z');
Main.resumeX = Integer.parseInt(line.substring(xx + 1, zz));
Main.resumeZ = Integer.parseInt(line.substring(zz + 1));
} }
*/ }
} }
in.close(); in.close();

View File

@ -14,11 +14,22 @@ public class MLG_input_CLI {
*/ */
public static int getInt(String msg) { public static int getInt(String msg) {
int Return = 0;
while (!(Main.sc.hasNextInt())) { while (!(Main.sc.hasNextInt())) {
Main.sc.nextLine(); Main.sc.nextLine();
Main.outP(Main.MLG + "Invalid Input. " + msg); Main.outP(Main.MLG + "Invalid Input. " + msg);
} }
return Main.sc.nextInt();
Return = Main.sc.nextInt();
if (Return < 1000) {
Main.out("Input must be 1000 or larger.");
Main.outP(Main.MLG + msg);
Return = getInt(msg);
}
return Return;
} }