1.7.0 test 3 (source only)
This commit is contained in:
parent
7580fe546b
commit
71b4bef098
65
src/corrodias/minecraft/landgenerator/MLG_Misc.java
Normal file
65
src/corrodias/minecraft/landgenerator/MLG_Misc.java
Normal file
@ -0,0 +1,65 @@
|
||||
package corrodias.minecraft.landgenerator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import morlok8k.minecraft.landgenerator.Coordinates;
|
||||
import morlok8k.minecraft.landgenerator.MLG_FileRead;
|
||||
|
||||
public class MLG_Misc {
|
||||
|
||||
//TODO: add description
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
static boolean printSpawn() {
|
||||
// ugh, sorry, this is an ugly hack, but it's a last-minute feature. this is a lot of duplicated code.
|
||||
// - Fixed by Morlok8k
|
||||
|
||||
MLG_FileRead.readConf();
|
||||
MLG_WorldVerify.verifyWorld();
|
||||
|
||||
File level = new File(Main.worldPath + Main.fileSeparator + "level.dat");
|
||||
try {
|
||||
Coordinates spawn = MLG_SpawnPoint.getSpawn(level);
|
||||
Main.out("The current spawn point is: [X,Y,Z] " + spawn);
|
||||
return true;
|
||||
} catch (IOException ex) {
|
||||
Main.err("Error while reading " + level.getPath());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* I'd love to use nio, but it requires Java 7.<br>
|
||||
* I could use Apache Commons, but i don't want to include a library for one little thing.<br>
|
||||
* Copies src file to dst file.<br>
|
||||
* If the dst file does not exist, it is created<br>
|
||||
*
|
||||
* @author Corrodias
|
||||
* @param src
|
||||
* @param dst
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void copyFile(File src, File dst) throws IOException {
|
||||
InputStream copyIn = new FileInputStream(src);
|
||||
OutputStream copyOut = new FileOutputStream(dst);
|
||||
|
||||
// Transfer bytes from in to out
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = copyIn.read(buf)) >= 0) {
|
||||
if (len > 0) {
|
||||
copyOut.write(buf, 0, len);
|
||||
}
|
||||
}
|
||||
copyIn.close();
|
||||
copyOut.flush();
|
||||
copyOut.close();
|
||||
}
|
||||
|
||||
}
|
300
src/corrodias/minecraft/landgenerator/MLG_Server.java
Normal file
300
src/corrodias/minecraft/landgenerator/MLG_Server.java
Normal file
@ -0,0 +1,300 @@
|
||||
package corrodias.minecraft.landgenerator;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class MLG_Server {
|
||||
|
||||
/**
|
||||
* Starts the process in the given ProcessBuilder, monitors its output for a "[INFO] Done!" message, and sends it a "stop\r\n" message. One message is printed to the console before launching and
|
||||
* one is printed to the console when the Done! message is detected. If "verbose" is true, the process's output will also be printed to the console.
|
||||
*
|
||||
* @param minecraft
|
||||
*
|
||||
* @throws IOException
|
||||
* @author Corrodias
|
||||
*/
|
||||
protected static boolean runMinecraft(boolean alternate) throws IOException {
|
||||
if (Main.verbose) {
|
||||
Main.out("Starting server.");
|
||||
}
|
||||
boolean serverSuccess = true;
|
||||
boolean warning = false;
|
||||
boolean warningsWeCanIgnore = false;
|
||||
final boolean ignoreWarningsOriginal = Main.ignoreWarnings;
|
||||
|
||||
// monitor output and print to console where required.
|
||||
// STOP the server when it's done.
|
||||
|
||||
if (alternate) { // Alternate - a replication (slightly stripped down) of MLG 1.3.0's code. simplest code possible.
|
||||
Main.out("Alternate Launch");
|
||||
Process process = Main.minecraft.start();
|
||||
|
||||
byte[] stop = { 's', 't', 'o', 'p', '\r', '\n' };
|
||||
|
||||
// monitor output and print to console where required.
|
||||
// STOP the server when it's done.
|
||||
BufferedReader pOut =
|
||||
new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String line;
|
||||
while ((line = pOut.readLine()) != null) {
|
||||
|
||||
line = line.trim(); //Trim spaces off the beginning and end, if any.
|
||||
|
||||
System.out.println(line);
|
||||
if (line.contains(Main.doneText)) { // EDITED By Morlok8k for Minecraft 1.3+ Beta
|
||||
OutputStream outputStream = process.getOutputStream();
|
||||
|
||||
Main.out("Stopping server... (Please Wait...)");
|
||||
outputStream.write(stop);
|
||||
outputStream.flush();
|
||||
|
||||
}
|
||||
}
|
||||
// readLine() returns null when the process exits
|
||||
|
||||
} else { // start minecraft server normally!
|
||||
Process process = Main.minecraft.start();
|
||||
if (Main.verbose) {
|
||||
Main.out("Started Server.");
|
||||
}
|
||||
BufferedReader pOut =
|
||||
new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
if (Main.verbose) {
|
||||
Main.out("Accessing Server Output...");
|
||||
}
|
||||
|
||||
String line = null;
|
||||
String shortLine = null;
|
||||
String outTmp = "";
|
||||
String outTmp2 = null;
|
||||
|
||||
byte[] stop = { 's', 't', 'o', 'p', '\r', '\n' }; // Moved here, so this code wont run every loop, thus Faster!
|
||||
// and no, i can't use a string here!
|
||||
|
||||
byte[] saveAll = { 's', 'a', 'v', 'e', '-', 'a', 'l', 'l', '\r', '\n' };
|
||||
|
||||
boolean prepTextFirst = true;
|
||||
|
||||
OutputStream outputStream = process.getOutputStream(); // moved here to remove some redundancy
|
||||
|
||||
/*
|
||||
2012-02-29 03:50:28 [INFO] Converting map!
|
||||
Scanning folders...
|
||||
Total conversion count is 9
|
||||
2012-02-29 03:50:29 [INFO] Converting... 8%
|
||||
2012-02-29 03:50:30 [INFO] Converting... 9%
|
||||
2012-02-29 03:50:31 [INFO] Converting... 10%
|
||||
2012-02-29 03:50:32 [INFO] Converting... 12%
|
||||
2012-02-29 03:50:33 [INFO] Converting... 13%
|
||||
*/
|
||||
|
||||
boolean convertedMapFormattingFlag = false; // This allows MLG to track if we converted a map to a new format (such as Chunk-file -> McRegion, or McRegion -> Anvil)
|
||||
// just so it gets a line ending after the % output finishes
|
||||
while ((line = pOut.readLine()) != null) {
|
||||
|
||||
int posBracket = line.lastIndexOf("]");
|
||||
if (posBracket != -1) {
|
||||
shortLine = line.substring(posBracket + 2);
|
||||
shortLine = shortLine.trim();
|
||||
} else {
|
||||
shortLine = line;
|
||||
}
|
||||
|
||||
line = line.trim();
|
||||
|
||||
if (Main.verbose) {
|
||||
Main.outS(shortLine);
|
||||
} else if (line.toLowerCase().contains("saving")) {
|
||||
Main.outS(shortLine);
|
||||
} else if (line.contains(Main.preparingText) || line.contains("Converting...")) {
|
||||
if (line.contains("Converting...")) {
|
||||
convertedMapFormattingFlag = true;
|
||||
}
|
||||
outTmp2 = line.substring(line.length() - 3, line.length());
|
||||
outTmp2 = outTmp2.trim(); //we are removing extra spaces here
|
||||
if (outTmp.equals(outTmp2)) {
|
||||
//instead of printing the same number, we add another dot
|
||||
Main.outP(".");
|
||||
} else {
|
||||
outTmp = outTmp2;
|
||||
|
||||
if (prepTextFirst) {
|
||||
Main.outP(Main.MLG + outTmp + "...");
|
||||
prepTextFirst = false;
|
||||
} else {
|
||||
Main.outP(" " + outTmp + "...");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else if (line.contains(Main.preparingLevel)) {
|
||||
prepTextFirst = true;
|
||||
|
||||
if (convertedMapFormattingFlag == true) {
|
||||
Main.outP(Main.newLine);
|
||||
convertedMapFormattingFlag = false;
|
||||
}
|
||||
|
||||
if (line.contains("level 0")) { // "Preparing start region for level 0"
|
||||
Main.outP(Main.MLG + Main.worldName + ": " + Main.level_0 + ":" + Main.newLine);
|
||||
} else if (line.contains("level 1")) { // "Preparing start region for level 1"
|
||||
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_1 + ":" + Main.newLine);
|
||||
} else if (line.contains("level 2")) { // "Preparing start region for level 2"
|
||||
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_2 + ":" + Main.newLine);
|
||||
} else if (line.contains("level 3")) { // "Preparing start region for level 3"
|
||||
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_3 + ":" + Main.newLine);
|
||||
} else if (line.contains("level 4")) { // "Preparing start region for level 4"
|
||||
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_4 + ":" + Main.newLine);
|
||||
} else if (line.contains("level 5")) { // "Preparing start region for level 5"
|
||||
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_5 + ":" + Main.newLine);
|
||||
} else if (line.contains("level 6")) { // "Preparing start region for level 6"
|
||||
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_6 + ":" + Main.newLine);
|
||||
} else if (line.contains("level 7")) { // "Preparing start region for level 7"
|
||||
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_7 + ":" + Main.newLine);
|
||||
} else if (line.contains("level 8")) { // "Preparing start region for level 8"
|
||||
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_8 + ":" + Main.newLine);
|
||||
} else if (line.contains("level 9")) { // "Preparing start region for level 9"
|
||||
Main.outP(Main.newLine + Main.MLG + Main.worldName + ": " + Main.level_9 + ":" + Main.newLine);
|
||||
} else {
|
||||
Main.outP(Main.newLine + Main.MLG + shortLine);
|
||||
}
|
||||
} else if (line.contains("server version") || line.contains("Converting map!")) { //TODO: add to .conf
|
||||
Main.outS(shortLine);
|
||||
|
||||
if (line.contains("server version") && Main.MC_Server_Version.isEmpty()) {
|
||||
// if server version, save string to variable, for use in arraylist save file.
|
||||
Main.MC_Server_Version = shortLine;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (line.contains(Main.doneText)) { // now this is configurable!
|
||||
|
||||
Main.outP(Main.newLine);
|
||||
Main.outS(line.substring(line.lastIndexOf("]") + 2, line.indexOf("!")));
|
||||
if (Main.waitSave) {
|
||||
Main.out("Waiting 30 seconds to save...");
|
||||
|
||||
int count = 1;
|
||||
while (count <= 30) {
|
||||
Main.outP(".");
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
count += 1;
|
||||
}
|
||||
Main.out("");
|
||||
}
|
||||
Main.out("Saving server data...");
|
||||
outputStream.write(saveAll);
|
||||
outputStream.flush();
|
||||
|
||||
Main.out("Stopping server... (Please Wait...)");
|
||||
// OutputStream outputStream = process.getOutputStream();
|
||||
outputStream.write(stop);
|
||||
outputStream.flush();
|
||||
// outputStream.close();
|
||||
|
||||
if (Main.waitSave) {
|
||||
Main.out("Waiting 10 seconds to save.");
|
||||
int count = 1;
|
||||
while (count <= 10) {
|
||||
Main.outP(".");
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
count += 1;
|
||||
}
|
||||
Main.out("");
|
||||
}
|
||||
}
|
||||
|
||||
//Here we want to ignore the most common warning: "Can't keep up!"
|
||||
if (line.contains("Can't keep up!")) { //TODO: add to .conf
|
||||
warningsWeCanIgnore = true; //[WARNING] Can't keep up! Did the system time change, or is the server overloaded?
|
||||
Main.ignoreWarnings = true;
|
||||
} else if (line.contains("[WARNING] To start the server with more ram")) {
|
||||
if (Main.verbose == false) { // If verbose is true, we already displayed it.
|
||||
Main.outS(line);
|
||||
}
|
||||
warningsWeCanIgnore = true; //we can safely ignore this...
|
||||
Main.ignoreWarnings = true;
|
||||
} else if (line.contains("Error occurred during initialization of VM")
|
||||
|| line.contains("Could not reserve enough space for object heap")) {
|
||||
if (Main.verbose == false) { // If verbose is true, we already displayed it.
|
||||
Main.outP("[Java Error] " + line);
|
||||
}
|
||||
warning = true;
|
||||
}
|
||||
|
||||
if (Main.ignoreWarnings == false) {
|
||||
if (line.contains("[WARNING]")) { // If we have a warning, stop...
|
||||
Main.out("");
|
||||
Main.out("Warning found: Stopping " + Main.PROG_NAME);
|
||||
if (Main.verbose == false) { // If verbose is true, we already displayed it.
|
||||
Main.outS(line);
|
||||
}
|
||||
Main.out("");
|
||||
Main.out("Forcing Save...");
|
||||
outputStream.write(saveAll);
|
||||
outputStream.flush();
|
||||
// OutputStream outputStream = process.getOutputStream();
|
||||
outputStream.write(stop); // if the warning was a fail to bind to port, we may need to write stop twice!
|
||||
outputStream.flush();
|
||||
outputStream.write(stop);
|
||||
outputStream.flush();
|
||||
// outputStream.close();
|
||||
warning = true;
|
||||
// System.exit(1);
|
||||
}
|
||||
if (line.contains("[SEVERE]")) { // If we have a severe error, stop...
|
||||
Main.out("");
|
||||
Main.out("Severe error found: Stopping server.");
|
||||
if (Main.verbose == false) { // If verbose is true, we already displayed it.
|
||||
Main.outS(line);
|
||||
}
|
||||
Main.out("");
|
||||
Main.out("Forcing Save...");
|
||||
outputStream.write(saveAll);
|
||||
outputStream.flush();
|
||||
// OutputStream outputStream = process.getOutputStream();
|
||||
outputStream.write(stop);
|
||||
outputStream.flush();
|
||||
outputStream.write(stop); // sometimes we need to do stop twice...
|
||||
outputStream.flush();
|
||||
// outputStream.close();
|
||||
warning = true;
|
||||
// System.exit(1);
|
||||
// Quit!
|
||||
}
|
||||
}
|
||||
|
||||
if (warningsWeCanIgnore) {
|
||||
Main.ignoreWarnings = ignoreWarningsOriginal;
|
||||
}
|
||||
}
|
||||
|
||||
if (warning == true) { // in 1.4.4 we had a issue. tried to write stop twice, but we had closed the stream already. this, and other lines should fix this.
|
||||
outputStream.flush();
|
||||
//outputStream.close();
|
||||
//System.exit(1);
|
||||
serverSuccess = false;
|
||||
}
|
||||
|
||||
outputStream.close();
|
||||
}
|
||||
|
||||
// readLine() returns null when the process exits
|
||||
return serverSuccess;
|
||||
}
|
||||
|
||||
}
|
143
src/corrodias/minecraft/landgenerator/MLG_SpawnPoint.java
Normal file
143
src/corrodias/minecraft/landgenerator/MLG_SpawnPoint.java
Normal file
@ -0,0 +1,143 @@
|
||||
package corrodias.minecraft.landgenerator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import morlok8k.minecraft.landgenerator.Coordinates;
|
||||
|
||||
import org.jnbt.CompoundTag;
|
||||
import org.jnbt.IntTag;
|
||||
import org.jnbt.LongTag;
|
||||
import org.jnbt.NBTInputStream;
|
||||
import org.jnbt.NBTOutputStream;
|
||||
import org.jnbt.Tag;
|
||||
|
||||
public class MLG_SpawnPoint {
|
||||
|
||||
/**
|
||||
* Changes the spawn point in the given Alpha/Beta level to the given coordinates.<br>
|
||||
* Note that, in Minecraft levels, the Y coordinate is height.<br>
|
||||
* (We picture maps from above, but the game was made from a different perspective)
|
||||
*
|
||||
* @param level
|
||||
* the level file to change the spawn point in
|
||||
* @param xyz
|
||||
* the Coordinates of the spawn point
|
||||
* @throws IOException
|
||||
* if there are any problems reading/writing the file
|
||||
* @author Corrodias
|
||||
*/
|
||||
protected static void setSpawn(File level, Coordinates xyz) throws IOException {
|
||||
|
||||
try {
|
||||
NBTInputStream input = new NBTInputStream(new FileInputStream(level));
|
||||
CompoundTag originalTopLevelTag = (CompoundTag) input.readTag();
|
||||
input.close();
|
||||
|
||||
//@formatter:off
|
||||
|
||||
//Note: The Following Information is Old (from 2010), compared to the Data inside a current "level.dat".
|
||||
//However, What we look at (SpawnX,Y,Z and RandomSeed) have not changed.
|
||||
|
||||
/* <editor-fold defaultstate="collapsed" desc="structure">
|
||||
* Structure:
|
||||
*
|
||||
*TAG_Compound("Data"): World data.
|
||||
* * TAG_Long("Time"): Stores the current "time of day" in ticks. There are 20 ticks per real-life second, and 24000 ticks per Minecraft day, making the day length 20 minutes. 0 appears to be sunrise, 12000 sunset and 24000 sunrise again.
|
||||
* * TAG_Long("LastPlayed"): Stores the Unix time stamp (in milliseconds) when the player saved the game.
|
||||
* * TAG_Compound("Player"): Player entity information. See Entity Format and Mob Entity Format for details. Has additional elements:
|
||||
* o TAG_List("Inventory"): Each TAG_Compound in this list defines an item the player is carrying, holding, or wearing as armor.
|
||||
* + TAG_Compound: Inventory item data
|
||||
* # TAG_Short("id"): Item or Block ID.
|
||||
* # TAG_Short("Damage"): The amount of wear each item has suffered. 0 means undamaged. When the Damage exceeds the item's durability, it breaks and disappears. Only tools and armor accumulate damage normally.
|
||||
* # TAG_Byte("Count"): Number of items stacked in this inventory slot. Any item can be stacked, including tools, armor, and vehicles. Range is 1-255. Values above 127 are not displayed in-game.
|
||||
* # TAG_Byte("Slot"): Indicates which inventory slot this item is in.
|
||||
* o TAG_Int("Score"): Current score, doesn't appear to be implemented yet. Always 0.
|
||||
* * TAG_Int("SpawnX"): X coordinate of the player's spawn position. Default is 0.
|
||||
* * TAG_Int("SpawnY"): Y coordinate of the player's spawn position. Default is 64.
|
||||
* * TAG_Int("SpawnZ"): Z coordinate of the player's spawn position. Default is 0.
|
||||
* * TAG_Byte("SnowCovered"): 1 enables, 0 disables, see Winter Mode
|
||||
* * TAG_Long("SizeOnDisk"): Estimated size of the entire world in bytes.
|
||||
* * TAG_Long("RandomSeed"): Random number providing the Random Seed for the terrain.
|
||||
* </editor-fold>
|
||||
*/
|
||||
|
||||
//@formatter:on
|
||||
|
||||
Map<String, Tag> originalData =
|
||||
((CompoundTag) originalTopLevelTag.getValue().get("Data")).getValue();
|
||||
// This is our map of data. It is an unmodifiable map, for some reason, so we have to make a copy.
|
||||
Map<String, Tag> newData = new LinkedHashMap<String, Tag>(originalData);
|
||||
|
||||
// .get() a couple of values, just to make sure we're dealing with a valid level file, here. Good for debugging, too.
|
||||
@SuppressWarnings("unused")
|
||||
IntTag spawnX = (IntTag) newData.get("SpawnX"); // we never use these... Its only here for potential debugging.
|
||||
@SuppressWarnings("unused")
|
||||
IntTag spawnY = (IntTag) newData.get("SpawnY"); // but whatever... so I (Morlok8k) suppressed these warnings.
|
||||
@SuppressWarnings("unused")
|
||||
IntTag spawnZ = (IntTag) newData.get("SpawnZ"); // I don't want to remove existing code, either by myself (Morlok8k) or Corrodias
|
||||
|
||||
newData.put("SpawnX", new IntTag("SpawnX", xyz.getX())); // pulling the data out of the Coordinates,
|
||||
newData.put("SpawnY", new IntTag("SpawnY", xyz.getY())); // and putting it into our IntTag's
|
||||
newData.put("SpawnZ", new IntTag("SpawnZ", xyz.getZ()));
|
||||
|
||||
// Again, we can't modify the data map in the old Tag, so we have to make a new one.
|
||||
CompoundTag newDataTag = new CompoundTag("Data", newData);
|
||||
Map<String, Tag> newTopLevelMap = new HashMap<String, Tag>(1);
|
||||
newTopLevelMap.put("Data", newDataTag);
|
||||
CompoundTag newTopLevelTag = new CompoundTag("", newTopLevelMap);
|
||||
|
||||
NBTOutputStream output = new NBTOutputStream(new FileOutputStream(level));
|
||||
output.writeTag(newTopLevelTag);
|
||||
output.close();
|
||||
} catch (ClassCastException ex) {
|
||||
throw new IOException("Invalid level format.");
|
||||
} catch (NullPointerException ex) {
|
||||
throw new IOException("Invalid level format.");
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: update this
|
||||
/**
|
||||
* @param level
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @author Corrodias
|
||||
*/
|
||||
protected static Coordinates getSpawn(File level) throws IOException {
|
||||
try {
|
||||
NBTInputStream input = new NBTInputStream(new FileInputStream(level));
|
||||
CompoundTag originalTopLevelTag = (CompoundTag) input.readTag();
|
||||
input.close();
|
||||
|
||||
Map<String, Tag> originalData =
|
||||
((CompoundTag) originalTopLevelTag.getValue().get("Data")).getValue();
|
||||
// This is our map of data. It is an unmodifiable map, for some
|
||||
// reason, so we have to make a copy.
|
||||
Map<String, Tag> newData = new LinkedHashMap<String, Tag>(originalData);
|
||||
// .get() a couple of values, just to make sure we're dealing with a
|
||||
// valid level file, here. Good for debugging, too.
|
||||
IntTag spawnX = (IntTag) newData.get("SpawnX");
|
||||
IntTag spawnY = (IntTag) newData.get("SpawnY");
|
||||
IntTag spawnZ = (IntTag) newData.get("SpawnZ");
|
||||
|
||||
LongTag Seed = (LongTag) newData.get("RandomSeed");
|
||||
Main.randomSeed = Seed.getValue();
|
||||
Main.out("Seed: " + Main.randomSeed); // lets output the seed, cause why not?
|
||||
|
||||
Coordinates ret =
|
||||
new Coordinates(spawnX.getValue(), spawnY.getValue(), spawnZ.getValue());
|
||||
return ret;
|
||||
} catch (ClassCastException ex) {
|
||||
throw new IOException("Invalid level format.");
|
||||
} catch (NullPointerException ex) {
|
||||
throw new IOException("Invalid level format.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
117
src/corrodias/minecraft/landgenerator/MLG_WorldVerify.java
Normal file
117
src/corrodias/minecraft/landgenerator/MLG_WorldVerify.java
Normal file
@ -0,0 +1,117 @@
|
||||
package corrodias.minecraft.landgenerator;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class MLG_WorldVerify {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static void verifyWorld() {
|
||||
//TODO: element comment
|
||||
|
||||
// verify that we ended up with a good server path, either from the file or from an argument.
|
||||
File file = new File(Main.serverPath);
|
||||
if (!file.exists() || !file.isDirectory()) {
|
||||
Main.err("The server directory is invalid: " + Main.serverPath);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// read the name of the current world from the server.properties file
|
||||
BufferedReader props =
|
||||
new BufferedReader(new FileReader(new File(Main.serverPath + Main.fileSeparator
|
||||
+ "server.properties")));
|
||||
String line;
|
||||
while ((line = props.readLine()) != null) {
|
||||
String property = "";
|
||||
String value = "";
|
||||
|
||||
int pos = line.indexOf('=');
|
||||
|
||||
int end = line.lastIndexOf('#'); // comments, ignored lines
|
||||
|
||||
if (end == -1) { // If we have no hash sign, then we read till the end of the line
|
||||
end = line.length();
|
||||
|
||||
}
|
||||
if (end <= (pos + 1)) { // If hash is before the '=', we may have an issue... it should be fine, cause we check for issues next, but lets make sure.
|
||||
end = line.length();
|
||||
pos = -1;
|
||||
}
|
||||
|
||||
if (end == 0) { //hash is first char, meaning entire line is a comment
|
||||
end = line.length();
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
if (pos != -1) {
|
||||
if (line.length() == 0) {
|
||||
property = "";
|
||||
value = "";
|
||||
} else {
|
||||
property = line.substring(0, pos).toLowerCase();
|
||||
value = line.substring(pos + 1);
|
||||
}
|
||||
|
||||
if (property.equals("level-name")) {
|
||||
Main.worldPath = Main.serverPath + Main.fileSeparator + value;
|
||||
Main.worldName = value;
|
||||
}
|
||||
if (Main.useRCON) {
|
||||
if (property.equals("enable-rcon")) {
|
||||
|
||||
if (value.contains("true")) {
|
||||
Main.rcon_Enabled = true;
|
||||
Main.out("RCON is set to be Enabled on the server.");
|
||||
} else {
|
||||
Main.rcon_Enabled = false;
|
||||
Main.useRCON = false;
|
||||
Main.err("RCON is not Enabled on the server.");
|
||||
}
|
||||
} else if (property.equals("rcon.password")) {
|
||||
Main.rcon_Password = value;
|
||||
if (Main.rcon_Password.isEmpty()) {
|
||||
Main.useRCON = false;
|
||||
Main.err("RCON Needs a password!.");
|
||||
}
|
||||
Main.out("RCON Password:" + Main.rcon_Password);
|
||||
} else if (property.equals("rcon.port")) {
|
||||
Main.rcon_Port = value;
|
||||
Main.out("RCON Port:" + Main.rcon_Port);
|
||||
} else if (property.equals("server-ip")) {
|
||||
String IP = value;
|
||||
if (IP.isEmpty()) {
|
||||
IP = "0.0.0.0";
|
||||
}
|
||||
Main.rcon_IPaddress = IP;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch (FileNotFoundException ex) {
|
||||
Main.err("Could not open " + Main.serverPath + Main.fileSeparator + "server.properties");
|
||||
return;
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
||||
return;
|
||||
}
|
||||
|
||||
File level = new File(Main.worldPath + Main.fileSeparator + "level.dat");
|
||||
if (!level.exists() || !level.isFile()) {
|
||||
Main.err("The currently-configured world does not exist. Please launch the server once, first.");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -10,7 +10,7 @@ package morlok8k.minecraft.landgenerator;
|
||||
*/
|
||||
public class Coordinates {
|
||||
//FYI: int's (Integer's) are good enough for Minecraft. They have a range of -2,147,483,648 to 2,147,483,647
|
||||
// Minecraft starts failing around ± 12,550,820 and ends at either ± 30,000,000 or ± 32,000,000 (depending on the version).
|
||||
// Minecraft starts failing around (+/-) 12,550,820 and ends at either (+/-) 30,000,000 or (+/-) 32,000,000 (depending on the version).
|
||||
// See: http://www.minecraftwiki.net/wiki/Far_Lands for more info.
|
||||
|
||||
public int X = 0;
|
||||
@ -89,7 +89,7 @@ public class Coordinates {
|
||||
|
||||
public static Coordinates parseString(String StringOfCoords) {
|
||||
//parse out string
|
||||
StringOfCoords.trim();
|
||||
StringOfCoords = StringOfCoords.trim();
|
||||
|
||||
int x = 0, y = 0, z = 0;
|
||||
|
||||
@ -108,13 +108,13 @@ public class Coordinates {
|
||||
firstComma = StringOfCoords.indexOf(",");
|
||||
secComma = StringOfCoords.lastIndexOf(",");
|
||||
|
||||
System.out.println(start + " " + end + " " + firstComma + " " + secComma);
|
||||
//System.out.println(start + " " + end + " " + firstComma + " " + secComma);
|
||||
|
||||
sX = StringOfCoords.substring(start + 1, firstComma);
|
||||
sY = StringOfCoords.substring(firstComma + 1, secComma);
|
||||
sZ = StringOfCoords.substring(secComma + 1, end);
|
||||
|
||||
System.out.println(sX + " " + sY + " " + sZ);
|
||||
//System.out.println(sX + " " + sY + " " + sZ);
|
||||
|
||||
x = Integer.parseInt(sX);
|
||||
y = Integer.parseInt(sY);
|
||||
|
@ -26,8 +26,4 @@ public class MLG_ArrayList {
|
||||
return list;
|
||||
}
|
||||
|
||||
//TODO: add read arraylist file
|
||||
|
||||
//TODO: add save arraylist file (save this file only after generation is complete)
|
||||
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ public class MLG_DownloadFile {
|
||||
timeTracking[1] = System.currentTimeMillis();
|
||||
//differenceTime = (timeTracking[1] - timeTracking[0]);
|
||||
if (Output) {
|
||||
Main.out("Elapsed Time: " + Main.displayTime(timeTracking[0], timeTracking[1]));
|
||||
Main.out("Elapsed Time: " + MLG_Time.displayTime(timeTracking[0], timeTracking[1]));
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
|
170
src/morlok8k/minecraft/landgenerator/MLG_FileRead.java
Normal file
170
src/morlok8k/minecraft/landgenerator/MLG_FileRead.java
Normal file
@ -0,0 +1,170 @@
|
||||
package morlok8k.minecraft.landgenerator;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import corrodias.minecraft.landgenerator.Main;
|
||||
|
||||
public class MLG_FileRead {
|
||||
|
||||
public static ArrayList<Coordinates> readArrayListCoordLog(String file) {
|
||||
|
||||
ArrayList<Coordinates> Return = new ArrayList<Coordinates>();
|
||||
|
||||
try {
|
||||
BufferedReader in = new BufferedReader(new FileReader(new File(file)));
|
||||
String line = "";
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
int end = line.indexOf('#'); // comments, ignored lines
|
||||
boolean ignoreLine = false;
|
||||
Coordinates c = new Coordinates();
|
||||
|
||||
if (end == -1) { // If we have no hash sign, then we read till the end of the line
|
||||
end = line.length();
|
||||
}
|
||||
|
||||
if (end == 0) { //hash is first char, meaning entire line is a comment
|
||||
ignoreLine = true;
|
||||
}
|
||||
|
||||
if (!(ignoreLine)) {
|
||||
c = Coordinates.parseString(line.substring(0, end));
|
||||
Return.add(c);
|
||||
} /* else {
|
||||
// other future stuff may go here.
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
in.close();
|
||||
|
||||
} catch (FileNotFoundException ex) {
|
||||
Main.out("Could not find " + file + ".");
|
||||
return Return;
|
||||
} catch (IOException ex) {
|
||||
Main.err("Could not read " + file + ".");
|
||||
return Return;
|
||||
}
|
||||
|
||||
return Return;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public static void readConf() {
|
||||
//TODO: element comment
|
||||
//String errorMsg = "";
|
||||
|
||||
try {
|
||||
File config = new File(Main.MinecraftLandGeneratorConf);
|
||||
BufferedReader in = new BufferedReader(new FileReader(config));
|
||||
String line = "";
|
||||
String property = "";
|
||||
String value = "";
|
||||
|
||||
while ((line = in.readLine()) != null) {
|
||||
int pos = line.indexOf('=');
|
||||
|
||||
int end = line.lastIndexOf('#'); // comments, ignored lines
|
||||
|
||||
if (end == -1) { // If we have no hash sign, then we read till the end of the line
|
||||
end = line.length();
|
||||
|
||||
}
|
||||
if (end <= (pos + 1)) { // If hash is before the '=', we may have an issue... it should be fine, cause we check for issues next, but lets make sure.
|
||||
end = line.length();
|
||||
pos = -1;
|
||||
}
|
||||
|
||||
if (end == 0) { //hash is first char, meaning entire line is a comment
|
||||
end = line.length();
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
if (pos != -1) {
|
||||
if (line.length() == 0) {
|
||||
property = "";
|
||||
value = "";
|
||||
} else {
|
||||
property = line.substring(0, pos).toLowerCase();
|
||||
value = line.substring(pos + 1, end);
|
||||
}
|
||||
|
||||
if (property.equals("serverpath")) {
|
||||
Main.serverPath = value;
|
||||
} else if (property.equals("java")) {
|
||||
Main.javaLine = value;
|
||||
} else if (property.equals("done_text")) {
|
||||
Main.doneText = value;
|
||||
} else if (property.equals("preparing_text")) {
|
||||
Main.preparingText = value;
|
||||
} else if (property.equals("preparing_level")) {
|
||||
Main.preparingLevel = value;
|
||||
} else if (property.equals("level-0")) {
|
||||
Main.level_0 = value;
|
||||
} else if (property.equals("level-1")) {
|
||||
Main.level_1 = value;
|
||||
} else if (property.equals("level-2")) {
|
||||
Main.level_2 = value;
|
||||
} else if (property.equals("level-3")) {
|
||||
Main.level_3 = value;
|
||||
} else if (property.equals("level-4")) {
|
||||
Main.level_4 = value;
|
||||
} else if (property.equals("level-5")) {
|
||||
Main.level_5 = value;
|
||||
} else if (property.equals("level-6")) {
|
||||
Main.level_6 = value;
|
||||
} else if (property.equals("level-7")) {
|
||||
Main.level_7 = value;
|
||||
} else if (property.equals("level-8")) {
|
||||
Main.level_8 = value;
|
||||
} else if (property.equals("level-9")) {
|
||||
Main.level_9 = value;
|
||||
} else if (property.equals("waitsave")) {
|
||||
if (value.toLowerCase().equals("true")) {
|
||||
Main.waitSave = true;
|
||||
} else {
|
||||
Main.waitSave = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
|
||||
if (Main.testing) {
|
||||
Main.outD("Test Output: Reading of Config File ");
|
||||
Main.outD(" serverPath: " + Main.serverPath);
|
||||
Main.outD(" javaLine: " + Main.javaLine);
|
||||
Main.outD(" doneText: " + Main.doneText);
|
||||
Main.outD(" preparingText: " + Main.preparingText);
|
||||
Main.outD("preparingLevel: " + Main.preparingLevel);
|
||||
Main.outD(" level_0: " + Main.level_0);
|
||||
Main.outD(" level_1: " + Main.level_1);
|
||||
Main.outD(" level_2: " + Main.level_2);
|
||||
Main.outD(" level_3: " + Main.level_3);
|
||||
Main.outD(" level_4: " + Main.level_4);
|
||||
Main.outD(" level_5: " + Main.level_5);
|
||||
Main.outD(" level_6: " + Main.level_6);
|
||||
Main.outD(" level_7: " + Main.level_7);
|
||||
Main.outD(" level_8: " + Main.level_8);
|
||||
Main.outD(" level_9: " + Main.level_9);
|
||||
Main.outD(" waitSave: " + Main.waitSave);
|
||||
}
|
||||
} catch (FileNotFoundException ex) {
|
||||
Main.out("Could not find "
|
||||
+ Main.MinecraftLandGeneratorConf
|
||||
+ ". It is recommended that you run the application with the -conf option to create it.");
|
||||
return;
|
||||
} catch (IOException ex) {
|
||||
Main.err("Could not read " + Main.MinecraftLandGeneratorConf + ".");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
123
src/morlok8k/minecraft/landgenerator/MLG_FileWrite.java
Normal file
123
src/morlok8k/minecraft/landgenerator/MLG_FileWrite.java
Normal file
@ -0,0 +1,123 @@
|
||||
package morlok8k.minecraft.landgenerator;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import corrodias.minecraft.landgenerator.Main;
|
||||
|
||||
/**
|
||||
* http://www.roseindia.net/java/example/java/io/java-append-to-file.shtml <br>
|
||||
* Append To File - Java Tutorial
|
||||
*/
|
||||
public class MLG_FileWrite {
|
||||
|
||||
public static final String newLine = Main.newLine;
|
||||
|
||||
/**
|
||||
* @param file
|
||||
* @param appendTxt
|
||||
*/
|
||||
public static void AppendTxtFile(String file, String appendTxt) {
|
||||
try {
|
||||
// Create file
|
||||
FileWriter fstream = new FileWriter(file, true);
|
||||
BufferedWriter out = new BufferedWriter(fstream);
|
||||
//String output = "Hello Java" + newLine;
|
||||
out.write(appendTxt);
|
||||
//Close the output stream
|
||||
out.close();
|
||||
} catch (Exception e) {//Catch exception if any
|
||||
System.err.println("Error: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param file
|
||||
* @param txt
|
||||
*/
|
||||
public static void writeTxtFile(String file, String txt) {
|
||||
//TODO: element comment
|
||||
|
||||
/*
|
||||
* NOTE: I don't include a generic readTxtFile method, as that code depends on what I'm reading.
|
||||
* For things like that I make a special method for it, if its used in more than one place.
|
||||
* Like reading the config file.
|
||||
*/
|
||||
|
||||
try {
|
||||
File oFile = new File(file);
|
||||
BufferedWriter outFile = new BufferedWriter(new FileWriter(oFile));
|
||||
outFile.write(txt);
|
||||
outFile.newLine();
|
||||
outFile.close();
|
||||
Main.out(file + " file created.");
|
||||
return;
|
||||
} catch (IOException ex) {
|
||||
Main.err("Could not create " + Main.MinecraftLandGeneratorConf + ".");
|
||||
ex.printStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a Config File.
|
||||
*
|
||||
* @param newConf
|
||||
* true: Uses Default values. false: uses existing values
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static void saveConf(boolean newConf) {
|
||||
|
||||
String jL = null; //javaLine
|
||||
String sP = null; //serverPath
|
||||
|
||||
if (newConf) {
|
||||
jL = Main.defaultJavaLine; // reads the default from a constant, makes it easier!
|
||||
sP = "."; //
|
||||
} else {
|
||||
jL = Main.javaLine; // we read these values from an existing Conf File.
|
||||
sP = Main.serverPath; //
|
||||
}
|
||||
|
||||
String txt = null;
|
||||
//@formatter:off
|
||||
txt = "#" + Main.PROG_NAME + " Configuration File: Version: " + Main.VERSION + Main.newLine
|
||||
+ "#Authors: " + Main.AUTHORS + Main.newLine
|
||||
+ "#Auto-Generated: " + Main.dateFormat.format(Main.date) + Main.newLine
|
||||
+ Main.newLine
|
||||
+ "#Line to run server:" + Main.newLine
|
||||
+ "Java=" + jL // reads the default from a constant, makes it easier!
|
||||
+ Main.newLine
|
||||
+ Main.newLine
|
||||
+ "#Location of server. use \".\" for the same folder as MLG" + Main.newLine
|
||||
+ "ServerPath=" + sP
|
||||
+ Main.newLine
|
||||
+ Main.newLine
|
||||
+ "#Strings read from the server" + Main.newLine
|
||||
+ "Done_Text=[INFO] Done" + Main.newLine
|
||||
+ "Preparing_Text=[INFO] Preparing spawn area:" + Main.newLine
|
||||
+ "Preparing_Level=[INFO] Preparing start region for" + Main.newLine
|
||||
+ "Level-0=The Overworld" + Main.newLine
|
||||
+ "Level-1=The Nether" + Main.newLine
|
||||
+ "Level-2=The End" + Main.newLine
|
||||
+ "Level-3=Level 3 (Future Level)" + Main.newLine
|
||||
+ "Level-4=Level 4 (Future Level)" + Main.newLine
|
||||
+ "Level-5=Level 5 (Future Level)" + Main.newLine
|
||||
+ "Level-6=Level 6 (Future Level)" + Main.newLine
|
||||
+ "Level-7=Level 7 (Future Level)" + Main.newLine
|
||||
+ "Level-8=Level 8 (Future Level)" + Main.newLine
|
||||
+ "Level-9=Level 9 (Future Level)" + Main.newLine
|
||||
+ Main.newLine
|
||||
+ "#Optional: Wait a few seconds after saving." + Main.newLine + "WaitSave=false";
|
||||
//@formatter:on
|
||||
|
||||
writeTxtFile(Main.MinecraftLandGeneratorConf, txt);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -201,7 +201,7 @@ public class MLG_Readme_and_HelpInfo {
|
||||
+ newLine;
|
||||
//@formatter:on
|
||||
|
||||
Main.writeTxtFile(readmeFile, ReadMeText + showHelpSTR);
|
||||
MLG_FileWrite.writeTxtFile(readmeFile, ReadMeText + showHelpSTR);
|
||||
|
||||
}
|
||||
|
||||
@ -304,4 +304,5 @@ public class MLG_Readme_and_HelpInfo {
|
||||
return returnString;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
36
src/morlok8k/minecraft/landgenerator/MLG_SelfAware.java
Normal file
36
src/morlok8k/minecraft/landgenerator/MLG_SelfAware.java
Normal file
@ -0,0 +1,36 @@
|
||||
package morlok8k.minecraft.landgenerator;
|
||||
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.lang.management.RuntimeMXBean;
|
||||
import java.util.List;
|
||||
|
||||
import corrodias.minecraft.landgenerator.Main;
|
||||
|
||||
public class MLG_SelfAware {
|
||||
|
||||
public static String JVMinfo() {
|
||||
|
||||
String Return = "";
|
||||
|
||||
RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
|
||||
List<String> aList = RuntimemxBean.getInputArguments();
|
||||
|
||||
for (int i = 0; i < aList.size(); i++) {
|
||||
Return = Return + (aList.get(i)) + " ";
|
||||
}
|
||||
|
||||
Return = Return.trim();
|
||||
|
||||
Return =
|
||||
"Launch info: JVM: " + Return + " JAR: " + System.getProperty("sun.java.command")
|
||||
+ " ARGS: ";
|
||||
|
||||
for (int i = 0; i < Main.originalArgs.length; i++) {
|
||||
Return = Return + (Main.originalArgs[i]) + " ";
|
||||
}
|
||||
|
||||
Return = Return.trim();
|
||||
return Return;
|
||||
}
|
||||
|
||||
}
|
103
src/morlok8k/minecraft/landgenerator/MLG_Time.java
Normal file
103
src/morlok8k/minecraft/landgenerator/MLG_Time.java
Normal file
@ -0,0 +1,103 @@
|
||||
package morlok8k.minecraft.landgenerator;
|
||||
|
||||
import corrodias.minecraft.landgenerator.Main;
|
||||
|
||||
public class MLG_Time {
|
||||
|
||||
/**
|
||||
* waits ten seconds. outputs 10%, 20%, etc after each second.
|
||||
*
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static void waitTenSec(boolean output) {
|
||||
|
||||
if (Main.dontWait) { return; } //Don't wait!
|
||||
|
||||
if (output) {
|
||||
Main.outP(Main.MLG); //here we wait 10 sec.
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
while (count <= 100) {
|
||||
if (output) {
|
||||
Main.outP(count + "% ");
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
count += 10;
|
||||
}
|
||||
if (output) {
|
||||
Main.outP(Main.newLine);
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time in a readable format between two points of time given in Millis.
|
||||
*
|
||||
* @param startTimeMillis
|
||||
* @param endTimeMillis
|
||||
* @author Morlok8k
|
||||
* @return String of Readable Time
|
||||
*/
|
||||
public static String displayTime(long startTimeMillis, long endTimeMillis) {
|
||||
|
||||
long millis = (endTimeMillis - startTimeMillis);
|
||||
//I just duplicated displayTime to have a start & end times, because it just made things simpler to code.
|
||||
return (MLG_Time.displayTime(millis));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the time in a readable format given a time in Millis.
|
||||
*
|
||||
* @param timeMillis
|
||||
* @author Morlok8k
|
||||
* @return String of Readable Time
|
||||
*/
|
||||
public static String displayTime(long timeMillis) {
|
||||
|
||||
long seconds = timeMillis / 1000;
|
||||
long minutes = seconds / 60;
|
||||
long hours = minutes / 60;
|
||||
long days = hours / 24;
|
||||
long years = days / 365;
|
||||
|
||||
String took =
|
||||
(years > 0 ? String.format("%d " + ((years) == 1 ? "Year, " : "Years, "), years)
|
||||
: "")
|
||||
+ (days > 0 ? String.format("%d "
|
||||
+ ((days % 365) == 1 ? "Day, " : "Days, "), days % 365) : "")
|
||||
+ (hours > 0 ? String.format("%d "
|
||||
+ ((hours % 24) == 1 ? "Hour, " : "Hours, "), hours % 24) : "")
|
||||
+ (minutes > 0 ? String.format("%d "
|
||||
+ ((minutes % 60) == 1 ? "Minute, " : "Minutes, "), minutes % 60)
|
||||
: "")
|
||||
+ String.format("%d " + ((seconds % 60) == 1 ? "Second" : "Seconds"),
|
||||
seconds % 60);
|
||||
|
||||
if (!(Main.verbose)) {
|
||||
int commaFirst = took.indexOf(",");
|
||||
int commaSecond = took.substring((commaFirst + 1), took.length()).indexOf(",");
|
||||
int end = (commaFirst + 1 + commaSecond);
|
||||
|
||||
if (commaSecond == -1) {
|
||||
end = commaFirst;
|
||||
}
|
||||
|
||||
if (commaFirst == -1) {
|
||||
end = took.length();
|
||||
}
|
||||
|
||||
took = took.substring(0, end);
|
||||
}
|
||||
|
||||
took = took.trim();
|
||||
return (took);
|
||||
}
|
||||
|
||||
}
|
@ -16,6 +16,7 @@ import java.util.Iterator;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import corrodias.minecraft.landgenerator.MLG_Misc;
|
||||
import corrodias.minecraft.landgenerator.Main;
|
||||
|
||||
public class MLG_Update {
|
||||
@ -67,7 +68,7 @@ public class MLG_Update {
|
||||
if (Main.MLG_Current_Hash == null) {
|
||||
|
||||
try {
|
||||
Main.MLG_Current_Hash = Main.fileMD5(Main.MLGFileName);
|
||||
Main.MLG_Current_Hash = MLG_MD5.fileMD5(Main.MLGFileName);
|
||||
// out(hash + " " + MLGFileName);
|
||||
} catch (Exception e) {
|
||||
Main.out("Error: MLG_MD5 from file failed");
|
||||
@ -127,7 +128,7 @@ public class MLG_Update {
|
||||
Main.out("\"" + Main.buildIDFile + "\" file not Found. Generating New \""
|
||||
+ Main.buildIDFile + "\" File");
|
||||
|
||||
Main.writeTxtFile(Main.buildIDFile,
|
||||
MLG_FileWrite.writeTxtFile(Main.buildIDFile,
|
||||
Main.MLG_Current_Hash + "=" + String.valueOf(time.getTime()) + "#MLG v"
|
||||
+ Main.VERSION + INFO);
|
||||
|
||||
@ -173,7 +174,7 @@ public class MLG_Update {
|
||||
if (Main.MLG_Current_Hash == null) {
|
||||
|
||||
try {
|
||||
Main.MLG_Current_Hash = Main.fileMD5(Main.MLGFileName);
|
||||
Main.MLG_Current_Hash = MLG_MD5.fileMD5(Main.MLGFileName);
|
||||
// out(hash + " " + MLGFileName);
|
||||
} catch (Exception e) {
|
||||
Main.out("Error: MLG_MD5 from file failed");
|
||||
@ -238,7 +239,8 @@ public class MLG_Update {
|
||||
new Long(line.substring(pos + 1, end));
|
||||
Main.MLG_Last_Modified_Date = new Date(Main.MLG_Last_Modified_Long);
|
||||
|
||||
Long highestModTime = Main.ZipGetModificationTime(Main.MLGFileName);
|
||||
Long highestModTime =
|
||||
MLG_Update.ZipGetModificationTime(Main.MLGFileName);
|
||||
long tCalc = Main.MLG_Last_Modified_Long - highestModTime;
|
||||
|
||||
if (Main.testing) {
|
||||
@ -339,7 +341,7 @@ public class MLG_Update {
|
||||
e1.printStackTrace();
|
||||
|
||||
try {
|
||||
Main.copyFile(new File(Main.MLG_JarFile), new File(Main.MLG_JarFile
|
||||
MLG_Misc.copyFile(new File(Main.MLG_JarFile), new File(Main.MLG_JarFile
|
||||
+ ".old"));
|
||||
File fileDelete = new File(Main.MLG_JarFile);
|
||||
fileDelete.delete();
|
||||
|
Reference in New Issue
Block a user