This repository has been archived by the owner on Mar 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
patches/net/minecraftforge/fml/relauncher/ServerLaunchWrapper.java.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- ../src-base/minecraft/net/minecraftforge/fml/relauncher/ServerLaunchWrapper.java | ||
+++ ../src-work/minecraft/net/minecraftforge/fml/relauncher/ServerLaunchWrapper.java | ||
@@ -20,10 +20,8 @@ | ||
package net.minecraftforge.fml.relauncher; | ||
|
||
import java.lang.reflect.Method; | ||
+import kettlefoundation.kettle.downloads.DownloadServerFiles; | ||
|
||
-import org.apache.logging.log4j.LogManager; | ||
-import org.apache.logging.log4j.core.LoggerContext; | ||
- | ||
public class ServerLaunchWrapper { | ||
|
||
/** | ||
@@ -31,7 +29,10 @@ | ||
*/ | ||
public static void main(String[] args) | ||
{ | ||
- new ServerLaunchWrapper().run(args); | ||
+ System.out.println("Starting Kettle"); | ||
+ DownloadServerFiles.downloadMinecraftServer(); | ||
+ DownloadServerFiles.downloadServerLibraries(); | ||
+ new ServerLaunchWrapper().run(args); | ||
} | ||
|
||
private ServerLaunchWrapper() | ||
@@ -56,8 +57,7 @@ | ||
{ | ||
System.err.printf("We appear to be missing one or more essential library files.\n" + | ||
"You will need to add them to your server before FML and Forge will run successfully."); | ||
- e.printStackTrace(System.err); | ||
- System.exit(1); | ||
+ | ||
} | ||
|
||
try |
93 changes: 93 additions & 0 deletions
93
src/main/java/kettlefoundation/kettle/downloads/DownloadServerFiles.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package kettlefoundation.kettle.downloads; | ||
|
||
import java.io.*; | ||
import java.net.URL; | ||
import java.nio.channels.Channels; | ||
import java.nio.channels.ReadableByteChannel; | ||
import java.util.zip.ZipEntry; | ||
import java.util.zip.ZipInputStream; | ||
|
||
/** | ||
* DownloadServerFiles | ||
* | ||
* @author Hexeption [email protected] | ||
* @since 02/05/2019 - 06:06 PM | ||
*/ | ||
public class DownloadServerFiles { | ||
|
||
/** | ||
* Downloads required Minecraft server jar from the Minecraft cdn. | ||
*/ | ||
public static void downloadMinecraftServer() { | ||
String fileName = "minecraft_server.1.12.2.jar"; | ||
String downloadLink = "https://launcher.mojang.com/v1/objects/886945bfb2b978778c3a0288fd7fab09d315b25f/server.jar"; | ||
|
||
File minecraftServerJar = new File(fileName); | ||
if (!minecraftServerJar.exists() && !minecraftServerJar.isDirectory()) { | ||
System.out.println("Downloading Minecraft Server Jar ..."); | ||
try { | ||
URL website = new URL(downloadLink); | ||
ReadableByteChannel rbc = Channels.newChannel(website.openStream()); | ||
FileOutputStream fos = new FileOutputStream(fileName); | ||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Downloads the required libraries zip from the git repo and extracts the libraries zip into the correct place. | ||
*/ | ||
public static void downloadServerLibraries() { | ||
String fileName = "libraries.zip"; | ||
String downloadLink = "https://raw.githubusercontent.com/KettleFoundation/Kettle/master/release/libraries.zip"; | ||
|
||
File minecraftlibraries = new File(fileName); | ||
if (!minecraftlibraries.exists() && !minecraftlibraries.isDirectory()) { | ||
System.out.println("Downloading Server Libraries ..."); | ||
try { | ||
URL website = new URL(downloadLink); | ||
ReadableByteChannel rbc = Channels.newChannel(website.openStream()); | ||
FileOutputStream fos = new FileOutputStream(fileName); | ||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); | ||
System.out.println("Extracting Zip"); | ||
unzip(minecraftlibraries, "."); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Extract files and folders in a zip file. | ||
* | ||
* @param source Zip file to extract data from. | ||
* @param out Folder location to put the extracted data into. | ||
* @throws IOException if there's an error extracting | ||
*/ | ||
private static void unzip(File source, String out) throws IOException { | ||
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(source))) { | ||
ZipEntry entry = zis.getNextEntry(); | ||
while (entry != null) { | ||
File file = new File(out, entry.getName()); | ||
if (entry.isDirectory()) { | ||
file.mkdirs(); | ||
} else { | ||
File parent = file.getParentFile(); | ||
if (!parent.exists()) { | ||
parent.mkdirs(); | ||
} | ||
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) { | ||
byte[] buffer = new byte[Math.toIntExact(entry.getSize())]; | ||
int location; | ||
while ((location = zis.read(buffer)) != -1) { | ||
bos.write(buffer, 0, location); | ||
} | ||
} | ||
} | ||
entry = zis.getNextEntry(); | ||
} | ||
} | ||
} | ||
} |