Major 1.7.1 refactoring!
Also removed RCON.
This commit is contained in:
parent
25f7d318fa
commit
4fe1099a28
@ -5,7 +5,6 @@ package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
/**
|
||||
* @author morlok8k
|
||||
*
|
||||
@ -18,7 +17,7 @@ public class Arraylist {
|
||||
boolean changed = false;
|
||||
changed = list.removeAll(remove);
|
||||
|
||||
if (Main.verbose) {
|
||||
if (var.verbose) {
|
||||
System.out.println("ArrayList changed: " + changed);
|
||||
}
|
||||
|
||||
|
@ -16,115 +16,6 @@ public class Coordinates {
|
||||
// Minecraft starts failing around (+/-) 12,550,820 and ends at either (+/-) 30,000,000 or (+/-) 32,000,000 (depending on the version).
|
||||
// See: http://www.minecraftwiki.net/wiki/Far_Lands for more info.
|
||||
|
||||
public int X = 0;
|
||||
public int Y = 0;
|
||||
public int Z = 0;
|
||||
|
||||
/**
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public Coordinates(final int x, final int y, final int z) {
|
||||
super();
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
/**
|
||||
* Someone created a new blank Coordinate! Lets set it to be [0,0,0].
|
||||
*/
|
||||
public Coordinates() {
|
||||
clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the x
|
||||
*/
|
||||
public int getX() {
|
||||
return X;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the y
|
||||
*/
|
||||
public int getY() {
|
||||
return Y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the z
|
||||
*/
|
||||
public int getZ() {
|
||||
return Z;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x
|
||||
* the x to set
|
||||
*/
|
||||
public void setX(final int x) {
|
||||
X = x;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param y
|
||||
* the y to set
|
||||
*/
|
||||
public void setY(final int y) {
|
||||
Y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param z
|
||||
* the z to set
|
||||
*/
|
||||
public void setZ(final int z) {
|
||||
Z = z;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
X = 0;
|
||||
Y = 0;
|
||||
Z = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a Coordinates object from a String. Leading and trailing garbage is ignored (FIXME).
|
||||
*
|
||||
* @param stringOfCoords
|
||||
* A short- or long-form coordinate string as described at the two toString() methods
|
||||
* @author jaseg
|
||||
*/
|
||||
public static Coordinates parseStringRegEx(String stringOfCoords) {
|
||||
int X = 0, Y = 0, Z = 0;
|
||||
boolean matched = false;
|
||||
Matcher shortForm = Pattern.compile("\\((-?\\d+),(-?\\d+)\\)").matcher(stringOfCoords);
|
||||
Matcher normalForm =
|
||||
Pattern.compile("\\[(-?\\d+),(-?\\d+),(-?\\d+)\\]").matcher(stringOfCoords);
|
||||
|
||||
if (shortForm.matches()) {
|
||||
X = Integer.parseInt(shortForm.group(1));
|
||||
Y = 64;
|
||||
Z = Integer.parseInt(shortForm.group(2));
|
||||
matched = true;
|
||||
}
|
||||
|
||||
if (normalForm.matches()) {
|
||||
X = Integer.parseInt(normalForm.group(1));
|
||||
Y = Integer.parseInt(normalForm.group(2));
|
||||
Z = Integer.parseInt(normalForm.group(3));
|
||||
matched = true;
|
||||
}
|
||||
|
||||
if (!matched) {
|
||||
System.err.println("Invalid coordinate format: " + stringOfCoords);
|
||||
System.err.println();
|
||||
}
|
||||
return new Coordinates(X, Y, Z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a Coordinates object from a String. Leading and trailing garbage is ignored (FIXME).
|
||||
*
|
||||
@ -195,51 +86,71 @@ public class Coordinates {
|
||||
return new Coordinates(x, y, z);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
// Java Language Specific Crap Below... Stuff *gotta* be there so Java won't cry... //
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
/**
|
||||
* Parses a Coordinates object from a String. Leading and trailing garbage is ignored (FIXME).
|
||||
*
|
||||
* @param stringOfCoords
|
||||
* A short- or long-form coordinate string as described at the two toString() methods
|
||||
* @author jaseg
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
// I am overriding the inherited toString method.
|
||||
// Because it doesn't know how to deal with my custom data.
|
||||
// So instead of getting "blahblahblah.Coordinates@745f"
|
||||
// (the location of the class and the hexstring of the hashcode)
|
||||
// I return "[X,Y,Z]"
|
||||
public static Coordinates parseStringRegEx(String stringOfCoords) {
|
||||
int X = 0, Y = 0, Z = 0;
|
||||
boolean matched = false;
|
||||
final Matcher shortForm =
|
||||
Pattern.compile("\\((-?\\d+),(-?\\d+)\\)").matcher(stringOfCoords);
|
||||
final Matcher normalForm =
|
||||
Pattern.compile("\\[(-?\\d+),(-?\\d+),(-?\\d+)\\]").matcher(stringOfCoords);
|
||||
|
||||
return ("[" + X + "," + Y + "," + Z + "]");
|
||||
|
||||
}
|
||||
|
||||
public String toString(final boolean Short) {
|
||||
if (Short) { // We are overloading toString with an additional option:
|
||||
return ("(" + X + "," + Z + ")"); // Basically just an option to return just X and Z (formatted differently as well: "(X,Z)")
|
||||
if (shortForm.matches()) {
|
||||
X = Integer.parseInt(shortForm.group(1));
|
||||
Y = 64;
|
||||
Z = Integer.parseInt(shortForm.group(2));
|
||||
matched = true;
|
||||
}
|
||||
return toString(); // Idiot catch. default to: "[X,Y,Z]"
|
||||
|
||||
if (normalForm.matches()) {
|
||||
X = Integer.parseInt(normalForm.group(1));
|
||||
Y = Integer.parseInt(normalForm.group(2));
|
||||
Z = Integer.parseInt(normalForm.group(3));
|
||||
matched = true;
|
||||
}
|
||||
|
||||
if (!matched) {
|
||||
System.err.println("Invalid coordinate format: " + stringOfCoords);
|
||||
System.err.println();
|
||||
}
|
||||
return new Coordinates(X, Y, Z);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
// I am overriding the inherited hashCode method.
|
||||
// Because it doesn't know how to deal with my custom data.
|
||||
// So instead of getting who knows what, we return valid data
|
||||
public int X = 0;
|
||||
|
||||
final int prime = 31; // My hard coded prime number
|
||||
int result = 1; // The hard coded number I start with
|
||||
result = (prime * result) + X; // Add the X data
|
||||
result = (prime * result) + Y; // Add the Y data
|
||||
result = (prime * result) + Z; // Add the Z data
|
||||
return result; //this result will consistently give the same result for the same data.
|
||||
// [0,0,0] will always give 29791. [1,2,3] will always give 30817.
|
||||
//yes, If I was lazy, I could just do a "return 0;" and it would still be technically valid.
|
||||
//but if I'm going override the method, I might as well do it right...
|
||||
public int Y = 0;
|
||||
|
||||
public int Z = 0;
|
||||
|
||||
/**
|
||||
* Someone created a new blank Coordinate! Lets set it to be [0,0,0].
|
||||
*/
|
||||
public Coordinates() {
|
||||
clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x
|
||||
* @param y
|
||||
* @param z
|
||||
*/
|
||||
public Coordinates(final int x, final int y, final int z) {
|
||||
super();
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
X = 0;
|
||||
Y = 0;
|
||||
Z = 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@ -269,4 +180,96 @@ public class Coordinates {
|
||||
if (Z != c.Z) { return false; }
|
||||
return true; // If none of the above returned something, they must be equal!
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the x
|
||||
*/
|
||||
public int getX() {
|
||||
return X;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the y
|
||||
*/
|
||||
public int getY() {
|
||||
return Y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the z
|
||||
*/
|
||||
public int getZ() {
|
||||
return Z;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
// I am overriding the inherited hashCode method.
|
||||
// Because it doesn't know how to deal with my custom data.
|
||||
// So instead of getting who knows what, we return valid data
|
||||
|
||||
final int prime = 31; // My hard coded prime number
|
||||
int result = 1; // The hard coded number I start with
|
||||
result = (prime * result) + X; // Add the X data
|
||||
result = (prime * result) + Y; // Add the Y data
|
||||
result = (prime * result) + Z; // Add the Z data
|
||||
return result; //this result will consistently give the same result for the same data.
|
||||
// [0,0,0] will always give 29791. [1,2,3] will always give 30817.
|
||||
//yes, If I was lazy, I could just do a "return 0;" and it would still be technically valid.
|
||||
//but if I'm going override the method, I might as well do it right...
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x
|
||||
* the x to set
|
||||
*/
|
||||
public void setX(final int x) {
|
||||
X = x;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
// Java Language Specific Crap Below... Stuff *gotta* be there so Java won't cry... //
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* @param y
|
||||
* the y to set
|
||||
*/
|
||||
public void setY(final int y) {
|
||||
Y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param z
|
||||
* the z to set
|
||||
*/
|
||||
public void setZ(final int z) {
|
||||
Z = z;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
// I am overriding the inherited toString method.
|
||||
// Because it doesn't know how to deal with my custom data.
|
||||
// So instead of getting "blahblahblah.Coordinates@745f"
|
||||
// (the location of the class and the hexstring of the hashcode)
|
||||
// I return "[X,Y,Z]"
|
||||
|
||||
return ("[" + X + "," + Y + "," + Z + "]");
|
||||
|
||||
}
|
||||
|
||||
public String toString(final boolean Short) {
|
||||
if (Short) { // We are overloading toString with an additional option:
|
||||
return ("(" + X + "," + Z + ")"); // Basically just an option to return just X and Z (formatted differently as well: "(X,Z)")
|
||||
}
|
||||
return toString(); // Idiot catch. default to: "[X,Y,Z]"
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import java.net.URL;
|
||||
|
||||
import org.w3c.bert_bos.UTF8URL.Unescape;
|
||||
|
||||
|
||||
public class DownloadFile {
|
||||
|
||||
/**
|
||||
@ -58,7 +57,7 @@ public class DownloadFile {
|
||||
timeTracking[0] = System.currentTimeMillis();
|
||||
|
||||
if (Output) {
|
||||
Main.outP(Main.MLG + "*");
|
||||
Main.outP(var.MLG + "*");
|
||||
}
|
||||
|
||||
try {
|
||||
@ -80,7 +79,7 @@ public class DownloadFile {
|
||||
bout.close();
|
||||
in.close();
|
||||
if (Output) {
|
||||
Main.outP(Main.newLine);
|
||||
Main.outP(var.newLine);
|
||||
Main.out(count + " byte(s) copied");
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class FileRead {
|
||||
|
||||
public static ArrayList<Coordinates> readArrayListCoordLog(final String file) {
|
||||
@ -45,8 +44,8 @@ public class FileRead {
|
||||
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));
|
||||
var.resumeX = Integer.parseInt(line.substring(xx + 1, zz));
|
||||
var.resumeZ = Integer.parseInt(line.substring(zz + 1));
|
||||
|
||||
}
|
||||
}
|
||||
@ -73,7 +72,7 @@ public class FileRead {
|
||||
//String errorMsg = "";
|
||||
|
||||
try {
|
||||
final File config = new File(Main.MinecraftLandGeneratorConf);
|
||||
final File config = new File(var.MinecraftLandGeneratorConf);
|
||||
final BufferedReader in = new BufferedReader(new FileReader(config));
|
||||
String line = "";
|
||||
String property = "";
|
||||
@ -108,79 +107,79 @@ public class FileRead {
|
||||
}
|
||||
|
||||
if (property.equals("serverpath")) {
|
||||
Main.serverPath = value;
|
||||
var.serverPath = value;
|
||||
} else if (property.equals("java")) {
|
||||
Main.javaLine = value;
|
||||
var.javaLine = value;
|
||||
} else if (property.equals("done_text")) {
|
||||
Main.doneText = value;
|
||||
var.doneText = value;
|
||||
} else if (property.equals("preparing_text")) {
|
||||
Main.preparingText = value;
|
||||
var.preparingText = value;
|
||||
} else if (property.equals("preparing_level")) {
|
||||
Main.preparingLevel = value;
|
||||
var.preparingLevel = value;
|
||||
} else if (property.equals("level-0")) {
|
||||
Main.level_0 = value;
|
||||
var.level_0 = value;
|
||||
} else if (property.equals("level-1")) {
|
||||
Main.level_1 = value;
|
||||
var.level_1 = value;
|
||||
} else if (property.equals("level-2")) {
|
||||
Main.level_2 = value;
|
||||
var.level_2 = value;
|
||||
} else if (property.equals("level-3")) {
|
||||
Main.level_3 = value;
|
||||
var.level_3 = value;
|
||||
} else if (property.equals("level-4")) {
|
||||
Main.level_4 = value;
|
||||
var.level_4 = value;
|
||||
} else if (property.equals("level-5")) {
|
||||
Main.level_5 = value;
|
||||
var.level_5 = value;
|
||||
} else if (property.equals("level-6")) {
|
||||
Main.level_6 = value;
|
||||
var.level_6 = value;
|
||||
} else if (property.equals("level-7")) {
|
||||
Main.level_7 = value;
|
||||
var.level_7 = value;
|
||||
} else if (property.equals("level-8")) {
|
||||
Main.level_8 = value;
|
||||
var.level_8 = value;
|
||||
} else if (property.equals("level-9")) {
|
||||
Main.level_9 = value;
|
||||
var.level_9 = value;
|
||||
} else if (property.equals("waitsave")) {
|
||||
if (value.toLowerCase().equals("true")) {
|
||||
Main.waitSave = true;
|
||||
var.waitSave = true;
|
||||
} else {
|
||||
Main.waitSave = false;
|
||||
var.waitSave = false;
|
||||
}
|
||||
} else if (property.equals("weblaunch")) {
|
||||
if (value.toLowerCase().equals("true")) {
|
||||
Main.webLaunch = true;
|
||||
var.webLaunch = true;
|
||||
} else {
|
||||
Main.webLaunch = false;
|
||||
var.webLaunch = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
|
||||
if (Main.testing) {
|
||||
if (var.testing) {
|
||||
Main.outD("Test Output: Reading of Config File ");
|
||||
Main.outD(" serverPath: " + Main.serverPath);
|
||||
Main.outD(" javaLine: " + Main.javaLine);
|
||||
Main.outD(" doneText: " + Main.doneText);
|
||||
Main.outD(" preparingText: " + Main.preparingText);
|
||||
Main.outD("preparingLevel: " + Main.preparingLevel);
|
||||
Main.outD(" level_0: " + Main.level_0);
|
||||
Main.outD(" level_1: " + Main.level_1);
|
||||
Main.outD(" level_2: " + Main.level_2);
|
||||
Main.outD(" level_3: " + Main.level_3);
|
||||
Main.outD(" level_4: " + Main.level_4);
|
||||
Main.outD(" level_5: " + Main.level_5);
|
||||
Main.outD(" level_6: " + Main.level_6);
|
||||
Main.outD(" level_7: " + Main.level_7);
|
||||
Main.outD(" level_8: " + Main.level_8);
|
||||
Main.outD(" level_9: " + Main.level_9);
|
||||
Main.outD(" waitSave: " + Main.waitSave);
|
||||
Main.outD(" webLaunch: " + Main.webLaunch);
|
||||
Main.outD(" serverPath: " + var.serverPath);
|
||||
Main.outD(" javaLine: " + var.javaLine);
|
||||
Main.outD(" doneText: " + var.doneText);
|
||||
Main.outD(" preparingText: " + var.preparingText);
|
||||
Main.outD("preparingLevel: " + var.preparingLevel);
|
||||
Main.outD(" level_0: " + var.level_0);
|
||||
Main.outD(" level_1: " + var.level_1);
|
||||
Main.outD(" level_2: " + var.level_2);
|
||||
Main.outD(" level_3: " + var.level_3);
|
||||
Main.outD(" level_4: " + var.level_4);
|
||||
Main.outD(" level_5: " + var.level_5);
|
||||
Main.outD(" level_6: " + var.level_6);
|
||||
Main.outD(" level_7: " + var.level_7);
|
||||
Main.outD(" level_8: " + var.level_8);
|
||||
Main.outD(" level_9: " + var.level_9);
|
||||
Main.outD(" waitSave: " + var.waitSave);
|
||||
Main.outD(" webLaunch: " + var.webLaunch);
|
||||
}
|
||||
} catch (final FileNotFoundException ex) {
|
||||
Main.out("Could not find "
|
||||
+ Main.MinecraftLandGeneratorConf
|
||||
+ var.MinecraftLandGeneratorConf
|
||||
+ ". It is recommended that you run the application with the -conf option to create it.");
|
||||
return;
|
||||
} catch (final IOException ex) {
|
||||
Main.err("Could not read " + Main.MinecraftLandGeneratorConf + ".");
|
||||
Main.err("Could not read " + var.MinecraftLandGeneratorConf + ".");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -5,14 +5,13 @@ import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* http://www.roseindia.net/java/example/java/io/java-append-to-file.shtml <br>
|
||||
* Append To File - Java Tutorial
|
||||
*/
|
||||
public class FileWrite {
|
||||
|
||||
public static final String newLine = Main.newLine;
|
||||
public static final String newLine = var.newLine;
|
||||
|
||||
/**
|
||||
* @param file
|
||||
@ -32,6 +31,66 @@ public class FileWrite {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a Config File.
|
||||
*
|
||||
* @param newConf
|
||||
* true: Uses Default values. false: uses existing values
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static void saveConf(final boolean newConf) {
|
||||
|
||||
String jL = null; //javaLine
|
||||
String sP = null; //serverPath
|
||||
|
||||
if (newConf) {
|
||||
jL = var.defaultJavaLine; // reads the default from a constant, makes it easier!
|
||||
sP = "."; //
|
||||
} else {
|
||||
jL = var.javaLine; // we read these values from an existing Conf File.
|
||||
sP = var.serverPath; //
|
||||
}
|
||||
|
||||
String txt = null;
|
||||
//@formatter:off
|
||||
txt = "#" + var.PROG_NAME + " Configuration File: Version: " + var.VERSION + var.newLine
|
||||
+ "#Authors: " + var.AUTHORS + var.newLine
|
||||
+ "#Auto-Generated: " + var.dateFormat.format(var.date) + var.newLine
|
||||
+ var.newLine
|
||||
+ "#Line to run server:" + var.newLine
|
||||
+ "Java=" + jL // reads the default from a constant, makes it easier!
|
||||
+ var.newLine
|
||||
+ var.newLine
|
||||
+ "#Location of server. use \".\" for the same folder as MLG" + var.newLine
|
||||
+ "ServerPath=" + sP
|
||||
+ var.newLine
|
||||
+ var.newLine
|
||||
+ "#Strings read from the server" + var.newLine
|
||||
+ "Done_Text=[INFO] Done" + var.newLine
|
||||
+ "Preparing_Text=[INFO] Preparing spawn area:" + var.newLine
|
||||
+ "Preparing_Level=[INFO] Preparing start region for" + var.newLine
|
||||
+ "Level-0=The Overworld" + var.newLine
|
||||
+ "Level-1=The Nether" + var.newLine
|
||||
+ "Level-2=The End" + var.newLine
|
||||
+ "Level-3=Level 3 (Future Level)" + var.newLine
|
||||
+ "Level-4=Level 4 (Future Level)" + var.newLine
|
||||
+ "Level-5=Level 5 (Future Level)" + var.newLine
|
||||
+ "Level-6=Level 6 (Future Level)" + var.newLine
|
||||
+ "Level-7=Level 7 (Future Level)" + var.newLine
|
||||
+ "Level-8=Level 8 (Future Level)" + var.newLine
|
||||
+ "Level-9=Level 9 (Future Level)" + var.newLine
|
||||
+ var.newLine
|
||||
+ "#Optional: Wait a few seconds after saving." + var.newLine
|
||||
+ "WaitSave=false" + var.newLine
|
||||
+ "webLaunch=true";
|
||||
//@formatter:on
|
||||
|
||||
writeTxtFile(var.MinecraftLandGeneratorConf, txt);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param file
|
||||
* @param txt
|
||||
@ -54,71 +113,11 @@ public class FileWrite {
|
||||
Main.out(file + " file created.");
|
||||
return;
|
||||
} catch (final IOException ex) {
|
||||
Main.err("Could not create " + Main.MinecraftLandGeneratorConf + ".");
|
||||
Main.err("Could not create " + var.MinecraftLandGeneratorConf + ".");
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a Config File.
|
||||
*
|
||||
* @param newConf
|
||||
* true: Uses Default values. false: uses existing values
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static void saveConf(final boolean newConf) {
|
||||
|
||||
String jL = null; //javaLine
|
||||
String sP = null; //serverPath
|
||||
|
||||
if (newConf) {
|
||||
jL = Main.defaultJavaLine; // reads the default from a constant, makes it easier!
|
||||
sP = "."; //
|
||||
} else {
|
||||
jL = Main.javaLine; // we read these values from an existing Conf File.
|
||||
sP = Main.serverPath; //
|
||||
}
|
||||
|
||||
String txt = null;
|
||||
//@formatter:off
|
||||
txt = "#" + Main.PROG_NAME + " Configuration File: Version: " + Main.VERSION + Main.newLine
|
||||
+ "#Authors: " + Main.AUTHORS + Main.newLine
|
||||
+ "#Auto-Generated: " + Main.dateFormat.format(Main.date) + Main.newLine
|
||||
+ Main.newLine
|
||||
+ "#Line to run server:" + Main.newLine
|
||||
+ "Java=" + jL // reads the default from a constant, makes it easier!
|
||||
+ Main.newLine
|
||||
+ Main.newLine
|
||||
+ "#Location of server. use \".\" for the same folder as MLG" + Main.newLine
|
||||
+ "ServerPath=" + sP
|
||||
+ Main.newLine
|
||||
+ Main.newLine
|
||||
+ "#Strings read from the server" + Main.newLine
|
||||
+ "Done_Text=[INFO] Done" + Main.newLine
|
||||
+ "Preparing_Text=[INFO] Preparing spawn area:" + Main.newLine
|
||||
+ "Preparing_Level=[INFO] Preparing start region for" + Main.newLine
|
||||
+ "Level-0=The Overworld" + Main.newLine
|
||||
+ "Level-1=The Nether" + Main.newLine
|
||||
+ "Level-2=The End" + Main.newLine
|
||||
+ "Level-3=Level 3 (Future Level)" + Main.newLine
|
||||
+ "Level-4=Level 4 (Future Level)" + Main.newLine
|
||||
+ "Level-5=Level 5 (Future Level)" + Main.newLine
|
||||
+ "Level-6=Level 6 (Future Level)" + Main.newLine
|
||||
+ "Level-7=Level 7 (Future Level)" + Main.newLine
|
||||
+ "Level-8=Level 8 (Future Level)" + Main.newLine
|
||||
+ "Level-9=Level 9 (Future Level)" + Main.newLine
|
||||
+ Main.newLine
|
||||
+ "#Optional: Wait a few seconds after saving." + Main.newLine
|
||||
+ "WaitSave=false" + Main.newLine
|
||||
+ "webLaunch=true";
|
||||
//@formatter:on
|
||||
|
||||
writeTxtFile(Main.MinecraftLandGeneratorConf, txt);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
|
||||
public class Input_CLI {
|
||||
|
||||
/**
|
||||
@ -15,16 +14,16 @@ public class Input_CLI {
|
||||
|
||||
int Return = 0;
|
||||
|
||||
while (!(Main.sc.hasNextInt())) {
|
||||
Main.sc.nextLine();
|
||||
Main.outP(Main.MLG + "Invalid Input. " + msg);
|
||||
while (!(var.sc.hasNextInt())) {
|
||||
var.sc.nextLine();
|
||||
Main.outP(var.MLG + "Invalid Input. " + msg);
|
||||
}
|
||||
|
||||
Return = Main.sc.nextInt();
|
||||
Return = var.sc.nextInt();
|
||||
|
||||
if (Return < 1000) {
|
||||
Main.out("Input must be 1000 or larger.");
|
||||
Main.outP(Main.MLG + msg);
|
||||
Main.outP(var.MLG + msg);
|
||||
Return = getInt(msg);
|
||||
}
|
||||
|
||||
|
@ -7,13 +7,9 @@ import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
import java.util.Scanner;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@ -24,119 +20,21 @@ import java.util.logging.Logger;
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
//
|
||||
//
|
||||
// Public Vars:
|
||||
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 VERSION = "1.7.0"; // Version Number!
|
||||
public static final String AUTHORS = "Corrodias, Morlok8k, pr0f1x"; // Authors
|
||||
|
||||
public static final String fileSeparator = System.getProperty("file.separator");
|
||||
public static final String newLine = System.getProperty("line.separator");
|
||||
|
||||
public static String[] originalArgs = {};
|
||||
|
||||
public static String MLG = "[MLG] ";
|
||||
public static String MLGe = "[MLG-ERROR] ";
|
||||
|
||||
public static DateFormat dateFormat_MDY = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
|
||||
public static Date MLG_Last_Modified_Date = null;
|
||||
|
||||
public static String MLGFileNameShort = null;
|
||||
public static Scanner sc = new Scanner(System.in);
|
||||
public static final String MinecraftLandGeneratorConf = "MinecraftLandGenerator.conf";
|
||||
public static final String defaultReadmeFile = "_MLG_Readme.txt";
|
||||
|
||||
public static String doneText = null;
|
||||
public static String preparingText = null;
|
||||
public static String preparingLevel = null;
|
||||
|
||||
public static String level_0 = null; // the world
|
||||
public static String level_1 = null; // the nether
|
||||
public static String level_2 = null; // the end
|
||||
public static String level_3 = null; // future worlds
|
||||
public static String level_4 = null;
|
||||
public static String level_5 = null;
|
||||
public static String level_6 = null;
|
||||
public static String level_7 = null;
|
||||
public static String level_8 = null;
|
||||
public static String level_9 = null;
|
||||
|
||||
public static ProcessBuilder minecraft = null;
|
||||
public static String javaLine = null;
|
||||
public static final String defaultJavaLine =
|
||||
"java -Djava.awt.headless=true -Djline.terminal=jline.UnsupportedTerminal -Duser.language=en"
|
||||
+ " -Xms1024m -Xmx1024m -Xincgc -jar minecraft_server.jar nogui";
|
||||
|
||||
public static String serverPath = null;
|
||||
public static String worldPath = null;
|
||||
public static String worldName = null;
|
||||
|
||||
public static boolean verbose = false;
|
||||
|
||||
public static boolean dontWait = false;
|
||||
public static boolean waitSave = false;
|
||||
public static boolean ignoreWarnings = false;
|
||||
public static Long randomSeed = (long) 0;
|
||||
|
||||
public static DateFormat dateFormat = new SimpleDateFormat( // Lets get a nice Date format for display
|
||||
"EEEE, MMMM d, yyyy 'at' h:mm a zzzz", Locale.ENGLISH);
|
||||
public static Date date = null; // date stuff
|
||||
public static Long MLG_Last_Modified_Long = 0L;
|
||||
|
||||
public static final Class<?> cls = Main.class;
|
||||
public static String MLGFileName = null;
|
||||
|
||||
public static final String rsrcError = "rsrcERROR";
|
||||
public static String buildIDFile = "MLG-BuildID";
|
||||
public static boolean isCompiledAsJar = false;
|
||||
public static String MLG_Current_Hash = null;
|
||||
public static int inf_loop_protect_BuildID = 0;
|
||||
public static boolean flag_downloadedBuildID = false;
|
||||
|
||||
public static String MC_Server_Version = "";
|
||||
|
||||
public static ArrayList<String> timeStamps = new ArrayList<String>();
|
||||
|
||||
public static final String MLG_JarFile = "MinecraftLandGenerator.jar";
|
||||
|
||||
public static final String github_URL =
|
||||
"https://raw.github.com/Morlok8k/MinecraftLandGenerator/master/bin/"; // just removing some redundancy
|
||||
public static final String github_MLG_Conf_URL = github_URL + MinecraftLandGeneratorConf;
|
||||
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 int resumeX = 0; //resume data, if needed.
|
||||
public static int resumeZ = 0;
|
||||
|
||||
//
|
||||
//
|
||||
//Private Vars:
|
||||
private static int MinecraftServerChunkPlayerCache = 625; //You see this number when you first launch the server in GUI mode, after the world is loaded, but before anyone has connected.
|
||||
private static int increment = (int) (Math.sqrt(MinecraftServerChunkPlayerCache) * 16) - 20; //private int increment = 380;
|
||||
|
||||
private int xRange = 0;
|
||||
private int zRange = 0;
|
||||
private Integer xOffset = null;
|
||||
|
||||
private Integer zOffset = null;
|
||||
|
||||
private boolean alternate = false;
|
||||
|
||||
private static Boolean recheckFlag = false;
|
||||
private static long startTime = 0L;
|
||||
public static boolean webLaunch = true; // Launch website after generation.
|
||||
|
||||
private static boolean assertsEnabled = false; //debugging use... use java -ea -jar MinecraftlandGenerator.jar...
|
||||
|
||||
// RCON Stuff (not currently used yet...)
|
||||
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 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_Password = "test"; //default is "", but a password must be entered.
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
// REMINDER: Because I always forget/mix up languages: //
|
||||
// "static" in java means "global" to this class //
|
||||
@ -144,6 +42,17 @@ public class Main {
|
||||
// public/private shows/hides between classes //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Outputs a formatted string to System.err as a line.
|
||||
*
|
||||
* @param str
|
||||
* String to display and format
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static void err(final String str) {
|
||||
System.err.println(var.MLGe + str);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* the command line arguments
|
||||
@ -152,7 +61,7 @@ public class Main {
|
||||
public static void main(String[] args) {
|
||||
startTime = System.currentTimeMillis();
|
||||
|
||||
originalArgs = args;
|
||||
var.originalArgs = args;
|
||||
|
||||
// This is really just here for debugging...
|
||||
// I plan on adding more asserts later, but for now, this will do.
|
||||
@ -161,11 +70,11 @@ public class Main {
|
||||
assert 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 (assertsEnabled) {
|
||||
outD("assertsEnabled: " + assertsEnabled);
|
||||
verbose = true;
|
||||
var.verbose = true;
|
||||
outD("Verbose mode forced!");
|
||||
testing = true;
|
||||
var.testing = true;
|
||||
outD("Debug mode forced!");
|
||||
dontWait = true;
|
||||
var.dontWait = true;
|
||||
outD("-nowait mode forced!");
|
||||
outD("");
|
||||
}
|
||||
@ -184,7 +93,7 @@ public class Main {
|
||||
//GUI Choosing code...
|
||||
if (!java.awt.GraphicsEnvironment.isHeadless() || (!NOGUI)) {
|
||||
GUI = true;
|
||||
if (testing) {
|
||||
if (var.testing) {
|
||||
outD("GUI: This is a graphical enviroment.");
|
||||
}
|
||||
|
||||
@ -194,7 +103,7 @@ public class Main {
|
||||
|
||||
} else {
|
||||
GUI = false; // No GUI for us today...
|
||||
if (testing) {
|
||||
if (var.testing) {
|
||||
outD("GUI: Command Line Only!");
|
||||
}
|
||||
}
|
||||
@ -217,6 +126,50 @@ public class Main {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a formatted string to System.out as a line.
|
||||
*
|
||||
* @param str
|
||||
* String to display and format
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static void out(final String str) {
|
||||
System.out.println(var.MLG + str); // is there a better/easier way to do this? I just wanted a lazier way to write "System.out.println(MLG + blah..."
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a formatted string to System.out as a line.
|
||||
*
|
||||
* @param str
|
||||
* String to display and format
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static void outD(final String str) {
|
||||
System.out.println(var.MLG + "[DEBUG] " + str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a string to System.out without a newline.
|
||||
*
|
||||
* @param str
|
||||
* String to display and format
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static void outP(final String str) {
|
||||
System.out.print(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a formatted string to System.out as a line.
|
||||
*
|
||||
* @param str
|
||||
* String to display and format
|
||||
* @author Morlok8k
|
||||
*/
|
||||
static void outS(final String str) {
|
||||
System.out.println("[Server] " + str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Start MinecraftLandGenerator (Command Line Interface)
|
||||
*
|
||||
@ -227,15 +180,16 @@ public class Main {
|
||||
private void runCLI(String[] args) {
|
||||
|
||||
// Lets get the date, and our BuildID
|
||||
date = new Date();
|
||||
var.date = new Date();
|
||||
Update.readBuildID();
|
||||
|
||||
// The following displays no matter what happens, so we needed this date stuff to happen first.
|
||||
|
||||
out(PROG_NAME + " version " + VERSION);
|
||||
out("BuildID: (" + MLG_Last_Modified_Date.getTime() + ")"); // instead of dateformatting the buildid, we return the raw Long number.
|
||||
out(var.PROG_NAME + " version " + var.VERSION);
|
||||
out("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
|
||||
out("This version was last modified on " + dateFormat.format(MLG_Last_Modified_Date));
|
||||
out("This version was last modified on "
|
||||
+ var.dateFormat.format(var.MLG_Last_Modified_Date));
|
||||
out("");
|
||||
out("Uses a Minecraft server to generate square land of a specified size.");
|
||||
out("");
|
||||
@ -252,16 +206,16 @@ public class Main {
|
||||
newArgs = StringArrayParse.Parse(newArgs, "-n"); //parse out -n
|
||||
newArgs = StringArrayParse.Parse(newArgs, "-nowait"); //parse out -nowait
|
||||
if (!(args.equals(newArgs))) { //do the freshly parsed args match the original?
|
||||
dontWait = true; //if not, we dont wait for anything!
|
||||
var.dontWait = true; //if not, we dont wait for anything!
|
||||
args = newArgs; //use the freshly parsed args for everything else now...
|
||||
out("Notice: Not waiting for anything...");
|
||||
}
|
||||
|
||||
if (args.length == 0) { //we didnt find a an X and Z size, so lets ask for one.
|
||||
out("Please Enter the size of world you want. Example: X:1000 Z:1000");
|
||||
outP(MLG + "X:");
|
||||
outP(var.MLG + "X:");
|
||||
xRange = Input_CLI.getInt("X:");
|
||||
outP(MLG + "Z:");
|
||||
outP(var.MLG + "Z:");
|
||||
zRange = Input_CLI.getInt("Z:");
|
||||
args = new String[] { String.valueOf(xRange), String.valueOf(zRange) };
|
||||
|
||||
@ -285,9 +239,9 @@ public class Main {
|
||||
if (args.length == 2) {
|
||||
if (args[1].equalsIgnoreCase("download")) {
|
||||
final boolean fileSuccess =
|
||||
DownloadFile.downloadFile(github_MLG_Conf_URL, testing);
|
||||
DownloadFile.downloadFile(var.github_MLG_Conf_URL, var.testing);
|
||||
if (fileSuccess) {
|
||||
out(MinecraftLandGeneratorConf + " file downloaded.");
|
||||
out(var.MinecraftLandGeneratorConf + " file downloaded.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -388,7 +342,7 @@ public class Main {
|
||||
return;
|
||||
|
||||
} else if (args.length == 1) {
|
||||
out("For help, use java -jar " + MLGFileNameShort + " -help");
|
||||
out("For help, use java -jar " + var.MLGFileNameShort + " -help");
|
||||
Time.waitTenSec(false);
|
||||
return;
|
||||
}
|
||||
@ -397,33 +351,33 @@ public class Main {
|
||||
|
||||
boolean oldConf = false; // This next section checks to see if we have a old configuration file (or none!)
|
||||
|
||||
if ((serverPath == null) || (javaLine == null)) { // MLG 1.2 Check for a valid .conf file.
|
||||
err(MinecraftLandGeneratorConf
|
||||
if ((var.serverPath == null) || (var.javaLine == null)) { // MLG 1.2 Check for a valid .conf file.
|
||||
err(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.
|
||||
|
||||
javaLine = defaultJavaLine;
|
||||
serverPath = ".";
|
||||
var.javaLine = var.defaultJavaLine;
|
||||
var.serverPath = ".";
|
||||
oldConf = true;
|
||||
}
|
||||
|
||||
if (doneText == null) { // MLG 1.4.0
|
||||
if (var.doneText == null) { // MLG 1.4.0
|
||||
oldConf = true;
|
||||
} else if (preparingText == null) { // MLG 1.4.0
|
||||
} else if (var.preparingText == null) { // MLG 1.4.0
|
||||
oldConf = true;
|
||||
} else if (preparingLevel == null) { // MLG 1.4.5 / 1.5.0
|
||||
} else if (var.preparingLevel == null) { // MLG 1.4.5 / 1.5.0
|
||||
oldConf = true;
|
||||
} else if (level_1 == null) { // MLG 1.4.5 / 1.5.0
|
||||
} else if (var.level_1 == null) { // MLG 1.4.5 / 1.5.0
|
||||
oldConf = true;
|
||||
} else if (level_0 == null) { // MLG 1.5.1 / 1.6.0
|
||||
} else if (var.level_0 == null) { // MLG 1.5.1 / 1.6.0
|
||||
oldConf = true;
|
||||
}
|
||||
|
||||
if (oldConf) {
|
||||
err("Old Version of " + MinecraftLandGeneratorConf + " found. Updating...");
|
||||
err("Old Version of " + var.MinecraftLandGeneratorConf + " found. Updating...");
|
||||
|
||||
FileWrite.saveConf(false); //old conf
|
||||
|
||||
@ -455,7 +409,7 @@ public class Main {
|
||||
//return;
|
||||
}
|
||||
|
||||
verbose = false; // Verifing that these vars are false
|
||||
var.verbose = false; // Verifing that these vars are false
|
||||
alternate = false; // before changing them...
|
||||
|
||||
// This is embarrassing. Don't look.
|
||||
@ -463,7 +417,7 @@ public class Main {
|
||||
for (int i = 0; i < (args.length - 2); i++) {
|
||||
final String nextSwitch = args[i + 2].toLowerCase();
|
||||
if (nextSwitch.equals("-verbose") || nextSwitch.equals("-v")) {
|
||||
verbose = true;
|
||||
var.verbose = true;
|
||||
out("Notice: Verbose Mode");
|
||||
|
||||
} else if (nextSwitch.startsWith("-i")) {
|
||||
@ -471,7 +425,7 @@ public class Main {
|
||||
out("Notice: Non-Default Increment: " + increment);
|
||||
|
||||
} else if (nextSwitch.startsWith("-w")) {
|
||||
ignoreWarnings = true;
|
||||
var.ignoreWarnings = true;
|
||||
out("Notice: Warnings from Server are Ignored");
|
||||
|
||||
} else if (nextSwitch.equals("-alt") || nextSwitch.equals("-a")) {
|
||||
@ -482,15 +436,6 @@ public class Main {
|
||||
xOffset = Integer.valueOf(args[i + 2].substring(2));
|
||||
out("Notice: X Offset: " + xOffset);
|
||||
|
||||
} else if (nextSwitch.startsWith("-rcon")) {
|
||||
if (testing) {
|
||||
useRCON = true;
|
||||
out("Notice: Attempting to use RCON to communicate with server...");
|
||||
} else {
|
||||
useRCON = false;
|
||||
err("MLG Using RCON is not enabled yet.");
|
||||
}
|
||||
|
||||
} else if (nextSwitch.startsWith("-y") || nextSwitch.startsWith("-z")) { //NOTE: "-y" is just here for backwards compatibility
|
||||
zOffset = Integer.valueOf(args[i + 2].substring(2));
|
||||
out("Notice: Z Offset: " + zOffset);
|
||||
@ -500,8 +445,8 @@ public class Main {
|
||||
}
|
||||
|
||||
} else {
|
||||
serverPath = args[i + 2];
|
||||
out("Notice: Attempting to use Alternate Server:" + serverPath);
|
||||
var.serverPath = args[i + 2];
|
||||
out("Notice: Attempting to use Alternate Server:" + var.serverPath);
|
||||
}
|
||||
}
|
||||
} catch (final NumberFormatException ex) {
|
||||
@ -512,7 +457,8 @@ public class Main {
|
||||
WorldVerify.verifyWorld();
|
||||
|
||||
{
|
||||
final File backupLevel = new File(worldPath + fileSeparator + "level_backup.dat");
|
||||
final File backupLevel =
|
||||
new File(var.worldPath + var.fileSeparator + "level_backup.dat");
|
||||
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"
|
||||
// + " or restore the backup.");
|
||||
@ -523,7 +469,7 @@ public class Main {
|
||||
out("Resuming...");
|
||||
|
||||
//use resume data
|
||||
final File serverLevel = new File(worldPath + fileSeparator + "level.dat");
|
||||
final File serverLevel = new File(var.worldPath + var.fileSeparator + "level.dat");
|
||||
try {
|
||||
Misc.copyFile(backupLevel, serverLevel);
|
||||
} catch (final IOException e) {
|
||||
@ -533,13 +479,13 @@ public class Main {
|
||||
|
||||
//return;
|
||||
|
||||
FileRead.readArrayListCoordLog(worldPath + fileSeparator
|
||||
FileRead.readArrayListCoordLog(var.worldPath + var.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;
|
||||
xRange = var.resumeX;
|
||||
zRange = var.resumeZ;
|
||||
|
||||
}
|
||||
}
|
||||
@ -548,17 +494,17 @@ public class Main {
|
||||
// PROCESSING
|
||||
// =====================================================================
|
||||
|
||||
out("Processing world \"" + worldPath + "\", in " + increment + " block increments, with: "
|
||||
+ javaLine);
|
||||
out("Processing world \"" + var.worldPath + "\", in " + increment
|
||||
+ " block increments, with: " + var.javaLine);
|
||||
// out( MLG + "Processing \"" + worldName + "\"...");
|
||||
|
||||
out("");
|
||||
|
||||
// prepare our two ProcessBuilders
|
||||
// minecraft = new ProcessBuilder(javaLine, "-Xms1024m", "-Xmx1024m", "-jar", jarFile, "nogui");
|
||||
minecraft = new ProcessBuilder(javaLine.split("\\s")); // is this always going to work? i don't know. (most likely yes)
|
||||
minecraft.directory(new File(serverPath));
|
||||
minecraft.redirectErrorStream(true);
|
||||
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);
|
||||
|
||||
try {
|
||||
out("Launching server once to make sure there is a world.");
|
||||
@ -578,17 +524,18 @@ public class Main {
|
||||
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.
|
||||
|
||||
FileWrite.AppendTxtFile(
|
||||
worldPath + fileSeparator + "MinecraftLandGenerator.log",
|
||||
"# " + PROG_NAME + " " + VERSION + " - " + SelfAware.JVMinfo() + newLine + "# "
|
||||
+ MC_Server_Version + newLine + "# Started: "
|
||||
+ dateFormat.format(generationStartTimeTracking) + newLine
|
||||
+ "##Size: X" + xRange + "Z" + zRange + newLine);
|
||||
FileWrite.AppendTxtFile(var.worldPath + var.fileSeparator
|
||||
+ "MinecraftLandGenerator.log",
|
||||
"# " + var.PROG_NAME + " " + var.VERSION + " - " + SelfAware.JVMinfo()
|
||||
+ var.newLine + "# " + var.MC_Server_Version + var.newLine
|
||||
+ "# Started: " + var.dateFormat.format(generationStartTimeTracking)
|
||||
+ var.newLine + "##Size: X" + xRange + "Z" + zRange + var.newLine);
|
||||
|
||||
out("");
|
||||
|
||||
final File serverLevel = new File(worldPath + fileSeparator + "level.dat");
|
||||
final File backupLevel = new File(worldPath + fileSeparator + "level_backup.dat");
|
||||
final File serverLevel = new File(var.worldPath + var.fileSeparator + "level.dat");
|
||||
final File backupLevel =
|
||||
new File(var.worldPath + var.fileSeparator + "level_backup.dat");
|
||||
|
||||
out("Backing up level.dat to level_backup.dat.");
|
||||
Misc.copyFile(serverLevel, backupLevel);
|
||||
@ -597,8 +544,9 @@ public class Main {
|
||||
final Coordinates spawn = SpawnPoint.getSpawn(serverLevel);
|
||||
out("Spawn point detected: [X,Y,Z] " + spawn);
|
||||
|
||||
FileWrite.AppendTxtFile(worldPath + fileSeparator + "MinecraftLandGenerator.log",
|
||||
"# Seed: " + randomSeed + newLine + "# Spawn: " + spawn.toString() + newLine);
|
||||
FileWrite.AppendTxtFile(var.worldPath + var.fileSeparator
|
||||
+ "MinecraftLandGenerator.log", "# Seed: " + var.randomSeed + var.newLine
|
||||
+ "# Spawn: " + spawn.toString() + var.newLine);
|
||||
|
||||
{
|
||||
boolean overridden = false;
|
||||
@ -677,7 +625,7 @@ public class Main {
|
||||
new Coordinates(currentX + xOffset, 64, currentZ + zOffset);
|
||||
launchList.add(tempCoords);
|
||||
|
||||
if (testing) {
|
||||
if (var.testing) {
|
||||
System.out.println(tempCoords);
|
||||
}
|
||||
}
|
||||
@ -696,7 +644,7 @@ public class Main {
|
||||
|
||||
//get existing list, and remove this list from launchList
|
||||
final ArrayList<Coordinates> removeList =
|
||||
FileRead.readArrayListCoordLog(worldPath + fileSeparator
|
||||
FileRead.readArrayListCoordLog(var.worldPath + var.fileSeparator
|
||||
+ "MinecraftLandGenerator.log");
|
||||
|
||||
if (!(removeList.isEmpty())) {
|
||||
@ -718,7 +666,7 @@ public class Main {
|
||||
//////// Start server launch code
|
||||
|
||||
String percentDone =
|
||||
Double.toString(((double) currentIteration / (double) totalIterations) * 100);
|
||||
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
|
||||
@ -751,8 +699,8 @@ public class Main {
|
||||
|
||||
if (serverSuccess) {
|
||||
// Write the current Coordinates to log file!
|
||||
FileWrite.AppendTxtFile(worldPath + fileSeparator
|
||||
+ "MinecraftLandGenerator.log", xyz.toString() + newLine);
|
||||
FileWrite.AppendTxtFile(var.worldPath + var.fileSeparator
|
||||
+ "MinecraftLandGenerator.log", xyz.toString() + var.newLine);
|
||||
} else {
|
||||
System.exit(1); // we got a warning or severe error
|
||||
}
|
||||
@ -775,19 +723,19 @@ public class Main {
|
||||
|
||||
//TODO: add if's
|
||||
|
||||
if (webLaunch) { //if webLaunch is already false, don't check for these things
|
||||
if (var.webLaunch) { //if webLaunch is already false, don't check for these things
|
||||
if (java.awt.GraphicsEnvironment.isHeadless()) {
|
||||
webLaunch = false; //headless enviroment - cant bring up webpage!
|
||||
var.webLaunch = false; //headless enviroment - cant bring up webpage!
|
||||
}
|
||||
final File web1 = new File("web");
|
||||
final File web2 = new File("web.txt"); //user has put in the magical file to not launch the webpage
|
||||
final File web3 = new File("web.txt.txt");
|
||||
if (web2.exists() || (web1.exists() || web3.exists())) { //check for "web.txt", if not found, check for "web", and if still not found, check for "web.txt.txt"
|
||||
webLaunch = false;
|
||||
var.webLaunch = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (webLaunch && java.awt.Desktop.isDesktopSupported()) {
|
||||
if (var.webLaunch && java.awt.Desktop.isDesktopSupported()) {
|
||||
final URI splashPage =
|
||||
//URI.create("https://sites.google.com/site/minecraftlandgenerator/home/mlg_splash");
|
||||
URI.create("http://adf.ly/520855/splashbanner");
|
||||
@ -807,59 +755,4 @@ public class Main {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a formatted string to System.out as a line.
|
||||
*
|
||||
* @param str
|
||||
* String to display and format
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static void out(final String str) {
|
||||
System.out.println(MLG + str); // is there a better/easier way to do this? I just wanted a lazier way to write "System.out.println(MLG + blah..."
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a formatted string to System.err as a line.
|
||||
*
|
||||
* @param str
|
||||
* String to display and format
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static void err(final String str) {
|
||||
System.err.println(MLGe + str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a string to System.out without a newline.
|
||||
*
|
||||
* @param str
|
||||
* String to display and format
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static void outP(final String str) {
|
||||
System.out.print(str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a formatted string to System.out as a line.
|
||||
*
|
||||
* @param str
|
||||
* String to display and format
|
||||
* @author Morlok8k
|
||||
*/
|
||||
static void outS(final String str) {
|
||||
System.out.println("[Server] " + str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs a formatted string to System.out as a line.
|
||||
*
|
||||
* @param str
|
||||
* String to display and format
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static void outD(final String str) {
|
||||
System.out.println(MLG + "[DEBUG] " + str);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -7,31 +7,8 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
|
||||
public class Misc {
|
||||
|
||||
//TODO: add description
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
static boolean printSpawn() {
|
||||
// ugh, sorry, this is an ugly hack, but it's a last-minute feature. this is a lot of duplicated code.
|
||||
// - Fixed by Morlok8k
|
||||
|
||||
FileRead.readConf();
|
||||
WorldVerify.verifyWorld();
|
||||
|
||||
final File level = new File(Main.worldPath + Main.fileSeparator + "level.dat");
|
||||
try {
|
||||
final Coordinates spawn = SpawnPoint.getSpawn(level);
|
||||
Main.out("The current spawn point is: [X,Y,Z] " + spawn);
|
||||
return true;
|
||||
} catch (final IOException ex) {
|
||||
Main.err("Error while reading " + level.getPath());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* I'd love to use nio, but it requires Java 7.<br>
|
||||
* I could use Apache Commons, but i don't want to include a library for one little thing.<br>
|
||||
@ -60,4 +37,26 @@ public class Misc {
|
||||
copyOut.close();
|
||||
}
|
||||
|
||||
//TODO: add description
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
static boolean printSpawn() {
|
||||
// ugh, sorry, this is an ugly hack, but it's a last-minute feature. this is a lot of duplicated code.
|
||||
// - Fixed by Morlok8k
|
||||
|
||||
FileRead.readConf();
|
||||
WorldVerify.verifyWorld();
|
||||
|
||||
final File level = new File(var.worldPath + var.fileSeparator + "level.dat");
|
||||
try {
|
||||
final Coordinates spawn = SpawnPoint.getSpawn(level);
|
||||
Main.out("The current spawn point is: [X,Y,Z] " + spawn);
|
||||
return true;
|
||||
} catch (final IOException ex) {
|
||||
Main.err("Error while reading " + level.getPath());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,43 +0,0 @@
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
|
||||
public class RCON {
|
||||
|
||||
/**
|
||||
* connects to server using RCON, sends a message, and disconnects. Not Functional yet.
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private static void rconConnectAndSendMsg(final String message) {
|
||||
//This is a placeholder for future code.
|
||||
/*
|
||||
step 1: connect to rcon_IPaddress : rcon_Port, with rcon_Password.
|
||||
step 2: send message (probably "stop" or "save-all")
|
||||
step 3: disconnect.
|
||||
*/
|
||||
Main.out("Connect to Server: " + Main.rcon_IPaddress + ":" + Main.rcon_Port + " Password: "
|
||||
+ Main.rcon_Password);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries the server using RCON to see if we can connect. Not functional yet.
|
||||
*
|
||||
* @return QuerySucess
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private static boolean rconQueryServer() {
|
||||
final boolean QuerySucess = false;
|
||||
|
||||
//This is a placeholder for future code.
|
||||
/*
|
||||
step 1: query rcon_IPaddress : rcon_Port
|
||||
step 2: return true or false if successful or not.
|
||||
*/
|
||||
Main.out("Query Server: " + Main.rcon_IPaddress + ":" + Main.rcon_Port);
|
||||
|
||||
return QuerySucess;
|
||||
}
|
||||
}
|
@ -1,12 +1,11 @@
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
|
||||
public class Readme_and_HelpInfo {
|
||||
|
||||
static String newLine = Main.newLine;
|
||||
static String MLGFileNameShort = Main.MLGFileNameShort;
|
||||
static String MinecraftLandGeneratorConf = Main.MinecraftLandGeneratorConf;
|
||||
static String defaultReadmeFile = Main.defaultReadmeFile;
|
||||
static String newLine = var.newLine;
|
||||
static String MLGFileNameShort = var.MLGFileNameShort;
|
||||
static String MinecraftLandGeneratorConf = var.MinecraftLandGeneratorConf;
|
||||
static String defaultReadmeFile = var.defaultReadmeFile;
|
||||
|
||||
/**
|
||||
* Saves a Readme file.
|
||||
@ -22,9 +21,9 @@ public class Readme_and_HelpInfo {
|
||||
}
|
||||
|
||||
final String MLG_Last_Modified_MDY =
|
||||
Main.dateFormat_MDY.format(Main.MLG_Last_Modified_Date);
|
||||
final String PROG_NAME = Main.PROG_NAME;
|
||||
final String VERSION = Main.VERSION;
|
||||
var.dateFormat_MDY.format(var.MLG_Last_Modified_Date);
|
||||
final String PROG_NAME = var.PROG_NAME;
|
||||
final String VERSION = var.VERSION;
|
||||
|
||||
String showHelpSTR = "";
|
||||
String ReadMeText = "";
|
||||
@ -34,7 +33,7 @@ public class Readme_and_HelpInfo {
|
||||
ReadMeText = PROG_NAME + " version " + VERSION + newLine
|
||||
+ newLine
|
||||
+ "Updated " + MLG_Last_Modified_MDY + newLine
|
||||
+ "(BuildID: " + Main.MLG_Last_Modified_Date.getTime() + ")" + newLine
|
||||
+ "(BuildID: " + var.MLG_Last_Modified_Date.getTime() + ")" + newLine
|
||||
+ newLine
|
||||
+ "Original Code by Corrodias November 2010" + newLine
|
||||
+ "Enhanced Code by Morlok8k Feb. 2011 to Now (or at least to " + MLG_Last_Modified_MDY + "!)" + newLine
|
||||
@ -46,7 +45,7 @@ public class Readme_and_HelpInfo {
|
||||
+ newLine
|
||||
+ "-----------------------------------------------" + newLine
|
||||
+ newLine
|
||||
+ "This program lets you generate an area of land with your Minecraft Beta SMP server (and is prossibly future-proof for newer versions). You set up your java command line and minecraft server paths in the MinecraftLandGenerator.conf file, set up the server's server.properties file with the name of the world you wish to use, and then run this program." + newLine
|
||||
+ "This program lets you generate an area of land with your Minecraft SMP server (and is prossibly future-proof for newer versions). You set up your java command line and minecraft server paths in the MinecraftLandGenerator.conf file, set up the server's server.properties file with the name of the world you wish to use, and then run this program." + newLine
|
||||
+ "When a Minecraft server is launched, it automatically generates chunks within a square area of 25x25 chunks (400x400 blocks), centered on the current spawn point (formally 20x20 chunks, 320x320 blocks). When provided X and Z ranges as arguments, this program will launch the server repeatedly, editing the level.dat file between sessions, to generate large amounts of land without players having to explore them. The generated land will have about the X and Z ranges as requested by the arguments, though it will not be exact due to the spawn point typically not on the border of a chunk. (Because of this, MLG by default adds a slight overlap with each pass - 380x380 blocks) You can use the -x and -z switches to override the spawn offset and center the land generation on a different point." + newLine
|
||||
+ "The program makes a backup of level.dat as level_backup.dat before editing, and restores the backup at the end. In the event that a level_backup.dat file already exists, the program will refuse to proceed, leaving the user to determine why the level_backup.dat file exists and whether they would rather restore it or delete it, which must be done manually." + newLine
|
||||
+ newLine
|
||||
@ -70,6 +69,14 @@ public class Readme_and_HelpInfo {
|
||||
+ newLine
|
||||
+ "Version History:" + newLine
|
||||
+ "Morlok8k:" + newLine
|
||||
+ "1.7.1" + newLine
|
||||
+ "- TODO: %done tweak" + newLine //TODO
|
||||
+ "- TODO: outliers issue / region fix" + newLine
|
||||
+ "- TODO: 16/512 block selecting" + newLine
|
||||
+ "- TODO: remember that the outside is 400, not 380!" + newLine
|
||||
+ "- TODO: always calculate from orgin, just adjust outer box to match" + newLine
|
||||
+ "- TODO: recaculate existing coords with new code" + newLine
|
||||
+ "- TODO: change 380 to 384?" + newLine //TODO
|
||||
+ "1.7.0" + newLine
|
||||
+ "- Major Code Optimization" + newLine
|
||||
+ "- Drastically reduced the amount of time it takes for MLG to expand a world after it has already done so before!" + newLine
|
||||
@ -226,12 +233,12 @@ public class Readme_and_HelpInfo {
|
||||
String Str = null;
|
||||
String NewLine = newLine;
|
||||
if (SysOut) {
|
||||
NewLine = NewLine + Main.MLG;
|
||||
NewLine = NewLine + var.MLG;
|
||||
}
|
||||
|
||||
MLGFileNameShort = Main.MLGFileNameShort;
|
||||
MinecraftLandGeneratorConf = Main.MinecraftLandGeneratorConf;
|
||||
defaultReadmeFile = Main.defaultReadmeFile;
|
||||
MLGFileNameShort = var.MLGFileNameShort;
|
||||
MinecraftLandGeneratorConf = var.MinecraftLandGeneratorConf;
|
||||
defaultReadmeFile = var.defaultReadmeFile;
|
||||
|
||||
//@formatter:off
|
||||
Str = "Usage: java -jar " + MLGFileNameShort + " x z [serverpath] [switches]" + NewLine
|
||||
|
@ -4,7 +4,6 @@ import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class SelfAware {
|
||||
|
||||
public static String JVMinfo() {
|
||||
@ -24,8 +23,8 @@ public class SelfAware {
|
||||
"Launch info: JVM: " + Return + " JAR: " + System.getProperty("sun.java.command")
|
||||
+ " ARGS: ";
|
||||
|
||||
for (int i = 0; i < Main.originalArgs.length; i++) {
|
||||
Return = Return + (Main.originalArgs[i]) + " ";
|
||||
for (int i = 0; i < var.originalArgs.length; i++) {
|
||||
Return = Return + (var.originalArgs[i]) + " ";
|
||||
}
|
||||
|
||||
Return = Return.trim();
|
||||
|
@ -17,20 +17,20 @@ public class Server {
|
||||
* @author Corrodias
|
||||
*/
|
||||
protected static boolean runMinecraft(final boolean alternate) throws IOException {
|
||||
if (Main.verbose) {
|
||||
if (var.verbose) {
|
||||
Main.out("Starting server.");
|
||||
}
|
||||
boolean serverSuccess = true;
|
||||
boolean warning = false;
|
||||
boolean warningsWeCanIgnore = false;
|
||||
final boolean ignoreWarningsOriginal = Main.ignoreWarnings;
|
||||
final boolean ignoreWarningsOriginal = var.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");
|
||||
final Process process = Main.minecraft.start();
|
||||
final Process process = var.minecraft.start();
|
||||
|
||||
//byte[] saveAll = { 's', 'a', 'v', 'e', '-', 'a', 'l', 'l', '\r', '\n' };
|
||||
final byte[] stop = { 's', 't', 'o', 'p', '\r', '\n' };
|
||||
@ -45,7 +45,7 @@ public class Server {
|
||||
line = line.trim();
|
||||
|
||||
System.out.println(line);
|
||||
if (line.contains(Main.doneText)) { // EDITED By Morlok8k for Minecraft 1.3+ Beta
|
||||
if (line.contains(var.doneText)) { // EDITED By Morlok8k for Minecraft 1.3+ Beta
|
||||
final OutputStream outputStream = process.getOutputStream();
|
||||
|
||||
Main.out("Stopping server... (Please Wait...)");
|
||||
@ -57,13 +57,13 @@ public class Server {
|
||||
// End while loop
|
||||
|
||||
} else { // start minecraft server normally!
|
||||
final Process process = Main.minecraft.start();
|
||||
if (Main.verbose) {
|
||||
final Process process = var.minecraft.start();
|
||||
if (var.verbose) {
|
||||
Main.out("Started Server.");
|
||||
}
|
||||
final BufferedReader pOut =
|
||||
new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
if (Main.verbose) {
|
||||
if (var.verbose) {
|
||||
Main.out("Accessing Server Output...");
|
||||
}
|
||||
|
||||
@ -95,11 +95,11 @@ public class Server {
|
||||
shortLine = line;
|
||||
}
|
||||
|
||||
if (Main.verbose) {
|
||||
if (var.verbose) {
|
||||
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...")) {
|
||||
} else if (line.contains(var.preparingText) || line.contains("Converting...")) {
|
||||
if (line.contains("Converting...")) {
|
||||
convertedMapFormattingFlag = true;
|
||||
}
|
||||
@ -113,71 +113,71 @@ public class Server {
|
||||
outTmp = outTmp2;
|
||||
|
||||
if (prepTextFirst) {
|
||||
Main.outP(Main.MLG + outTmp + "...");
|
||||
Main.outP(var.MLG + outTmp + "...");
|
||||
prepTextFirst = false;
|
||||
} else {
|
||||
//Main.outP(" " + outTmp + "...");
|
||||
Main.outP("\r" + Main.MLG + outTmp + "..."); //here we use \r to go back to the previous line, and rewrite it
|
||||
Main.outP("\r" + var.MLG + outTmp + "..."); //here we use \r to go back to the previous line, and rewrite it
|
||||
}
|
||||
|
||||
//}
|
||||
|
||||
} else if (line.contains(Main.preparingLevel)) {
|
||||
} else if (line.contains(var.preparingLevel)) {
|
||||
prepTextFirst = true;
|
||||
|
||||
if (convertedMapFormattingFlag == true) {
|
||||
Main.outP(Main.newLine);
|
||||
Main.outP(var.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(var.MLG + var.worldName + ": " + var.level_0 + ":"
|
||||
+ var.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(var.newLine + var.MLG + var.worldName + ": " + var.level_1
|
||||
+ ":" + var.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(var.newLine + var.MLG + var.worldName + ": " + var.level_2
|
||||
+ ":" + var.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(var.newLine + var.MLG + var.worldName + ": " + var.level_3
|
||||
+ ":" + var.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(var.newLine + var.MLG + var.worldName + ": " + var.level_4
|
||||
+ ":" + var.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(var.newLine + var.MLG + var.worldName + ": " + var.level_5
|
||||
+ ":" + var.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(var.newLine + var.MLG + var.worldName + ": " + var.level_6
|
||||
+ ":" + var.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(var.newLine + var.MLG + var.worldName + ": " + var.level_7
|
||||
+ ":" + var.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(var.newLine + var.MLG + var.worldName + ": " + var.level_8
|
||||
+ ":" + var.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(var.newLine + var.MLG + var.worldName + ": " + var.level_9
|
||||
+ ":" + var.newLine);
|
||||
} else {
|
||||
Main.outP(Main.newLine + Main.MLG + shortLine);
|
||||
Main.outP(var.newLine + var.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 (line.contains("server version") && var.MC_Server_Version.isEmpty()) {
|
||||
// if server version, save string to variable, for use in arraylist save file.
|
||||
Main.MC_Server_Version = shortLine;
|
||||
var.MC_Server_Version = shortLine;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (line.contains(Main.doneText)) { // now this is configurable!
|
||||
if (line.contains(var.doneText)) { // now this is configurable!
|
||||
|
||||
Main.outP(Main.newLine);
|
||||
Main.outP(var.newLine);
|
||||
Main.outS(line.substring(line.lastIndexOf("]") + 2, line.indexOf("!")));
|
||||
if (Main.waitSave) {
|
||||
if (var.waitSave) {
|
||||
Main.out("Waiting 30 seconds to save...");
|
||||
|
||||
int count = 1;
|
||||
@ -203,7 +203,7 @@ public class Server {
|
||||
outputStream.flush();
|
||||
// outputStream.close();
|
||||
|
||||
if (Main.waitSave) {
|
||||
if (var.waitSave) {
|
||||
Main.out("Waiting 10 seconds to save.");
|
||||
int count = 1;
|
||||
while (count <= 10) {
|
||||
@ -223,26 +223,26 @@ public class Server {
|
||||
//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?
|
||||
Main.ignoreWarnings = true;
|
||||
var.ignoreWarnings = true;
|
||||
} else if (line.contains("[WARNING] To start the server with more ram")) {
|
||||
if (Main.verbose == false) { // If verbose is true, we already displayed it.
|
||||
if (var.verbose == false) { // If verbose is true, we already displayed it.
|
||||
Main.outS(line);
|
||||
}
|
||||
warningsWeCanIgnore = true; //we can safely ignore this...
|
||||
Main.ignoreWarnings = true;
|
||||
var.ignoreWarnings = true;
|
||||
} else if (line.contains("Error occurred during initialization of VM")
|
||||
|| line.contains("Could not reserve enough space for object heap")) {
|
||||
if (Main.verbose == false) { // If verbose is true, we already displayed it.
|
||||
if (var.verbose == false) { // If verbose is true, we already displayed it.
|
||||
Main.outP("[Java Error] " + line);
|
||||
}
|
||||
warning = true;
|
||||
}
|
||||
|
||||
if (Main.ignoreWarnings == false) {
|
||||
if (var.ignoreWarnings == false) {
|
||||
if (line.contains("[WARNING]")) { // If we have a warning, stop...
|
||||
Main.out("");
|
||||
Main.out("Warning found: Stopping " + Main.PROG_NAME);
|
||||
if (Main.verbose == false) { // If verbose is true, we already displayed it.
|
||||
Main.out("Warning found: Stopping " + var.PROG_NAME);
|
||||
if (var.verbose == false) { // If verbose is true, we already displayed it.
|
||||
Main.outS(line);
|
||||
}
|
||||
Main.out("");
|
||||
@ -261,7 +261,7 @@ public class Server {
|
||||
if (line.contains("[SEVERE]")) { // If we have a severe error, stop...
|
||||
Main.out("");
|
||||
Main.out("Severe error found: Stopping server.");
|
||||
if (Main.verbose == false) { // If verbose is true, we already displayed it.
|
||||
if (var.verbose == false) { // If verbose is true, we already displayed it.
|
||||
Main.outS(line);
|
||||
}
|
||||
Main.out("");
|
||||
@ -281,7 +281,7 @@ public class Server {
|
||||
}
|
||||
|
||||
if (warningsWeCanIgnore) {
|
||||
Main.ignoreWarnings = ignoreWarningsOriginal;
|
||||
var.ignoreWarnings = ignoreWarningsOriginal;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@ import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
import org.jnbt.CompoundTag;
|
||||
import org.jnbt.IntTag;
|
||||
import org.jnbt.LongTag;
|
||||
@ -18,6 +17,44 @@ import org.jnbt.Tag;
|
||||
|
||||
public class SpawnPoint {
|
||||
|
||||
//TODO: update this
|
||||
/**
|
||||
* @param level
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @author Corrodias
|
||||
*/
|
||||
protected static Coordinates getSpawn(final File level) throws IOException {
|
||||
try {
|
||||
final NBTInputStream input = new NBTInputStream(new FileInputStream(level));
|
||||
final CompoundTag originalTopLevelTag = (CompoundTag) input.readTag();
|
||||
input.close();
|
||||
|
||||
final Map<String, Tag> originalData =
|
||||
((CompoundTag) originalTopLevelTag.getValue().get("Data")).getValue();
|
||||
// This is our map of data. It is an unmodifiable map, for some
|
||||
// reason, so we have to make a copy.
|
||||
final Map<String, Tag> newData = new LinkedHashMap<String, Tag>(originalData);
|
||||
// .get() a couple of values, just to make sure we're dealing with a
|
||||
// valid level file, here. Good for debugging, too.
|
||||
final IntTag spawnX = (IntTag) newData.get("SpawnX");
|
||||
final IntTag spawnY = (IntTag) newData.get("SpawnY");
|
||||
final IntTag spawnZ = (IntTag) newData.get("SpawnZ");
|
||||
|
||||
final LongTag Seed = (LongTag) newData.get("RandomSeed");
|
||||
var.randomSeed = Seed.getValue();
|
||||
Main.out("Seed: " + var.randomSeed); // lets output the seed, cause why not?
|
||||
|
||||
final Coordinates ret =
|
||||
new Coordinates(spawnX.getValue(), spawnY.getValue(), spawnZ.getValue());
|
||||
return ret;
|
||||
} catch (final ClassCastException ex) {
|
||||
throw new IOException("Invalid level format.");
|
||||
} catch (final NullPointerException ex) {
|
||||
throw new IOException("Invalid level format.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the spawn point in the given Alpha/Beta level to the given coordinates.<br>
|
||||
* Note that, in Minecraft levels, the Y coordinate is height.<br>
|
||||
@ -101,42 +138,4 @@ public class SpawnPoint {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: update this
|
||||
/**
|
||||
* @param level
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @author Corrodias
|
||||
*/
|
||||
protected static Coordinates getSpawn(final File level) throws IOException {
|
||||
try {
|
||||
final NBTInputStream input = new NBTInputStream(new FileInputStream(level));
|
||||
final CompoundTag originalTopLevelTag = (CompoundTag) input.readTag();
|
||||
input.close();
|
||||
|
||||
final Map<String, Tag> originalData =
|
||||
((CompoundTag) originalTopLevelTag.getValue().get("Data")).getValue();
|
||||
// This is our map of data. It is an unmodifiable map, for some
|
||||
// reason, so we have to make a copy.
|
||||
final Map<String, Tag> newData = new LinkedHashMap<String, Tag>(originalData);
|
||||
// .get() a couple of values, just to make sure we're dealing with a
|
||||
// valid level file, here. Good for debugging, too.
|
||||
final IntTag spawnX = (IntTag) newData.get("SpawnX");
|
||||
final IntTag spawnY = (IntTag) newData.get("SpawnY");
|
||||
final IntTag spawnZ = (IntTag) newData.get("SpawnZ");
|
||||
|
||||
final LongTag Seed = (LongTag) newData.get("RandomSeed");
|
||||
Main.randomSeed = Seed.getValue();
|
||||
Main.out("Seed: " + Main.randomSeed); // lets output the seed, cause why not?
|
||||
|
||||
final Coordinates ret =
|
||||
new Coordinates(spawnX.getValue(), spawnY.getValue(), spawnZ.getValue());
|
||||
return ret;
|
||||
} catch (final ClassCastException ex) {
|
||||
throw new IOException("Invalid level format.");
|
||||
} catch (final NullPointerException ex) {
|
||||
throw new IOException("Invalid level format.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,56 +1,7 @@
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
|
||||
public class Time {
|
||||
|
||||
/**
|
||||
* waits ten seconds. outputs 10%, 20%, etc after each second.
|
||||
*
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static void waitTenSec(final boolean output) {
|
||||
|
||||
if (Main.dontWait) { return; } //Don't wait!
|
||||
|
||||
if (output) {
|
||||
Main.outP(Main.MLG); //here we wait 10 sec.
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
while (count <= 100) {
|
||||
if (output) {
|
||||
Main.outP(count + "% ");
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
count += 10;
|
||||
}
|
||||
if (output) {
|
||||
Main.outP(Main.newLine);
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time in a readable format between two points of time given in Millis.
|
||||
*
|
||||
* @param startTimeMillis
|
||||
* @param endTimeMillis
|
||||
* @author Morlok8k
|
||||
* @return String of Readable Time
|
||||
*/
|
||||
public static String displayTime(final long startTimeMillis, final long endTimeMillis) {
|
||||
|
||||
final long millis = (endTimeMillis - startTimeMillis);
|
||||
//I just duplicated displayTime to have a start & end times, because it just made things simpler to code.
|
||||
return (Time.displayTime(millis));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time in a readable format given a time in Millis.
|
||||
*
|
||||
@ -79,7 +30,7 @@ public class Time {
|
||||
+ String.format("%d " + ((seconds % 60) == 1 ? "Second" : "Seconds"),
|
||||
seconds % 60);
|
||||
|
||||
if (!(Main.verbose)) {
|
||||
if (!(var.verbose)) {
|
||||
final int commaFirst = took.indexOf(",");
|
||||
final int commaSecond = took.substring((commaFirst + 1), took.length()).indexOf(",");
|
||||
int end = (commaFirst + 1 + commaSecond);
|
||||
@ -99,4 +50,52 @@ public class Time {
|
||||
return (took);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time in a readable format between two points of time given in Millis.
|
||||
*
|
||||
* @param startTimeMillis
|
||||
* @param endTimeMillis
|
||||
* @author Morlok8k
|
||||
* @return String of Readable Time
|
||||
*/
|
||||
public static String displayTime(final long startTimeMillis, final long endTimeMillis) {
|
||||
|
||||
final long millis = (endTimeMillis - startTimeMillis);
|
||||
//I just duplicated displayTime to have a start & end times, because it just made things simpler to code.
|
||||
return (Time.displayTime(millis));
|
||||
}
|
||||
|
||||
/**
|
||||
* waits ten seconds. outputs 10%, 20%, etc after each second.
|
||||
*
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static void waitTenSec(final boolean output) {
|
||||
|
||||
if (var.dontWait) { return; } //Don't wait!
|
||||
|
||||
if (output) {
|
||||
Main.outP(var.MLG); //here we wait 10 sec.
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
while (count <= 100) {
|
||||
if (output) {
|
||||
Main.outP(count + "% ");
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (final InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
count += 10;
|
||||
}
|
||||
if (output) {
|
||||
Main.outP(var.newLine);
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ import java.util.Iterator;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
|
||||
public class Update {
|
||||
|
||||
/**
|
||||
@ -36,37 +35,37 @@ public class Update {
|
||||
|
||||
// download BuildID from Github.
|
||||
final boolean fileSuccess =
|
||||
DownloadFile.downloadFile(Main.github_MLG_BuildID_URL, Main.testing);
|
||||
DownloadFile.downloadFile(var.github_MLG_BuildID_URL, var.testing);
|
||||
if (fileSuccess) {
|
||||
Main.out(Main.buildIDFile + " file downloaded.");
|
||||
Main.flag_downloadedBuildID = true;
|
||||
Main.out(var.buildIDFile + " file downloaded.");
|
||||
var.flag_downloadedBuildID = true;
|
||||
|
||||
if (downloadOnly) { return; }
|
||||
|
||||
}
|
||||
|
||||
if (downloadOnly) {
|
||||
Main.err("Couldn't Download new " + Main.buildIDFile);
|
||||
Main.err("Couldn't Download new " + var.buildIDFile);
|
||||
return;
|
||||
}
|
||||
|
||||
// If not available, create.
|
||||
// After downloading, check to see if it matches hash.
|
||||
|
||||
if (Main.MLGFileName == null) {
|
||||
if (var.MLGFileName == null) {
|
||||
try {
|
||||
Main.MLGFileName = getClassLoader(Main.cls);
|
||||
var.MLGFileName = getClassLoader(var.cls);
|
||||
} catch (final Exception e) {
|
||||
Main.out("Error: Finding file failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (Main.MLGFileName.equals(Main.rsrcError)) { return; }
|
||||
if (var.MLGFileName.equals(var.rsrcError)) { return; }
|
||||
}
|
||||
|
||||
if (Main.MLG_Current_Hash == null) {
|
||||
if (var.MLG_Current_Hash == null) {
|
||||
|
||||
try {
|
||||
Main.MLG_Current_Hash = MD5.fileMD5(Main.MLGFileName);
|
||||
var.MLG_Current_Hash = MD5.fileMD5(var.MLGFileName);
|
||||
// out(hash + " " + MLGFileName);
|
||||
} catch (final Exception e) {
|
||||
Main.out("Error: MD5 from file failed");
|
||||
@ -77,7 +76,7 @@ public class Update {
|
||||
Date time = new Date(new Long(0));
|
||||
|
||||
try {
|
||||
time = getCompileTimeStamp(Main.cls);
|
||||
time = getCompileTimeStamp(var.cls);
|
||||
} catch (final Exception e) {
|
||||
Main.out("Error: TimeStamp from file failed");
|
||||
e.printStackTrace();
|
||||
@ -86,22 +85,22 @@ public class Update {
|
||||
|
||||
boolean notNew = false;
|
||||
String INFO = "";
|
||||
if (Main.isCompiledAsJar == false) {
|
||||
if (var.isCompiledAsJar == false) {
|
||||
INFO = " (Class File, Not .Jar)";
|
||||
}
|
||||
|
||||
try {
|
||||
String line;
|
||||
|
||||
final BufferedReader inFile = new BufferedReader(new FileReader(Main.buildIDFile));
|
||||
final BufferedReader inFile = new BufferedReader(new FileReader(var.buildIDFile));
|
||||
final BufferedWriter outFile =
|
||||
new BufferedWriter(new FileWriter(Main.buildIDFile + ".temp"));
|
||||
new BufferedWriter(new FileWriter(var.buildIDFile + ".temp"));
|
||||
|
||||
while ((line = inFile.readLine()) != null) {
|
||||
|
||||
if (line.contains(Main.MLG_Current_Hash)) {
|
||||
if (line.contains(var.MLG_Current_Hash)) {
|
||||
notNew = true;
|
||||
if (Main.testing) {
|
||||
if (var.testing) {
|
||||
Main.outD("NotNew");
|
||||
}
|
||||
}
|
||||
@ -111,260 +110,33 @@ public class Update {
|
||||
}
|
||||
|
||||
if (notNew == false) {
|
||||
outFile.write(Main.MLG_Current_Hash + "=" + String.valueOf(time.getTime())
|
||||
+ "# MLG v" + Main.VERSION + INFO);
|
||||
outFile.write(var.MLG_Current_Hash + "=" + String.valueOf(time.getTime())
|
||||
+ "# MLG v" + var.VERSION + INFO);
|
||||
outFile.newLine();
|
||||
}
|
||||
outFile.close();
|
||||
inFile.close();
|
||||
|
||||
final File fileDelete = new File(Main.buildIDFile);
|
||||
final File fileDelete = new File(var.buildIDFile);
|
||||
fileDelete.delete();
|
||||
final File fileRename = new File(Main.buildIDFile + ".temp");
|
||||
fileRename.renameTo(new File(Main.buildIDFile));
|
||||
final File fileRename = new File(var.buildIDFile + ".temp");
|
||||
fileRename.renameTo(new File(var.buildIDFile));
|
||||
|
||||
} catch (final FileNotFoundException ex) {
|
||||
Main.out("\"" + Main.buildIDFile + "\" file not Found. Generating New \""
|
||||
+ Main.buildIDFile + "\" File");
|
||||
Main.out("\"" + var.buildIDFile + "\" file not Found. Generating New \""
|
||||
+ var.buildIDFile + "\" File");
|
||||
|
||||
FileWrite.writeTxtFile(Main.buildIDFile,
|
||||
Main.MLG_Current_Hash + "=" + String.valueOf(time.getTime()) + "#MLG v"
|
||||
+ Main.VERSION + INFO);
|
||||
FileWrite.writeTxtFile(var.buildIDFile,
|
||||
var.MLG_Current_Hash + "=" + String.valueOf(time.getTime()) + "#MLG v"
|
||||
+ var.VERSION + INFO);
|
||||
|
||||
} catch (final IOException ex) {
|
||||
Main.err("Could not create \"" + Main.buildIDFile + "\".");
|
||||
Main.err("Could not create \"" + var.buildIDFile + "\".");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the BuildID for MLG
|
||||
*
|
||||
* @author Morlok8k
|
||||
*
|
||||
*/
|
||||
public static void readBuildID() {
|
||||
|
||||
if (Main.inf_loop_protect_BuildID > 10) {
|
||||
Main.MLG_Last_Modified_Date = new Date(new Long(0)); //set the day to Jan 1, 1970 for failure
|
||||
return;
|
||||
}
|
||||
Main.inf_loop_protect_BuildID++; // this is to prevent an infinite loop (however unlikely)
|
||||
|
||||
if (Main.MLGFileName == null) {
|
||||
try {
|
||||
Main.MLGFileName = getClassLoader(Main.cls);
|
||||
} catch (final Exception e) {
|
||||
Main.out("Error: Finding file failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (Main.MLGFileName.equals(Main.rsrcError)) { return; }
|
||||
}
|
||||
|
||||
Main.MLGFileNameShort =
|
||||
Main.MLGFileName.substring(Main.MLGFileName.lastIndexOf(Main.fileSeparator) + 1,
|
||||
Main.MLGFileName.length());
|
||||
|
||||
if (Main.testing) {
|
||||
Main.outD("Currently Running as file:" + Main.MLGFileNameShort);
|
||||
}
|
||||
|
||||
if (Main.MLG_Current_Hash == null) {
|
||||
|
||||
try {
|
||||
Main.MLG_Current_Hash = MD5.fileMD5(Main.MLGFileName);
|
||||
// out(hash + " " + MLGFileName);
|
||||
} catch (final Exception e) {
|
||||
Main.out("Error: MD5 from file failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
int tsCount = 0;
|
||||
|
||||
Main.timeStamps.clear();
|
||||
|
||||
if (Main.MLG_Last_Modified_Date == null) {
|
||||
boolean foundLine = false;
|
||||
try {
|
||||
final BufferedReader in = new BufferedReader(new FileReader(Main.buildIDFile));
|
||||
String line;
|
||||
|
||||
if (Main.testing) {
|
||||
Main.outD("TimeStamps in buildIDFile:");
|
||||
}
|
||||
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) {
|
||||
Main.timeStamps.add(line.substring(pos + 1, end));
|
||||
}
|
||||
}
|
||||
|
||||
//timeStamps.add(line.substring(pos + 1, end));
|
||||
|
||||
if (Main.testing) {
|
||||
Main.outD(Main.timeStamps.get(tsCount));
|
||||
}
|
||||
|
||||
tsCount++;
|
||||
|
||||
if (line.contains(Main.MLG_Current_Hash)) {
|
||||
// out("[DEBUG] Found!");
|
||||
foundLine = true;
|
||||
|
||||
if (pos != -1) {
|
||||
if (line.substring(0, pos).equals(Main.MLG_Current_Hash)) {
|
||||
Main.MLG_Last_Modified_Long =
|
||||
new Long(line.substring(pos + 1, end));
|
||||
Main.MLG_Last_Modified_Date = new Date(Main.MLG_Last_Modified_Long);
|
||||
|
||||
final Long highestModTime =
|
||||
Update.ZipGetModificationTime(Main.MLGFileName);
|
||||
final long tCalc = Main.MLG_Last_Modified_Long - highestModTime;
|
||||
|
||||
if (Main.testing) {
|
||||
Main.outD("tCalc\tMLG_Last_Modified_Long\thighestModTime"
|
||||
+ Main.newLine + tCalc + "\t"
|
||||
+ Main.MLG_Last_Modified_Long + "\t" + highestModTime);
|
||||
}
|
||||
|
||||
if (highestModTime == 0L) {
|
||||
|
||||
Main.err("Archive Intergrity Check Failed: .zip/.jar file Issue.");
|
||||
Main.err("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)");
|
||||
|
||||
} else {
|
||||
if (tCalc < -15000L) {
|
||||
|
||||
//time is newer? (.zip file is newer than BuildID)
|
||||
Main.err("Archive Intergrity Check Failed: .zip file is newer than BuildID. Offset: "
|
||||
+ (tCalc / 1000) + "sec.");
|
||||
Main.err("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)");
|
||||
}
|
||||
|
||||
if (tCalc < 15000L) {
|
||||
|
||||
//times are within 30 seconds (+/- 15 seconds) of each other. (typically 1-2 seconds, but left room for real-world error)
|
||||
if (Main.testing | Main.flag_downloadedBuildID) {
|
||||
Main.out("Archive Intergrity Check Passed. Offset: "
|
||||
+ (tCalc / 1000) + "sec.");
|
||||
}
|
||||
|
||||
} else {
|
||||
//times dont match. (.zip file is older than specified BuildID)
|
||||
Main.err("Archive Intergrity Check Failed: .zip file is older than BuildID. Offset: "
|
||||
+ (tCalc / 1000) + "sec.");
|
||||
Main.err("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)");
|
||||
}
|
||||
}
|
||||
//return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
in.close();
|
||||
|
||||
if (foundLine == false) {
|
||||
// out("[DEBUG] FoundLine False");
|
||||
buildID(false);
|
||||
readBuildID(); // yes I'm calling the function from itself. potential infinite loop? possibly. I haven't encountered it yet!
|
||||
return;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
Main.err("Cant Read " + Main.buildIDFile + "!");
|
||||
Main.err(e.getLocalizedMessage());
|
||||
Main.err("");
|
||||
// e.printStackTrace();
|
||||
buildID(false);
|
||||
readBuildID();
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates MLG to the Latest Version
|
||||
*
|
||||
* @author Morlok8k
|
||||
*
|
||||
*/
|
||||
public static void updateMLG() {
|
||||
|
||||
buildID(true); //get latest BuildID file.
|
||||
Main.MLG_Last_Modified_Date = null;
|
||||
readBuildID();
|
||||
|
||||
final Iterator<String> e = Main.timeStamps.iterator();
|
||||
String s;
|
||||
int diff;
|
||||
|
||||
//boolean renameFailed = false;
|
||||
|
||||
while (e.hasNext()) {
|
||||
s = e.next();
|
||||
diff = Main.MLG_Last_Modified_Date.compareTo(new Date(new Long(s)));
|
||||
//out(diff);
|
||||
|
||||
if (diff < 0) { // if this is less than 0, there is a new version of MLG on the Internet!
|
||||
Main.out("There is a NEW VERSION Of " + Main.PROG_NAME + " available online!");
|
||||
|
||||
try {
|
||||
final File fileRename = new File(Main.MLG_JarFile);
|
||||
fileRename.renameTo(new File(Main.MLG_JarFile + ".old"));
|
||||
} catch (final Exception e1) {
|
||||
Main.out("Rename attempt #1 failed!");
|
||||
e1.printStackTrace();
|
||||
|
||||
try {
|
||||
Misc.copyFile(new File(Main.MLG_JarFile), new File(Main.MLG_JarFile
|
||||
+ ".old"));
|
||||
final File fileDelete = new File(Main.MLG_JarFile);
|
||||
fileDelete.delete();
|
||||
} catch (final Exception e2) {
|
||||
Main.out("Rename attempt #2 failed!");
|
||||
e2.printStackTrace();
|
||||
//renameFailed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final boolean fileSuccess =
|
||||
DownloadFile.downloadFile(Main.github_MLG_jar_URL, true);
|
||||
if (fileSuccess) {
|
||||
Main.out(Main.MLG_JarFile + " downloaded.");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets the filename of a .jar (typically this one!)
|
||||
*
|
||||
@ -393,10 +165,10 @@ public class Update {
|
||||
Main.err("THIS WAS COMPILED USING \"org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader\"! ");
|
||||
Main.err("DO NOT PACKAGE YOUR .JAR'S WITH THIS CLASSLOADER CODE!");
|
||||
Main.err("(Your Libraries need to be extracted.)");
|
||||
return Main.rsrcError;
|
||||
return var.rsrcError;
|
||||
}
|
||||
if (filename.contains(".jar")) {
|
||||
Main.isCompiledAsJar = true;
|
||||
var.isCompiledAsJar = true;
|
||||
}
|
||||
filename = filename.replace('/', File.separatorChar);
|
||||
final String returnString = filename.substring(file, bang);
|
||||
@ -427,6 +199,233 @@ public class Update {
|
||||
return (time != 0L) ? new Date(time) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the BuildID for MLG
|
||||
*
|
||||
* @author Morlok8k
|
||||
*
|
||||
*/
|
||||
public static void readBuildID() {
|
||||
|
||||
if (var.inf_loop_protect_BuildID > 10) {
|
||||
var.MLG_Last_Modified_Date = new Date(new Long(0)); //set the day to Jan 1, 1970 for failure
|
||||
return;
|
||||
}
|
||||
var.inf_loop_protect_BuildID++; // this is to prevent an infinite loop (however unlikely)
|
||||
|
||||
if (var.MLGFileName == null) {
|
||||
try {
|
||||
var.MLGFileName = getClassLoader(var.cls);
|
||||
} catch (final Exception e) {
|
||||
Main.out("Error: Finding file failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (var.MLGFileName.equals(var.rsrcError)) { return; }
|
||||
}
|
||||
|
||||
var.MLGFileNameShort =
|
||||
var.MLGFileName.substring(var.MLGFileName.lastIndexOf(var.fileSeparator) + 1,
|
||||
var.MLGFileName.length());
|
||||
|
||||
if (var.testing) {
|
||||
Main.outD("Currently Running as file:" + var.MLGFileNameShort);
|
||||
}
|
||||
|
||||
if (var.MLG_Current_Hash == null) {
|
||||
|
||||
try {
|
||||
var.MLG_Current_Hash = MD5.fileMD5(var.MLGFileName);
|
||||
// out(hash + " " + MLGFileName);
|
||||
} catch (final Exception e) {
|
||||
Main.out("Error: MD5 from file failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
int tsCount = 0;
|
||||
|
||||
var.timeStamps.clear();
|
||||
|
||||
if (var.MLG_Last_Modified_Date == null) {
|
||||
boolean foundLine = false;
|
||||
try {
|
||||
final BufferedReader in = new BufferedReader(new FileReader(var.buildIDFile));
|
||||
String line;
|
||||
|
||||
if (var.testing) {
|
||||
Main.outD("TimeStamps in buildIDFile:");
|
||||
}
|
||||
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) {
|
||||
var.timeStamps.add(line.substring(pos + 1, end));
|
||||
}
|
||||
}
|
||||
|
||||
//timeStamps.add(line.substring(pos + 1, end));
|
||||
|
||||
if (var.testing) {
|
||||
Main.outD(var.timeStamps.get(tsCount));
|
||||
}
|
||||
|
||||
tsCount++;
|
||||
|
||||
if (line.contains(var.MLG_Current_Hash)) {
|
||||
// out("[DEBUG] Found!");
|
||||
foundLine = true;
|
||||
|
||||
if (pos != -1) {
|
||||
if (line.substring(0, pos).equals(var.MLG_Current_Hash)) {
|
||||
var.MLG_Last_Modified_Long =
|
||||
new Long(line.substring(pos + 1, end));
|
||||
var.MLG_Last_Modified_Date = new Date(var.MLG_Last_Modified_Long);
|
||||
|
||||
final Long highestModTime =
|
||||
Update.ZipGetModificationTime(var.MLGFileName);
|
||||
final long tCalc = var.MLG_Last_Modified_Long - highestModTime;
|
||||
|
||||
if (var.testing) {
|
||||
Main.outD("tCalc\tMLG_Last_Modified_Long\thighestModTime"
|
||||
+ var.newLine + tCalc + "\t"
|
||||
+ var.MLG_Last_Modified_Long + "\t" + highestModTime);
|
||||
}
|
||||
|
||||
if (highestModTime == 0L) {
|
||||
|
||||
Main.err("Archive Intergrity Check Failed: .zip/.jar file Issue.");
|
||||
Main.err("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)");
|
||||
|
||||
} else {
|
||||
if (tCalc < -15000L) {
|
||||
|
||||
//time is newer? (.zip file is newer than BuildID)
|
||||
Main.err("Archive Intergrity Check Failed: .zip file is newer than BuildID. Offset: "
|
||||
+ (tCalc / 1000) + "sec.");
|
||||
Main.err("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)");
|
||||
}
|
||||
|
||||
if (tCalc < 15000L) {
|
||||
|
||||
//times are within 30 seconds (+/- 15 seconds) of each other. (typically 1-2 seconds, but left room for real-world error)
|
||||
if (var.testing | var.flag_downloadedBuildID) {
|
||||
Main.out("Archive Intergrity Check Passed. Offset: "
|
||||
+ (tCalc / 1000) + "sec.");
|
||||
}
|
||||
|
||||
} else {
|
||||
//times dont match. (.zip file is older than specified BuildID)
|
||||
Main.err("Archive Intergrity Check Failed: .zip file is older than BuildID. Offset: "
|
||||
+ (tCalc / 1000) + "sec.");
|
||||
Main.err("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)");
|
||||
}
|
||||
}
|
||||
//return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
in.close();
|
||||
|
||||
if (foundLine == false) {
|
||||
// out("[DEBUG] FoundLine False");
|
||||
buildID(false);
|
||||
readBuildID(); // yes I'm calling the function from itself. potential infinite loop? possibly. I haven't encountered it yet!
|
||||
return;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
Main.err("Cant Read " + var.buildIDFile + "!");
|
||||
Main.err(e.getLocalizedMessage());
|
||||
Main.err("");
|
||||
// e.printStackTrace();
|
||||
buildID(false);
|
||||
readBuildID();
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates MLG to the Latest Version
|
||||
*
|
||||
* @author Morlok8k
|
||||
*
|
||||
*/
|
||||
public static void updateMLG() {
|
||||
|
||||
buildID(true); //get latest BuildID file.
|
||||
var.MLG_Last_Modified_Date = null;
|
||||
readBuildID();
|
||||
|
||||
final Iterator<String> e = var.timeStamps.iterator();
|
||||
String s;
|
||||
int diff;
|
||||
|
||||
//boolean renameFailed = false;
|
||||
|
||||
while (e.hasNext()) {
|
||||
s = e.next();
|
||||
diff = var.MLG_Last_Modified_Date.compareTo(new Date(new Long(s)));
|
||||
//out(diff);
|
||||
|
||||
if (diff < 0) { // if this is less than 0, there is a new version of MLG on the Internet!
|
||||
Main.out("There is a NEW VERSION Of " + var.PROG_NAME + " available online!");
|
||||
|
||||
try {
|
||||
final File fileRename = new File(var.MLG_JarFile);
|
||||
fileRename.renameTo(new File(var.MLG_JarFile + ".old"));
|
||||
} catch (final Exception e1) {
|
||||
Main.out("Rename attempt #1 failed!");
|
||||
e1.printStackTrace();
|
||||
|
||||
try {
|
||||
Misc.copyFile(new File(var.MLG_JarFile), new File(var.MLG_JarFile
|
||||
+ ".old"));
|
||||
final File fileDelete = new File(var.MLG_JarFile);
|
||||
fileDelete.delete();
|
||||
} catch (final Exception e2) {
|
||||
Main.out("Rename attempt #2 failed!");
|
||||
e2.printStackTrace();
|
||||
//renameFailed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final boolean fileSuccess =
|
||||
DownloadFile.downloadFile(var.github_MLG_jar_URL, true);
|
||||
if (fileSuccess) {
|
||||
Main.out(var.MLG_JarFile + " downloaded.");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>.zip file Get Modification Time</b><br>
|
||||
*
|
||||
@ -455,7 +454,7 @@ public class Update {
|
||||
|
||||
final Enumeration<? extends ZipEntry> e = zipF.entries();
|
||||
|
||||
if (Main.testing) {
|
||||
if (var.testing) {
|
||||
Main.outD("File Name\t\tCRC\t\tModification Time\n---------------------------------\n");
|
||||
}
|
||||
|
||||
@ -472,7 +471,7 @@ public class Update {
|
||||
highestModTime = modTime;
|
||||
}
|
||||
|
||||
if (Main.testing) {
|
||||
if (var.testing) {
|
||||
|
||||
final String entryName = entry.getName();
|
||||
final Date modificationTime = new Date(modTime);
|
||||
|
@ -17,16 +17,16 @@ public class WorldVerify {
|
||||
//TODO: element comment
|
||||
|
||||
// verify that we ended up with a good server path, either from the file or from an argument.
|
||||
final File file = new File(Main.serverPath);
|
||||
final File file = new File(var.serverPath);
|
||||
if (!file.exists() || !file.isDirectory()) {
|
||||
Main.err("The server directory is invalid: " + Main.serverPath);
|
||||
Main.err("The server directory is invalid: " + var.serverPath);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// read the name of the current world from the server.properties file
|
||||
final BufferedReader props =
|
||||
new BufferedReader(new FileReader(new File(Main.serverPath + Main.fileSeparator
|
||||
new BufferedReader(new FileReader(new File(var.serverPath + var.fileSeparator
|
||||
+ "server.properties")));
|
||||
String line;
|
||||
while ((line = props.readLine()) != null) {
|
||||
@ -61,38 +61,8 @@ public class WorldVerify {
|
||||
}
|
||||
|
||||
if (property.equals("level-name")) {
|
||||
Main.worldPath = Main.serverPath + Main.fileSeparator + value;
|
||||
Main.worldName = value;
|
||||
}
|
||||
if (Main.useRCON) {
|
||||
if (property.equals("enable-rcon")) {
|
||||
|
||||
if (value.contains("true")) {
|
||||
Main.rcon_Enabled = true;
|
||||
Main.out("RCON is set to be Enabled on the server.");
|
||||
} else {
|
||||
Main.rcon_Enabled = false;
|
||||
Main.useRCON = false;
|
||||
Main.err("RCON is not Enabled on the server.");
|
||||
}
|
||||
} else if (property.equals("rcon.password")) {
|
||||
Main.rcon_Password = value;
|
||||
if (Main.rcon_Password.isEmpty()) {
|
||||
Main.useRCON = false;
|
||||
Main.err("RCON Needs a password!.");
|
||||
}
|
||||
Main.out("RCON Password:" + Main.rcon_Password);
|
||||
} else if (property.equals("rcon.port")) {
|
||||
Main.rcon_Port = value;
|
||||
Main.out("RCON Port:" + Main.rcon_Port);
|
||||
} else if (property.equals("server-ip")) {
|
||||
String IP = value;
|
||||
if (IP.isEmpty()) {
|
||||
IP = "0.0.0.0";
|
||||
}
|
||||
Main.rcon_IPaddress = IP;
|
||||
|
||||
}
|
||||
var.worldPath = var.serverPath + var.fileSeparator + value;
|
||||
var.worldName = value;
|
||||
}
|
||||
|
||||
}
|
||||
@ -101,14 +71,14 @@ public class WorldVerify {
|
||||
props.close();
|
||||
|
||||
} catch (final FileNotFoundException ex) {
|
||||
Main.err("Could not open " + Main.serverPath + Main.fileSeparator + "server.properties");
|
||||
Main.err("Could not open " + var.serverPath + var.fileSeparator + "server.properties");
|
||||
return;
|
||||
} catch (final IOException ex) {
|
||||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return;
|
||||
}
|
||||
|
||||
final File level = new File(Main.worldPath + Main.fileSeparator + "level.dat");
|
||||
final File level = new File(var.worldPath + var.fileSeparator + "level.dat");
|
||||
if (!level.exists() || !level.isFile()) {
|
||||
Main.err("The currently-configured world does not exist.");
|
||||
return;
|
||||
|
80
src/morlok8k/MinecraftLandGenerator/var.java
Normal file
80
src/morlok8k/MinecraftLandGenerator/var.java
Normal file
@ -0,0 +1,80 @@
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class var {
|
||||
|
||||
//
|
||||
//
|
||||
// Public Vars:
|
||||
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 VERSION = "1.7.1 test 10"; // Version Number!
|
||||
public static final String AUTHORS = "Corrodias, Morlok8k, pr0f1x"; // Authors
|
||||
public static final String fileSeparator = System.getProperty("file.separator");
|
||||
public static final String newLine = System.getProperty("line.separator");
|
||||
public static String[] originalArgs = {};
|
||||
public static String MLG = "[MLG] ";
|
||||
public static String MLGe = "[MLG-ERROR] ";
|
||||
public static DateFormat dateFormat_MDY = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
|
||||
public static Date MLG_Last_Modified_Date = null;
|
||||
public static String MLGFileNameShort = null;
|
||||
public static Scanner sc = new Scanner(System.in);
|
||||
public static final String MinecraftLandGeneratorConf = "MinecraftLandGenerator.conf";
|
||||
public static final String defaultReadmeFile = "_MLG_Readme.txt";
|
||||
public static String doneText = null;
|
||||
public static String preparingText = null;
|
||||
public static String preparingLevel = null;
|
||||
public static String level_0 = null; // the world
|
||||
public static String level_1 = null; // the nether
|
||||
public static String level_2 = null; // the end
|
||||
public static String level_3 = null; // future worlds
|
||||
public static String level_4 = null;
|
||||
public static String level_5 = null;
|
||||
public static String level_6 = null;
|
||||
public static String level_7 = null;
|
||||
public static String level_8 = null;
|
||||
public static String level_9 = null;
|
||||
public static ProcessBuilder minecraft = null;
|
||||
public static String javaLine = null;
|
||||
public static final String defaultJavaLine =
|
||||
"java -Djava.awt.headless=true -Djline.terminal=jline.UnsupportedTerminal -Duser.language=en"
|
||||
+ " -Xms1024m -Xmx1024m -Xincgc -jar minecraft_server.jar nogui";
|
||||
public static String serverPath = null;
|
||||
public static String worldPath = null;
|
||||
public static String worldName = null;
|
||||
public static boolean verbose = false;
|
||||
public static boolean dontWait = false;
|
||||
public static boolean waitSave = false;
|
||||
public static boolean ignoreWarnings = false;
|
||||
public static Long randomSeed = (long) 0;
|
||||
public static DateFormat dateFormat = new SimpleDateFormat( // Lets get a nice Date format for display
|
||||
"EEEE, MMMM d, yyyy 'at' h:mm a zzzz", Locale.ENGLISH);
|
||||
public static Date date = null; // date stuff
|
||||
public static Long MLG_Last_Modified_Long = 0L;
|
||||
public static final Class<?> cls = Main.class;
|
||||
public static String MLGFileName = null;
|
||||
public static final String rsrcError = "rsrcERROR";
|
||||
public static String buildIDFile = "MLG-BuildID";
|
||||
public static boolean isCompiledAsJar = false;
|
||||
public static String MLG_Current_Hash = null;
|
||||
public static int inf_loop_protect_BuildID = 0;
|
||||
public static boolean flag_downloadedBuildID = false;
|
||||
public static String MC_Server_Version = "";
|
||||
public static ArrayList<String> timeStamps = new ArrayList<String>();
|
||||
public static final String MLG_JarFile = "MinecraftLandGenerator.jar";
|
||||
public static final String github_URL =
|
||||
"https://raw.github.com/Morlok8k/MinecraftLandGenerator/master/bin/"; // just removing some redundancy
|
||||
public static final String github_MLG_Conf_URL = github_URL + MinecraftLandGeneratorConf;
|
||||
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 int resumeX = 0; //resume data, if needed.
|
||||
public static int resumeZ = 0;
|
||||
public static boolean webLaunch = true; // Launch website after generation.
|
||||
|
||||
}
|
Reference in New Issue
Block a user