From 55b872aa9409db97b1996929556f96db232151d0 Mon Sep 17 00:00:00 2001 From: Morlok8k Date: Tue, 11 Sep 2012 01:06:47 -0700 Subject: [PATCH] More refactoring, cleaning up... --- .../MinecraftLandGenerator/DownloadFile.java | 16 +- .../MinecraftLandGenerator/FileRead.java | 44 ++--- .../MinecraftLandGenerator/FileWrite.java | 4 +- .../MinecraftLandGenerator/Input_CLI.java | 6 +- src/morlok8k/MinecraftLandGenerator/Main.java | 175 ++++++------------ src/morlok8k/MinecraftLandGenerator/Misc.java | 4 +- src/morlok8k/MinecraftLandGenerator/Out.java | 60 ++++++ .../Readme_and_HelpInfo.java | 4 +- .../MinecraftLandGenerator/Server.java | 86 ++++----- .../MinecraftLandGenerator/SpawnPoint.java | 2 +- src/morlok8k/MinecraftLandGenerator/Time.java | 6 +- .../MinecraftLandGenerator/Update.java | 68 +++---- .../MinecraftLandGenerator/WorldVerify.java | 6 +- 13 files changed, 243 insertions(+), 238 deletions(-) create mode 100644 src/morlok8k/MinecraftLandGenerator/Out.java diff --git a/src/morlok8k/MinecraftLandGenerator/DownloadFile.java b/src/morlok8k/MinecraftLandGenerator/DownloadFile.java index 7f2a773..6d5486b 100644 --- a/src/morlok8k/MinecraftLandGenerator/DownloadFile.java +++ b/src/morlok8k/MinecraftLandGenerator/DownloadFile.java @@ -48,8 +48,8 @@ public class DownloadFile { fileName = Unescape.unescape(fileName); if (Output) { - Main.out("Downloading: " + URL); - Main.out("Saving as: " + fileName); + Out.out("Downloading: " + URL); + Out.out("Saving as: " + fileName); } final long differenceTime = System.currentTimeMillis(); @@ -57,7 +57,7 @@ public class DownloadFile { timeTracking[0] = System.currentTimeMillis(); if (Output) { - Main.outP(var.MLG + "*"); + Out.outP(var.MLG + "*"); } try { @@ -73,20 +73,20 @@ public class DownloadFile { bout.write(data, 0, x); count = count + x; if (Output) { - Main.outP("*"); + Out.outP("*"); } } bout.close(); in.close(); if (Output) { - Main.outP(var.newLine); - Main.out(count + " byte(s) copied"); + Out.outP(var.newLine); + Out.out(count + " byte(s) copied"); } timeTracking[1] = System.currentTimeMillis(); //differenceTime = (timeTracking[1] - timeTracking[0]); 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) { e.printStackTrace(); @@ -99,7 +99,7 @@ public class DownloadFile { success = false; } if (Output) { - Main.out("Done"); + Out.out("Done"); } return success; } diff --git a/src/morlok8k/MinecraftLandGenerator/FileRead.java b/src/morlok8k/MinecraftLandGenerator/FileRead.java index 63be908..273bab3 100644 --- a/src/morlok8k/MinecraftLandGenerator/FileRead.java +++ b/src/morlok8k/MinecraftLandGenerator/FileRead.java @@ -54,10 +54,10 @@ public class FileRead { in.close(); } catch (final FileNotFoundException ex) { - Main.out("Could not find " + file + "."); + Out.out("Could not find " + file + "."); return Return; } catch (final IOException ex) { - Main.err("Could not read " + file + "."); + Out.err("Could not read " + file + "."); return Return; } @@ -154,32 +154,32 @@ public class FileRead { in.close(); if (var.testing) { - Main.outD("Test Output: Reading of Config File "); - 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); + Out.outD("Test Output: Reading of Config File "); + Out.outD(" serverPath: " + var.serverPath); + Out.outD(" javaLine: " + var.javaLine); + Out.outD(" doneText: " + var.doneText); + Out.outD(" preparingText: " + var.preparingText); + Out.outD("preparingLevel: " + var.preparingLevel); + Out.outD(" level_0: " + var.level_0); + Out.outD(" level_1: " + var.level_1); + Out.outD(" level_2: " + var.level_2); + Out.outD(" level_3: " + var.level_3); + Out.outD(" level_4: " + var.level_4); + Out.outD(" level_5: " + var.level_5); + Out.outD(" level_6: " + var.level_6); + Out.outD(" level_7: " + var.level_7); + Out.outD(" level_8: " + var.level_8); + Out.outD(" level_9: " + var.level_9); + Out.outD(" waitSave: " + var.waitSave); + Out.outD(" webLaunch: " + var.webLaunch); } } catch (final FileNotFoundException ex) { - Main.out("Could not find " + Out.out("Could not find " + var.MinecraftLandGeneratorConf + ". It is recommended that you run the application with the -conf option to create it."); return; } catch (final IOException ex) { - Main.err("Could not read " + var.MinecraftLandGeneratorConf + "."); + Out.err("Could not read " + var.MinecraftLandGeneratorConf + "."); return; } } diff --git a/src/morlok8k/MinecraftLandGenerator/FileWrite.java b/src/morlok8k/MinecraftLandGenerator/FileWrite.java index ed391db..f1b0fea 100644 --- a/src/morlok8k/MinecraftLandGenerator/FileWrite.java +++ b/src/morlok8k/MinecraftLandGenerator/FileWrite.java @@ -107,10 +107,10 @@ public class FileWrite { outFile.write(txt); outFile.newLine(); outFile.close(); - Main.out(file + " file created."); + Out.out(file + " file created."); return; } catch (final IOException ex) { - Main.err("Could not create " + var.MinecraftLandGeneratorConf + "."); + Out.err("Could not create " + var.MinecraftLandGeneratorConf + "."); ex.printStackTrace(); return; } diff --git a/src/morlok8k/MinecraftLandGenerator/Input_CLI.java b/src/morlok8k/MinecraftLandGenerator/Input_CLI.java index a4e6ee8..efd99a8 100644 --- a/src/morlok8k/MinecraftLandGenerator/Input_CLI.java +++ b/src/morlok8k/MinecraftLandGenerator/Input_CLI.java @@ -16,14 +16,14 @@ public class Input_CLI { while (!(var.sc.hasNextInt())) { var.sc.nextLine(); - Main.outP(var.MLG + "Invalid Input. " + msg); + Out.outP(var.MLG + "Invalid Input. " + msg); } Return = var.sc.nextInt(); if (Return < 1000) { - Main.out("Input must be 1000 or larger."); - Main.outP(var.MLG + msg); + Out.out("Input must be 1000 or larger."); + Out.outP(var.MLG + msg); Return = getInt(msg); } diff --git a/src/morlok8k/MinecraftLandGenerator/Main.java b/src/morlok8k/MinecraftLandGenerator/Main.java index ca1fcd0..c4602dd 100644 --- a/src/morlok8k/MinecraftLandGenerator/Main.java +++ b/src/morlok8k/MinecraftLandGenerator/Main.java @@ -48,14 +48,14 @@ public class Main { // java -enableassertions -jar MinecraftLandGenerator.jar assert var.assertsEnabled = true; // Intentional side-effect!!! (This may cause a Warning, which is safe to ignore: "Possible accidental assignment in place of a comparison. A condition expression should not be reduced to an assignment") if (var.assertsEnabled) { - outD("assertsEnabled: " + var.assertsEnabled); + Out.outD("assertsEnabled: " + var.assertsEnabled); var.verbose = true; - outD("Verbose mode forced!"); + Out.outD("Verbose mode forced!"); var.testing = true; - outD("Debug mode forced!"); + Out.outD("Debug mode forced!"); var.dontWait = true; - outD("-nowait mode forced!"); - outD(""); + Out.outD("-nowait mode forced!"); + Out.outD(""); } boolean GUI = false; @@ -73,7 +73,7 @@ public class Main { if (!java.awt.GraphicsEnvironment.isHeadless() || (!NOGUI)) { GUI = true; 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 { GUI = false; // No GUI for us today... 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) * @@ -175,15 +120,15 @@ public class Main { // The following displays no matter what happens, so we needed this date stuff to happen first. - 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(var.PROG_NAME + " version " + var.VERSION); + 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 - out("This version was last modified on " + Out.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(""); - out(""); + Out.out(""); + Out.out("Uses a Minecraft server to generate square land of a specified size."); + Out.out(""); + Out.out(""); // ===================================================================== // INSTRUCTIONS @@ -198,14 +143,14 @@ public class Main { if (!(args.equals(newArgs))) { //do the freshly parsed args match the original? 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..."); + 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. - out("Please Enter the size of world you want. Example: X:1000 Z:1000"); - outP(var.MLG + "X:"); + Out.out("Please Enter the size of world you want. Example: X:1000 Z:1000"); + Out.outP(var.MLG + "X:"); xRange = Input_CLI.getInt("X:"); - outP(var.MLG + "Z:"); + Out.outP(var.MLG + "Z:"); zRange = Input_CLI.getInt("Z:"); args = new String[] { String.valueOf(xRange), String.valueOf(zRange) }; @@ -231,7 +176,7 @@ public class Main { final boolean fileSuccess = DownloadFile.downloadFile(var.github_MLG_Conf_URL, var.testing); if (fileSuccess) { - out(var.MinecraftLandGeneratorConf + " file downloaded."); + Out.out(var.MinecraftLandGeneratorConf + " file downloaded."); return; } } @@ -264,7 +209,7 @@ public class Main { if (args.length == 2) { DownloadFile.downloadFile(args[1], true); } else { - out("No File to Download!"); + Out.out("No File to Download!"); Time.waitTenSec(false); } return; @@ -326,13 +271,13 @@ public class Main { return; } } else { - out("No File with links!"); + Out.out("No File with links!"); Time.waitTenSec(false); } return; } 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); 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!) 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. // return; @@ -367,7 +312,7 @@ public class Main { } if (oldConf) { - err("Old Version of " + var.MinecraftLandGeneratorConf + " found. Updating..."); + Out.err("Old Version of " + var.MinecraftLandGeneratorConf + " found. Updating..."); FileWrite.saveConf(false); //old conf @@ -383,16 +328,16 @@ public class Main { if ((xRange < 1000) && (xRange != 0)) { xRange = 1000; //if less than 1000, (and not 0) set to 1000 (Calculations don't work well on very small maps) - err("X size too small - Changing X to 1000"); + Out.err("X size too small - Changing X to 1000"); } if ((zRange < 1000) && (zRange != 0)) { zRange = 1000; - err("Z size too small - Changing Z to 1000"); + Out.err("Z size too small - Changing Z to 1000"); } } catch (final NumberFormatException ex) { - err("Invalid X or Z argument."); - err("Please Enter the size of world you want. Example: X:1000 Z:1000"); + Out.err("Invalid X or Z argument."); + Out.err("Please Enter the size of world you want. Example: X:1000 Z:1000"); xRange = Input_CLI.getInt("X:"); zRange = Input_CLI.getInt("Z:"); @@ -408,39 +353,39 @@ public class Main { final String nextSwitch = args[i + 2].toLowerCase(); if (nextSwitch.equals("-verbose") || nextSwitch.equals("-v")) { var.verbose = true; - out("Notice: Verbose Mode"); + Out.out("Notice: Verbose Mode"); } else if (nextSwitch.startsWith("-i")) { 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")) { 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")) { var.alternate = true; - out("Notice: Using Alternate Launching"); + Out.out("Notice: Using Alternate Launching"); } else if (nextSwitch.startsWith("-x")) { 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 zOffset = Integer.valueOf(args[i + 2].substring(2)); - out("Notice: Z Offset: " + zOffset); + Out.out("Notice: Z Offset: " + zOffset); 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); } } else { 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) { - err("Invalid switch value."); + Out.err("Invalid switch value."); return; } @@ -455,8 +400,8 @@ public class Main { //err("You most likely will want to restore the backup!"); //Time.waitTenSec(false); - err("There is a level_backup.dat file left over from a previous attempt that failed."); - out("Resuming..."); + Out.err("There is a level_backup.dat file left over from a previous attempt that failed."); + Out.out("Resuming..."); //use resume data final File serverLevel = new File(var.worldPath + var.fileSeparator + "level.dat"); @@ -484,11 +429,11 @@ public class Main { // PROCESSING // ===================================================================== - out("Processing world \"" + var.worldPath + "\", in " + var.increment + Out.out("Processing world \"" + var.worldPath + "\", in " + var.increment + " block increments, with: " + var.javaLine); // out( MLG + "Processing \"" + worldName + "\"..."); - out(""); + Out.out(""); // prepare our two ProcessBuilders // minecraft = new ProcessBuilder(javaLine, "-Xms1024m", "-Xmx1024m", "-jar", jarFile, "nogui"); @@ -497,7 +442,7 @@ public class Main { var.minecraft.redirectErrorStream(true); 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. @@ -521,18 +466,18 @@ public class Main { + "# Started: " + var.dateFormat.format(generationStartTimeTracking) + 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 backupLevel = 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); - out(""); + Out.out(""); 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 + "MinecraftLandGenerator.log", "# Seed: " + var.randomSeed + var.newLine @@ -551,11 +496,11 @@ public class Main { overridden = true; } if (overridden) { - out("Centering land generation on [" + xOffset + ", " + zOffset + Out.out("Centering land generation on [" + xOffset + ", " + zOffset + "] due to switches."); } } - out(""); + Out.out(""); double xLoops, zLoops; int curXloops = 0; @@ -580,7 +525,7 @@ public class Main { zRangeAdj = (int) (zLoops * var.increment); zLoops = zLoops + 1; - out("Calculating Spawn Points..."); + Out.out("Calculating Spawn Points..."); int totalIterations = (int) (xLoops * zLoops); int currentIteration = 0; @@ -666,7 +611,7 @@ public class Main { (percentDone.indexOf(".") == -1 ? percentDone.length() : 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 timeTracking = System.currentTimeMillis(); @@ -675,7 +620,7 @@ public class Main { differenceTime = (timeTracking - generationStartTimeTracking) / (currentIteration + 1); // Updated. we now count all runs, instead of the last 4. differenceTime *= 1 + (totalIterations - currentIteration); // this should provide a more accurate result. - 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 SpawnPoint.setSpawn(serverLevel, xyz); @@ -684,7 +629,7 @@ public class Main { boolean serverSuccess = false; serverSuccess = Server.runMinecraft(); - out(""); + Out.out(""); //////// End server launch code @@ -699,16 +644,16 @@ public class Main { } if (currentIteration == 0) { - out("Nothing to generate!"); + Out.out("Nothing to generate!"); } else { - out("Finished generating chunks."); + Out.out("Finished generating chunks."); } Misc.copyFile(backupLevel, serverLevel); 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.waitTenSec(false); @@ -733,12 +678,12 @@ public class Main { try { java.awt.Desktop.getDesktop().browse(splashPage); } catch (final IOException e) { - err("Error displaying webpage... " + e.getLocalizedMessage()); + Out.err("Error displaying webpage... " + e.getLocalizedMessage()); } } else { - out("Please Visit: http://adf.ly/520855/mlg"); - out("Or: https://sites.google.com/site/minecraftlandgenerator/"); - out("Thanks!"); + Out.out("Please Visit: http://adf.ly/520855/mlg"); + Out.out("Or: https://sites.google.com/site/minecraftlandgenerator/"); + Out.out("Thanks!"); } } catch (final IOException ex) { diff --git a/src/morlok8k/MinecraftLandGenerator/Misc.java b/src/morlok8k/MinecraftLandGenerator/Misc.java index 05ec642..a70a3e4 100644 --- a/src/morlok8k/MinecraftLandGenerator/Misc.java +++ b/src/morlok8k/MinecraftLandGenerator/Misc.java @@ -50,10 +50,10 @@ public class Misc { 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); + Out.out("The current spawn point is: [X,Y,Z] " + spawn); return true; } catch (final IOException ex) { - Main.err("Error while reading " + level.getPath()); + Out.err("Error while reading " + level.getPath()); return false; } } diff --git a/src/morlok8k/MinecraftLandGenerator/Out.java b/src/morlok8k/MinecraftLandGenerator/Out.java new file mode 100644 index 0000000..95d4a98 --- /dev/null +++ b/src/morlok8k/MinecraftLandGenerator/Out.java @@ -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); + } + +} diff --git a/src/morlok8k/MinecraftLandGenerator/Readme_and_HelpInfo.java b/src/morlok8k/MinecraftLandGenerator/Readme_and_HelpInfo.java index efdb9d5..f4405e1 100644 --- a/src/morlok8k/MinecraftLandGenerator/Readme_and_HelpInfo.java +++ b/src/morlok8k/MinecraftLandGenerator/Readme_and_HelpInfo.java @@ -303,8 +303,8 @@ public class Readme_and_HelpInfo { String returnString = null; if (SysOut) { - Main.out(Str); - Main.out(""); + Out.out(Str); + Out.out(""); } else { returnString = Str; } diff --git a/src/morlok8k/MinecraftLandGenerator/Server.java b/src/morlok8k/MinecraftLandGenerator/Server.java index 6fe1dc6..e4879f4 100644 --- a/src/morlok8k/MinecraftLandGenerator/Server.java +++ b/src/morlok8k/MinecraftLandGenerator/Server.java @@ -19,7 +19,7 @@ public class Server { protected static boolean runMinecraft() throws IOException { if (var.verbose) { - Main.out("Starting server."); + Out.out("Starting server."); } boolean serverSuccess = true; boolean warning = false; @@ -30,7 +30,7 @@ public class Server { // 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. - Main.out("Alternate Launch"); + Out.out("Alternate Launch"); final Process process = var.minecraft.start(); //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 final OutputStream outputStream = process.getOutputStream(); - Main.out("Stopping server... (Please Wait...)"); + Out.out("Stopping server... (Please Wait...)"); outputStream.write(stop); outputStream.flush(); @@ -60,12 +60,12 @@ public class Server { } else { // start minecraft server normally! final Process process = var.minecraft.start(); if (var.verbose) { - Main.out("Started Server."); + Out.out("Started Server."); } final BufferedReader pOut = new BufferedReader(new InputStreamReader(process.getInputStream())); if (var.verbose) { - Main.out("Accessing Server Output..."); + Out.out("Accessing Server Output..."); } String line = null; @@ -97,7 +97,7 @@ public class Server { } if (var.verbose) { - Main.outS(shortLine); + Out.outS(shortLine); //} else if (line.toLowerCase().contains("saving")) { //this was just clutter // Main.outS(shortLine); } else if (line.contains(var.preparingText) || line.contains("Converting...")) { @@ -114,11 +114,11 @@ public class Server { outTmp = outTmp2; if (prepTextFirst) { - Main.outP(var.MLG + outTmp + "..."); + Out.outP(var.MLG + outTmp + "..."); prepTextFirst = false; } else { //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; if (convertedMapFormattingFlag == true) { - Main.outP(var.newLine); + Out.outP(var.newLine); convertedMapFormattingFlag = false; } 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" - Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_1 + ":" + Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_1 + ":" + var.newLine); } else if (line.contains("level 2")) { // "Preparing start region for level 2" - Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_2 + ":" + Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_2 + ":" + var.newLine); } else if (line.contains("level 3")) { // "Preparing start region for level 3" - Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_3 + ":" + Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_3 + ":" + var.newLine); } else if (line.contains("level 4")) { // "Preparing start region for level 4" - Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_4 + ":" + Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_4 + ":" + var.newLine); } else if (line.contains("level 5")) { // "Preparing start region for level 5" - Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_5 + ":" + Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_5 + ":" + var.newLine); } else if (line.contains("level 6")) { // "Preparing start region for level 6" - Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_6 + ":" + Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_6 + ":" + var.newLine); } else if (line.contains("level 7")) { // "Preparing start region for level 7" - Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_7 + ":" + Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_7 + ":" + var.newLine); } else if (line.contains("level 8")) { // "Preparing start region for level 8" - Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_8 + ":" + Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_8 + ":" + var.newLine); } else if (line.contains("level 9")) { // "Preparing start region for level 9" - Main.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_9 + ":" + Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_9 + ":" + var.newLine); } 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 - Main.outS(shortLine); + Out.outS(shortLine); if (line.contains("server version") && var.MC_Server_Version.isEmpty()) { // 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! - Main.outP(var.newLine); - Main.outS(line.substring(line.lastIndexOf("]") + 2, line.indexOf("!"))); + Out.outP(var.newLine); + Out.outS(line.substring(line.lastIndexOf("]") + 2, line.indexOf("!"))); if (var.waitSave) { - Main.out("Waiting 30 seconds to save..."); + Out.out("Waiting 30 seconds to save..."); int count = 1; while (count <= 30) { - Main.outP("."); + Out.outP("."); try { Thread.sleep(1000); @@ -191,23 +191,23 @@ public class Server { } count += 1; } - Main.out(""); + Out.out(""); } - Main.out("Saving server data..."); + Out.out("Saving server data..."); outputStream.write(saveAll); outputStream.flush(); - Main.out("Stopping server... (Please Wait...)"); + Out.out("Stopping server... (Please Wait...)"); // OutputStream outputStream = process.getOutputStream(); outputStream.write(stop); outputStream.flush(); // outputStream.close(); if (var.waitSave) { - Main.out("Waiting 10 seconds to save."); + Out.out("Waiting 10 seconds to save."); int count = 1; while (count <= 10) { - Main.outP("."); + Out.outP("."); try { Thread.sleep(1000); @@ -216,7 +216,7 @@ public class Server { } count += 1; } - Main.out(""); + Out.out(""); } } @@ -226,27 +226,27 @@ public class Server { var.ignoreWarnings = true; } else if (line.contains("[WARNING] To start the server with more ram")) { if (var.verbose == false) { // If verbose is true, we already displayed it. - Main.outS(line); + Out.outS(line); } warningsWeCanIgnore = true; //we can safely ignore this... var.ignoreWarnings = true; } else if (line.contains("Error occurred during initialization of VM") || line.contains("Could not reserve enough space for object heap")) { if (var.verbose == false) { // If verbose is true, we already displayed it. - Main.outP("[Java Error] " + line); + Out.outP("[Java Error] " + line); } warning = true; } if (var.ignoreWarnings == false) { if (line.contains("[WARNING]")) { // If we have a warning, stop... - Main.out(""); - Main.out("Warning found: Stopping " + var.PROG_NAME); + Out.out(""); + Out.out("Warning found: Stopping " + var.PROG_NAME); if (var.verbose == false) { // If verbose is true, we already displayed it. - Main.outS(line); + Out.outS(line); } - Main.out(""); - Main.out("Forcing Save..."); + Out.out(""); + Out.out("Forcing Save..."); outputStream.write(saveAll); outputStream.flush(); // OutputStream outputStream = process.getOutputStream(); @@ -259,13 +259,13 @@ public class Server { // System.exit(1); } if (line.contains("[SEVERE]")) { // If we have a severe error, stop... - Main.out(""); - Main.out("Severe error found: Stopping server."); + Out.out(""); + Out.out("Severe error found: Stopping server."); if (var.verbose == false) { // If verbose is true, we already displayed it. - Main.outS(line); + Out.outS(line); } - Main.out(""); - Main.out("Forcing Save..."); + Out.out(""); + Out.out("Forcing Save..."); outputStream.write(saveAll); outputStream.flush(); // OutputStream outputStream = process.getOutputStream(); diff --git a/src/morlok8k/MinecraftLandGenerator/SpawnPoint.java b/src/morlok8k/MinecraftLandGenerator/SpawnPoint.java index 1d378ca..75312cb 100644 --- a/src/morlok8k/MinecraftLandGenerator/SpawnPoint.java +++ b/src/morlok8k/MinecraftLandGenerator/SpawnPoint.java @@ -43,7 +43,7 @@ public class SpawnPoint { final LongTag Seed = (LongTag) newData.get("RandomSeed"); 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 = new Coordinates(spawnX.getValue(), spawnY.getValue(), spawnZ.getValue()); diff --git a/src/morlok8k/MinecraftLandGenerator/Time.java b/src/morlok8k/MinecraftLandGenerator/Time.java index cb3bba1..b51bf21 100644 --- a/src/morlok8k/MinecraftLandGenerator/Time.java +++ b/src/morlok8k/MinecraftLandGenerator/Time.java @@ -75,13 +75,13 @@ public class Time { if (var.dontWait) { return; } //Don't wait! if (output) { - Main.outP(var.MLG); //here we wait 10 sec. + Out.outP(var.MLG); //here we wait 10 sec. } int count = 0; while (count <= 100) { if (output) { - Main.outP(count + "% "); + Out.outP(count + "% "); } try { @@ -92,7 +92,7 @@ public class Time { count += 10; } if (output) { - Main.outP(var.newLine); + Out.outP(var.newLine); } return; diff --git a/src/morlok8k/MinecraftLandGenerator/Update.java b/src/morlok8k/MinecraftLandGenerator/Update.java index fab7933..b7da739 100644 --- a/src/morlok8k/MinecraftLandGenerator/Update.java +++ b/src/morlok8k/MinecraftLandGenerator/Update.java @@ -37,7 +37,7 @@ public class Update { final boolean fileSuccess = DownloadFile.downloadFile(var.github_MLG_BuildID_URL, var.testing); if (fileSuccess) { - Main.out(var.buildIDFile + " file downloaded."); + Out.out(var.buildIDFile + " file downloaded."); var.flag_downloadedBuildID = true; if (downloadOnly) { return; } @@ -45,7 +45,7 @@ public class Update { } if (downloadOnly) { - Main.err("Couldn't Download new " + var.buildIDFile); + Out.err("Couldn't Download new " + var.buildIDFile); return; } @@ -56,7 +56,7 @@ public class Update { try { var.MLGFileName = getClassLoader(var.cls); } catch (final Exception e) { - Main.out("Error: Finding file failed"); + Out.out("Error: Finding file failed"); e.printStackTrace(); } if (var.MLGFileName.equals(var.rsrcError)) { return; } @@ -68,7 +68,7 @@ public class Update { var.MLG_Current_Hash = MD5.fileMD5(var.MLGFileName); // out(hash + " " + MLGFileName); } catch (final Exception e) { - Main.out("Error: MD5 from file failed"); + Out.out("Error: MD5 from file failed"); e.printStackTrace(); } } @@ -78,7 +78,7 @@ public class Update { try { time = getCompileTimeStamp(var.cls); } catch (final Exception e) { - Main.out("Error: TimeStamp from file failed"); + Out.out("Error: TimeStamp from file failed"); e.printStackTrace(); } // out(d.toString()); @@ -101,7 +101,7 @@ public class Update { if (line.contains(var.MLG_Current_Hash)) { notNew = true; if (var.testing) { - Main.outD("NotNew"); + Out.outD("NotNew"); } } @@ -123,7 +123,7 @@ public class Update { fileRename.renameTo(new File(var.buildIDFile)); } 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"); FileWrite.writeTxtFile(var.buildIDFile, @@ -131,7 +131,7 @@ public class Update { + var.VERSION + INFO); } catch (final IOException ex) { - Main.err("Could not create \"" + var.buildIDFile + "\"."); + Out.err("Could not create \"" + var.buildIDFile + "\"."); return; } @@ -162,9 +162,9 @@ public class Update { file = 0; } if (filename.contains("rsrc:")) { - 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.)"); + Out.err("THIS WAS COMPILED USING \"org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader\"! "); + Out.err("DO NOT PACKAGE YOUR .JAR'S WITH THIS CLASSLOADER CODE!"); + Out.err("(Your Libraries need to be extracted.)"); return var.rsrcError; } if (filename.contains(".jar")) { @@ -217,7 +217,7 @@ public class Update { try { var.MLGFileName = getClassLoader(var.cls); } catch (final Exception e) { - Main.out("Error: Finding file failed"); + Out.out("Error: Finding file failed"); e.printStackTrace(); } if (var.MLGFileName.equals(var.rsrcError)) { return; } @@ -228,7 +228,7 @@ public class Update { var.MLGFileName.length()); 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) { @@ -237,7 +237,7 @@ public class Update { var.MLG_Current_Hash = MD5.fileMD5(var.MLGFileName); // out(hash + " " + MLGFileName); } catch (final Exception e) { - Main.out("Error: MD5 from file failed"); + Out.out("Error: MD5 from file failed"); e.printStackTrace(); } } @@ -253,7 +253,7 @@ public class Update { String line; if (var.testing) { - Main.outD("TimeStamps in buildIDFile:"); + Out.outD("TimeStamps in buildIDFile:"); } while ((line = in.readLine()) != null) { @@ -284,7 +284,7 @@ public class Update { //timeStamps.add(line.substring(pos + 1, end)); if (var.testing) { - Main.outD(var.timeStamps.get(tsCount)); + Out.outD(var.timeStamps.get(tsCount)); } tsCount++; @@ -304,38 +304,38 @@ public class Update { final long tCalc = var.MLG_Last_Modified_Long - highestModTime; if (var.testing) { - Main.outD("tCalc\tMLG_Last_Modified_Long\thighestModTime" + Out.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.)"); + Out.err("Archive Intergrity Check Failed: .zip/.jar file Issue."); + Out.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: " + Out.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.)"); + Out.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: " + Out.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: " + Out.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.)"); + Out.err("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)"); } } //return; @@ -354,9 +354,9 @@ public class Update { return; } } catch (final Exception e) { - Main.err("Cant Read " + var.buildIDFile + "!"); - Main.err(e.getLocalizedMessage()); - Main.err(""); + Out.err("Cant Read " + var.buildIDFile + "!"); + Out.err(e.getLocalizedMessage()); + Out.err(""); // e.printStackTrace(); buildID(false); readBuildID(); @@ -391,13 +391,13 @@ public class Update { //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!"); + Out.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!"); + Out.out("Rename attempt #1 failed!"); e1.printStackTrace(); try { @@ -406,7 +406,7 @@ public class Update { final File fileDelete = new File(var.MLG_JarFile); fileDelete.delete(); } catch (final Exception e2) { - Main.out("Rename attempt #2 failed!"); + Out.out("Rename attempt #2 failed!"); e2.printStackTrace(); //renameFailed = true; return; @@ -417,7 +417,7 @@ public class Update { final boolean fileSuccess = DownloadFile.downloadFile(var.github_MLG_jar_URL, true); if (fileSuccess) { - Main.out(var.MLG_JarFile + " downloaded."); + Out.out(var.MLG_JarFile + " downloaded."); return; } @@ -455,7 +455,7 @@ public class Update { final Enumeration e = zipF.entries(); 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()) { @@ -477,7 +477,7 @@ public class Update { final Date modificationTime = new Date(modTime); 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()); } @@ -488,7 +488,7 @@ public class Update { return highestModTime; } 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 } } diff --git a/src/morlok8k/MinecraftLandGenerator/WorldVerify.java b/src/morlok8k/MinecraftLandGenerator/WorldVerify.java index 90b48bb..ab99118 100644 --- a/src/morlok8k/MinecraftLandGenerator/WorldVerify.java +++ b/src/morlok8k/MinecraftLandGenerator/WorldVerify.java @@ -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. final File file = new File(var.serverPath); if (!file.exists() || !file.isDirectory()) { - Main.err("The server directory is invalid: " + var.serverPath); + Out.err("The server directory is invalid: " + var.serverPath); return; } @@ -71,7 +71,7 @@ public class WorldVerify { props.close(); } 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; } catch (final IOException 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"); if (!level.exists() || !level.isFile()) { - Main.err("The currently-configured world does not exist."); + Out.err("The currently-configured world does not exist."); return; }