More refactoring, cleaning up...

This commit is contained in:
Morlok8k 2012-09-11 01:06:47 -07:00
parent e534d3cc75
commit 55b872aa94
13 changed files with 243 additions and 238 deletions

View File

@ -48,8 +48,8 @@ public class DownloadFile {
fileName = Unescape.unescape(fileName); fileName = Unescape.unescape(fileName);
if (Output) { if (Output) {
Main.out("Downloading: " + URL); Out.out("Downloading: " + URL);
Main.out("Saving as: " + fileName); Out.out("Saving as: " + fileName);
} }
final long differenceTime = System.currentTimeMillis(); final long differenceTime = System.currentTimeMillis();
@ -57,7 +57,7 @@ public class DownloadFile {
timeTracking[0] = System.currentTimeMillis(); timeTracking[0] = System.currentTimeMillis();
if (Output) { if (Output) {
Main.outP(var.MLG + "*"); Out.outP(var.MLG + "*");
} }
try { try {
@ -73,20 +73,20 @@ public class DownloadFile {
bout.write(data, 0, x); bout.write(data, 0, x);
count = count + x; count = count + x;
if (Output) { if (Output) {
Main.outP("*"); Out.outP("*");
} }
} }
bout.close(); bout.close();
in.close(); in.close();
if (Output) { if (Output) {
Main.outP(var.newLine); Out.outP(var.newLine);
Main.out(count + " byte(s) copied"); Out.out(count + " byte(s) copied");
} }
timeTracking[1] = System.currentTimeMillis(); timeTracking[1] = System.currentTimeMillis();
//differenceTime = (timeTracking[1] - timeTracking[0]); //differenceTime = (timeTracking[1] - timeTracking[0]);
if (Output) { if (Output) {
Main.out("Elapsed Time: " + Time.displayTime(timeTracking[0], timeTracking[1])); Out.out("Elapsed Time: " + Time.displayTime(timeTracking[0], timeTracking[1]));
} }
} catch (final FileNotFoundException e) { } catch (final FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
@ -99,7 +99,7 @@ public class DownloadFile {
success = false; success = false;
} }
if (Output) { if (Output) {
Main.out("Done"); Out.out("Done");
} }
return success; return success;
} }

View File

@ -54,10 +54,10 @@ public class FileRead {
in.close(); in.close();
} catch (final FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
Main.out("Could not find " + file + "."); Out.out("Could not find " + file + ".");
return Return; return Return;
} catch (final IOException ex) { } catch (final IOException ex) {
Main.err("Could not read " + file + "."); Out.err("Could not read " + file + ".");
return Return; return Return;
} }
@ -154,32 +154,32 @@ public class FileRead {
in.close(); in.close();
if (var.testing) { if (var.testing) {
Main.outD("Test Output: Reading of Config File "); Out.outD("Test Output: Reading of Config File ");
Main.outD(" serverPath: " + var.serverPath); Out.outD(" serverPath: " + var.serverPath);
Main.outD(" javaLine: " + var.javaLine); Out.outD(" javaLine: " + var.javaLine);
Main.outD(" doneText: " + var.doneText); Out.outD(" doneText: " + var.doneText);
Main.outD(" preparingText: " + var.preparingText); Out.outD(" preparingText: " + var.preparingText);
Main.outD("preparingLevel: " + var.preparingLevel); Out.outD("preparingLevel: " + var.preparingLevel);
Main.outD(" level_0: " + var.level_0); Out.outD(" level_0: " + var.level_0);
Main.outD(" level_1: " + var.level_1); Out.outD(" level_1: " + var.level_1);
Main.outD(" level_2: " + var.level_2); Out.outD(" level_2: " + var.level_2);
Main.outD(" level_3: " + var.level_3); Out.outD(" level_3: " + var.level_3);
Main.outD(" level_4: " + var.level_4); Out.outD(" level_4: " + var.level_4);
Main.outD(" level_5: " + var.level_5); Out.outD(" level_5: " + var.level_5);
Main.outD(" level_6: " + var.level_6); Out.outD(" level_6: " + var.level_6);
Main.outD(" level_7: " + var.level_7); Out.outD(" level_7: " + var.level_7);
Main.outD(" level_8: " + var.level_8); Out.outD(" level_8: " + var.level_8);
Main.outD(" level_9: " + var.level_9); Out.outD(" level_9: " + var.level_9);
Main.outD(" waitSave: " + var.waitSave); Out.outD(" waitSave: " + var.waitSave);
Main.outD(" webLaunch: " + var.webLaunch); Out.outD(" webLaunch: " + var.webLaunch);
} }
} catch (final FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
Main.out("Could not find " Out.out("Could not find "
+ var.MinecraftLandGeneratorConf + var.MinecraftLandGeneratorConf
+ ". It is recommended that you run the application with the -conf option to create it."); + ". It is recommended that you run the application with the -conf option to create it.");
return; return;
} catch (final IOException ex) { } catch (final IOException ex) {
Main.err("Could not read " + var.MinecraftLandGeneratorConf + "."); Out.err("Could not read " + var.MinecraftLandGeneratorConf + ".");
return; return;
} }
} }

View File

@ -107,10 +107,10 @@ public class FileWrite {
outFile.write(txt); outFile.write(txt);
outFile.newLine(); outFile.newLine();
outFile.close(); outFile.close();
Main.out(file + " file created."); Out.out(file + " file created.");
return; return;
} catch (final IOException ex) { } catch (final IOException ex) {
Main.err("Could not create " + var.MinecraftLandGeneratorConf + "."); Out.err("Could not create " + var.MinecraftLandGeneratorConf + ".");
ex.printStackTrace(); ex.printStackTrace();
return; return;
} }

View File

@ -16,14 +16,14 @@ public class Input_CLI {
while (!(var.sc.hasNextInt())) { while (!(var.sc.hasNextInt())) {
var.sc.nextLine(); var.sc.nextLine();
Main.outP(var.MLG + "Invalid Input. " + msg); Out.outP(var.MLG + "Invalid Input. " + msg);
} }
Return = var.sc.nextInt(); Return = var.sc.nextInt();
if (Return < 1000) { if (Return < 1000) {
Main.out("Input must be 1000 or larger."); Out.out("Input must be 1000 or larger.");
Main.outP(var.MLG + msg); Out.outP(var.MLG + msg);
Return = getInt(msg); Return = getInt(msg);
} }

View File

@ -48,14 +48,14 @@ public class Main {
// java -enableassertions -jar MinecraftLandGenerator.jar // java -enableassertions -jar MinecraftLandGenerator.jar
assert var.assertsEnabled = true; // Intentional side-effect!!! (This may cause a Warning, which is safe to ignore: "Possible accidental assignment in place of a comparison. A condition expression should not be reduced to an assignment") assert var.assertsEnabled = true; // Intentional side-effect!!! (This may cause a Warning, which is safe to ignore: "Possible accidental assignment in place of a comparison. A condition expression should not be reduced to an assignment")
if (var.assertsEnabled) { if (var.assertsEnabled) {
outD("assertsEnabled: " + var.assertsEnabled); Out.outD("assertsEnabled: " + var.assertsEnabled);
var.verbose = true; var.verbose = true;
outD("Verbose mode forced!"); Out.outD("Verbose mode forced!");
var.testing = true; var.testing = true;
outD("Debug mode forced!"); Out.outD("Debug mode forced!");
var.dontWait = true; var.dontWait = true;
outD("-nowait mode forced!"); Out.outD("-nowait mode forced!");
outD(""); Out.outD("");
} }
boolean GUI = false; boolean GUI = false;
@ -73,7 +73,7 @@ public class Main {
if (!java.awt.GraphicsEnvironment.isHeadless() || (!NOGUI)) { if (!java.awt.GraphicsEnvironment.isHeadless() || (!NOGUI)) {
GUI = true; GUI = true;
if (var.testing) { if (var.testing) {
outD("GUI: This is a graphical enviroment."); Out.outD("GUI: This is a graphical enviroment.");
} }
////// //////
@ -83,7 +83,7 @@ public class Main {
} else { } else {
GUI = false; // No GUI for us today... GUI = false; // No GUI for us today...
if (var.testing) { if (var.testing) {
outD("GUI: Command Line Only!"); Out.outD("GUI: Command Line Only!");
} }
} }
@ -105,61 +105,6 @@ 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);
}
/**
* 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);
}
/** /**
* Start MinecraftLandGenerator (Command Line Interface) * Start MinecraftLandGenerator (Command Line Interface)
* *
@ -175,15 +120,15 @@ public class Main {
// The following displays no matter what happens, so we needed this date stuff to happen first. // The following displays no matter what happens, so we needed this date stuff to happen first.
out(var.PROG_NAME + " version " + var.VERSION); Out.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. Out.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 // thus different timezones wont display a different buildID
out("This version was last modified on " Out.out("This version was last modified on "
+ var.dateFormat.format(var.MLG_Last_Modified_Date)); + var.dateFormat.format(var.MLG_Last_Modified_Date));
out(""); Out.out("");
out("Uses a Minecraft server to generate square land of a specified size."); Out.out("Uses a Minecraft server to generate square land of a specified size.");
out(""); Out.out("");
out(""); Out.out("");
// ===================================================================== // =====================================================================
// INSTRUCTIONS // INSTRUCTIONS
@ -198,14 +143,14 @@ public class Main {
if (!(args.equals(newArgs))) { //do the freshly parsed args match the original? if (!(args.equals(newArgs))) { //do the freshly parsed args match the original?
var.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... args = newArgs; //use the freshly parsed args for everything else now...
out("Notice: Not waiting for anything..."); Out.out("Notice: Not waiting for anything...");
} }
if (args.length == 0) { //we didn't find a an X and Z size, so lets ask for one. if (args.length == 0) { //we didn't 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"); Out.out("Please Enter the size of world you want. Example: X:1000 Z:1000");
outP(var.MLG + "X:"); Out.outP(var.MLG + "X:");
xRange = Input_CLI.getInt("X:"); xRange = Input_CLI.getInt("X:");
outP(var.MLG + "Z:"); Out.outP(var.MLG + "Z:");
zRange = Input_CLI.getInt("Z:"); zRange = Input_CLI.getInt("Z:");
args = new String[] { String.valueOf(xRange), String.valueOf(zRange) }; args = new String[] { String.valueOf(xRange), String.valueOf(zRange) };
@ -231,7 +176,7 @@ public class Main {
final boolean fileSuccess = final boolean fileSuccess =
DownloadFile.downloadFile(var.github_MLG_Conf_URL, var.testing); DownloadFile.downloadFile(var.github_MLG_Conf_URL, var.testing);
if (fileSuccess) { if (fileSuccess) {
out(var.MinecraftLandGeneratorConf + " file downloaded."); Out.out(var.MinecraftLandGeneratorConf + " file downloaded.");
return; return;
} }
} }
@ -264,7 +209,7 @@ public class Main {
if (args.length == 2) { if (args.length == 2) {
DownloadFile.downloadFile(args[1], true); DownloadFile.downloadFile(args[1], true);
} else { } else {
out("No File to Download!"); Out.out("No File to Download!");
Time.waitTenSec(false); Time.waitTenSec(false);
} }
return; return;
@ -326,13 +271,13 @@ public class Main {
return; return;
} }
} else { } else {
out("No File with links!"); Out.out("No File with links!");
Time.waitTenSec(false); Time.waitTenSec(false);
} }
return; return;
} else if (args.length == 1) { } else if (args.length == 1) {
out("For help, use java -jar " + var.MLGFileNameShort + " -help"); Out.out("For help, use java -jar " + var.MLGFileNameShort + " -help");
Time.waitTenSec(false); Time.waitTenSec(false);
return; return;
} }
@ -342,7 +287,7 @@ public class Main {
boolean oldConf = false; // This next section checks to see if we have a old configuration file (or none!) boolean oldConf = false; // This next section checks to see if we have a old configuration file (or none!)
if ((var.serverPath == null) || (var.javaLine == null)) { // MLG 1.2 Check for a valid .conf file. if ((var.serverPath == null) || (var.javaLine == null)) { // MLG 1.2 Check for a valid .conf file.
err(var.MinecraftLandGeneratorConf Out.err(var.MinecraftLandGeneratorConf
+ " does not contain all required properties. Making New File!"); // Please recreate it by running this application with -conf. + " does not contain all required properties. Making New File!"); // Please recreate it by running this application with -conf.
// return; // return;
@ -367,7 +312,7 @@ public class Main {
} }
if (oldConf) { if (oldConf) {
err("Old Version of " + var.MinecraftLandGeneratorConf + " found. Updating..."); Out.err("Old Version of " + var.MinecraftLandGeneratorConf + " found. Updating...");
FileWrite.saveConf(false); //old conf FileWrite.saveConf(false); //old conf
@ -383,16 +328,16 @@ public class Main {
if ((xRange < 1000) && (xRange != 0)) { if ((xRange < 1000) && (xRange != 0)) {
xRange = 1000; //if less than 1000, (and not 0) set to 1000 (Calculations don't work well on very small maps) xRange = 1000; //if less than 1000, (and not 0) set to 1000 (Calculations don't work well on very small maps)
err("X size too small - Changing X to 1000"); Out.err("X size too small - Changing X to 1000");
} }
if ((zRange < 1000) && (zRange != 0)) { if ((zRange < 1000) && (zRange != 0)) {
zRange = 1000; zRange = 1000;
err("Z size too small - Changing Z to 1000"); Out.err("Z size too small - Changing Z to 1000");
} }
} catch (final NumberFormatException ex) { } catch (final NumberFormatException ex) {
err("Invalid X or Z argument."); Out.err("Invalid X or Z argument.");
err("Please Enter the size of world you want. Example: X:1000 Z:1000"); Out.err("Please Enter the size of world you want. Example: X:1000 Z:1000");
xRange = Input_CLI.getInt("X:"); xRange = Input_CLI.getInt("X:");
zRange = Input_CLI.getInt("Z:"); zRange = Input_CLI.getInt("Z:");
@ -408,39 +353,39 @@ public class Main {
final String nextSwitch = args[i + 2].toLowerCase(); final String nextSwitch = args[i + 2].toLowerCase();
if (nextSwitch.equals("-verbose") || nextSwitch.equals("-v")) { if (nextSwitch.equals("-verbose") || nextSwitch.equals("-v")) {
var.verbose = true; var.verbose = true;
out("Notice: Verbose Mode"); Out.out("Notice: Verbose Mode");
} else if (nextSwitch.startsWith("-i")) { } else if (nextSwitch.startsWith("-i")) {
var.increment = Integer.parseInt(args[i + 2].substring(2)); var.increment = Integer.parseInt(args[i + 2].substring(2));
out("Notice: Non-Default Increment: " + var.increment); Out.out("Notice: Non-Default Increment: " + var.increment);
} else if (nextSwitch.startsWith("-w")) { } else if (nextSwitch.startsWith("-w")) {
var.ignoreWarnings = true; var.ignoreWarnings = true;
out("Notice: Warnings from Server are Ignored"); Out.out("Notice: Warnings from Server are Ignored");
} else if (nextSwitch.equals("-alt") || nextSwitch.equals("-a")) { } else if (nextSwitch.equals("-alt") || nextSwitch.equals("-a")) {
var.alternate = true; var.alternate = true;
out("Notice: Using Alternate Launching"); Out.out("Notice: Using Alternate Launching");
} else if (nextSwitch.startsWith("-x")) { } else if (nextSwitch.startsWith("-x")) {
xOffset = Integer.valueOf(args[i + 2].substring(2)); xOffset = Integer.valueOf(args[i + 2].substring(2));
out("Notice: X Offset: " + xOffset); Out.out("Notice: X Offset: " + xOffset);
} else if (nextSwitch.startsWith("-y") || nextSwitch.startsWith("-z")) { //NOTE: "-y" is just here for backwards compatibility } else if (nextSwitch.startsWith("-y") || nextSwitch.startsWith("-z")) { //NOTE: "-y" is just here for backwards compatibility
zOffset = Integer.valueOf(args[i + 2].substring(2)); zOffset = Integer.valueOf(args[i + 2].substring(2));
out("Notice: Z Offset: " + zOffset); Out.out("Notice: Z Offset: " + zOffset);
if (nextSwitch.startsWith("-y")) { if (nextSwitch.startsWith("-y")) {
out("Notice: MLG now uses Z instead of Y. Please use the -z switch instead"); Out.out("Notice: MLG now uses Z instead of Y. Please use the -z switch instead");
Time.waitTenSec(false); Time.waitTenSec(false);
} }
} else { } else {
var.serverPath = args[i + 2]; var.serverPath = args[i + 2];
out("Notice: Attempting to use Alternate Server:" + var.serverPath); Out.out("Notice: Attempting to use Alternate Server:" + var.serverPath);
} }
} }
} catch (final NumberFormatException ex) { } catch (final NumberFormatException ex) {
err("Invalid switch value."); Out.err("Invalid switch value.");
return; return;
} }
@ -455,8 +400,8 @@ public class Main {
//err("You most likely will want to restore the backup!"); //err("You most likely will want to restore the backup!");
//Time.waitTenSec(false); //Time.waitTenSec(false);
err("There is a level_backup.dat file left over from a previous attempt that failed."); Out.err("There is a level_backup.dat file left over from a previous attempt that failed.");
out("Resuming..."); Out.out("Resuming...");
//use resume data //use resume data
final File serverLevel = new File(var.worldPath + var.fileSeparator + "level.dat"); final File serverLevel = new File(var.worldPath + var.fileSeparator + "level.dat");
@ -484,11 +429,11 @@ public class Main {
// PROCESSING // PROCESSING
// ===================================================================== // =====================================================================
out("Processing world \"" + var.worldPath + "\", in " + var.increment Out.out("Processing world \"" + var.worldPath + "\", in " + var.increment
+ " block increments, with: " + var.javaLine); + " block increments, with: " + var.javaLine);
// out( MLG + "Processing \"" + worldName + "\"..."); // out( MLG + "Processing \"" + worldName + "\"...");
out(""); Out.out("");
// prepare our two ProcessBuilders // prepare our two ProcessBuilders
// minecraft = new ProcessBuilder(javaLine, "-Xms1024m", "-Xmx1024m", "-jar", jarFile, "nogui"); // minecraft = new ProcessBuilder(javaLine, "-Xms1024m", "-Xmx1024m", "-jar", jarFile, "nogui");
@ -497,7 +442,7 @@ public class Main {
var.minecraft.redirectErrorStream(true); var.minecraft.redirectErrorStream(true);
try { try {
out("Launching server once to make sure there is a world."); Out.out("Launching server once to make sure there is a world.");
final long generationStartTimeTracking = System.currentTimeMillis(); //Start of time remaining calculations. final long generationStartTimeTracking = System.currentTimeMillis(); //Start of time remaining calculations.
@ -521,18 +466,18 @@ public class Main {
+ "# Started: " + var.dateFormat.format(generationStartTimeTracking) + "# Started: " + var.dateFormat.format(generationStartTimeTracking)
+ var.newLine + "##Size: X" + xRange + "Z" + zRange + var.newLine); + var.newLine + "##Size: X" + xRange + "Z" + zRange + var.newLine);
out(""); Out.out("");
final File serverLevel = new File(var.worldPath + var.fileSeparator + "level.dat"); final File serverLevel = new File(var.worldPath + var.fileSeparator + "level.dat");
final File backupLevel = final File backupLevel =
new File(var.worldPath + var.fileSeparator + "level_backup.dat"); new File(var.worldPath + var.fileSeparator + "level_backup.dat");
out("Backing up level.dat to level_backup.dat."); Out.out("Backing up level.dat to level_backup.dat.");
Misc.copyFile(serverLevel, backupLevel); Misc.copyFile(serverLevel, backupLevel);
out(""); Out.out("");
final Coordinates spawn = SpawnPoint.getSpawn(serverLevel); final Coordinates spawn = SpawnPoint.getSpawn(serverLevel);
out("Spawn point detected: [X,Y,Z] " + spawn); Out.out("Spawn point detected: [X,Y,Z] " + spawn);
FileWrite.AppendTxtFile(var.worldPath + var.fileSeparator FileWrite.AppendTxtFile(var.worldPath + var.fileSeparator
+ "MinecraftLandGenerator.log", "# Seed: " + var.randomSeed + var.newLine + "MinecraftLandGenerator.log", "# Seed: " + var.randomSeed + var.newLine
@ -551,11 +496,11 @@ public class Main {
overridden = true; overridden = true;
} }
if (overridden) { if (overridden) {
out("Centering land generation on [" + xOffset + ", " + zOffset Out.out("Centering land generation on [" + xOffset + ", " + zOffset
+ "] due to switches."); + "] due to switches.");
} }
} }
out(""); Out.out("");
double xLoops, zLoops; double xLoops, zLoops;
int curXloops = 0; int curXloops = 0;
@ -580,7 +525,7 @@ public class Main {
zRangeAdj = (int) (zLoops * var.increment); zRangeAdj = (int) (zLoops * var.increment);
zLoops = zLoops + 1; zLoops = zLoops + 1;
out("Calculating Spawn Points..."); Out.out("Calculating Spawn Points...");
int totalIterations = (int) (xLoops * zLoops); int totalIterations = (int) (xLoops * zLoops);
int currentIteration = 0; int currentIteration = 0;
@ -666,7 +611,7 @@ public class Main {
(percentDone.indexOf(".") == -1 ? percentDone.length() (percentDone.indexOf(".") == -1 ? percentDone.length()
: percentIndex)); //Trim output, unless whole number : percentIndex)); //Trim output, unless whole number
out("Setting spawn to [X,Y,Z]: " + xyz + " (" + currentIteration + " of " Out.out("Setting spawn to [X,Y,Z]: " + xyz + " (" + currentIteration + " of "
+ totalIterations + ") " + percentDone + "% Done"); // Time Remaining estimate + totalIterations + ") " + percentDone + "% Done"); // Time Remaining estimate
timeTracking = System.currentTimeMillis(); timeTracking = System.currentTimeMillis();
@ -675,7 +620,7 @@ public class Main {
differenceTime = differenceTime =
(timeTracking - generationStartTimeTracking) / (currentIteration + 1); // Updated. we now count all runs, instead of the last 4. (timeTracking - generationStartTimeTracking) / (currentIteration + 1); // Updated. we now count all runs, instead of the last 4.
differenceTime *= 1 + (totalIterations - currentIteration); // this should provide a more accurate result. differenceTime *= 1 + (totalIterations - currentIteration); // this should provide a more accurate result.
out("Estimated time remaining: " + Time.displayTime(differenceTime)); // I've noticed it gets pretty accurate after about 8 launches! Out.out("Estimated time remaining: " + Time.displayTime(differenceTime)); // I've noticed it gets pretty accurate after about 8 launches!
// Set the spawn point // Set the spawn point
SpawnPoint.setSpawn(serverLevel, xyz); SpawnPoint.setSpawn(serverLevel, xyz);
@ -684,7 +629,7 @@ public class Main {
boolean serverSuccess = false; boolean serverSuccess = false;
serverSuccess = Server.runMinecraft(); serverSuccess = Server.runMinecraft();
out(""); Out.out("");
//////// End server launch code //////// End server launch code
@ -699,16 +644,16 @@ public class Main {
} }
if (currentIteration == 0) { if (currentIteration == 0) {
out("Nothing to generate!"); Out.out("Nothing to generate!");
} else { } else {
out("Finished generating chunks."); Out.out("Finished generating chunks.");
} }
Misc.copyFile(backupLevel, serverLevel); Misc.copyFile(backupLevel, serverLevel);
backupLevel.delete(); backupLevel.delete();
out("Restored original level.dat."); Out.out("Restored original level.dat.");
out("Generation complete in: " Out.out("Generation complete in: "
+ Time.displayTime(var.startTime, System.currentTimeMillis())); + Time.displayTime(var.startTime, System.currentTimeMillis()));
Time.waitTenSec(false); Time.waitTenSec(false);
@ -733,12 +678,12 @@ public class Main {
try { try {
java.awt.Desktop.getDesktop().browse(splashPage); java.awt.Desktop.getDesktop().browse(splashPage);
} catch (final IOException e) { } catch (final IOException e) {
err("Error displaying webpage... " + e.getLocalizedMessage()); Out.err("Error displaying webpage... " + e.getLocalizedMessage());
} }
} else { } else {
out("Please Visit: http://adf.ly/520855/mlg"); Out.out("Please Visit: http://adf.ly/520855/mlg");
out("Or: https://sites.google.com/site/minecraftlandgenerator/"); Out.out("Or: https://sites.google.com/site/minecraftlandgenerator/");
out("Thanks!"); Out.out("Thanks!");
} }
} catch (final IOException ex) { } catch (final IOException ex) {

View File

@ -50,10 +50,10 @@ public class Misc {
final File level = new File(var.worldPath + var.fileSeparator + "level.dat"); final File level = new File(var.worldPath + var.fileSeparator + "level.dat");
try { try {
final Coordinates spawn = SpawnPoint.getSpawn(level); final Coordinates spawn = SpawnPoint.getSpawn(level);
Main.out("The current spawn point is: [X,Y,Z] " + spawn); Out.out("The current spawn point is: [X,Y,Z] " + spawn);
return true; return true;
} catch (final IOException ex) { } catch (final IOException ex) {
Main.err("Error while reading " + level.getPath()); Out.err("Error while reading " + level.getPath());
return false; return false;
} }
} }

View File

@ -0,0 +1,60 @@
package morlok8k.MinecraftLandGenerator;
public class Out {
/**
* 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);
}
/**
* 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);
}
}

View File

@ -303,8 +303,8 @@ public class Readme_and_HelpInfo {
String returnString = null; String returnString = null;
if (SysOut) { if (SysOut) {
Main.out(Str); Out.out(Str);
Main.out(""); Out.out("");
} else { } else {
returnString = Str; returnString = Str;
} }

View File

@ -19,7 +19,7 @@ public class Server {
protected static boolean runMinecraft() throws IOException { protected static boolean runMinecraft() throws IOException {
if (var.verbose) { if (var.verbose) {
Main.out("Starting server."); Out.out("Starting server.");
} }
boolean serverSuccess = true; boolean serverSuccess = true;
boolean warning = false; boolean warning = false;
@ -30,7 +30,7 @@ public class Server {
// STOP the server when it's done. // STOP the server when it's done.
if (var.alternate) { // Alternate - a replication (slightly stripped down) of MLG 1.3.0's code. simplest code possible. if (var.alternate) { // Alternate - a replication (slightly stripped down) of MLG 1.3.0's code. simplest code possible.
Main.out("Alternate Launch"); Out.out("Alternate Launch");
final Process process = var.minecraft.start(); final Process process = var.minecraft.start();
//byte[] saveAll = { 's', 'a', 'v', 'e', '-', 'a', 'l', 'l', '\r', '\n' }; //byte[] saveAll = { 's', 'a', 'v', 'e', '-', 'a', 'l', 'l', '\r', '\n' };
@ -49,7 +49,7 @@ public class Server {
if (line.contains(var.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(); final OutputStream outputStream = process.getOutputStream();
Main.out("Stopping server... (Please Wait...)"); Out.out("Stopping server... (Please Wait...)");
outputStream.write(stop); outputStream.write(stop);
outputStream.flush(); outputStream.flush();
@ -60,12 +60,12 @@ public class Server {
} else { // start minecraft server normally! } else { // start minecraft server normally!
final Process process = var.minecraft.start(); final Process process = var.minecraft.start();
if (var.verbose) { if (var.verbose) {
Main.out("Started Server."); Out.out("Started Server.");
} }
final BufferedReader pOut = final BufferedReader pOut =
new BufferedReader(new InputStreamReader(process.getInputStream())); new BufferedReader(new InputStreamReader(process.getInputStream()));
if (var.verbose) { if (var.verbose) {
Main.out("Accessing Server Output..."); Out.out("Accessing Server Output...");
} }
String line = null; String line = null;
@ -97,7 +97,7 @@ public class Server {
} }
if (var.verbose) { if (var.verbose) {
Main.outS(shortLine); Out.outS(shortLine);
//} else if (line.toLowerCase().contains("saving")) { //this was just clutter //} else if (line.toLowerCase().contains("saving")) { //this was just clutter
// Main.outS(shortLine); // Main.outS(shortLine);
} else if (line.contains(var.preparingText) || line.contains("Converting...")) { } else if (line.contains(var.preparingText) || line.contains("Converting...")) {
@ -114,11 +114,11 @@ public class Server {
outTmp = outTmp2; outTmp = outTmp2;
if (prepTextFirst) { if (prepTextFirst) {
Main.outP(var.MLG + outTmp + "..."); Out.outP(var.MLG + outTmp + "...");
prepTextFirst = false; prepTextFirst = false;
} else { } else {
//Main.outP(" " + outTmp + "..."); //Main.outP(" " + outTmp + "...");
Main.outP("\r" + var.MLG + outTmp + "..."); //here we use \r to go back to the previous line, and rewrite it Out.outP("\r" + var.MLG + outTmp + "..."); //here we use \r to go back to the previous line, and rewrite it
} }
//} //}
@ -127,44 +127,44 @@ public class Server {
prepTextFirst = true; prepTextFirst = true;
if (convertedMapFormattingFlag == true) { if (convertedMapFormattingFlag == true) {
Main.outP(var.newLine); Out.outP(var.newLine);
convertedMapFormattingFlag = false; convertedMapFormattingFlag = false;
} }
if (line.contains("level 0")) { // "Preparing start region for level 0" if (line.contains("level 0")) { // "Preparing start region for level 0"
Main.outP(var.MLG + var.worldName + ": " + var.level_0 + ":" + var.newLine); Out.outP(var.MLG + var.worldName + ": " + var.level_0 + ":" + var.newLine);
} else if (line.contains("level 1")) { // "Preparing start region for level 1" } else if (line.contains("level 1")) { // "Preparing start region for level 1"
Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_1 + ":" Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_1 + ":"
+ var.newLine); + var.newLine);
} else if (line.contains("level 2")) { // "Preparing start region for level 2" } else if (line.contains("level 2")) { // "Preparing start region for level 2"
Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_2 + ":" Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_2 + ":"
+ var.newLine); + var.newLine);
} else if (line.contains("level 3")) { // "Preparing start region for level 3" } else if (line.contains("level 3")) { // "Preparing start region for level 3"
Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_3 + ":" Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_3 + ":"
+ var.newLine); + var.newLine);
} else if (line.contains("level 4")) { // "Preparing start region for level 4" } else if (line.contains("level 4")) { // "Preparing start region for level 4"
Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_4 + ":" Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_4 + ":"
+ var.newLine); + var.newLine);
} else if (line.contains("level 5")) { // "Preparing start region for level 5" } else if (line.contains("level 5")) { // "Preparing start region for level 5"
Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_5 + ":" Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_5 + ":"
+ var.newLine); + var.newLine);
} else if (line.contains("level 6")) { // "Preparing start region for level 6" } else if (line.contains("level 6")) { // "Preparing start region for level 6"
Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_6 + ":" Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_6 + ":"
+ var.newLine); + var.newLine);
} else if (line.contains("level 7")) { // "Preparing start region for level 7" } else if (line.contains("level 7")) { // "Preparing start region for level 7"
Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_7 + ":" Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_7 + ":"
+ var.newLine); + var.newLine);
} else if (line.contains("level 8")) { // "Preparing start region for level 8" } else if (line.contains("level 8")) { // "Preparing start region for level 8"
Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_8 + ":" Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_8 + ":"
+ var.newLine); + var.newLine);
} else if (line.contains("level 9")) { // "Preparing start region for level 9" } else if (line.contains("level 9")) { // "Preparing start region for level 9"
Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_9 + ":" Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_9 + ":"
+ var.newLine); + var.newLine);
} else { } else {
Main.outP(var.newLine + var.MLG + shortLine); Out.outP(var.newLine + var.MLG + shortLine);
} }
} else if (line.contains("server version") || line.contains("Converting map!")) { //TODO: add to .conf } else if (line.contains("server version") || line.contains("Converting map!")) { //TODO: add to .conf
Main.outS(shortLine); Out.outS(shortLine);
if (line.contains("server version") && var.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. // if server version, save string to variable, for use in arraylist save file.
@ -175,14 +175,14 @@ public class Server {
if (line.contains(var.doneText)) { // now this is configurable! if (line.contains(var.doneText)) { // now this is configurable!
Main.outP(var.newLine); Out.outP(var.newLine);
Main.outS(line.substring(line.lastIndexOf("]") + 2, line.indexOf("!"))); Out.outS(line.substring(line.lastIndexOf("]") + 2, line.indexOf("!")));
if (var.waitSave) { if (var.waitSave) {
Main.out("Waiting 30 seconds to save..."); Out.out("Waiting 30 seconds to save...");
int count = 1; int count = 1;
while (count <= 30) { while (count <= 30) {
Main.outP("."); Out.outP(".");
try { try {
Thread.sleep(1000); Thread.sleep(1000);
@ -191,23 +191,23 @@ public class Server {
} }
count += 1; count += 1;
} }
Main.out(""); Out.out("");
} }
Main.out("Saving server data..."); Out.out("Saving server data...");
outputStream.write(saveAll); outputStream.write(saveAll);
outputStream.flush(); outputStream.flush();
Main.out("Stopping server... (Please Wait...)"); Out.out("Stopping server... (Please Wait...)");
// OutputStream outputStream = process.getOutputStream(); // OutputStream outputStream = process.getOutputStream();
outputStream.write(stop); outputStream.write(stop);
outputStream.flush(); outputStream.flush();
// outputStream.close(); // outputStream.close();
if (var.waitSave) { if (var.waitSave) {
Main.out("Waiting 10 seconds to save."); Out.out("Waiting 10 seconds to save.");
int count = 1; int count = 1;
while (count <= 10) { while (count <= 10) {
Main.outP("."); Out.outP(".");
try { try {
Thread.sleep(1000); Thread.sleep(1000);
@ -216,7 +216,7 @@ public class Server {
} }
count += 1; count += 1;
} }
Main.out(""); Out.out("");
} }
} }
@ -226,27 +226,27 @@ public class Server {
var.ignoreWarnings = true; var.ignoreWarnings = true;
} else if (line.contains("[WARNING] To start the server with more ram")) { } else if (line.contains("[WARNING] To start the server with more ram")) {
if (var.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); Out.outS(line);
} }
warningsWeCanIgnore = true; //we can safely ignore this... warningsWeCanIgnore = true; //we can safely ignore this...
var.ignoreWarnings = true; var.ignoreWarnings = true;
} else if (line.contains("Error occurred during initialization of VM") } else if (line.contains("Error occurred during initialization of VM")
|| line.contains("Could not reserve enough space for object heap")) { || line.contains("Could not reserve enough space for object heap")) {
if (var.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); Out.outP("[Java Error] " + line);
} }
warning = true; warning = true;
} }
if (var.ignoreWarnings == false) { if (var.ignoreWarnings == false) {
if (line.contains("[WARNING]")) { // If we have a warning, stop... if (line.contains("[WARNING]")) { // If we have a warning, stop...
Main.out(""); Out.out("");
Main.out("Warning found: Stopping " + var.PROG_NAME); Out.out("Warning found: Stopping " + var.PROG_NAME);
if (var.verbose == false) { // If verbose is true, we already displayed it. if (var.verbose == false) { // If verbose is true, we already displayed it.
Main.outS(line); Out.outS(line);
} }
Main.out(""); Out.out("");
Main.out("Forcing Save..."); Out.out("Forcing Save...");
outputStream.write(saveAll); outputStream.write(saveAll);
outputStream.flush(); outputStream.flush();
// OutputStream outputStream = process.getOutputStream(); // OutputStream outputStream = process.getOutputStream();
@ -259,13 +259,13 @@ public class Server {
// System.exit(1); // System.exit(1);
} }
if (line.contains("[SEVERE]")) { // If we have a severe error, stop... if (line.contains("[SEVERE]")) { // If we have a severe error, stop...
Main.out(""); Out.out("");
Main.out("Severe error found: Stopping server."); Out.out("Severe error found: Stopping server.");
if (var.verbose == false) { // If verbose is true, we already displayed it. if (var.verbose == false) { // If verbose is true, we already displayed it.
Main.outS(line); Out.outS(line);
} }
Main.out(""); Out.out("");
Main.out("Forcing Save..."); Out.out("Forcing Save...");
outputStream.write(saveAll); outputStream.write(saveAll);
outputStream.flush(); outputStream.flush();
// OutputStream outputStream = process.getOutputStream(); // OutputStream outputStream = process.getOutputStream();

View File

@ -43,7 +43,7 @@ public class SpawnPoint {
final LongTag Seed = (LongTag) newData.get("RandomSeed"); final LongTag Seed = (LongTag) newData.get("RandomSeed");
var.randomSeed = Seed.getValue(); var.randomSeed = Seed.getValue();
Main.out("Seed: " + var.randomSeed); // lets output the seed, cause why not? Out.out("Seed: " + var.randomSeed); // lets output the seed, cause why not?
final Coordinates ret = final Coordinates ret =
new Coordinates(spawnX.getValue(), spawnY.getValue(), spawnZ.getValue()); new Coordinates(spawnX.getValue(), spawnY.getValue(), spawnZ.getValue());

View File

@ -75,13 +75,13 @@ public class Time {
if (var.dontWait) { return; } //Don't wait! if (var.dontWait) { return; } //Don't wait!
if (output) { if (output) {
Main.outP(var.MLG); //here we wait 10 sec. Out.outP(var.MLG); //here we wait 10 sec.
} }
int count = 0; int count = 0;
while (count <= 100) { while (count <= 100) {
if (output) { if (output) {
Main.outP(count + "% "); Out.outP(count + "% ");
} }
try { try {
@ -92,7 +92,7 @@ public class Time {
count += 10; count += 10;
} }
if (output) { if (output) {
Main.outP(var.newLine); Out.outP(var.newLine);
} }
return; return;

View File

@ -37,7 +37,7 @@ public class Update {
final boolean fileSuccess = final boolean fileSuccess =
DownloadFile.downloadFile(var.github_MLG_BuildID_URL, var.testing); DownloadFile.downloadFile(var.github_MLG_BuildID_URL, var.testing);
if (fileSuccess) { if (fileSuccess) {
Main.out(var.buildIDFile + " file downloaded."); Out.out(var.buildIDFile + " file downloaded.");
var.flag_downloadedBuildID = true; var.flag_downloadedBuildID = true;
if (downloadOnly) { return; } if (downloadOnly) { return; }
@ -45,7 +45,7 @@ public class Update {
} }
if (downloadOnly) { if (downloadOnly) {
Main.err("Couldn't Download new " + var.buildIDFile); Out.err("Couldn't Download new " + var.buildIDFile);
return; return;
} }
@ -56,7 +56,7 @@ public class Update {
try { try {
var.MLGFileName = getClassLoader(var.cls); var.MLGFileName = getClassLoader(var.cls);
} catch (final Exception e) { } catch (final Exception e) {
Main.out("Error: Finding file failed"); Out.out("Error: Finding file failed");
e.printStackTrace(); e.printStackTrace();
} }
if (var.MLGFileName.equals(var.rsrcError)) { return; } if (var.MLGFileName.equals(var.rsrcError)) { return; }
@ -68,7 +68,7 @@ public class Update {
var.MLG_Current_Hash = MD5.fileMD5(var.MLGFileName); var.MLG_Current_Hash = MD5.fileMD5(var.MLGFileName);
// out(hash + " " + MLGFileName); // out(hash + " " + MLGFileName);
} catch (final Exception e) { } catch (final Exception e) {
Main.out("Error: MD5 from file failed"); Out.out("Error: MD5 from file failed");
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -78,7 +78,7 @@ public class Update {
try { try {
time = getCompileTimeStamp(var.cls); time = getCompileTimeStamp(var.cls);
} catch (final Exception e) { } catch (final Exception e) {
Main.out("Error: TimeStamp from file failed"); Out.out("Error: TimeStamp from file failed");
e.printStackTrace(); e.printStackTrace();
} }
// out(d.toString()); // out(d.toString());
@ -101,7 +101,7 @@ public class Update {
if (line.contains(var.MLG_Current_Hash)) { if (line.contains(var.MLG_Current_Hash)) {
notNew = true; notNew = true;
if (var.testing) { if (var.testing) {
Main.outD("NotNew"); Out.outD("NotNew");
} }
} }
@ -123,7 +123,7 @@ public class Update {
fileRename.renameTo(new File(var.buildIDFile)); fileRename.renameTo(new File(var.buildIDFile));
} catch (final FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
Main.out("\"" + var.buildIDFile + "\" file not Found. Generating New \"" Out.out("\"" + var.buildIDFile + "\" file not Found. Generating New \""
+ var.buildIDFile + "\" File"); + var.buildIDFile + "\" File");
FileWrite.writeTxtFile(var.buildIDFile, FileWrite.writeTxtFile(var.buildIDFile,
@ -131,7 +131,7 @@ public class Update {
+ var.VERSION + INFO); + var.VERSION + INFO);
} catch (final IOException ex) { } catch (final IOException ex) {
Main.err("Could not create \"" + var.buildIDFile + "\"."); Out.err("Could not create \"" + var.buildIDFile + "\".");
return; return;
} }
@ -162,9 +162,9 @@ public class Update {
file = 0; file = 0;
} }
if (filename.contains("rsrc:")) { if (filename.contains("rsrc:")) {
Main.err("THIS WAS COMPILED USING \"org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader\"! "); Out.err("THIS WAS COMPILED USING \"org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader\"! ");
Main.err("DO NOT PACKAGE YOUR .JAR'S WITH THIS CLASSLOADER CODE!"); Out.err("DO NOT PACKAGE YOUR .JAR'S WITH THIS CLASSLOADER CODE!");
Main.err("(Your Libraries need to be extracted.)"); Out.err("(Your Libraries need to be extracted.)");
return var.rsrcError; return var.rsrcError;
} }
if (filename.contains(".jar")) { if (filename.contains(".jar")) {
@ -217,7 +217,7 @@ public class Update {
try { try {
var.MLGFileName = getClassLoader(var.cls); var.MLGFileName = getClassLoader(var.cls);
} catch (final Exception e) { } catch (final Exception e) {
Main.out("Error: Finding file failed"); Out.out("Error: Finding file failed");
e.printStackTrace(); e.printStackTrace();
} }
if (var.MLGFileName.equals(var.rsrcError)) { return; } if (var.MLGFileName.equals(var.rsrcError)) { return; }
@ -228,7 +228,7 @@ public class Update {
var.MLGFileName.length()); var.MLGFileName.length());
if (var.testing) { if (var.testing) {
Main.outD("Currently Running as file:" + var.MLGFileNameShort); Out.outD("Currently Running as file:" + var.MLGFileNameShort);
} }
if (var.MLG_Current_Hash == null) { if (var.MLG_Current_Hash == null) {
@ -237,7 +237,7 @@ public class Update {
var.MLG_Current_Hash = MD5.fileMD5(var.MLGFileName); var.MLG_Current_Hash = MD5.fileMD5(var.MLGFileName);
// out(hash + " " + MLGFileName); // out(hash + " " + MLGFileName);
} catch (final Exception e) { } catch (final Exception e) {
Main.out("Error: MD5 from file failed"); Out.out("Error: MD5 from file failed");
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -253,7 +253,7 @@ public class Update {
String line; String line;
if (var.testing) { if (var.testing) {
Main.outD("TimeStamps in buildIDFile:"); Out.outD("TimeStamps in buildIDFile:");
} }
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
@ -284,7 +284,7 @@ public class Update {
//timeStamps.add(line.substring(pos + 1, end)); //timeStamps.add(line.substring(pos + 1, end));
if (var.testing) { if (var.testing) {
Main.outD(var.timeStamps.get(tsCount)); Out.outD(var.timeStamps.get(tsCount));
} }
tsCount++; tsCount++;
@ -304,38 +304,38 @@ public class Update {
final long tCalc = var.MLG_Last_Modified_Long - highestModTime; final long tCalc = var.MLG_Last_Modified_Long - highestModTime;
if (var.testing) { if (var.testing) {
Main.outD("tCalc\tMLG_Last_Modified_Long\thighestModTime" Out.outD("tCalc\tMLG_Last_Modified_Long\thighestModTime"
+ var.newLine + tCalc + "\t" + var.newLine + tCalc + "\t"
+ var.MLG_Last_Modified_Long + "\t" + highestModTime); + var.MLG_Last_Modified_Long + "\t" + highestModTime);
} }
if (highestModTime == 0L) { if (highestModTime == 0L) {
Main.err("Archive Intergrity Check Failed: .zip/.jar file Issue."); Out.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.)"); Out.err("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)");
} else { } else {
if (tCalc < -15000L) { if (tCalc < -15000L) {
//time is newer? (.zip file is newer than BuildID) //time is newer? (.zip file is newer than BuildID)
Main.err("Archive Intergrity Check Failed: .zip file is newer than BuildID. Offset: " Out.err("Archive Intergrity Check Failed: .zip file is newer than BuildID. Offset: "
+ (tCalc / 1000) + "sec."); + (tCalc / 1000) + "sec.");
Main.err("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)"); Out.err("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)");
} }
if (tCalc < 15000L) { if (tCalc < 15000L) {
//times are within 30 seconds (+/- 15 seconds) of each other. (typically 1-2 seconds, but left room for real-world error) //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) { if (var.testing | var.flag_downloadedBuildID) {
Main.out("Archive Intergrity Check Passed. Offset: " Out.out("Archive Intergrity Check Passed. Offset: "
+ (tCalc / 1000) + "sec."); + (tCalc / 1000) + "sec.");
} }
} else { } else {
//times dont match. (.zip file is older than specified BuildID) //times dont match. (.zip file is older than specified BuildID)
Main.err("Archive Intergrity Check Failed: .zip file is older than BuildID. Offset: " Out.err("Archive Intergrity Check Failed: .zip file is older than BuildID. Offset: "
+ (tCalc / 1000) + "sec."); + (tCalc / 1000) + "sec.");
Main.err("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)"); Out.err("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)");
} }
} }
//return; //return;
@ -354,9 +354,9 @@ public class Update {
return; return;
} }
} catch (final Exception e) { } catch (final Exception e) {
Main.err("Cant Read " + var.buildIDFile + "!"); Out.err("Cant Read " + var.buildIDFile + "!");
Main.err(e.getLocalizedMessage()); Out.err(e.getLocalizedMessage());
Main.err(""); Out.err("");
// e.printStackTrace(); // e.printStackTrace();
buildID(false); buildID(false);
readBuildID(); readBuildID();
@ -391,13 +391,13 @@ public class Update {
//out(diff); //out(diff);
if (diff < 0) { // if this is less than 0, there is a new version of MLG on the Internet! 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!"); Out.out("There is a NEW VERSION Of " + var.PROG_NAME + " available online!");
try { try {
final File fileRename = new File(var.MLG_JarFile); final File fileRename = new File(var.MLG_JarFile);
fileRename.renameTo(new File(var.MLG_JarFile + ".old")); fileRename.renameTo(new File(var.MLG_JarFile + ".old"));
} catch (final Exception e1) { } catch (final Exception e1) {
Main.out("Rename attempt #1 failed!"); Out.out("Rename attempt #1 failed!");
e1.printStackTrace(); e1.printStackTrace();
try { try {
@ -406,7 +406,7 @@ public class Update {
final File fileDelete = new File(var.MLG_JarFile); final File fileDelete = new File(var.MLG_JarFile);
fileDelete.delete(); fileDelete.delete();
} catch (final Exception e2) { } catch (final Exception e2) {
Main.out("Rename attempt #2 failed!"); Out.out("Rename attempt #2 failed!");
e2.printStackTrace(); e2.printStackTrace();
//renameFailed = true; //renameFailed = true;
return; return;
@ -417,7 +417,7 @@ public class Update {
final boolean fileSuccess = final boolean fileSuccess =
DownloadFile.downloadFile(var.github_MLG_jar_URL, true); DownloadFile.downloadFile(var.github_MLG_jar_URL, true);
if (fileSuccess) { if (fileSuccess) {
Main.out(var.MLG_JarFile + " downloaded."); Out.out(var.MLG_JarFile + " downloaded.");
return; return;
} }
@ -455,7 +455,7 @@ public class Update {
final Enumeration<? extends ZipEntry> e = zipF.entries(); final Enumeration<? extends ZipEntry> e = zipF.entries();
if (var.testing) { if (var.testing) {
Main.outD("File Name\t\tCRC\t\tModification Time\n---------------------------------\n"); Out.outD("File Name\t\tCRC\t\tModification Time\n---------------------------------\n");
} }
while (e.hasMoreElements()) { while (e.hasMoreElements()) {
@ -477,7 +477,7 @@ public class Update {
final Date modificationTime = new Date(modTime); final Date modificationTime = new Date(modTime);
final String CRC = Long.toHexString(entry.getCrc()); final String CRC = Long.toHexString(entry.getCrc());
Main.outD(entryName + "\t" + CRC + "\t" + modificationTime + "\t" Out.outD(entryName + "\t" + CRC + "\t" + modificationTime + "\t"
+ modTime.toString()); + modTime.toString());
} }
@ -488,7 +488,7 @@ public class Update {
return highestModTime; return highestModTime;
} catch (final IOException ioe) { } catch (final IOException ioe) {
Main.out("Error opening zip file" + ioe); Out.out("Error opening zip file" + ioe);
return 0L; //return Jan. 1, 1970 12:00 GMT for failures return 0L; //return Jan. 1, 1970 12:00 GMT for failures
} }
} }

View File

@ -19,7 +19,7 @@ public class WorldVerify {
// verify that we ended up with a good server path, either from the file or from an argument. // verify that we ended up with a good server path, either from the file or from an argument.
final File file = new File(var.serverPath); final File file = new File(var.serverPath);
if (!file.exists() || !file.isDirectory()) { if (!file.exists() || !file.isDirectory()) {
Main.err("The server directory is invalid: " + var.serverPath); Out.err("The server directory is invalid: " + var.serverPath);
return; return;
} }
@ -71,7 +71,7 @@ public class WorldVerify {
props.close(); props.close();
} catch (final FileNotFoundException ex) { } catch (final FileNotFoundException ex) {
Main.err("Could not open " + var.serverPath + var.fileSeparator + "server.properties"); Out.err("Could not open " + var.serverPath + var.fileSeparator + "server.properties");
return; return;
} catch (final IOException ex) { } catch (final IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
@ -80,7 +80,7 @@ public class WorldVerify {
final File level = new File(var.worldPath + var.fileSeparator + "level.dat"); final File level = new File(var.worldPath + var.fileSeparator + "level.dat");
if (!level.exists() || !level.isFile()) { if (!level.exists() || !level.isFile()) {
Main.err("The currently-configured world does not exist."); Out.err("The currently-configured world does not exist.");
return; return;
} }