Delete even more unused stuff
Cancelled features: Self-updating, the GUI, ...
This commit is contained in:
parent
95f8909888
commit
741f5f6188
@ -1,302 +0,0 @@
|
||||
///*
|
||||
// * ####################################################################### # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE # # Version 2, December 2004 # # # # Copyright (C) 2004 Sam Hocevar
|
||||
// * <sam@hocevar.net> # # # # Everyone is permitted to copy and distribute verbatim or modified # # copies of this license document, and changing it is allowed as long # # as the name is changed. # # #
|
||||
// * # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE # # TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION # # # # 0. You just DO WHAT THE FUCK YOU WANT TO. # # #
|
||||
// * #######################################################################
|
||||
// */
|
||||
//
|
||||
////package morlok8k.MinecraftLandGenerator;
|
||||
//
|
||||
//import org.joml.Vector3i;
|
||||
//
|
||||
///**
|
||||
// * Coordinates are in the form of [X,Y,Z] or (X,Z)<br>
|
||||
// * <br>
|
||||
// * x-axis (longitude): the distance east (positive) or west (negative) of the origin point<br>
|
||||
// * z-axis (latitude): the distance south (positive) or north (negative) of the origin point<br>
|
||||
// * y-axis (elevation): how high or low (from 0 to 255 (previously 128), with 64 being sea level) <br>
|
||||
// * The origin point: When both X and Z are both zero. (elevation is irrelevant)<br>
|
||||
// */
|
||||
////public class Coordinates {
|
||||
///*
|
||||
//
|
||||
// */
|
||||
///**
|
||||
// * Parses a Coordinates object from a String. Leading and trailing garbage is ignored (FIXME).
|
||||
// *
|
||||
// * @param StringOfCoords A short- or long-form coordinate string as described at the two toString() methods
|
||||
// * @return
|
||||
// * @author Morlok8k
|
||||
// *//*
|
||||
//
|
||||
//
|
||||
//*/
|
||||
///* public static Vector3i parseString(String StringOfCoords) {
|
||||
// //parse out string
|
||||
// StringOfCoords = StringOfCoords.trim();
|
||||
//
|
||||
// int x = 0, y = 0, z = 0;
|
||||
//
|
||||
// int start, end;
|
||||
// String sX = "", sY = "", sZ = "";
|
||||
// boolean shortMode = false, notCoords = false;
|
||||
//
|
||||
// start = StringOfCoords.indexOf("[");
|
||||
// end = StringOfCoords.indexOf("]");
|
||||
//
|
||||
// if ((start == -1) || (end == -1)) {
|
||||
// start = StringOfCoords.indexOf("(");
|
||||
// end = StringOfCoords.indexOf(")");
|
||||
//
|
||||
// if ((start != -1) && (end != -1)) {
|
||||
// shortMode = true;
|
||||
// } else {
|
||||
// notCoords = true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (notCoords) {
|
||||
// return new Vector3i(0, 0, 0);
|
||||
// }
|
||||
//
|
||||
// String[] coords = StringOfCoords.substring(start, end).split(",");
|
||||
// if (shortMode) {
|
||||
// return new Vector3i(Integer.valueOf(coords[0]), 64, Integer.valueOf(coords[2]));
|
||||
// // sX = StringOfCoords.substring(start + 1, firstComma);
|
||||
// // sY = "64";
|
||||
// // sZ = StringOfCoords.substring(firstComma + 1, end);
|
||||
//
|
||||
// } else {
|
||||
// return new Vector3i(Integer.valueOf(coords[0]), Integer.valueOf(coords[1]), Integer.valueOf(coords[2]));
|
||||
// // StringOfCoords = StringOfCoords.substring(start, end);
|
||||
//
|
||||
// // firstComma = StringOfCoords.indexOf(",");
|
||||
// // secComma = StringOfCoords.lastIndexOf(",");
|
||||
//
|
||||
// // sX = StringOfCoords.substring(start + 1, firstComma);
|
||||
// // sY = StringOfCoords.substring(firstComma + 1, secComma);
|
||||
// // sZ = StringOfCoords.substring(secComma + 1, end);
|
||||
//
|
||||
// }
|
||||
//
|
||||
// //try {
|
||||
// // x = Integer.parseInt(sX);
|
||||
// // y = Integer.parseInt(sY);
|
||||
// // z = Integer.parseInt(sZ);
|
||||
// //} catch (final NumberFormatException e) {
|
||||
// // return new Coordinates(0, 0, 0);
|
||||
// //}
|
||||
//
|
||||
// //return new Coordinates(x, y, z);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// *//*
|
||||
//
|
||||
//*/
|
||||
///* public int X = 0;
|
||||
// /**
|
||||
// *
|
||||
// *//*
|
||||
//
|
||||
// public int Y = 0;
|
||||
// */
|
||||
///**
|
||||
// *
|
||||
// *//*
|
||||
//
|
||||
// public int Z = 0;
|
||||
//
|
||||
// */
|
||||
///**
|
||||
// * Someone created a new blank Coordinate! Lets set it to be [0,0,0].
|
||||
// *//*
|
||||
//
|
||||
// public Coordinates() {
|
||||
// clear();
|
||||
// }
|
||||
//
|
||||
// */
|
||||
///**
|
||||
// * @param x
|
||||
// * @param y
|
||||
// * @param z
|
||||
// *//*
|
||||
//
|
||||
// public Coordinates(final int x, final int y, final int z) {
|
||||
// super();
|
||||
// X = x;
|
||||
// Y = y;
|
||||
// Z = z;
|
||||
// }
|
||||
//
|
||||
// */
|
||||
///**
|
||||
// *
|
||||
// *//*
|
||||
//
|
||||
// public void clear() {
|
||||
// X = 0;
|
||||
// Y = 0;
|
||||
// Z = 0;
|
||||
// }
|
||||
//
|
||||
// */
|
||||
///* (non-Javadoc)
|
||||
// * @see java.lang.Object#equals(java.lang.Object)
|
||||
// *//*
|
||||
//
|
||||
// @SuppressWarnings({"unused", "null"})
|
||||
// @Override
|
||||
// public boolean equals(final Object obj) {
|
||||
// // I am overriding the inherited equals method.
|
||||
// // Because it doesn't know how to deal with my custom data.
|
||||
// // So instead of always failing, it actually works!
|
||||
// // (by default it gets the memory addresses of each object.)
|
||||
//
|
||||
// // An object must equal itself
|
||||
// if (this == obj) {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// // No object equals null
|
||||
// if (obj == null) {
|
||||
// return false;
|
||||
// }
|
||||
// if (this == null) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// // Objects of different types are never equal
|
||||
// if (getClass() != obj.getClass()) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// // Cast to an Coordinates, then compare the data
|
||||
// final Coordinates c = (Coordinates) obj;
|
||||
// if (X != c.X) {
|
||||
// return false;
|
||||
// }
|
||||
// if (Y != c.Y) {
|
||||
// return false;
|
||||
// }
|
||||
// if (Z != c.Z) {
|
||||
// return false;
|
||||
// }
|
||||
// return true; // If none of the above returned something, they must be equal!
|
||||
// }
|
||||
//
|
||||
// */
|
||||
///**
|
||||
// * @return the x
|
||||
// *//*
|
||||
//
|
||||
// public int getX() {
|
||||
// return X;
|
||||
// }
|
||||
//
|
||||
// */
|
||||
///**
|
||||
// * @return the y
|
||||
// *//*
|
||||
//
|
||||
// public int getY() {
|
||||
// return Y;
|
||||
// }
|
||||
//
|
||||
// */
|
||||
///**
|
||||
// * @return the z
|
||||
// *//*
|
||||
//
|
||||
// public int getZ() {
|
||||
// return Z;
|
||||
// }
|
||||
//
|
||||
// */
|
||||
///* (non-Javadoc)
|
||||
// * @see java.lang.Object#hashCode()
|
||||
// *//*
|
||||
//
|
||||
// @Override
|
||||
// public int hashCode() {
|
||||
// // I am overriding the inherited hashCode method.
|
||||
// // Because it doesn't know how to deal with my custom data.
|
||||
// // So instead of getting who knows what, we return valid data
|
||||
//
|
||||
// final int prime = 31; // My hard coded prime number
|
||||
// int result = 1; // The hard coded number I start with
|
||||
// result = (prime * result) + X; // Add the X data
|
||||
// result = (prime * result) + Y; // Add the Y data
|
||||
// result = (prime * result) + Z; // Add the Z data
|
||||
// return result; //this result will consistently give the same result for the same data.
|
||||
// // [0,0,0] will always give 29791. [1,2,3] will always give 30817.
|
||||
// //yes, If I was lazy, I could just do a "return 0;" and it would still be technically valid.
|
||||
// //but if I'm going override the method, I might as well do it right...
|
||||
// }
|
||||
//
|
||||
// */
|
||||
///**
|
||||
// * @param x the x to set
|
||||
// *//*
|
||||
//
|
||||
// public void setX(final int x) {
|
||||
// X = x;
|
||||
// }
|
||||
//
|
||||
// ///////////////////////////////////////////////////////////////////////////////////////
|
||||
// // Java Language Specific Crap Below... Stuff *gotta* be there so Java won't cry... //
|
||||
// ///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// */
|
||||
///**
|
||||
// * @param y the y to set
|
||||
// *//*
|
||||
//
|
||||
// public void setY(final int y) {
|
||||
// Y = y;
|
||||
// }
|
||||
//
|
||||
// */
|
||||
///**
|
||||
// * @param z the z to set
|
||||
// *//*
|
||||
//
|
||||
// public void setZ(final int z) {
|
||||
// Z = z;
|
||||
// }
|
||||
//
|
||||
// */
|
||||
///* (non-Javadoc)
|
||||
// * @see java.lang.Object#toString()
|
||||
// *//*
|
||||
//
|
||||
// @Override
|
||||
// public String toString() {
|
||||
// // I am overriding the inherited toString method.
|
||||
// // Because it doesn't know how to deal with my custom data.
|
||||
// // So instead of getting "blahblahblah.Coordinates@745f"
|
||||
// // (the location of the class and the hexstring of the hashcode)
|
||||
// // I return "[X,Y,Z]"
|
||||
//
|
||||
// return ("[" + X + "," + Y + "," + Z + "]");
|
||||
//
|
||||
// }
|
||||
//
|
||||
// */
|
||||
///**
|
||||
// * @param Short
|
||||
// * @return
|
||||
// *//*
|
||||
//
|
||||
// public String toString(final boolean Short) {
|
||||
// if (Short) { // We are overloading toString with an additional option:
|
||||
// return ("(" + X + "," + Z + ")"); // Basically just an option to return just X and Z (formatted differently as well: "(X,Z)")
|
||||
// }
|
||||
// return toString(); // Idiot catch. default to: "[X,Y,Z]"
|
||||
//
|
||||
// }
|
||||
//
|
||||
//*/
|
||||
////}
|
@ -1,61 +0,0 @@
|
||||
/*
|
||||
#######################################################################
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# Version 2, December 2004 #
|
||||
# #
|
||||
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> #
|
||||
# #
|
||||
# Everyone is permitted to copy and distribute verbatim or modified #
|
||||
# copies of this license document, and changing it is allowed as long #
|
||||
# as the name is changed. #
|
||||
# #
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION #
|
||||
# #
|
||||
# 0. You just DO WHAT THE FUCK YOU WANT TO. #
|
||||
# #
|
||||
#######################################################################
|
||||
*/
|
||||
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
* @author morlok8k
|
||||
*/
|
||||
public class DownloadFile {
|
||||
|
||||
private static Log log = LogFactory.getLog(Main.class);
|
||||
|
||||
/**
|
||||
* Downloads a File using a URL in a String.
|
||||
*
|
||||
* @param url
|
||||
* The URL of the file to download
|
||||
* @param Output
|
||||
* Deprecated, does nothing
|
||||
* @return true if download was successful, false if not
|
||||
* @author piegames
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean downloadFile(final String url, final boolean Output) {
|
||||
try {
|
||||
URL download = new URL(url);
|
||||
File dest = new File(FilenameUtils.getName(download.getPath()));
|
||||
log.info("Downloading " + url + " to " + dest);
|
||||
FileUtils.copyURLToFile(download, dest);
|
||||
} catch (IOException e) {
|
||||
log.warn("Could not download " + url, e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,733 +0,0 @@
|
||||
/*
|
||||
#######################################################################
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# Version 2, December 2004 #
|
||||
# #
|
||||
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> #
|
||||
# #
|
||||
# Everyone is permitted to copy and distribute verbatim or modified #
|
||||
# copies of this license document, and changing it is allowed as long #
|
||||
# as the name is changed. #
|
||||
# #
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION #
|
||||
# #
|
||||
# 0. You just DO WHAT THE FUCK YOU WANT TO. #
|
||||
# #
|
||||
#######################################################################
|
||||
*/
|
||||
|
||||
package morlok8k.MinecraftLandGenerator.GUI;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.text.NumberFormat;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.ButtonGroup;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JFormattedTextField;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JProgressBar;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.plaf.metal.MetalLookAndFeel;
|
||||
import javax.swing.plaf.metal.OceanTheme;
|
||||
|
||||
import morlok8k.MinecraftLandGenerator.Startup;
|
||||
import morlok8k.MinecraftLandGenerator.Update;
|
||||
import morlok8k.MinecraftLandGenerator.var;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author morlok8k
|
||||
*/
|
||||
public class MLG_GUI {
|
||||
|
||||
final Font arial = new Font("Arial", Font.PLAIN, 12);
|
||||
final Font arialBold = new Font("Arial", Font.BOLD, 12);
|
||||
|
||||
public static JFrame frmMLG_GUI;
|
||||
|
||||
static JButton btnStart;
|
||||
static JButton btnStop;
|
||||
|
||||
static JFormattedTextField txtSizeX;
|
||||
static JFormattedTextField txtSizeZ;
|
||||
|
||||
static JFormattedTextField txtCPX;
|
||||
static JFormattedTextField txtCPZ;
|
||||
|
||||
static JProgressBar pgbTotPer;
|
||||
static JProgressBar pgbCurPer;
|
||||
|
||||
static JLabel lblTotPer;
|
||||
static JLabel lblCurPer;
|
||||
|
||||
static JRadioButton rdbtnSizeSquarify;
|
||||
static JRadioButton rdbtnSizeCustomSize;
|
||||
|
||||
static JRadioButton rdbtnAlignRegions;
|
||||
static JRadioButton rdbtnAlignChunks;
|
||||
|
||||
static JRadioButton rdbtnCenterSpawnPoint;
|
||||
static JRadioButton rdbtnCenterOther;
|
||||
|
||||
static JLabel lblTimeRem;
|
||||
static JLabel lblCurLoc;
|
||||
static JLabel lblCurStatus;
|
||||
|
||||
static JLabel lblSizeZ;
|
||||
static JLabel lblSizeX;
|
||||
|
||||
static JLabel lblCPX;
|
||||
static JLabel lblCPZ;
|
||||
static JMenuItem mntmStart;
|
||||
static JMenuItem mntmStop;
|
||||
static JCheckBoxMenuItem chckbxmntmImportCustomList;
|
||||
|
||||
/**
|
||||
* Create the application.
|
||||
*/
|
||||
public MLG_GUI() {
|
||||
|
||||
var.UsingGUI = true;
|
||||
|
||||
// Program-wide UI stuff here...
|
||||
MetalLookAndFeel.setCurrentTheme(new OceanTheme());
|
||||
try {
|
||||
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
UIManager.put("Button.font", arial);
|
||||
UIManager.put("ToggleButton.font", arial);
|
||||
UIManager.put("RadioButton.font", arial);
|
||||
UIManager.put("CheckBox.font", arial);
|
||||
UIManager.put("ColorChooser.font", arial);
|
||||
UIManager.put("ComboBox.font", arial);
|
||||
UIManager.put("Label.font", arial);
|
||||
UIManager.put("List.font", arial);
|
||||
UIManager.put("MenuBar.font", arial);
|
||||
UIManager.put("MenuItem.font", arial);
|
||||
UIManager.put("RadioButtonMenuItem.font", arial);
|
||||
UIManager.put("CheckBoxMenuItem.font", arial);
|
||||
UIManager.put("Menu.font", arial);
|
||||
UIManager.put("PopupMenu.font", arial);
|
||||
UIManager.put("OptionPane.font", arial);
|
||||
UIManager.put("Panel.font", arial);
|
||||
UIManager.put("ProgressBar.font", arial);
|
||||
UIManager.put("ScrollPane.font", arial);
|
||||
UIManager.put("Viewport.font", arial);
|
||||
UIManager.put("TabbedPane.font", arial);
|
||||
UIManager.put("Table.font", arial);
|
||||
UIManager.put("TableHeader.font", arial);
|
||||
UIManager.put("TextField.font", arial);
|
||||
UIManager.put("PasswordField.font", arial);
|
||||
UIManager.put("TextArea.font", arial);
|
||||
UIManager.put("TextPane.font", arial);
|
||||
UIManager.put("EditorPane.font", arial);
|
||||
UIManager.put("TitledBorder.font", arial);
|
||||
UIManager.put("ToolBar.font", arial);
|
||||
UIManager.put("ToolTip.font", arial);
|
||||
UIManager.put("Tree.font", arial);
|
||||
|
||||
// End Look and Feel code
|
||||
|
||||
initialize();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the contents of the frame.
|
||||
*/
|
||||
private void initialize() {
|
||||
|
||||
// Basic Program Initialization
|
||||
Startup.initialStart();
|
||||
boolean quit = false;
|
||||
quit = Startup.confFile();
|
||||
if (quit) { return; }
|
||||
|
||||
//WorldVerify.verifyWorld(); //TODO: need to do this at a later point
|
||||
|
||||
// Frame:
|
||||
frmMLG_GUI = new JFrame();
|
||||
frmMLG_GUI.setTitle("Minecraft Land Generator - Loading...");
|
||||
frmMLG_GUI.setResizable(false);
|
||||
frmMLG_GUI.setBounds(100, 100, 475, 400);
|
||||
frmMLG_GUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frmMLG_GUI.setVisible(true);
|
||||
frmMLG_GUI.getContentPane().setLayout(new BorderLayout(0, 0));
|
||||
|
||||
// Menu Bar:
|
||||
final JMenuBar menuBar = new JMenuBar();
|
||||
frmMLG_GUI.setJMenuBar(menuBar);
|
||||
|
||||
// Top Level Menus:
|
||||
final JMenu mnFile = new JMenu("File");
|
||||
final JMenu mnInfo = new JMenu("Info");
|
||||
final JMenu mnHelp = new JMenu("Help");
|
||||
|
||||
// File Menu Objects:
|
||||
mntmStart = new JMenuItem("Start");
|
||||
mntmStart.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent arg0) {
|
||||
|
||||
Start.start_GUI();
|
||||
}
|
||||
});
|
||||
|
||||
mntmStop = new JMenuItem("Stop");
|
||||
mntmStop.setEnabled(false);
|
||||
mntmStop.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
|
||||
stop_GUI();
|
||||
}
|
||||
});
|
||||
|
||||
final JSeparator hzlFile1 = new JSeparator();
|
||||
|
||||
chckbxmntmImportCustomList = new JCheckBoxMenuItem("Import Custom List");
|
||||
chckbxmntmImportCustomList.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
|
||||
ImportCustomList();
|
||||
|
||||
}
|
||||
});
|
||||
chckbxmntmImportCustomList.setEnabled(false);
|
||||
|
||||
final JSeparator hzlFile2 = new JSeparator();
|
||||
|
||||
final JMenuItem mntmExit = new JMenuItem("Exit");
|
||||
mntmExit.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent arg0) {
|
||||
|
||||
Exit();
|
||||
|
||||
}
|
||||
});
|
||||
mntmExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_MASK));
|
||||
|
||||
// Info Menu Objects:
|
||||
final JMenuItem mntmMapInfo = new JMenuItem("Map Info");
|
||||
mntmMapInfo.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
|
||||
MapInfo();
|
||||
}
|
||||
});
|
||||
|
||||
// Help Menu Objects:
|
||||
final JMenuItem mntmAboutMlg = new JMenuItem("About MLG");
|
||||
mntmAboutMlg.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
|
||||
AboutMLG();
|
||||
}
|
||||
});
|
||||
|
||||
final JSeparator hzlHelp1 = new JSeparator();
|
||||
|
||||
final JMenuItem mntmUpdateMlg = new JMenuItem("Update MLG");
|
||||
mntmUpdateMlg.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
|
||||
UpdateMLG();
|
||||
}
|
||||
});
|
||||
|
||||
// Create Menu Bar:
|
||||
menuBar.add(mnFile);
|
||||
menuBar.add(mnInfo);
|
||||
menuBar.add(mnHelp);
|
||||
|
||||
// File:
|
||||
mnFile.add(mntmStart);
|
||||
mnFile.add(mntmStop);
|
||||
mnFile.add(hzlFile1);
|
||||
mnFile.add(chckbxmntmImportCustomList);
|
||||
mnFile.add(hzlFile2);
|
||||
mnFile.add(mntmExit);
|
||||
|
||||
// Info:
|
||||
mnInfo.add(mntmMapInfo);
|
||||
|
||||
// Help:
|
||||
mnHelp.add(mntmAboutMlg);
|
||||
mnHelp.add(hzlHelp1);
|
||||
mnHelp.add(mntmUpdateMlg);
|
||||
|
||||
// NumberFormats
|
||||
final NumberFormat nfSizeInt = NumberFormat.getIntegerInstance();
|
||||
nfSizeInt.setParseIntegerOnly(true);
|
||||
final NumberFormat nfCPInt = NumberFormat.getIntegerInstance();
|
||||
nfCPInt.setParseIntegerOnly(true);
|
||||
|
||||
// Create Main Panels, Interior Panels, and Objects...
|
||||
// TODO: Refactor this clusterf*ck!
|
||||
final JPanel mainWest = new JPanel(new BorderLayout());
|
||||
final JPanel mainEast = new JPanel(new BorderLayout());
|
||||
final JPanel mainSouth = new JPanel(new BorderLayout());
|
||||
final JPanel mainNorth = new JPanel(new BorderLayout());
|
||||
|
||||
mainSouth.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createTitledBorder("Progress:"),
|
||||
BorderFactory.createEmptyBorder(5, 5, 5, 5)));
|
||||
|
||||
// Create Interior Panels
|
||||
final JPanel pnlStartStop = new JPanel(new BorderLayout());
|
||||
final JPanel pnlStatus = new JPanel();
|
||||
pnlStatus.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createTitledBorder("Status:"),
|
||||
BorderFactory.createEmptyBorder(5, 5, 5, 5)));
|
||||
|
||||
btnStart = new JButton("Start");
|
||||
btnStart.addActionListener(new ActionListener() {
|
||||
|
||||
//@SuppressWarnings("unused")
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new Start().run();
|
||||
}
|
||||
});
|
||||
}
|
||||
}).start(); // start the thread
|
||||
}
|
||||
});
|
||||
btnStop = new JButton("Stop");
|
||||
btnStop.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
|
||||
stop_GUI();
|
||||
|
||||
}
|
||||
});
|
||||
btnStop.setEnabled(false);
|
||||
|
||||
final JLabel lblMinecraftLandGenerator = new JLabel("Minecraft Land Generator");
|
||||
lblMinecraftLandGenerator.setFont(new Font("Arial", Font.BOLD, 14));
|
||||
lblMinecraftLandGenerator.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
|
||||
// Add Objects to interior panels
|
||||
|
||||
mainNorth.add(lblMinecraftLandGenerator, BorderLayout.CENTER);
|
||||
|
||||
pnlStartStop.add(btnStart, BorderLayout.LINE_START);
|
||||
pnlStartStop.add(btnStop, BorderLayout.LINE_END);
|
||||
|
||||
// Add interior panels to Main panels
|
||||
|
||||
mainWest.add(pnlStartStop, BorderLayout.NORTH);
|
||||
|
||||
final Component horizontalStrutStartStop = Box.createHorizontalStrut(25);
|
||||
pnlStartStop.add(horizontalStrutStartStop, BorderLayout.CENTER);
|
||||
mainWest.add(pnlStatus, BorderLayout.CENTER);
|
||||
pnlStatus.setLayout(null);
|
||||
|
||||
final JLabel lblCurrentStatus = new JLabel("Current Status:");
|
||||
lblCurrentStatus.setBounds(12, 12, 118, 15);
|
||||
pnlStatus.add(lblCurrentStatus);
|
||||
lblCurrentStatus.setFont(arialBold);
|
||||
|
||||
lblCurStatus = new JLabel("Idle");
|
||||
lblCurStatus.setBounds(12, 24, 118, 15);
|
||||
pnlStatus.add(lblCurStatus);
|
||||
lblCurStatus.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
|
||||
final JLabel lblCurrentLocation = new JLabel("Current Location:");
|
||||
lblCurrentLocation.setBounds(12, 48, 118, 15);
|
||||
pnlStatus.add(lblCurrentLocation);
|
||||
lblCurrentLocation.setFont(arialBold);
|
||||
|
||||
lblCurLoc = new JLabel("[0,0,0]");
|
||||
lblCurLoc.setBounds(12, 60, 118, 15);
|
||||
pnlStatus.add(lblCurLoc);
|
||||
lblCurLoc.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
|
||||
final JLabel lblTimeRemaining = new JLabel("Time Remaining:");
|
||||
lblTimeRemaining.setBounds(12, 84, 118, 15);
|
||||
pnlStatus.add(lblTimeRemaining);
|
||||
lblTimeRemaining.setFont(arialBold);
|
||||
|
||||
lblTimeRem = new JLabel("0 Seconds");
|
||||
lblTimeRem.setBounds(12, 96, 118, 15);
|
||||
pnlStatus.add(lblTimeRem);
|
||||
lblTimeRem.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||
|
||||
// add Main panels to Top-Level Panel
|
||||
|
||||
frmMLG_GUI.getContentPane().add(mainNorth, BorderLayout.NORTH);
|
||||
frmMLG_GUI.getContentPane().add(mainWest, BorderLayout.WEST);
|
||||
frmMLG_GUI.getContentPane().add(mainEast, BorderLayout.EAST);
|
||||
|
||||
final JPanel pnlOptions = new JPanel();
|
||||
mainEast.add(pnlOptions, BorderLayout.CENTER);
|
||||
pnlOptions.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createTitledBorder("Options:"),
|
||||
BorderFactory.createEmptyBorder(5, 5, 5, 5)));
|
||||
pnlOptions.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
final JPanel pnlSize = new JPanel();
|
||||
pnlSize.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createTitledBorder("Size:"),
|
||||
BorderFactory.createEmptyBorder(5, 5, 5, 5)));
|
||||
pnlOptions.add(pnlSize, BorderLayout.NORTH);
|
||||
pnlSize.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
final JPanel pnlSizeX = new JPanel();
|
||||
pnlSize.add(pnlSizeX, BorderLayout.WEST);
|
||||
pnlSizeX.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
lblSizeX = new JLabel("X: ");
|
||||
pnlSizeX.add(lblSizeX, BorderLayout.WEST);
|
||||
|
||||
txtSizeX = new JFormattedTextField(nfSizeInt);
|
||||
txtSizeX.setFont(arial);
|
||||
txtSizeX.setText("1000");
|
||||
pnlSizeX.add(txtSizeX, BorderLayout.EAST);
|
||||
txtSizeX.setColumns(7);
|
||||
|
||||
final JPanel pnlSizeZ = new JPanel();
|
||||
pnlSize.add(pnlSizeZ, BorderLayout.EAST);
|
||||
pnlSizeZ.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
lblSizeZ = new JLabel(" Z: ");
|
||||
pnlSizeZ.add(lblSizeZ, BorderLayout.WEST);
|
||||
|
||||
txtSizeZ = new JFormattedTextField(nfSizeInt);
|
||||
txtSizeZ.setFont(arial);
|
||||
txtSizeZ.setText("1000");
|
||||
txtSizeZ.setColumns(7);
|
||||
pnlSizeZ.add(txtSizeZ, BorderLayout.EAST);
|
||||
|
||||
final JPanel pnlSizeXZ = new JPanel();
|
||||
pnlSize.add(pnlSizeXZ, BorderLayout.NORTH);
|
||||
pnlSizeXZ.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
rdbtnSizeCustomSize = new JRadioButton("Custom Size:");
|
||||
rdbtnSizeCustomSize.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
|
||||
SizeSetEnable(true);
|
||||
}
|
||||
});
|
||||
|
||||
rdbtnSizeCustomSize.setSelected(true);
|
||||
pnlSizeXZ.add(rdbtnSizeCustomSize, BorderLayout.CENTER);
|
||||
|
||||
final JPanel pnlSizeSquarify = new JPanel();
|
||||
pnlSize.add(pnlSizeSquarify, BorderLayout.SOUTH);
|
||||
pnlSizeSquarify.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
rdbtnSizeSquarify = new JRadioButton("Squarify Existing Land");
|
||||
rdbtnSizeSquarify.setToolTipText("Not Functional Yet...");
|
||||
rdbtnSizeSquarify.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
|
||||
SizeSetEnable(false);
|
||||
CenterPointSetEnable(false);
|
||||
|
||||
}
|
||||
});
|
||||
pnlSizeSquarify.add(rdbtnSizeSquarify, BorderLayout.CENTER);
|
||||
|
||||
final JPanel pnlCenterPoint = new JPanel();
|
||||
pnlCenterPoint.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createTitledBorder("Center Point:"),
|
||||
BorderFactory.createEmptyBorder(5, 5, 5, 5)));
|
||||
pnlOptions.add(pnlCenterPoint, BorderLayout.CENTER);
|
||||
pnlCenterPoint.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
final JPanel pnlCPrb = new JPanel();
|
||||
pnlCenterPoint.add(pnlCPrb, BorderLayout.NORTH);
|
||||
pnlCPrb.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
rdbtnCenterSpawnPoint = new JRadioButton("Spawn Point");
|
||||
rdbtnCenterSpawnPoint.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
|
||||
CenterPointSetEnable(false);
|
||||
|
||||
}
|
||||
});
|
||||
rdbtnCenterSpawnPoint.setSelected(true);
|
||||
pnlCPrb.add(rdbtnCenterSpawnPoint, BorderLayout.WEST);
|
||||
|
||||
rdbtnCenterOther = new JRadioButton("Other:");
|
||||
rdbtnCenterOther.addActionListener(new ActionListener() {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
|
||||
CenterPointSetEnable(true);
|
||||
|
||||
}
|
||||
});
|
||||
pnlCPrb.add(rdbtnCenterOther, BorderLayout.EAST);
|
||||
|
||||
final ButtonGroup bgCenterPoint = new ButtonGroup();
|
||||
bgCenterPoint.add(rdbtnCenterSpawnPoint);
|
||||
bgCenterPoint.add(rdbtnCenterOther);
|
||||
|
||||
final JPanel pnlCPSelection = new JPanel();
|
||||
pnlCenterPoint.add(pnlCPSelection, BorderLayout.SOUTH);
|
||||
pnlCPSelection.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
final JPanel pnlCPx = new JPanel();
|
||||
pnlCPSelection.add(pnlCPx, BorderLayout.WEST);
|
||||
pnlCPx.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
lblCPX = new JLabel("X: ");
|
||||
lblCPX.setEnabled(false);
|
||||
pnlCPx.add(lblCPX, BorderLayout.WEST);
|
||||
|
||||
txtCPX = new JFormattedTextField(nfCPInt);
|
||||
txtCPX.setFont(arial);
|
||||
txtCPX.setEnabled(false);
|
||||
txtCPX.setText("0");
|
||||
pnlCPx.add(txtCPX, BorderLayout.EAST);
|
||||
txtCPX.setColumns(7);
|
||||
|
||||
final JPanel pnlCPz = new JPanel();
|
||||
pnlCPSelection.add(pnlCPz, BorderLayout.EAST);
|
||||
pnlCPz.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
lblCPZ = new JLabel("Z: ");
|
||||
lblCPZ.setEnabled(false);
|
||||
pnlCPz.add(lblCPZ, BorderLayout.WEST);
|
||||
|
||||
txtCPZ = new JFormattedTextField(nfCPInt);
|
||||
txtCPZ.setEnabled(false);
|
||||
txtCPZ.setFont(arial);
|
||||
txtCPZ.setText("0");
|
||||
pnlCPz.add(txtCPZ, BorderLayout.EAST);
|
||||
txtCPZ.setColumns(7);
|
||||
|
||||
final JPanel pnlAlignment = new JPanel();
|
||||
pnlAlignment.setBorder(BorderFactory.createCompoundBorder(
|
||||
BorderFactory.createTitledBorder("Alignment:"),
|
||||
BorderFactory.createEmptyBorder(5, 5, 5, 5)));
|
||||
pnlOptions.add(pnlAlignment, BorderLayout.SOUTH);
|
||||
pnlAlignment.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
rdbtnAlignChunks = new JRadioButton("Chunks");
|
||||
rdbtnAlignChunks.setSelected(true);
|
||||
pnlAlignment.add(rdbtnAlignChunks, BorderLayout.WEST);
|
||||
|
||||
rdbtnAlignRegions = new JRadioButton("Regions");
|
||||
pnlAlignment.add(rdbtnAlignRegions, BorderLayout.EAST);
|
||||
|
||||
final ButtonGroup bgAlignment = new ButtonGroup();
|
||||
|
||||
bgAlignment.add(rdbtnAlignChunks);
|
||||
bgAlignment.add(rdbtnAlignRegions);
|
||||
|
||||
final ButtonGroup bgSize = new ButtonGroup();
|
||||
bgSize.add(rdbtnSizeCustomSize);
|
||||
bgSize.add(rdbtnSizeSquarify);
|
||||
|
||||
frmMLG_GUI.getContentPane().add(mainSouth, BorderLayout.SOUTH);
|
||||
|
||||
final JPanel pnlCurPrg = new JPanel();
|
||||
mainSouth.add(pnlCurPrg, BorderLayout.NORTH);
|
||||
pnlCurPrg.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
final JLabel lblCurrentProgress = new JLabel("Current Progress: ");
|
||||
pnlCurPrg.add(lblCurrentProgress, BorderLayout.WEST);
|
||||
|
||||
lblCurPer = new JLabel("100%");
|
||||
pnlCurPrg.add(lblCurPer, BorderLayout.EAST);
|
||||
|
||||
pgbCurPer = new JProgressBar();
|
||||
pnlCurPrg.add(pgbCurPer, BorderLayout.CENTER);
|
||||
|
||||
final JPanel pnlTotPrg = new JPanel();
|
||||
mainSouth.add(pnlTotPrg, BorderLayout.SOUTH);
|
||||
pnlTotPrg.setLayout(new BorderLayout(0, 0));
|
||||
|
||||
final JLabel lblTotalProgress = new JLabel("Total Progress: ");
|
||||
pnlTotPrg.add(lblTotalProgress, BorderLayout.WEST);
|
||||
|
||||
lblTotPer = new JLabel("100%");
|
||||
pnlTotPrg.add(lblTotPer, BorderLayout.EAST);
|
||||
|
||||
pgbTotPer = new JProgressBar();
|
||||
pnlTotPrg.add(pgbTotPer, BorderLayout.CENTER);
|
||||
|
||||
// Frame size and location
|
||||
|
||||
frmMLG_GUI.validate();
|
||||
frmMLG_GUI.pack();
|
||||
frmMLG_GUI.setLocationRelativeTo(null);
|
||||
frmMLG_GUI.setTitle("Minecraft Land Generator");
|
||||
// Finished creation of frame
|
||||
}
|
||||
|
||||
static void MapInfo() {
|
||||
|
||||
// TODO: Display Map Info
|
||||
JOptionPane.showMessageDialog(frmMLG_GUI, "Seed:" + var.newLine + "SpawnPoint:");
|
||||
|
||||
}
|
||||
|
||||
static void AboutMLG() {
|
||||
|
||||
final String n = var.newLine;
|
||||
final String N = n + n;
|
||||
final String message =
|
||||
"This program uses the Minecraft Server to expand your Minecraft world." + N
|
||||
+ var.WEBSITE + N + "Authors: " + var.AUTHORS + n
|
||||
+ "Special Thanks to: Graham Edgecombe (aka ancient) for JNBT" + N
|
||||
+ "BuildID: (" + var.MLG_Last_Modified_Date.getTime() + ")" + n
|
||||
+ "This version was last modified on "
|
||||
+ var.dateFormat.format(var.MLG_Last_Modified_Date);
|
||||
final String title = var.PROG_NAME + " v" + var.VERSION;
|
||||
|
||||
//JOptionPane.showMessageDialog(frmMLG_GUI, message, title, JOptionPane.INFORMATION_MESSAGE);
|
||||
System.out.println(message + title+ JOptionPane.INFORMATION_MESSAGE);
|
||||
|
||||
}
|
||||
|
||||
static void UpdateMLG() {
|
||||
|
||||
final boolean update = Update.updateMLG();
|
||||
|
||||
if (update) {
|
||||
//TODO: add a popup saying we got a new version
|
||||
Exit();
|
||||
} else {
|
||||
//TODO: popup: no new version / error
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ImportCustomList() {
|
||||
|
||||
// TODO: add Import Custom List
|
||||
|
||||
// TODO: disable/enable size objects
|
||||
|
||||
}
|
||||
|
||||
static void Exit() {
|
||||
|
||||
// TODO: Make sure everything has finished...
|
||||
|
||||
// Lets Exit!
|
||||
System.exit(0);
|
||||
|
||||
}
|
||||
|
||||
static void SizeSetEnable(final boolean enabled) {
|
||||
|
||||
txtSizeX.setEnabled(enabled);
|
||||
txtSizeZ.setEnabled(enabled);
|
||||
lblSizeX.setEnabled(enabled);
|
||||
lblSizeZ.setEnabled(enabled);
|
||||
|
||||
}
|
||||
|
||||
static void CenterPointSetEnable(final boolean enabled) {
|
||||
|
||||
txtCPX.setEnabled(enabled);
|
||||
txtCPZ.setEnabled(enabled);
|
||||
lblCPX.setEnabled(enabled);
|
||||
lblCPZ.setEnabled(enabled);
|
||||
|
||||
}
|
||||
|
||||
static void stop_GUI() {
|
||||
|
||||
btnStop.setEnabled(false);
|
||||
|
||||
var.stoppingServerGUI = true;
|
||||
|
||||
|
||||
while (var.runningServerGUI) {
|
||||
//;
|
||||
}
|
||||
|
||||
// TODO: add additional stop code
|
||||
|
||||
if (rdbtnSizeCustomSize.isSelected()) {
|
||||
SizeSetEnable(true);
|
||||
} else {
|
||||
SizeSetEnable(false);
|
||||
}
|
||||
|
||||
if (rdbtnCenterSpawnPoint.isSelected()) {
|
||||
CenterPointSetEnable(false);
|
||||
} else {
|
||||
CenterPointSetEnable(true);
|
||||
}
|
||||
|
||||
//rdbtnSizeSquarify.setEnabled(true);
|
||||
rdbtnSizeCustomSize.setEnabled(true);
|
||||
|
||||
rdbtnAlignRegions.setEnabled(true);
|
||||
rdbtnAlignChunks.setEnabled(true);
|
||||
|
||||
rdbtnCenterSpawnPoint.setEnabled(true);
|
||||
rdbtnCenterOther.setEnabled(true);
|
||||
|
||||
mntmStop.setEnabled(false);
|
||||
mntmStart.setEnabled(true);
|
||||
|
||||
btnStart.setEnabled(true);
|
||||
btnStop.setEnabled(false);
|
||||
|
||||
pgbCurPer.setIndeterminate(false);
|
||||
pgbTotPer.setIndeterminate(false);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
/*
|
||||
#######################################################################
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# Version 2, December 2004 #
|
||||
# #
|
||||
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> #
|
||||
# #
|
||||
# Everyone is permitted to copy and distribute verbatim or modified #
|
||||
# copies of this license document, and changing it is allowed as long #
|
||||
# as the name is changed. #
|
||||
# #
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION #
|
||||
# #
|
||||
# 0. You just DO WHAT THE FUCK YOU WANT TO. #
|
||||
# #
|
||||
#######################################################################
|
||||
*/
|
||||
|
||||
package morlok8k.MinecraftLandGenerator.GUI;
|
||||
|
||||
import morlok8k.MinecraftLandGenerator.var;
|
||||
|
||||
public class Start implements Runnable {
|
||||
|
||||
static void start_GUI() {
|
||||
|
||||
// TODO: add additional start code
|
||||
|
||||
var.runningServerGUI = true;
|
||||
|
||||
MLG_GUI.btnStop.setEnabled(true);
|
||||
MLG_GUI.btnStart.setEnabled(false);
|
||||
|
||||
MLG_GUI.mntmStop.setEnabled(true);
|
||||
MLG_GUI.mntmStart.setEnabled(false);
|
||||
|
||||
MLG_GUI.SizeSetEnable(false);
|
||||
MLG_GUI.CenterPointSetEnable(false);
|
||||
|
||||
MLG_GUI.rdbtnSizeSquarify.setEnabled(false);
|
||||
MLG_GUI.rdbtnSizeCustomSize.setEnabled(false);
|
||||
|
||||
MLG_GUI.rdbtnAlignRegions.setEnabled(false);
|
||||
MLG_GUI.rdbtnAlignChunks.setEnabled(false);
|
||||
|
||||
MLG_GUI.rdbtnCenterSpawnPoint.setEnabled(false);
|
||||
MLG_GUI.rdbtnCenterOther.setEnabled(false);
|
||||
|
||||
MLG_GUI.pgbCurPer.setIndeterminate(true);
|
||||
MLG_GUI.pgbTotPer.setIndeterminate(true);
|
||||
|
||||
//TODO: add values from textboxes and radio buttons to the actual vars.
|
||||
|
||||
if (MLG_GUI.rdbtnAlignRegions.isSelected()) {
|
||||
var.useChunks = false;
|
||||
} else {
|
||||
var.useChunks = true;
|
||||
}
|
||||
|
||||
if (MLG_GUI.rdbtnSizeCustomSize.isSelected()) {
|
||||
var.xRange = Integer.parseInt(MLG_GUI.txtSizeX.getText().trim());
|
||||
var.zRange = Integer.parseInt(MLG_GUI.txtSizeZ.getText().trim());
|
||||
} else {
|
||||
var.xRange = 1000; // Umm... This code shouldn't run at this point in time...
|
||||
var.zRange = 1000;
|
||||
|
||||
//TODO: add squarifying code here.
|
||||
|
||||
}
|
||||
|
||||
if (MLG_GUI.rdbtnCenterOther.isSelected()) {
|
||||
|
||||
var.xOffset = Integer.parseInt(MLG_GUI.txtCPX.getText().trim());
|
||||
var.zOffset = Integer.parseInt(MLG_GUI.txtCPZ.getText().trim());
|
||||
|
||||
} else {
|
||||
|
||||
var.xOffset = 0;
|
||||
var.zOffset = 0;
|
||||
// TODO: get spawnpoint
|
||||
|
||||
MLG_GUI.txtCPX.setText(var.xOffset.toString());
|
||||
MLG_GUI.txtCPZ.setText(var.zOffset.toString());
|
||||
|
||||
}
|
||||
|
||||
while (var.stoppingServerGUI == false) {
|
||||
// this is where we run the server loops!
|
||||
MLG_GUI.frmMLG_GUI.repaint();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// TODO Auto-generated method stub
|
||||
start_GUI();
|
||||
}
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
#######################################################################
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# Version 2, December 2004 #
|
||||
# #
|
||||
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> #
|
||||
# #
|
||||
# Everyone is permitted to copy and distribute verbatim or modified #
|
||||
# copies of this license document, and changing it is allowed as long #
|
||||
# as the name is changed. #
|
||||
# #
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION #
|
||||
# #
|
||||
# 0. You just DO WHAT THE FUCK YOU WANT TO. #
|
||||
# #
|
||||
#######################################################################
|
||||
*/
|
||||
|
||||
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
|
||||
*
|
||||
* @param msg
|
||||
* String
|
||||
* @return int
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static int getInt(final String msg) {
|
||||
|
||||
|
||||
int Return = 0;
|
||||
|
||||
while (!(var.sc.hasNextInt())) {
|
||||
var.sc.nextLine();
|
||||
log.error(var.MLG + "Invalid Input. " + msg);
|
||||
}
|
||||
|
||||
Return = var.sc.nextInt();
|
||||
|
||||
if (Return < 1000) {
|
||||
log.info("Input must be 1000 or larger.");
|
||||
log.info(var.MLG + msg);
|
||||
Return = getInt(msg);
|
||||
}
|
||||
|
||||
return Return;
|
||||
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
#######################################################################
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# Version 2, December 2004 #
|
||||
# #
|
||||
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> #
|
||||
# #
|
||||
# Everyone is permitted to copy and distribute verbatim or modified #
|
||||
# copies of this license document, and changing it is allowed as long #
|
||||
# as the name is changed. #
|
||||
# #
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION #
|
||||
# #
|
||||
# 0. You just DO WHAT THE FUCK YOU WANT TO. #
|
||||
# #
|
||||
#######################################################################
|
||||
*/
|
||||
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author morlok8k
|
||||
*/
|
||||
public class MD5 {
|
||||
|
||||
/**
|
||||
* This gets the MD5 of a file <br>
|
||||
* <br>
|
||||
* Thanks to R.J. Lorimer at <br>
|
||||
* <a href="http://www.javalobby.org/java/forums/t84420.html">http://www. javalobby.org/java/forums/t84420.html</a>
|
||||
*
|
||||
* @param fileName
|
||||
* @return
|
||||
* @throws NoSuchAlgorithmException
|
||||
* @throws FileNotFoundException
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static String fileMD5(final String fileName) throws NoSuchAlgorithmException,
|
||||
FileNotFoundException {
|
||||
// out("");
|
||||
// out("");
|
||||
final MessageDigest digest = MessageDigest.getInstance("MD5");
|
||||
final InputStream is = new FileInputStream(fileName);
|
||||
final byte[] buffer = new byte[8192];
|
||||
int read = 0;
|
||||
try {
|
||||
while ((read = is.read(buffer)) > 0) {
|
||||
digest.update(buffer, 0, read);
|
||||
}
|
||||
final byte[] md5sum = digest.digest();
|
||||
final BigInteger bigInt = new BigInteger(1, md5sum);
|
||||
final String output = String.format("%1$032X", bigInt); //pad on left to 32 chars with 0's, also capitalize.
|
||||
// out("MD5: " + output);
|
||||
return output.toUpperCase(Locale.ENGLISH);
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException("Unable to process file for MD5", e);
|
||||
} finally {
|
||||
try {
|
||||
is.close();
|
||||
} catch (final IOException e) {
|
||||
throw new RuntimeException("Unable to close input stream for MD5 calculation", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
#######################################################################
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# Version 2, December 2004 #
|
||||
# #
|
||||
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> #
|
||||
# #
|
||||
# Everyone is permitted to copy and distribute verbatim or modified #
|
||||
# copies of this license document, and changing it is allowed as long #
|
||||
# as the name is changed. #
|
||||
# #
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION #
|
||||
# #
|
||||
# 0. You just DO WHAT THE FUCK YOU WANT TO. #
|
||||
# #
|
||||
#######################################################################
|
||||
*/
|
||||
|
||||
package morlok8k.MinecraftLandGenerator;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.joml.Vector3i;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author morlok8k
|
||||
*/
|
||||
public class Misc {
|
||||
private static Log log = LogFactory.getLog(Main.class);
|
||||
|
||||
// TODO replace with Java Copy Path
|
||||
@Deprecated
|
||||
public static void copyFile(final File src, final File dst) throws IOException {
|
||||
FileUtils.copyFile(src, dst);
|
||||
}
|
||||
|
||||
//TODO: add description
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
static boolean printSpawn() {
|
||||
// ugh, sorry, this is an ugly hack
|
||||
|
||||
FileRead.readConf();
|
||||
try {
|
||||
Setup.doSetup();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
final File level = new File(var.worldPath + var.fileSeparator + "level.dat");
|
||||
try {
|
||||
final Vector3i spawn = SpawnPoint.getSpawn(level);
|
||||
log.info("The current spawn point is: [X,Y,Z] " + spawn);
|
||||
return true;
|
||||
} catch (final IOException ex) {
|
||||
log.error("Error while reading " + level.getPath());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,529 +0,0 @@
|
||||
/*
|
||||
#######################################################################
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# Version 2, December 2004 #
|
||||
# #
|
||||
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> #
|
||||
# #
|
||||
# Everyone is permitted to copy and distribute verbatim or modified #
|
||||
# copies of this license document, and changing it is allowed as long #
|
||||
# as the name is changed. #
|
||||
# #
|
||||
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE #
|
||||
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION #
|
||||
# #
|
||||
# 0. You just DO WHAT THE FUCK YOU WANT TO. #
|
||||
# #
|
||||
#######################################################################
|
||||
*/
|
||||
|
||||
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;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
/**
|
||||
* @author morlok8k
|
||||
*/
|
||||
public class Update {
|
||||
|
||||
/**
|
||||
* This is an "undocumented" function to create a BuildID file. It should only be used right after compiling a .jar file<br>
|
||||
* The resulting BuildID file is uploaded to github, and also distributed with the program.<br>
|
||||
* <b>THE FILE SHOULD ONLY BE MADE FROM SCRATCH AT THE TIME OF PUBLISHING!</b><br>
|
||||
* (Otherwise, the purpose is defeated!)<br>
|
||||
* <br>
|
||||
* The problem is that when a .jar file is downloaded from the internet, it gets a new date stamp - the time that it was downloaded. Only the original copy that was compiled on the original
|
||||
* computer will have the correct time stamp. (or possibly a copy from the original computer)<br>
|
||||
* <br>
|
||||
* 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) {
|
||||
log.info(var.buildIDFile + " file downloaded.");
|
||||
var.flag_downloadedBuildID = true;
|
||||
|
||||
if (downloadOnly) {
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (downloadOnly) {
|
||||
log.error("Couldn't Download new " + var.buildIDFile);
|
||||
return;
|
||||
}
|
||||
|
||||
// If not available, create.
|
||||
// After downloading, check to see if it matches hash.
|
||||
|
||||
if (var.MLGFileName == null) {
|
||||
try {
|
||||
var.MLGFileName = getClassLoader(var.cls);
|
||||
} catch (final Exception e) {
|
||||
log.info("Error: Finding file failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (var.MLGFileName.equals(var.rsrcError)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (var.MLG_Current_Hash == null) {
|
||||
|
||||
try {
|
||||
var.MLG_Current_Hash = MD5.fileMD5(var.MLGFileName);
|
||||
// out(hash + " " + MLGFileName);
|
||||
} catch (final Exception e) {
|
||||
log.info("Error: MD5 from file failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Date time = new Date(new Long(0));
|
||||
|
||||
try {
|
||||
time = getCompileTimeStamp(var.cls);
|
||||
} catch (final Exception e) {
|
||||
log.info("Error: TimeStamp from file failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
// out(d.toString());
|
||||
|
||||
boolean notNew = false;
|
||||
String INFO = "";
|
||||
if (var.isCompiledAsJar == false) {
|
||||
INFO = " (Class File, Not .Jar)";
|
||||
}
|
||||
|
||||
try {
|
||||
String line;
|
||||
|
||||
final BufferedReader inFile = new BufferedReader(new FileReader(var.buildIDFile));
|
||||
final BufferedWriter outFile =
|
||||
new BufferedWriter(new FileWriter(var.buildIDFile + ".temp"));
|
||||
|
||||
while ((line = inFile.readLine()) != null) {
|
||||
|
||||
if (line.contains(var.MLG_Current_Hash)) {
|
||||
notNew = true;
|
||||
if (var.testing) {
|
||||
log.info("NotNew");
|
||||
}
|
||||
}
|
||||
|
||||
outFile.write(line);
|
||||
outFile.newLine();
|
||||
}
|
||||
|
||||
if (notNew == false) {
|
||||
outFile.write(var.MLG_Current_Hash + "=" + String.valueOf(time.getTime())
|
||||
+ "# MLG v" + var.VERSION + INFO);
|
||||
outFile.newLine();
|
||||
}
|
||||
outFile.close();
|
||||
inFile.close();
|
||||
|
||||
final File fileDelete = new File(var.buildIDFile);
|
||||
fileDelete.delete();
|
||||
final File fileRename = new File(var.buildIDFile + ".temp");
|
||||
fileRename.renameTo(new File(var.buildIDFile));
|
||||
|
||||
} catch (final FileNotFoundException ex) {
|
||||
log.info("\"" + var.buildIDFile + "\" file not Found. Generating New \""
|
||||
+ var.buildIDFile + "\" File");
|
||||
|
||||
FileWrite.writeTxtFile(var.buildIDFile,
|
||||
var.MLG_Current_Hash + "=" + String.valueOf(time.getTime()) + "#MLG v"
|
||||
+ var.VERSION + INFO);
|
||||
|
||||
} catch (final IOException ex) {
|
||||
log.error("Could not create \"" + var.buildIDFile + "\".");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets the filename of a .jar (typically this one!)
|
||||
*
|
||||
* @param classFile
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static String getClassLoader(final Class<?> classFile) throws IOException {
|
||||
final ClassLoader loader = classFile.getClassLoader();
|
||||
String filename = classFile.getName().replace('.', '/') + ".class";
|
||||
final URL resource =
|
||||
(loader != null) ? loader.getResource(filename) : ClassLoader
|
||||
.getSystemResource(filename);
|
||||
filename = URLDecoder.decode(resource.toString(), "UTF-8");
|
||||
// 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 file = filename.indexOf("file:"); // removes junk from the beginning of the path
|
||||
file = file + 5;
|
||||
if (file == -1) {
|
||||
file = 0;
|
||||
}
|
||||
if (filename.contains("rsrc:")) {
|
||||
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")) {
|
||||
var.isCompiledAsJar = true;
|
||||
}
|
||||
filename = filename.replace('/', File.separatorChar);
|
||||
final String returnString = filename.substring(file, bang);
|
||||
// END Garbage removal
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets the TimeStamp (last modified date) of a class file (typically this one!) <br>
|
||||
* <br>
|
||||
* Thanks to Roedy Green at <br>
|
||||
* <a href="http://mindprod.com/jgloss/compiletimestamp.html">http://mindprod .com/jgloss/compiletimestamp.html</a>
|
||||
*
|
||||
* @param classFile
|
||||
* @return
|
||||
* @throws IOException
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static Date getCompileTimeStamp(final Class<?> classFile) throws IOException {
|
||||
final ClassLoader loader = classFile.getClassLoader();
|
||||
final String filename = classFile.getName().replace('.', '/') + ".class";
|
||||
// get the corresponding class file as a Resource.
|
||||
final URL resource =
|
||||
(loader != null) ? loader.getResource(filename) : ClassLoader
|
||||
.getSystemResource(filename);
|
||||
final URLConnection connection = resource.openConnection();
|
||||
// Note, we are using Connection.getLastModified not File.lastModifed.
|
||||
// This will then work both or members of jars or standalone class files.
|
||||
// NOTE: NOT TRUE! IT READS THE JAR, NOT THE FILES INSIDE!
|
||||
final long time = connection.getLastModified();
|
||||
return (time != 0L) ? new Date(time) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the BuildID for MLG
|
||||
*
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static void readBuildID() {
|
||||
|
||||
if (var.inf_loop_protect_BuildID > 10) {
|
||||
var.MLG_Last_Modified_Date = new Date(new Long(0)); //set the day to Jan 1, 1970 for failure
|
||||
return;
|
||||
}
|
||||
var.inf_loop_protect_BuildID++; // this is to prevent an infinite loop (however unlikely)
|
||||
|
||||
if (var.MLGFileName == null) {
|
||||
try {
|
||||
var.MLGFileName = getClassLoader(var.cls);
|
||||
} catch (final Exception e) {
|
||||
log.info("Error: Finding file failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (var.MLGFileName.equals(var.rsrcError)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var.MLGFileNameShort =
|
||||
var.MLGFileName.substring(var.MLGFileName.lastIndexOf(var.fileSeparator) + 1,
|
||||
var.MLGFileName.length());
|
||||
|
||||
if (var.testing) {
|
||||
log.info("Currently Running as file:" + var.MLGFileNameShort);
|
||||
}
|
||||
|
||||
if (var.MLG_Current_Hash == null) {
|
||||
|
||||
try {
|
||||
var.MLG_Current_Hash = MD5.fileMD5(var.MLGFileName);
|
||||
// out(hash + " " + MLGFileName);
|
||||
} catch (final Exception e) {
|
||||
log.info("Error: MD5 from file failed");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
int tsCount = 0;
|
||||
|
||||
var.timeStamps.clear();
|
||||
|
||||
if (var.MLG_Last_Modified_Date == null) {
|
||||
boolean foundLine = false;
|
||||
try {
|
||||
final BufferedReader in = new BufferedReader(new FileReader(var.buildIDFile));
|
||||
String line;
|
||||
|
||||
if (var.testing) {
|
||||
log.info("TimeStamps in buildIDFile:");
|
||||
}
|
||||
while ((line = in.readLine()) != null) {
|
||||
|
||||
int pos = line.indexOf('=');
|
||||
|
||||
int end = line.lastIndexOf('#'); // comments, ignored lines
|
||||
|
||||
if (end == -1) { // If we have no hash sign, then we read till the end of the line
|
||||
end = line.length();
|
||||
|
||||
}
|
||||
if (end <= (pos + 1)) { // If hash is before the '=', we may have an issue... it should be fine, cause we check for issues next, but lets make sure.
|
||||
end = line.length();
|
||||
pos = -1;
|
||||
}
|
||||
|
||||
if (end == 0) { //hash is first char, meaning entire line is a comment
|
||||
end = line.length();
|
||||
pos = 0;
|
||||
}
|
||||
|
||||
if (pos != -1) {
|
||||
if (line.length() != 0) {
|
||||
var.timeStamps.add(line.substring(pos + 1, end));
|
||||
}
|
||||
}
|
||||
|
||||
//timeStamps.add(line.substring(pos + 1, end));
|
||||
|
||||
if (var.testing) {
|
||||
log.info(var.timeStamps.get(tsCount));
|
||||
}
|
||||
|
||||
tsCount++;
|
||||
|
||||
if (line.contains(var.MLG_Current_Hash)) {
|
||||
// out("[DEBUG] Found!");
|
||||
foundLine = true;
|
||||
|
||||
if (pos != -1) {
|
||||
if (line.substring(0, pos).equals(var.MLG_Current_Hash)) {
|
||||
var.MLG_Last_Modified_Long = new Long(line.substring(pos + 1, end));
|
||||
var.MLG_Last_Modified_Date = new Date(var.MLG_Last_Modified_Long);
|
||||
|
||||
final Long highestModTime =
|
||||
Update.ZipGetModificationTime(var.MLGFileName);
|
||||
final long tCalc = var.MLG_Last_Modified_Long - highestModTime;
|
||||
|
||||
if (var.testing) {
|
||||
log.info("tCalc\tMLG_Last_Modified_Long\thighestModTime"
|
||||
+ var.newLine + tCalc + "\t"
|
||||
+ var.MLG_Last_Modified_Long + "\t" + highestModTime);
|
||||
}
|
||||
|
||||
if (highestModTime == 0L) {
|
||||
|
||||
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)
|
||||
log.error("Archive Intergrity Check Failed: .zip file is newer than BuildID. Offset: "
|
||||
+ (tCalc / 1000) + "sec.");
|
||||
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) {
|
||||
log.info("Archive Intergrity Check Passed. Offset: "
|
||||
+ (tCalc / 1000) + "sec.");
|
||||
}
|
||||
|
||||
} else {
|
||||
//times dont match. (.zip file is older than specified BuildID)
|
||||
log.error("Archive Intergrity Check Failed: .zip file is older than BuildID. Offset: "
|
||||
+ (tCalc / 1000) + "sec.");
|
||||
log.error("Archive Intergrity Check Failed: (MLG will still run. Just note that this may not be an official version.)");
|
||||
}
|
||||
}
|
||||
//return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
in.close();
|
||||
|
||||
if (foundLine == false) {
|
||||
// out("[DEBUG] FoundLine False");
|
||||
buildID(false);
|
||||
readBuildID(); // yes I'm calling the function from itself. potential infinite loop? possibly. I haven't encountered it yet!
|
||||
return;
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
log.error("Cant Read " + var.buildIDFile + "!");
|
||||
log.error(e.getLocalizedMessage());
|
||||
log.error("");
|
||||
// e.printStackTrace();
|
||||
buildID(false);
|
||||
readBuildID();
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates MLG to the Latest Version
|
||||
*
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static boolean updateMLG() {
|
||||
|
||||
buildID(true); //get latest BuildID file.
|
||||
var.MLG_Last_Modified_Date = null;
|
||||
readBuildID();
|
||||
|
||||
final Iterator<String> e = var.timeStamps.iterator();
|
||||
String s;
|
||||
int diff;
|
||||
|
||||
while (e.hasNext()) {
|
||||
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!
|
||||
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) {
|
||||
log.info("Rename attempt #1 failed!");
|
||||
e1.printStackTrace();
|
||||
|
||||
try {
|
||||
Misc.copyFile(new File(var.MLG_JarFile), new File(var.MLG_JarFile + ".old"));
|
||||
final File fileDelete = new File(var.MLG_JarFile);
|
||||
fileDelete.delete();
|
||||
} catch (final Exception e2) {
|
||||
log.info("Rename attempt #2 failed!");
|
||||
e2.printStackTrace();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final boolean fileSuccess = DownloadFile.downloadFile(var.github_MLG_jar_URL, true);
|
||||
if (fileSuccess) {
|
||||
log.info(var.MLG_JarFile + " downloaded.");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* <b>.zip file Get Modification Time</b><br>
|
||||
* <p>
|
||||
* Takes a string of a path to a .zip file (or .jar), and and returns a Long of the latest "Last Time Modified". <br>
|
||||
* <br>
|
||||
* <p>
|
||||
* Thanks to the following:<br>
|
||||
* <a href="http://www.java-examples.com/get-modification-time-zip-entry-example">http://www.java-examples.com/get-modification-time-zip-entry-example</a><br>
|
||||
* <a href="http://www.java-examples.com/get-crc-32-checksum-zip-entry-example">http://www.java-examples.com/get-crc-32-checksum-zip-entry-example</a>
|
||||
*
|
||||
* @param zipFile
|
||||
* @return
|
||||
* @author Morlok8k
|
||||
*/
|
||||
public static Long ZipGetModificationTime(final String zipFile) {
|
||||
|
||||
Long highestModTime = 0L;
|
||||
|
||||
try {
|
||||
|
||||
final ZipFile zipF = new ZipFile(zipFile);
|
||||
|
||||
/*
|
||||
* Get list of zip entries using entries method of ZipFile class.
|
||||
*/
|
||||
|
||||
final Enumeration<? extends ZipEntry> e = zipF.entries();
|
||||
|
||||
if (var.testing) {
|
||||
log.info("File Name\t\tCRC\t\tModification Time\n---------------------------------\n");
|
||||
}
|
||||
|
||||
while (e.hasMoreElements()) {
|
||||
final ZipEntry entry = e.nextElement();
|
||||
|
||||
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.
|
||||
modTime = 0L;
|
||||
}
|
||||
|
||||
if (highestModTime < modTime) {
|
||||
highestModTime = modTime;
|
||||
}
|
||||
|
||||
if (var.testing) {
|
||||
|
||||
final String entryName = entry.getName();
|
||||
final Date modificationTime = new Date(modTime);
|
||||
final String CRC = Long.toHexString(entry.getCrc());
|
||||
|
||||
log.info(entryName + "\t" + CRC + "\t" + modificationTime + "\t"
|
||||
+ modTime.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
zipF.close();
|
||||
|
||||
return highestModTime;
|
||||
|
||||
} catch (final IOException ioe) {
|
||||
log.info("Error opening zip file" + ioe);
|
||||
return 0L; //return Jan. 1, 1970 12:00 GMT for failures
|
||||
}
|
||||
}
|
||||
}
|
@ -1,102 +0,0 @@
|
||||
/*
|
||||
This work (and included software, documentation such as READMEs, or other related items) is being provided by the copyright holders under the following license.
|
||||
License
|
||||
By obtaining, using and/or copying this work, you (the licensee) agree that you have read, understood, and will comply with the following terms and conditions.
|
||||
Permission to copy, modify, and distribute this software and its documentation, with or without modification, for any purpose and without fee or royalty is hereby granted, provided that you include the following on ALL copies of the software and documentation or portions thereof, including modifications:
|
||||
The full text of this NOTICE in a location viewable to users of the redistributed or derivative work.
|
||||
Any pre-existing intellectual property disclaimers, notices, or terms and conditions. If none exist, the W3C Software Short Notice should be included (hypertext is preferred, text is permitted) within the body of any redistributed or derivative code.
|
||||
Notice of any changes or modifications to the files, including the date changes were made. (We recommend you provide URIs to the location from which the code is derived.)
|
||||
Disclaimers
|
||||
THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
|
||||
COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.
|
||||
The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to the software without specific, written prior permission. Title to copyright in this software and any associated documentation will at all times remain with copyright holders.
|
||||
*/
|
||||
|
||||
package org.w3c.bert_bos.UTF8URL;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author morlok8k
|
||||
*/
|
||||
public class Unescape {
|
||||
|
||||
/* Morlok8k:
|
||||
* Just a note about this unescape method:
|
||||
* I am quite amazed at this code. It is vastly superior to my own coding ability.
|
||||
* I had to look up many things in it to see how it works, and I still don't quite follow it.
|
||||
* (I have never worked with raw bytes in Java... Never needed to.)
|
||||
* But it works and it works very well. I tip my hat at you Bert!
|
||||
*
|
||||
* I just needed to say this somewhere, even though very few people will ever read this.
|
||||
*/
|
||||
/**
|
||||
* Created: 17 April 1997<br>
|
||||
* Author: Bert Bos <<a href="mailto:bert@w3.org">bert@w3.org</a>><br>
|
||||
* <br>
|
||||
* unescape: <a href="http://www.w3.org/International/unescape.java">http://www.w3.org/International/unescape.java</a><br>
|
||||
* <br>
|
||||
* Copyright © 1997 World Wide Web Consortium, (Massachusetts Institute of Technology, European Research Consortium for Informatics and Mathematics, Keio University). All Rights Reserved.
|
||||
* This work is distributed under the W3C® Software License [1] in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE.<br>
|
||||
* <br>
|
||||
* [1] <a href="http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231">http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231</a>
|
||||
*
|
||||
* @param s
|
||||
* string of URL
|
||||
* @return decoded string of URL
|
||||
* @author Bert Bos
|
||||
*/
|
||||
public static String unescape(final String s) {
|
||||
final StringBuffer sbuf = new StringBuffer();
|
||||
final int l = s.length();
|
||||
int ch = -1;
|
||||
int b, sumb = 0;
|
||||
for (int i = 0, more = -1; i < l; i++) {
|
||||
/* Get next byte b from URL segment s */
|
||||
switch (ch = s.charAt(i)) {
|
||||
case '%':
|
||||
ch = s.charAt(++i);
|
||||
final int hb =
|
||||
(Character.isDigit((char) ch) ? ch - '0' : (10 + Character
|
||||
.toLowerCase((char) ch)) - 'a') & 0xF;
|
||||
ch = s.charAt(++i);
|
||||
final int lb =
|
||||
(Character.isDigit((char) ch) ? ch - '0' : (10 + Character
|
||||
.toLowerCase((char) ch)) - 'a') & 0xF;
|
||||
b = (hb << 4) | lb;
|
||||
break;
|
||||
case '+':
|
||||
b = ' ';
|
||||
break;
|
||||
default:
|
||||
b = ch;
|
||||
}
|
||||
/* Decode byte b as UTF-8, sumb collects incomplete chars */
|
||||
if ((b & 0xc0) == 0x80) { // 10xxxxxx (continuation byte)
|
||||
sumb = (sumb << 6) | (b & 0x3f); // Add 6 bits to sumb
|
||||
if (--more == 0) {
|
||||
sbuf.append((char) sumb); // Add char to sbuf
|
||||
}
|
||||
} else if ((b & 0x80) == 0x00) { // 0xxxxxxx (yields 7 bits)
|
||||
sbuf.append((char) b); // Store in sbuf
|
||||
} else if ((b & 0xe0) == 0xc0) { // 110xxxxx (yields 5 bits)
|
||||
sumb = b & 0x1f;
|
||||
more = 1; // Expect 1 more byte
|
||||
} else if ((b & 0xf0) == 0xe0) { // 1110xxxx (yields 4 bits)
|
||||
sumb = b & 0x0f;
|
||||
more = 2; // Expect 2 more bytes
|
||||
} else if ((b & 0xf8) == 0xf0) { // 11110xxx (yields 3 bits)
|
||||
sumb = b & 0x07;
|
||||
more = 3; // Expect 3 more bytes
|
||||
} else if ((b & 0xfc) == 0xf8) { // 111110xx (yields 2 bits)
|
||||
sumb = b & 0x03;
|
||||
more = 4; // Expect 4 more bytes
|
||||
} else /*if ((b & 0xfe) == 0xfc)*/{ // 1111110x (yields 1 bit)
|
||||
sumb = b & 0x01;
|
||||
more = 5; // Expect 5 more bytes
|
||||
}
|
||||
/* We don't test if the UTF-8 encoding is well-formed */
|
||||
}
|
||||
return sbuf.toString();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user