+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/MLG-BuildID b/MLG-BuildID
index 2a53b35..73eed9b 100644
--- a/MLG-BuildID
+++ b/MLG-BuildID
@@ -68,3 +68,4 @@ EC40B0ECC52B37571EE65F780994CEDE=1360299846000# MLG v1.7.3
2ADFF46BCF1E77A559E6D9DB9C7586E8=1381398906000# MLG v1.7.5
3223FFFEE274215C50C88372D79B9E5C=1421666774000# MLG v1.7.6
6BAC4CB261A1F7494D7B9802B7462121=1540554341000# MLG v1.7.7 (Class File, Not .Jar)
+0706D1A8BCC148805EDAB29B7549B5A7=1541865384000# MLG v1.7.7 (Class File, Not .Jar)
diff --git a/src/main/java/morlok8k/MinecraftLandGenerator/Coordinates.java b/src/main/java/morlok8k/MinecraftLandGenerator/Coordinates.java
index b154c5b..a6ac751 100644
--- a/src/main/java/morlok8k/MinecraftLandGenerator/Coordinates.java
+++ b/src/main/java/morlok8k/MinecraftLandGenerator/Coordinates.java
@@ -9,6 +9,7 @@ package morlok8k.MinecraftLandGenerator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import java.util.regex.*;
/**
* Coordinates are in the form of [X,Y,Z] or (X,Z)
@@ -31,6 +32,7 @@ public class Coordinates {
* @return
* @author Morlok8k
*/
+
public static Coordinates parseString(String StringOfCoords) {
//parse out string
StringOfCoords = StringOfCoords.trim();
@@ -95,7 +97,7 @@ public class Coordinates {
/**
* Parses a Coordinates object from a String. Leading and trailing garbage is ignored.
- *
+ *
* @param stringOfCoords
* A short- or long-form coordinate string as described at the two toString() methods
* @return
@@ -137,7 +139,6 @@ public class Coordinates {
if (!matched) {
System.err.println("Invalid coordinate format: " + stringOfCoords);
- System.err.println();
}
return new Coordinates(X, Y, Z);
}
@@ -289,14 +290,14 @@ public class Coordinates {
// Because it doesn't know how to deal with my custom data.
// So instead of getting "blahblahblah.Coordinates@745f"
// (the location of the class and the hexstring of the hashcode)
- // I return "[X,Y,Z]"
+ // I return "[X,Y,Z]"
return ("[" + X + "," + Y + "," + Z + "]");
}
/**
- *
+ *
* @param Short
* @return
*/
@@ -307,4 +308,9 @@ public class Coordinates {
return toString(); // Idiot catch. default to: "[X,Y,Z]"
}
+ public static Coordinates parse(String coords){
+ String [] splitted = coords.substring(1,coords.length()-2).trim().split(",");
+
+ return null;
+ }
}
diff --git a/src/main/java/morlok8k/MinecraftLandGenerator/FileWrite.java b/src/main/java/morlok8k/MinecraftLandGenerator/FileWrite.java
index b754975..e0e6503 100644
--- a/src/main/java/morlok8k/MinecraftLandGenerator/FileWrite.java
+++ b/src/main/java/morlok8k/MinecraftLandGenerator/FileWrite.java
@@ -19,6 +19,9 @@
package morlok8k.MinecraftLandGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
@@ -30,6 +33,8 @@ import java.io.IOException;
*/
public class FileWrite {
+ private static Log log = LogFactory.getLog(Main.class);
+
/**
* http://www.roseindia.net/java/example/java/io/java-append-to-file.shtml
* Append To File - Java Tutorial
@@ -130,10 +135,10 @@ public class FileWrite {
outFile.write(txt);
outFile.newLine();
outFile.close();
- Out.out(file + " file created.");
+ log.info(file + " file created.");
return;
} catch (final IOException ex) {
- Out.err("Could not create " + var.MinecraftLandGeneratorConf + ".");
+ log.error("Could not create " + var.MinecraftLandGeneratorConf + ".");
ex.printStackTrace();
return;
}
diff --git a/src/main/java/morlok8k/MinecraftLandGenerator/GUI/MLG_GUI.java b/src/main/java/morlok8k/MinecraftLandGenerator/GUI/MLG_GUI.java
index 28bf3c0..d642ba5 100644
--- a/src/main/java/morlok8k/MinecraftLandGenerator/GUI/MLG_GUI.java
+++ b/src/main/java/morlok8k/MinecraftLandGenerator/GUI/MLG_GUI.java
@@ -51,9 +51,7 @@ import javax.swing.UIManager;
import javax.swing.plaf.metal.MetalLookAndFeel;
import javax.swing.plaf.metal.OceanTheme;
-import morlok8k.MinecraftLandGenerator.Out;
import morlok8k.MinecraftLandGenerator.Startup;
-import morlok8k.MinecraftLandGenerator.Time;
import morlok8k.MinecraftLandGenerator.Update;
import morlok8k.MinecraftLandGenerator.var;
@@ -635,7 +633,7 @@ public class MLG_GUI {
final String title = var.PROG_NAME + " v" + var.VERSION;
//JOptionPane.showMessageDialog(frmMLG_GUI, message, title, JOptionPane.INFORMATION_MESSAGE);
- Out.msg(message, title, JOptionPane.INFORMATION_MESSAGE);
+ System.out.println(message + title+ JOptionPane.INFORMATION_MESSAGE);
}
@@ -693,7 +691,6 @@ public class MLG_GUI {
var.stoppingServerGUI = true;
- Time.waitTenSec(true);
while (var.runningServerGUI) {
//;
diff --git a/src/main/java/morlok8k/MinecraftLandGenerator/GUI/Start.java b/src/main/java/morlok8k/MinecraftLandGenerator/GUI/Start.java
index c42fbc9..98f2146 100644
--- a/src/main/java/morlok8k/MinecraftLandGenerator/GUI/Start.java
+++ b/src/main/java/morlok8k/MinecraftLandGenerator/GUI/Start.java
@@ -19,7 +19,6 @@
package morlok8k.MinecraftLandGenerator.GUI;
-import morlok8k.MinecraftLandGenerator.Time;
import morlok8k.MinecraftLandGenerator.var;
public class Start implements Runnable {
@@ -89,7 +88,6 @@ public class Start implements Runnable {
while (var.stoppingServerGUI == false) {
// this is where we run the server loops!
MLG_GUI.frmMLG_GUI.repaint();
- Time.waitTenSec(true);
}
}
diff --git a/src/main/java/morlok8k/MinecraftLandGenerator/Input_CLI.java b/src/main/java/morlok8k/MinecraftLandGenerator/Input_CLI.java
index 76007b9..171e76a 100644
--- a/src/main/java/morlok8k/MinecraftLandGenerator/Input_CLI.java
+++ b/src/main/java/morlok8k/MinecraftLandGenerator/Input_CLI.java
@@ -19,12 +19,15 @@
package morlok8k.MinecraftLandGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
/**
*
* @author morlok8k
*/
public class Input_CLI {
-
+ private static Log log = LogFactory.getLog(Main.class);
/**
* getInt(String msg) - outputs a message, will only accept a valid integer from keyboard
*
@@ -35,18 +38,19 @@ public class Input_CLI {
*/
public static int getInt(final String msg) {
+
int Return = 0;
while (!(var.sc.hasNextInt())) {
var.sc.nextLine();
- Out.outP(var.MLG + "Invalid Input. " + msg);
+ log.error(var.MLG + "Invalid Input. " + msg);
}
Return = var.sc.nextInt();
if (Return < 1000) {
- Out.out("Input must be 1000 or larger.");
- Out.outP(var.MLG + msg);
+ log.info("Input must be 1000 or larger.");
+ log.info(var.MLG + msg);
Return = getInt(msg);
}
diff --git a/src/main/java/morlok8k/MinecraftLandGenerator/Main.java b/src/main/java/morlok8k/MinecraftLandGenerator/Main.java
index 54d1c20..253d936 100644
--- a/src/main/java/morlok8k/MinecraftLandGenerator/Main.java
+++ b/src/main/java/morlok8k/MinecraftLandGenerator/Main.java
@@ -205,7 +205,6 @@ public class Main {
log.info("Backing up level.dat to level_backup.dat.\n");
Misc.copyFile(serverLevel, backupLevel);
- Files.copy()
final Coordinates spawn = SpawnPoint.getSpawn(serverLevel);
log.info("Spawn point detected: [X,Y,Z] " + spawn);
diff --git a/src/main/java/morlok8k/MinecraftLandGenerator/Misc.java b/src/main/java/morlok8k/MinecraftLandGenerator/Misc.java
index 0c5aad5..5dccddc 100644
--- a/src/main/java/morlok8k/MinecraftLandGenerator/Misc.java
+++ b/src/main/java/morlok8k/MinecraftLandGenerator/Misc.java
@@ -19,6 +19,9 @@
package morlok8k.MinecraftLandGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
@@ -31,6 +34,7 @@ import java.io.OutputStream;
* @author morlok8k
*/
public class Misc {
+ private static Log log = LogFactory.getLog(Main.class);
/**
* I'd love to use nio, but it requires Java 7.
@@ -80,10 +84,10 @@ public class Misc {
final File level = new File(var.worldPath + var.fileSeparator + "level.dat");
try {
final Coordinates spawn = SpawnPoint.getSpawn(level);
- Out.out("The current spawn point is: [X,Y,Z] " + spawn);
+ log.info("The current spawn point is: [X,Y,Z] " + spawn);
return true;
} catch (final IOException ex) {
- Out.err("Error while reading " + level.getPath());
+ log.error("Error while reading " + level.getPath());
return false;
}
}
diff --git a/src/main/java/morlok8k/MinecraftLandGenerator/Server.java b/src/main/java/morlok8k/MinecraftLandGenerator/Server.java
index 3bd7c89..02df4b6 100644
--- a/src/main/java/morlok8k/MinecraftLandGenerator/Server.java
+++ b/src/main/java/morlok8k/MinecraftLandGenerator/Server.java
@@ -7,6 +7,9 @@
package morlok8k.MinecraftLandGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -26,11 +29,12 @@ public class Server {
* @throws IOException
* @author Corrodias, Morlok8k
*/
+ private static Log log = LogFactory.getLog(Main.class);
protected static boolean runMinecraft() throws IOException {
if (var.verbose) {
- Out.out("Starting server.");
+ log.info("Starting server.");
}
boolean serverSuccess = true;
boolean warning = false;
@@ -41,7 +45,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.
- Out.out("Alternate Launch");
+ log.info("Alternate Launch");
final Process process = var.minecraft.start();
final byte[] saveAll = { 's', 'a', 'v', 'e', '-', 'a', 'l', 'l', '\r', '\n' };
@@ -60,7 +64,7 @@ public class Server {
if (line.contains(var.doneText)) { // EDITED By Morlok8k for Minecraft 1.3+ Beta
final OutputStream outputStream = process.getOutputStream();
- Out.out("Stopping server... (Please Wait...)");
+ log.info("Stopping server... (Please Wait...)");
outputStream.write(saveAll);
outputStream.flush();
outputStream.write(stop);
@@ -73,12 +77,12 @@ public class Server {
} else { // start minecraft server normally!
final Process process = var.minecraft.start();
if (var.verbose) {
- Out.out("Started Server.");
+ log.info("Started Server.");
}
final BufferedReader pOut =
new BufferedReader(new InputStreamReader(process.getInputStream()));
if (var.verbose) {
- Out.out("Accessing Server Output...");
+ log.info("Accessing Server Output...");
}
String line = null;
@@ -118,7 +122,7 @@ public class Server {
}
if (var.verbose) {
- Out.outS(shortLine);
+ log.info(shortLine);
//} else if (line.toLowerCase().contains("saving")) { //this was just clutter
// Main.outS(shortLine);
} else if (line.contains(var.preparingText) || line.contains("Converting...")) {
@@ -135,11 +139,11 @@ public class Server {
outTmp = outTmp2;
if (prepTextFirst) {
- Out.outP(var.MLG + outTmp + "...");
+ log.info(var.MLG + outTmp + "...");
prepTextFirst = false;
} else {
//Main.outP(" " + outTmp + "...");
- Out.outP("\r" + var.MLG + outTmp + "..."); //here we use \r to go back to the previous line, and rewrite it
+ log.info("\r" + var.MLG + outTmp + "..."); //here we use \r to go back to the previous line, and rewrite it
}
//}
@@ -148,44 +152,44 @@ public class Server {
prepTextFirst = true;
if (convertedMapFormattingFlag == true) {
- Out.outP(var.newLine);
+ log.info(var.newLine);
convertedMapFormattingFlag = false;
}
if (line.contains("level 0")) { // "Preparing start region for level 0"
- Out.outP(var.MLG + var.worldName + ": " + var.level_0 + ":" + var.newLine);
+ log.info(var.MLG + var.worldName + ": " + var.level_0 + ":" + var.newLine);
} else if (line.contains("level 1")) { // "Preparing start region for level 1"
- Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_1 + ":"
+ log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_1 + ":"
+ var.newLine);
} else if (line.contains("level 2")) { // "Preparing start region for level 2"
- Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_2 + ":"
+ log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_2 + ":"
+ var.newLine);
} else if (line.contains("level 3")) { // "Preparing start region for level 3"
- Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_3 + ":"
+ log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_3 + ":"
+ var.newLine);
} else if (line.contains("level 4")) { // "Preparing start region for level 4"
- Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_4 + ":"
+ log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_4 + ":"
+ var.newLine);
} else if (line.contains("level 5")) { // "Preparing start region for level 5"
- Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_5 + ":"
+ log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_5 + ":"
+ var.newLine);
} else if (line.contains("level 6")) { // "Preparing start region for level 6"
- Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_6 + ":"
+ log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_6 + ":"
+ var.newLine);
} else if (line.contains("level 7")) { // "Preparing start region for level 7"
- Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_7 + ":"
+ log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_7 + ":"
+ var.newLine);
} else if (line.contains("level 8")) { // "Preparing start region for level 8"
- Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_8 + ":"
+ log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_8 + ":"
+ var.newLine);
} else if (line.contains("level 9")) { // "Preparing start region for level 9"
- Out.outP(var.newLine + var.MLG + var.worldName + ": " + var.level_9 + ":"
+ log.info(var.newLine + var.MLG + var.worldName + ": " + var.level_9 + ":"
+ var.newLine);
} else {
- Out.outP(var.newLine + var.MLG + shortLine + var.newLine);
+ log.info(var.newLine + var.MLG + shortLine + var.newLine);
}
} else if (line.contains("server version") || line.contains("Converting map!")) { //TODO: add to .conf
- Out.outS(shortLine);
+ log.info(shortLine);
if (line.contains("server version") && var.MC_Server_Version.isEmpty()) {
// if server version, save string to variable, for use in arraylist save file.
@@ -196,14 +200,14 @@ public class Server {
if (line.contains(var.doneText)) { // now this is configurable!
- Out.outP(var.newLine);
- Out.outS(line.substring(line.lastIndexOf("]") + 2, line.indexOf("!")));
+ log.info(var.newLine);
+ log.info(line.substring(line.lastIndexOf("]") + 2, line.indexOf("!")));
if (var.waitSave) {
- Out.out("Waiting 30 seconds to save...");
+ log.info("Waiting 30 seconds to save...");
int count = 1;
while (count <= 30) {
- Out.outP(".");
+ log.info(".");
try {
Thread.sleep(1000);
@@ -212,23 +216,23 @@ public class Server {
}
count += 1;
}
- Out.out("");
+ log.info("");
}
- Out.out("Saving server data...");
+ log.info("Saving server data...");
outputStream.write(saveAll);
outputStream.flush();
- Out.out("Stopping server... (Please Wait...)");
+ log.info("Stopping server... (Please Wait...)");
// OutputStream outputStream = process.getOutputStream();
outputStream.write(stop);
outputStream.flush();
// outputStream.close();
if (var.waitSave) {
- Out.out("Waiting 10 seconds to save.");
+ log.info("Waiting 10 seconds to save.");
int count = 1;
while (count <= 10) {
- Out.outP(".");
+ log.info(".");
try {
Thread.sleep(1000);
@@ -237,7 +241,7 @@ public class Server {
}
count += 1;
}
- Out.out("");
+ log.info("");
}
}
@@ -247,27 +251,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.
- Out.outS(line);
+ log.info(line);
}
warningsWeCanIgnore = true; //we can safely ignore this...
var.ignoreWarnings = true;
} else if (line.contains("Error occurred during initialization of VM")
|| line.contains("Could not reserve enough space for object heap")) {
if (var.verbose == false) { // If verbose is true, we already displayed it.
- Out.outP("[Java Error] " + line);
+ log.info("[Java Error] " + line);
}
warning = true;
}
if (var.ignoreWarnings == false) {
if (line.contains("[WARNING]")) { // If we have a warning, stop...
- Out.out("");
- Out.out("Warning found: Stopping " + var.PROG_NAME);
+ log.info("");
+ log.info("Warning found: Stopping " + var.PROG_NAME);
if (var.verbose == false) { // If verbose is true, we already displayed it.
- Out.outS(line);
+ log.info(line);
}
- Out.out("");
- Out.out("Forcing Save...");
+ log.info("");
+ log.info("Forcing Save...");
outputStream.write(saveAll);
outputStream.flush();
// OutputStream outputStream = process.getOutputStream();
@@ -280,13 +284,13 @@ public class Server {
// System.exit(1);
}
if (line.contains("[SEVERE]")) { // If we have a severe error, stop...
- Out.out("");
- Out.out("Severe error found: Stopping server.");
+ log.info("");
+ log.info("Severe error found: Stopping server.");
if (var.verbose == false) { // If verbose is true, we already displayed it.
- Out.outS(line);
+ log.info(line);
}
- Out.out("");
- Out.out("Forcing Save...");
+ log.info("");
+ log.info("Forcing Save...");
outputStream.write(saveAll);
outputStream.flush();
// OutputStream outputStream = process.getOutputStream();
diff --git a/src/main/java/morlok8k/MinecraftLandGenerator/Setup.java b/src/main/java/morlok8k/MinecraftLandGenerator/Setup.java
index 77b5dbd..ac03ef1 100644
--- a/src/main/java/morlok8k/MinecraftLandGenerator/Setup.java
+++ b/src/main/java/morlok8k/MinecraftLandGenerator/Setup.java
@@ -19,6 +19,9 @@
package morlok8k.MinecraftLandGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
@@ -33,6 +36,8 @@ import java.io.IOException;
public class Setup {
+ private static Log log = LogFactory.getLog(Main.class);
+
static boolean doSetup() throws IOException {
final File serverPathFile;
final BufferedReader serverPropertiesFile;
@@ -47,7 +52,7 @@ public class Setup {
/*FileNotFoundException fileException =
new FileNotFoundException("The server directory is invalid: " + var.serverPath);
throw fileException;*/
- Out.err("The server directory is invalid: " + var.serverPath);
+ log.error("The server directory is invalid: " + var.serverPath);
return true;
}
@@ -57,7 +62,7 @@ public class Setup {
new BufferedReader(new FileReader(new File(var.serverPath + var.fileSeparator
+ "server.properties")));
} catch (IOException e) {
- Out.err("Could not open the server.properties file.");
+ log.error("Could not open the server.properties file.");
return true;
}
@@ -95,7 +100,7 @@ public class Setup {
if (var.worldName == null) { // If after all this we still don't have a proper world name, stop everything and throw an exception
/*NullPointerException noNameException = new NullPointerException("There is no world name defined in the server.properties file!");
throw noNameException;*/
- Out.err("There is no world name defined in the server.properties file!");
+ log.error("There is no world name defined in the server.properties file!");
return true;
}
@@ -111,8 +116,8 @@ public class Setup {
if (levelDat.exists() && levelDat.isFile()) {
if (backupLevel.exists()) {
- Out.err("There is a level_backup.dat file left over from a previous attempt that failed.");
- Out.out("Resuming...");
+ log.error("There is a level_backup.dat file left over from a previous attempt that failed.");
+ log.info("Resuming...");
//use resume data
final File serverLevel = new File(var.worldPath + var.fileSeparator + "level.dat");
@@ -136,19 +141,19 @@ public class Setup {
} else {
/*FileNotFoundException fileException =
new FileNotFoundException("The currently configured world does not exist.");*/
- Out.err("The currently configured world does not exist! Launching the server once to create it...");
+ log.error("The currently configured world does not exist! Launching the server once to create it...");
try {
var.minecraft = new ProcessBuilder(var.javaLine.split("\\s")); // is this always going to work? i don't know. (most likely yes)
var.minecraft.directory(new File(var.serverPath));
var.minecraft.redirectErrorStream(true);
if (!(Server.runMinecraft())) {
- Out.err("Huh oh! Something went wrong with the server! Exiting...");
+ log.error("Huh oh! Something went wrong with the server! Exiting...");
System.exit(1); // we got a warning or severe error
}
} catch (IOException e) {
return true;
}
- Out.err("World created! Starting world generation...");
+ log.error("World created! Starting world generation...");
}
return false;
}
diff --git a/src/main/java/morlok8k/MinecraftLandGenerator/SpawnPoint.java b/src/main/java/morlok8k/MinecraftLandGenerator/SpawnPoint.java
index 6d753dd..cb9a503 100644
--- a/src/main/java/morlok8k/MinecraftLandGenerator/SpawnPoint.java
+++ b/src/main/java/morlok8k/MinecraftLandGenerator/SpawnPoint.java
@@ -66,7 +66,7 @@ public class SpawnPoint {
final LongTag Seed = (LongTag) newData.get("RandomSeed");
var.randomSeed = Seed.getValue();
- Out.out("Seed: " + var.randomSeed); // lets output the seed, cause why not?
+ System.out.println("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/main/java/morlok8k/MinecraftLandGenerator/Startup.java b/src/main/java/morlok8k/MinecraftLandGenerator/Startup.java
index 7acb898..61f3766 100644
--- a/src/main/java/morlok8k/MinecraftLandGenerator/Startup.java
+++ b/src/main/java/morlok8k/MinecraftLandGenerator/Startup.java
@@ -19,6 +19,9 @@
package morlok8k.MinecraftLandGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
@@ -35,6 +38,7 @@ import java.util.Date;
*
*/
public class Startup {
+ private static Log log = LogFactory.getLog(Main.class);
public static void initialStart() {
@@ -44,15 +48,15 @@ public class Startup {
// The following displays no matter what happens, so we needed this date stuff to happen first.
- 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.
+ log.info(var.PROG_NAME + " version " + var.VERSION);
+ log.info("BuildID: (" + var.MLG_Last_Modified_Date.getTime() + ")"); // instead of dateformatting the buildid, we return the raw Long number.
// thus different timezones wont display a different buildID
- Out.out("This version was last modified on "
+ log.info("This version was last modified on "
+ 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("");
- Out.out("");
+ log.info("");
+ log.info("Uses a Minecraft server to generate square land of a specified size.");
+ log.info("");
+ log.info("");
}
@@ -77,14 +81,14 @@ public class Startup {
if (!(var.args.equals(newArgs))) { //do the freshly parsed args match the original?
var.dontWait = true; //if not, we dont wait for anything!
var.args = newArgs; //use the freshly parsed args for everything else now...
- Out.out("Notice: Not waiting for anything...");
+ log.info("Notice: Not waiting for anything...");
}
if (var.args.length == 0) { //we didn't find a an X and Z size, so lets ask for one.
- Out.out("Please Enter the size of world you want. Example: X:1000 Z:1000");
- Out.outP(var.MLG + "X:");
+ log.info("Please Enter the size of world you want. Example: X:1000 Z:1000");
+ log.info(var.MLG + "X:");
var.xRange = Input_CLI.getInt("X:");
- Out.outP(var.MLG + "Z:");
+ log.info(var.MLG + "Z:");
var.zRange = Input_CLI.getInt("Z:");
var.args = new String[] { String.valueOf(var.xRange), String.valueOf(var.zRange) };
@@ -110,7 +114,7 @@ public class Startup {
final boolean fileSuccess =
DownloadFile.downloadFile(var.github_MLG_Conf_URL, var.testing);
if (fileSuccess) {
- Out.out(var.MinecraftLandGeneratorConf + " file downloaded.");
+ log.info(var.MinecraftLandGeneratorConf + " file downloaded.");
return true;
}
}
@@ -123,14 +127,12 @@ public class Startup {
|| var.args[0].equalsIgnoreCase("-printspawn")) {
// okay, sorry, this is an ugly hack, but it's just a last-minute feature.
Misc.printSpawn();
- Time.waitTenSec(false);
return true;
} else if (var.args[0].equalsIgnoreCase("-build")) {
Update.buildID(false);
return true;
} else if (var.args[0].equalsIgnoreCase("-update")) {
Update.updateMLG();
- Time.waitTenSec(false);
return true;
} else if (var.args[0].equalsIgnoreCase("-readme")) {
@@ -144,8 +146,7 @@ public class Startup {
if (var.args.length == 2) {
DownloadFile.downloadFile(var.args[1], true);
} else {
- Out.out("No File to Download!");
- Time.waitTenSec(false);
+ log.info("No File to Download!");
}
return true;
@@ -198,22 +199,18 @@ public class Startup {
} catch (final FileNotFoundException ex) {
System.err.println(var.args[1] + " - File not found");
- Time.waitTenSec(false);
return true;
} catch (final IOException ex) {
System.err.println(var.args[1] + " - Could not read file.");
- Time.waitTenSec(false);
return true;
}
} else {
- Out.out("No File with links!");
- Time.waitTenSec(false);
+ log.info("No File with links!");
}
return true;
} else if (var.args.length == 1) {
- Out.out("For help, use java -jar " + var.MLGFileNameShort + " -help");
- Time.waitTenSec(false);
+ log.info("For help, use java -jar " + var.MLGFileNameShort + " -help");
return true;
}
@@ -224,16 +221,16 @@ public class Startup {
if ((var.xRange < 1000) && (var.xRange != 0)) {
var.xRange = 1000; //if less than 1000, (and not 0) set to 1000 (Calculations don't work well on very small maps)
- Out.err("X size too small - Changing X to 1000");
+ log.error("X size too small - Changing X to 1000");
}
if ((var.zRange < 1000) && (var.zRange != 0)) {
var.zRange = 1000;
- Out.err("Z size too small - Changing Z to 1000");
+ log.error("Z size too small - Changing Z to 1000");
}
} catch (final NumberFormatException ex) {
- Out.err("Invalid X or Z argument.");
- Out.err("Please Enter the size of world you want. Example: X:1000 Z:1000");
+ log.error("Invalid X or Z argument.");
+ log.error("Please Enter the size of world you want. Example: X:1000 Z:1000");
var.xRange = Input_CLI.getInt("X:");
var.zRange = Input_CLI.getInt("Z:");
@@ -246,43 +243,42 @@ public class Startup {
final String nextSwitch = var.args[i + 2].toLowerCase();
if (nextSwitch.equals("-verbose") || nextSwitch.equals("-v")) {
var.verbose = true;
- Out.out("Notice: Verbose Mode");
+ log.info("Notice: Verbose Mode");
} else if (nextSwitch.startsWith("-i")) {
var.increment = Integer.parseInt(var.args[i + 2].substring(2));
- Out.out("Notice: Non-Default Increment: " + var.increment);
+ log.info("Notice: Non-Default Increment: " + var.increment);
} else if (nextSwitch.startsWith("-w")) {
var.ignoreWarnings = true;
- Out.out("Notice: Warnings from Server are Ignored");
+ log.info("Notice: Warnings from Server are Ignored");
} else if (nextSwitch.equals("-alt") || nextSwitch.equals("-a")) {
var.alternate = true;
- Out.out("Notice: Using Alternate Launching");
+ log.info("Notice: Using Alternate Launching");
} else if (nextSwitch.equals("-chunk") || nextSwitch.equals("-c")) {
var.useChunks = true;
- Out.out("Notice: Using Chunks instead of Regions");
+ log.info("Notice: Using Chunks instead of Regions");
} else if (nextSwitch.startsWith("-x")) {
var.xOffset = Integer.valueOf(var.args[i + 2].substring(2));
- Out.out("Notice: X Offset: " + var.xOffset);
+ log.info("Notice: X Offset: " + var.xOffset);
} else if (nextSwitch.startsWith("-y") || nextSwitch.startsWith("-z")) { //NOTE: "-y" is just here for backwards compatibility
var.zOffset = Integer.valueOf(var.args[i + 2].substring(2));
- Out.out("Notice: Z Offset: " + var.zOffset);
+ log.info("Notice: Z Offset: " + var.zOffset);
if (nextSwitch.startsWith("-y")) {
- Out.out("Notice: MLG now uses Z instead of Y. Please use the -z switch instead");
- Time.waitTenSec(false);
+ log.info("Notice: MLG now uses Z instead of Y. Please use the -z switch instead");
}
} else {
var.serverPath = var.args[i + 2];
- Out.out("Notice: Attempting to use Alternate Server:" + var.serverPath);
+ log.info("Notice: Attempting to use Alternate Server:" + var.serverPath);
}
}
} catch (final NumberFormatException ex) {
- Out.err("Invalid switch value.");
+ log.error("Invalid switch value.");
return true;
}
@@ -295,7 +291,7 @@ public class Startup {
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.
- Out.err(var.MinecraftLandGeneratorConf
+ log.error(var.MinecraftLandGeneratorConf
+ " does not contain all required properties. Making New File!"); // Please recreate it by running this application with -conf.
// return;
@@ -320,11 +316,10 @@ public class Startup {
}
if (oldConf) {
- Out.err("Old Version of " + var.MinecraftLandGeneratorConf + " found. Updating...");
+ log.error("Old Version of " + var.MinecraftLandGeneratorConf + " found. Updating...");
FileWrite.saveConf(false); //old conf
- Time.waitTenSec(false);
return true;
}
diff --git a/src/main/java/morlok8k/MinecraftLandGenerator/Time.java b/src/main/java/morlok8k/MinecraftLandGenerator/Time.java
index 2fd53e7..713a0ca 100644
--- a/src/main/java/morlok8k/MinecraftLandGenerator/Time.java
+++ b/src/main/java/morlok8k/MinecraftLandGenerator/Time.java
@@ -114,13 +114,13 @@ public class Time {
if (var.dontWait) { return; } //Don't wait!
if (output) {
- Out.outP(var.MLG); //here we wait 10 sec.
+ log.infoP(var.MLG); //here we wait 10 sec.
}
int count = 0;
while (count <= 100) {
if (output) {
- Out.outP(count + "% ");
+ log.infoP(count + "% ");
}
try {
@@ -131,7 +131,7 @@ public class Time {
count += 10;
}
if (output) {
- Out.outP(var.newLine);
+ log.infoP(var.newLine);
}
return;
diff --git a/src/main/java/morlok8k/MinecraftLandGenerator/Update.java b/src/main/java/morlok8k/MinecraftLandGenerator/Update.java
index 7ca1a56..4a74d63 100644
--- a/src/main/java/morlok8k/MinecraftLandGenerator/Update.java
+++ b/src/main/java/morlok8k/MinecraftLandGenerator/Update.java
@@ -19,6 +19,9 @@
package morlok8k.MinecraftLandGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
@@ -36,7 +39,6 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
/**
- *
* @author morlok8k
*/
public class Update {
@@ -51,25 +53,30 @@ public class Update {
* computer will have the correct time stamp. (or possibly a copy from the original computer)
*
* This saves the hash and the timestamp (now known as the BuildID)
- *
+ *
* @param downloadOnly
* @author Morlok8k
*/
+ private static Log log = LogFactory.getLog(Main.class);
+
public static void buildID(final boolean downloadOnly) {
+
// download BuildID from Github.
final boolean fileSuccess =
DownloadFile.downloadFile(var.github_MLG_BuildID_URL, var.testing);
if (fileSuccess) {
- Out.out(var.buildIDFile + " file downloaded.");
+ log.info(var.buildIDFile + " file downloaded.");
var.flag_downloadedBuildID = true;
- if (downloadOnly) { return; }
+ if (downloadOnly) {
+ return;
+ }
}
if (downloadOnly) {
- Out.err("Couldn't Download new " + var.buildIDFile);
+ log.error("Couldn't Download new " + var.buildIDFile);
return;
}
@@ -80,10 +87,12 @@ public class Update {
try {
var.MLGFileName = getClassLoader(var.cls);
} catch (final Exception e) {
- Out.out("Error: Finding file failed");
+ log.info("Error: Finding file failed");
e.printStackTrace();
}
- if (var.MLGFileName.equals(var.rsrcError)) { return; }
+ if (var.MLGFileName.equals(var.rsrcError)) {
+ return;
+ }
}
if (var.MLG_Current_Hash == null) {
@@ -92,7 +101,7 @@ public class Update {
var.MLG_Current_Hash = MD5.fileMD5(var.MLGFileName);
// out(hash + " " + MLGFileName);
} catch (final Exception e) {
- Out.out("Error: MD5 from file failed");
+ log.info("Error: MD5 from file failed");
e.printStackTrace();
}
}
@@ -102,7 +111,7 @@ public class Update {
try {
time = getCompileTimeStamp(var.cls);
} catch (final Exception e) {
- Out.out("Error: TimeStamp from file failed");
+ log.info("Error: TimeStamp from file failed");
e.printStackTrace();
}
// out(d.toString());
@@ -125,7 +134,7 @@ public class Update {
if (line.contains(var.MLG_Current_Hash)) {
notNew = true;
if (var.testing) {
- Out.outD("NotNew");
+ log.info("NotNew");
}
}
@@ -147,7 +156,7 @@ public class Update {
fileRename.renameTo(new File(var.buildIDFile));
} catch (final FileNotFoundException ex) {
- Out.out("\"" + var.buildIDFile + "\" file not Found. Generating New \""
+ log.info("\"" + var.buildIDFile + "\" file not Found. Generating New \""
+ var.buildIDFile + "\" File");
FileWrite.writeTxtFile(var.buildIDFile,
@@ -155,7 +164,7 @@ public class Update {
+ var.VERSION + INFO);
} catch (final IOException ex) {
- Out.err("Could not create \"" + var.buildIDFile + "\".");
+ log.error("Could not create \"" + var.buildIDFile + "\".");
return;
}
@@ -163,7 +172,7 @@ public class Update {
/**
* This gets the filename of a .jar (typically this one!)
- *
+ *
* @param classFile
* @return
* @throws IOException
@@ -179,19 +188,19 @@ public class Update {
// out(filename);
// START Garbage removal:
- int bang = filename.indexOf("!"); // remove everything after xxxx.jar
- if (bang == -1) { // a real example:
- bang = filename.length(); // jar:file:/home/morlok8k/test.jar!/me/Morlok8k/test/Main.class
+ int bang = filename.indexOf("!"); // remove everything after xxxx.jar
+ if (bang == -1) { // a real example:
+ bang = filename.length(); // jar:file:/home/morlok8k/test.jar!/me/Morlok8k/test/Main.class
}
- int file = filename.indexOf("file:"); // removes junk from the beginning of the path
+ int file = filename.indexOf("file:"); // removes junk from the beginning of the path
file = file + 5;
if (file == -1) {
file = 0;
}
if (filename.contains("rsrc:")) {
- 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.)");
+ log.error("THIS WAS COMPILED USING \"org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader\"! ");
+ log.error("DO NOT PACKAGE YOUR .JAR'S WITH THIS CLASSLOADER CODE!");
+ log.error("(Your Libraries need to be extracted.)");
return var.rsrcError;
}
if (filename.contains(".jar")) {
@@ -208,7 +217,7 @@ public class Update {
*
* Thanks to Roedy Green at
* http://mindprod .com/jgloss/compiletimestamp.html
- *
+ *
* @param classFile
* @return
* @throws IOException
@@ -231,9 +240,8 @@ public class Update {
/**
* Gets the BuildID for MLG
- *
+ *
* @author Morlok8k
- *
*/
public static void readBuildID() {
@@ -241,16 +249,18 @@ public class Update {
var.MLG_Last_Modified_Date = new Date(new Long(0)); //set the day to Jan 1, 1970 for failure
return;
}
- var.inf_loop_protect_BuildID++; // this is to prevent an infinite loop (however unlikely)
+ var.inf_loop_protect_BuildID++; // this is to prevent an infinite loop (however unlikely)
if (var.MLGFileName == null) {
try {
var.MLGFileName = getClassLoader(var.cls);
} catch (final Exception e) {
- Out.out("Error: Finding file failed");
+ log.info("Error: Finding file failed");
e.printStackTrace();
}
- if (var.MLGFileName.equals(var.rsrcError)) { return; }
+ if (var.MLGFileName.equals(var.rsrcError)) {
+ return;
+ }
}
var.MLGFileNameShort =
@@ -258,7 +268,7 @@ public class Update {
var.MLGFileName.length());
if (var.testing) {
- Out.outD("Currently Running as file:" + var.MLGFileNameShort);
+ log.info("Currently Running as file:" + var.MLGFileNameShort);
}
if (var.MLG_Current_Hash == null) {
@@ -267,7 +277,7 @@ public class Update {
var.MLG_Current_Hash = MD5.fileMD5(var.MLGFileName);
// out(hash + " " + MLGFileName);
} catch (final Exception e) {
- Out.out("Error: MD5 from file failed");
+ log.info("Error: MD5 from file failed");
e.printStackTrace();
}
}
@@ -283,7 +293,7 @@ public class Update {
String line;
if (var.testing) {
- Out.outD("TimeStamps in buildIDFile:");
+ log.info("TimeStamps in buildIDFile:");
}
while ((line = in.readLine()) != null) {
@@ -300,7 +310,7 @@ public class Update {
pos = -1;
}
- if (end == 0) { //hash is first char, meaning entire line is a comment
+ if (end == 0) { //hash is first char, meaning entire line is a comment
end = line.length();
pos = 0;
}
@@ -314,7 +324,7 @@ public class Update {
//timeStamps.add(line.substring(pos + 1, end));
if (var.testing) {
- Out.outD(var.timeStamps.get(tsCount));
+ log.info(var.timeStamps.get(tsCount));
}
tsCount++;
@@ -333,38 +343,38 @@ public class Update {
final long tCalc = var.MLG_Last_Modified_Long - highestModTime;
if (var.testing) {
- Out.outD("tCalc\tMLG_Last_Modified_Long\thighestModTime"
+ log.info("tCalc\tMLG_Last_Modified_Long\thighestModTime"
+ var.newLine + tCalc + "\t"
+ var.MLG_Last_Modified_Long + "\t" + highestModTime);
}
if (highestModTime == 0L) {
- 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.)");
+ log.error("Archive Intergrity Check Failed: .zip/.jar file Issue.");
+ log.error("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)");
} else {
if (tCalc < -43200000L) {
//time is newer? (.zip file is newer than BuildID)
- Out.err("Archive Intergrity Check Failed: .zip file is newer than BuildID. Offset: "
+ log.error("Archive Intergrity Check Failed: .zip file is newer than BuildID. Offset: "
+ (tCalc / 1000) + "sec.");
- Out.err("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)");
+ log.error("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)");
}
if (tCalc < 43200000L) {
//times are within 24 hours (+/- 12 hours) of each other. (typically 1-2 seconds, but left room for real-world error - due to timezone bugs with some operating systems)
if (var.testing | var.flag_downloadedBuildID) {
- Out.out("Archive Intergrity Check Passed. Offset: "
+ log.info("Archive Intergrity Check Passed. Offset: "
+ (tCalc / 1000) + "sec.");
}
} else {
//times dont match. (.zip file is older than specified BuildID)
- Out.err("Archive Intergrity Check Failed: .zip file is older than BuildID. Offset: "
+ log.error("Archive Intergrity Check Failed: .zip file is older than BuildID. Offset: "
+ (tCalc / 1000) + "sec.");
- Out.err("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)");
+ log.error("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)");
}
}
//return;
@@ -379,13 +389,13 @@ public class Update {
if (foundLine == false) {
// out("[DEBUG] FoundLine False");
buildID(false);
- readBuildID(); // yes I'm calling the function from itself. potential infinite loop? possibly. I haven't encountered it yet!
+ readBuildID(); // yes I'm calling the function from itself. potential infinite loop? possibly. I haven't encountered it yet!
return;
}
} catch (final Exception e) {
- Out.err("Cant Read " + var.buildIDFile + "!");
- Out.err(e.getLocalizedMessage());
- Out.err("");
+ log.error("Cant Read " + var.buildIDFile + "!");
+ log.error(e.getLocalizedMessage());
+ log.error("");
// e.printStackTrace();
buildID(false);
readBuildID();
@@ -398,13 +408,12 @@ public class Update {
/**
* Updates MLG to the Latest Version
- *
+ *
* @author Morlok8k
- *
*/
public static boolean updateMLG() {
- buildID(true); //get latest BuildID file.
+ buildID(true); //get latest BuildID file.
var.MLG_Last_Modified_Date = null;
readBuildID();
@@ -416,14 +425,14 @@ public class Update {
s = e.next();
diff = var.MLG_Last_Modified_Date.compareTo(new Date(new Long(s)));
- if (diff < 0) { // if this is less than 0, there is a new version of MLG on the Internet!
- Out.out("There is a NEW VERSION Of " + var.PROG_NAME + " available online!");
+ if (diff < 0) { // if this is less than 0, there is a new version of MLG on the Internet!
+ log.info("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) {
- Out.out("Rename attempt #1 failed!");
+ log.info("Rename attempt #1 failed!");
e1.printStackTrace();
try {
@@ -431,7 +440,7 @@ public class Update {
final File fileDelete = new File(var.MLG_JarFile);
fileDelete.delete();
} catch (final Exception e2) {
- Out.out("Rename attempt #2 failed!");
+ log.info("Rename attempt #2 failed!");
e2.printStackTrace();
return false;
@@ -441,7 +450,7 @@ public class Update {
final boolean fileSuccess = DownloadFile.downloadFile(var.github_MLG_jar_URL, true);
if (fileSuccess) {
- Out.out(var.MLG_JarFile + " downloaded.");
+ log.info(var.MLG_JarFile + " downloaded.");
return true;
}
@@ -453,14 +462,14 @@ public class Update {
/**
* .zip file Get Modification Time
- *
+ *
* Takes a string of a path to a .zip file (or .jar), and and returns a Long of the latest "Last Time Modified".
*
- *
+ *
* Thanks to the following:
* http://www.java-examples.com/get-modification-time-zip-entry-example
* http://www.java-examples.com/get-crc-32-checksum-zip-entry-example
- *
+ *
* @param zipFile
* @return
* @author Morlok8k
@@ -480,7 +489,7 @@ public class Update {
final Enumeration extends ZipEntry> e = zipF.entries();
if (var.testing) {
- Out.outD("File Name\t\tCRC\t\tModification Time\n---------------------------------\n");
+ log.info("File Name\t\tCRC\t\tModification Time\n---------------------------------\n");
}
while (e.hasMoreElements()) {
@@ -488,7 +497,7 @@ public class Update {
Long modTime = entry.getTime();
- if (!(entry.getName().toUpperCase().contains(".CLASS"))) { //ignore highest timestamp for non .class files, as they can be injected into the .jar file much later after compiling.
+ if (!(entry.getName().toUpperCase().contains(".CLASS"))) { //ignore highest timestamp for non .class files, as they can be injected into the .jar file much later after compiling.
modTime = 0L;
}
@@ -502,7 +511,7 @@ public class Update {
final Date modificationTime = new Date(modTime);
final String CRC = Long.toHexString(entry.getCrc());
- Out.outD(entryName + "\t" + CRC + "\t" + modificationTime + "\t"
+ log.info(entryName + "\t" + CRC + "\t" + modificationTime + "\t"
+ modTime.toString());
}
@@ -513,8 +522,8 @@ public class Update {
return highestModTime;
} catch (final IOException ioe) {
- Out.out("Error opening zip file" + ioe);
- return 0L; //return Jan. 1, 1970 12:00 GMT for failures
+ log.info("Error opening zip file" + ioe);
+ return 0L; //return Jan. 1, 1970 12:00 GMT for failures
}
}
}