From 19d9006f264e051b1b1669d78efef35952a9f950 Mon Sep 17 00:00:00 2001 From: Puyodead1 <23562356riley@gmail.com> Date: Mon, 10 Dec 2018 10:06:31 -0500 Subject: [PATCH] Updates and Stablity, 1.13 ALPHA --- .gitignore | 6 + README.md | 5 + src/io/github/puyodead1/SSB/DownloadURL.java | 36 +++ src/io/github/puyodead1/SSB/MainGUI.java | 244 +++++++++++++++++ src/io/github/puyodead1/SSB/SSB.java | 63 +++++ src/io/github/puyodead1/SSB/utils/Utils.java | 263 +++++++++++++++++++ 6 files changed, 617 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 src/io/github/puyodead1/SSB/DownloadURL.java create mode 100644 src/io/github/puyodead1/SSB/MainGUI.java create mode 100644 src/io/github/puyodead1/SSB/SSB.java create mode 100644 src/io/github/puyodead1/SSB/utils/Utils.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..47e5145 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +server +ssb.jar +.project +.classpath +.settings +bin \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5b82b56 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +V5.0 - After adding output path, press enter, you should see a confirmation message in console. +V5.0 - Freezing + +For any issues, use the Issues section or contact me via Discord: Puyodead1#0982 or join the official Discord Server: +https://discord.gg/sSH4yQN \ No newline at end of file diff --git a/src/io/github/puyodead1/SSB/DownloadURL.java b/src/io/github/puyodead1/SSB/DownloadURL.java new file mode 100644 index 0000000..8bd83f4 --- /dev/null +++ b/src/io/github/puyodead1/SSB/DownloadURL.java @@ -0,0 +1,36 @@ +package io.github.puyodead1.SSB; + +import java.io.BufferedInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.net.UnknownHostException; + +public class DownloadURL { + public static boolean Download(String url, String output) { + try { + downloadUsingStream(url, output); + return true; + } catch (UnknownHostException e) { + SSB.Log("[ERROR]: Unknown Host, please make sure you are connected to the internet and try again."); + return false; + } catch(IOException e) { + SSB.Log("[ERROR]: Unknown Error Occured!"); + return false; + } + } + + private static void downloadUsingStream(String urlStr, String file) throws IOException{ + URL url = new URL(urlStr); + BufferedInputStream bis = new BufferedInputStream(url.openStream()); + FileOutputStream fis = new FileOutputStream(file); + byte[] buffer = new byte[1024]; + int count=0; + while((count = bis.read(buffer,0,1024)) != -1) + { + fis.write(buffer, 0, count); + } + fis.close(); + bis.close(); + } +} diff --git a/src/io/github/puyodead1/SSB/MainGUI.java b/src/io/github/puyodead1/SSB/MainGUI.java new file mode 100644 index 0000000..20bac23 --- /dev/null +++ b/src/io/github/puyodead1/SSB/MainGUI.java @@ -0,0 +1,244 @@ +package io.github.puyodead1.SSB; + +import java.util.Arrays; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.KeyAdapter; +import org.eclipse.swt.events.KeyEvent; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.List; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +public class MainGUI { + + protected Shell shlSpigotServerBuilder; + private Text txtOut; + public static String outputPath; + public static String version; + public static Text console; + + public static void Rev() { + switch (version) { + case "latest": + SSB.rev = "latest"; + break; + case "1.12.2": + SSB.rev = "1.12.2"; + break; + case "1.12.1": + SSB.rev = "1.12.1"; + break; + case "1.12": + SSB.rev = "1.12"; + break; + case "1.11": + SSB.rev = "1.11"; + break; + case "1.10": + SSB.rev = "1.10"; + break; + case "1.9.4": + SSB.rev = "1.9.4"; + break; + case "1.9.2": + SSB.rev = "1.9.2"; + break; + case "1.9": + SSB.rev = "1.9"; + break; + case "1.8.8": + SSB.rev = "1.8.8"; + break; + case "1.8.7": + SSB.rev = "1.8.7"; + break; + case "1.8.3": + SSB.rev = "1.8.3"; + break; + case "1.8": + SSB.rev = "1.8"; + break; + default: + SSB.rev = "latest"; + break; + } + } + + /** + * Launch the application. + * + * @param args + */ + public static void main(String[] args) { + try { + MainGUI window = new MainGUI(); + window.open(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Open the window. + */ + public void open() { + Display display = Display.getDefault(); + createContents(); + shlSpigotServerBuilder.open(); + shlSpigotServerBuilder.layout(); + while (!shlSpigotServerBuilder.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + } + + /** + * Create contents of the window. + */ + protected void createContents() { + shlSpigotServerBuilder = new Shell(); + shlSpigotServerBuilder.setSize(1220, 780); + shlSpigotServerBuilder.setText("Spigot Server Builder V2.1 by Puyodead1"); + shlSpigotServerBuilder.setLayout(null); + + List list = new List(shlSpigotServerBuilder, SWT.BORDER); + list.addMouseListener(new MouseAdapter() { + @Override + public void mouseDown(MouseEvent arg0) { + String selectedVersion = Arrays.toString(list.getSelection()); + switch (selectedVersion) { + case "[latest]": + version = "latest"; + break; + case "[1.13]": + version = "1.13"; + break; + case "[1.12.2]": + version = "1.12.2"; + break; + case "[1.12.1]": + version = "1.12.1"; + break; + case "[1.12]": + version = "1.12"; + break; + case "[1.11]": + version = "1.11"; + break; + case "[1.10]": + version = "1.10"; + break; + case "[1.9.4]": + version = "1.9.4"; + break; + case "[1.9.2]": + version = "1.9.2"; + break; + case "[1.9]": + version = "1.9"; + break; + case "[1.8.8]": + version = "1.8.8"; + break; + case "[1.8.7]": + version = "1.8.7"; + break; + case "[1.8.3]": + version = "1.8.3"; + break; + case "[1.8]": + version = "1.8"; + break; + } + Rev(); + } + }); + list.setBounds(34, 31, 63, 207); + + Label lblSelectAVersion = new Label(shlSpigotServerBuilder, SWT.NONE); + lblSelectAVersion.setBounds(24, 10, 93, 15); + lblSelectAVersion.setText("Select a version:"); + + Label lblChooseOutputPath = new Label(shlSpigotServerBuilder, SWT.NONE); + lblChooseOutputPath.setBounds(150, 10, 167, 15); + lblChooseOutputPath.setText("Enter Path to output directory:"); + + Label lblCopyright = new Label(shlSpigotServerBuilder, SWT.NONE); + lblCopyright.setBounds(15, 250, 300, 15); + lblCopyright.setText("Copyright 2018 Puyodead1 and Puyodead1 Development"); + + Label lblCompiledOn = new Label(shlSpigotServerBuilder, SWT.NONE); + lblCompiledOn.setBounds(15, 300, 300, 15); + lblCompiledOn.setText("Compiled on 12/09/2018 at 10:11PM EST"); + + txtOut = new Text(shlSpigotServerBuilder, SWT.BORDER); + txtOut.addKeyListener(new KeyAdapter() { + @Override + public void keyPressed(KeyEvent arg0) { + if (arg0.keyCode == 13) { + outputPath = txtOut.getText(); + console.append("Set output path to: " + outputPath + "\n"); + } + } + }); + + txtOut.setText("Directory output path"); + txtOut.setBounds(160, 32, 126, 21); + + Button btnGo = new Button(shlSpigotServerBuilder, SWT.NONE); + btnGo.addMouseListener(new MouseAdapter() { + @Override + public void mouseDown(MouseEvent e1) { + console.setText(" "); + if (txtOut.getText() != null || txtOut.getText() != "Directory output path") { + outputPath = txtOut.getText(); + console.append("Set output path to: " + outputPath + "\n"); + } + console.append("Started!\n"); + SSB.Init(); + } + }); + btnGo.setBounds(163, 83, 126, 74); + btnGo.setText("GO!"); + + Label label = new Label(shlSpigotServerBuilder, SWT.SEPARATOR | SWT.VERTICAL); + label.setBounds(332, 0, 2, 464); + + Label lblOutput = new Label(shlSpigotServerBuilder, SWT.NONE); + lblOutput.setAlignment(SWT.CENTER); + lblOutput.setBounds(571, 10, 296, 15); + lblOutput.setText("Output:"); + + Label label_1 = new Label(shlSpigotServerBuilder, SWT.SEPARATOR | SWT.HORIZONTAL); + label_1.setBounds(123, 59, 211, 2); + + Label label_2 = new Label(shlSpigotServerBuilder, SWT.SEPARATOR | SWT.VERTICAL); + label_2.setBounds(123, 0, 2, 246); + + Label label_3 = new Label(shlSpigotServerBuilder, SWT.SEPARATOR | SWT.HORIZONTAL); + label_3.setBounds(0, 244, 334, 2); + + ScrolledComposite scrolledComposite = new ScrolledComposite(shlSpigotServerBuilder, + SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); + scrolledComposite.setBounds(340, 51, 854, 412); + scrolledComposite.setExpandHorizontal(true); + scrolledComposite.setExpandVertical(true); + + console = new Text(scrolledComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.CANCEL); + console.setEditable(false); + scrolledComposite.setContent(console); + scrolledComposite.setMinSize(console.computeSize(SWT.DEFAULT, SWT.DEFAULT)); + String[] versions = { "latest", "1.13", "1.12.2", "1.12.1", "1.12", "1.11", "1.10", "1.9.4", "1.9.2", "1.9", + "1.8.8", "1.8.7", "1.8.3", "1.8" }; + for (int i = 0; i < versions.length; i++) { + list.add(versions[i]); + } + } +} diff --git a/src/io/github/puyodead1/SSB/SSB.java b/src/io/github/puyodead1/SSB/SSB.java new file mode 100644 index 0000000..52bc1f5 --- /dev/null +++ b/src/io/github/puyodead1/SSB/SSB.java @@ -0,0 +1,63 @@ +package io.github.puyodead1.SSB; + +import io.github.puyodead1.SSB.utils.Utils; + +public class SSB { + public static String rev; + public static String buildToolsDownloadURL = "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar"; + + public static void Log(String log) { + MainGUI.console.append(log + "\n"); + } + + public static void Init() { + Utils.GetOS(); + if (Utils.isWindows()) { + Log("Windows Detected"); + InitWindows(); + } else if (Utils.isUnix()) { + InitLinux(); + } else if(Utils.isMac()) { + SSB.Log("Sorry, Mac is currently unsupported! 0_0 D:"); + return; + } else if(Utils.isSolaris()) { + SSB.Log("Sorry, Solaris is currntly unsupported! 0_0 D:"); + return; + }else { + SSB.Log("Hm, nice OS, unfortunatly its unsupported 0_0 D:, please contact me and let me know what OS this is so I can possibly add it :D"); + return; + } + } + + private static void InitWindows() { + Utils.CheckForDirectory(MainGUI.outputPath); + Utils.CheckForDirectory(MainGUI.outputPath + "\\SpigotServer"); + Utils.CheckForDirectory(MainGUI.outputPath + "\\BuildTools"); + Log("Checking for BuildTools.jar in BuildTools Directory..."); + if (!Utils.CheckForBuildTools(MainGUI.outputPath)) { + SSB.Log("GREAT ERROR!"); + System.out.println("GREAT ERROR"); + return; + } + // BuildTools.jar found and so was an Existing Spigot jar! + System.out.println("DEBUG 1"); + Utils.CreateEULA(); + Utils.LauncherHandlerWindows(); + return; + } + + public static void executeScript(String script) { + try { + ProcessBuilder pb = new ProcessBuilder(script); + Process p = pb.start(); // Start the process. + p.waitFor(); // Wait for the process to finish. + System.out.println("Script executed successfully"); + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void InitLinux() { + + } +} \ No newline at end of file diff --git a/src/io/github/puyodead1/SSB/utils/Utils.java b/src/io/github/puyodead1/SSB/utils/Utils.java new file mode 100644 index 0000000..42be070 --- /dev/null +++ b/src/io/github/puyodead1/SSB/utils/Utils.java @@ -0,0 +1,263 @@ +package io.github.puyodead1.SSB.utils; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.Paths; + +import org.apache.commons.io.FileUtils; + +import io.github.puyodead1.SSB.DownloadURL; +import io.github.puyodead1.SSB.MainGUI; +import io.github.puyodead1.SSB.SSB; + +public class Utils { + public static String OS; + private static File msysDir; + + public static void Complete() { + SSB.Log(">>>>>>> --------------------------------------------------------------------------- <<<<<<<"); + SSB.Log(">>>>>>> Complete! Please use the Launcher.bat file to start your new server! Enjoy! <<<<<<<"); + SSB.Log(">>>>>>> --------------------------------------------------------------------------- <<<<<<<"); + } + public static boolean CreateEULA() { + SSB.Log(">>>>>>> ------------------------------------------------------- <<<<<<<"); + SSB.Log(">>>>>>> PLEASE MAKE SURE YOU READ AND AGREE TO THE Mojang EULA! <<<<<<<"); + SSB.Log(">>>>>>> ------------------------------------------------------- <<<<<<<"); + SSB.Log("Continuing in 5 seconds..."); + try { + Thread.sleep(5000); + } catch (InterruptedException e1) { + SSB.Log(e1.getMessage()); + } + if (!Utils.CheckForFile(MainGUI.outputPath + "\\SpigotServer\\eula.txt")) { + // EULA file doesn't exist, we create it here + try { + PrintWriter pw = new PrintWriter(MainGUI.outputPath + "\\SpigotServer\\eula.txt"); + pw.write("eula=true"); + pw.close(); + SSB.Log("EULA Re-Write complete..."); + // EULA Created successfully! + return true; + } catch (IOException e) { + // Error creating that EULA file 0_0 + SSB.Log("Error creating the EULA.txt file!" + e.getMessage()); + return false; + } + } else { + // EULA file does exist, we can skip to launching the server! YAY! + SSB.Log("Found EULA, Deleting and Re-Writing."); + File eula = new File(MainGUI.outputPath + "\\SpigotServer\\eula.txt"); + eula.delete(); + try { + eula.createNewFile(); + PrintWriter pw = new PrintWriter(MainGUI.outputPath + "\\SpigotServer\\eula.txt"); + pw.write("eula=true"); + pw.close(); + SSB.Log("EULA Re-Write Complete!"); + return true; + } catch (IOException e) { + e.printStackTrace(); + return false; + } + } + } + + public static boolean CheckForFile(String path) { + File in = new File(path); + if (!in.exists()) { + // return false If we don't find file + return false; + } else { + // return true If we find file + return true; + } + } + + public static boolean CheckForBuildTools(String path) { + String btpath = path + "\\BuildTools\\BuildTools.jar"; + File in = new File(btpath); + if (!in.exists()) { + SSB.Log("BuildTools.jar not found, Checking for Spigot"); + Utils.CheckForSpigotInBT(MainGUI.outputPath); + return false; + } else { + // true. we found BT + SSB.Log("BuildTools.jar found, Checking for Spigot"); + Utils.CheckForSpigotInBT(MainGUI.outputPath); + return true; + } + } + + public static boolean CheckForSpigotInBT(String path) { + String spath = path + "\\BuildTools\\spigot-" + MainGUI.version + ".jar"; + File in = new File(spath); + if (!in.exists()) { + SSB.Log("We didn't find Spigot :("); + DownloadBuildTools(); + runBT(); + return false; + } else { + // return true If we find file + SSB.Log("Found Existing Spigot jar. Using it!"); + // TODO: COPY SPIGOT + CopyFile(MainGUI.outputPath + "\\BuildTools\\spigot-1.12.2.jar", + MainGUI.outputPath + "\\SpigotServer\\spigot-1.12.2.jar"); + return true; + } + } + + public static boolean LauncherHandlerWindows() { + if (CheckForFile(MainGUI.outputPath + "\\SpigotServer\\Launcher.bat")) { + // true if exists + SSB.Log("Launcher exists.. Skipping..."); + Complete(); + return true; + } else { + // false if no + File launcher = new File(MainGUI.outputPath + "\\SpigotServer\\Launcher.bat"); + try { + launcher.createNewFile(); + PrintWriter pw = new PrintWriter(MainGUI.outputPath + "\\SpigotServer\\Launcher.bat"); + pw.write("java -jar spigot-" + MainGUI.version + ".jar"); + pw.close(); + SSB.Log("Launcher write complete."); + Complete(); + return true; + } catch (IOException e) { + e.printStackTrace(); + return false; + } + } + } + + public static boolean LauncherHandlerLinux() { + return false; + } + + public static boolean CheckForDirectory(String path) { + File in = new File(path); + if (!in.exists()) { + // false not exists + try { + CreateDirectory(path); + SSB.Log("Created Directory at: " + path); + return true; + } catch (Exception e) { + SSB.Log(e.getMessage()); + System.exit(1); + } + return false; + } else { + // return true If we find file + SSB.Log("Directory Exists!"); + return true; + } + } + + public static boolean CreateDirectory(String path) { + try { + Files.createDirectory(Paths.get(path)); + return true; + } catch (IOException e) { + if (e.toString().contains("FileAlreadyExists")) { // TODO this might be a bad way of checking... + SSB.Log("Directory already exists! Skipping..."); + return false; + } else { + SSB.Log("Oops, an error occured creating directory..."); + SSB.Log(e.toString()); + return false; + } + } + } + + public static boolean DownloadBuildTools() { + if (DownloadURL.Download( + "https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar", + MainGUI.outputPath + "\\BuildTools\\BuildTools.jar")) { + SSB.Log("Downloaded BuildTools.jar!"); + return true; // if Success + } else { + SSB.Log("Failed to download BuildTools.jar! Sleeping for 10 seconds then exiting!"); + try { + Thread.sleep(10000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + SSB.Log(e.getMessage()); + } + System.exit(1); + return false;// iF Fail + } + } + + public static boolean DownloadBuildToolsLinux() { + return false; + } + + public static void runBT() { + String[] command = { "CMD", "/C", + "cd " + MainGUI.outputPath + "\\BuildTools && start java -jar BuildTools.jar && exit && exit" }; + try { + ProcessBuilder builder = new ProcessBuilder(command); + // builder.redirectErrorStream(true); + SSB.Log("Waiting..."); + Process p = builder.start(); + p.waitFor(); + System.out.println(p.getInputStream().read()); + try { + int exitValue = p.waitFor(); + System.out.println("\n\nExit Value is " + exitValue); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + SSB.Log("Done..."); + } catch (Exception e) { + e.printStackTrace(); + SSB.Log("Error"); + System.exit(1); + } + } + + public static boolean isWindows() { + + return (OS.indexOf("win") >= 0); + + } + + public static boolean isMac() { + + return (OS.indexOf("mac") >= 0); + + } + + public static boolean isUnix() { + + return (OS.indexOf("nix") >= 0 || OS.indexOf("nux") >= 0 || OS.indexOf("aix") > 0); + + } + + public static boolean isSolaris() { + + return (OS.indexOf("sunos") >= 0); + + } + + public static void GetOS() { + OS = System.getProperty("os.name").toLowerCase(); + } + + public static boolean CopyFile(String sourcePath, String destPath) { + File source = new File(sourcePath); + File dest = new File(destPath); + try { + FileUtils.copyFile(source, dest); + SSB.Log("File Copied!"); + return true; + } catch (IOException e) { + SSB.Log("Failed to copy File!" + e.getMessage()); + return false; + } + } +}