Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.InputStream;
- import java.net.URL;
- import java.nio.channels.Channels;
- import java.nio.channels.ReadableByteChannel;
- import java.nio.file.Files;
- import java.util.Enumeration;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipFile;
- import java.util.zip.ZipOutputStream;
- public class SetupPaperMC {
- public static void main(String[] args) {
- try {
- System.out.println("Setting up PaperMC versions...");
- File cache = new File("cache");
- if (cache.exists()) {
- File[] files = cache.listFiles();
- if (files != null)
- for (File file : files)
- file.delete();
- }
- for (int i = 0; i < args.length; i++) {
- String[] v = args[i].split(":");
- File paperclip = new File("paper.jar");
- paperclip.delete();
- System.out.println("Downloading PaperMC " + args[i] + "...");
- ReadableByteChannel rbc = Channels.newChannel(new URL("https://papermc.io/api/v2/projects/paper/versions/" + v[0] + "/builds/" + v[1] + "/downloads/paper-" + v[0] + "-" + v[1] + ".jar").openStream());
- FileOutputStream fos = new FileOutputStream(paperclip);
- fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
- fos.close();
- rbc.close();
- new ProcessBuilder("java", "-Dpaperclip.patchonly=true", "-jar", paperclip.getAbsolutePath())
- .inheritIO()
- .start()
- .waitFor();
- System.out.println("Generating NMS...");
- File[] jars = cache.listFiles();
- if (jars != null)
- for (File jarFile : jars) {
- if (jarFile.getName().startsWith("patched_")) {
- File nmsFile = new File(jarFile.getParentFile(), jarFile.getName().replace("patched_", "nms_"));
- if (!nmsFile.exists()) {
- if (i == args.length - 1) {
- Files.copy(jarFile.toPath(), nmsFile.toPath());
- } else {
- ZipFile jarZip = new ZipFile(jarFile);
- try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(nmsFile))) {
- Enumeration<? extends ZipEntry> entries = jarZip.entries();
- while (entries.hasMoreElements()) {
- ZipEntry entry = entries.nextElement();
- if (!entry.getName().startsWith("net/minecraft/server/v") && !entry.getName().startsWith("org/bukkit/craftbukkit/v"))
- continue;
- zos.putNextEntry(entry);
- InputStream is = jarZip.getInputStream(entry);
- byte[] buf = new byte[1024];
- int len;
- while((len = is.read(buf)) > 0)
- zos.write(buf, 0, len);
- is.close();
- }
- }
- jarZip.close();
- }
- break;
- }
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement