Skip to content
This repository was archived by the owner on Jun 7, 2022. It is now read-only.

Commit 908c3d7

Browse files
derropGiantTreeLP
authored andcommitted
Changeable path for the output spigot.jar in Paper/SpigotBuilder
1 parent ed3c0b4 commit 908c3d7

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

cloudnet-cord/cloudnet-setup/src/main/java/de/dytanic/cloudnet/setup/spigot/PaperBuilder.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.net.URL;
1111
import java.net.URLConnection;
1212
import java.nio.file.Files;
13+
import java.nio.file.Path;
1314
import java.nio.file.Paths;
1415
import java.nio.file.StandardCopyOption;
1516
import java.util.Arrays;
@@ -29,7 +30,7 @@ public final class PaperBuilder {
2930
*
3031
* @param reader Read the answer from console
3132
*/
32-
public static void start(ConsoleReader reader) {
33+
public static void start(ConsoleReader reader, Path outputPath) {
3334
try {
3435
System.out.println("Fetch Versions");
3536
URLConnection connection = new URL(apiProjectUrl).openConnection();
@@ -55,7 +56,7 @@ public static void start(ConsoleReader reader) {
5556
String finalAnswer = name;
5657
if (Arrays.stream(paperMCProject.getVersions()).anyMatch(e -> e.equalsIgnoreCase(finalAnswer))) {
5758
answer = name;
58-
buildPaperVersion(answer);
59+
buildPaperVersion(answer, outputPath);
5960
} else if (Arrays.stream(paperMCProject.getVersions()).noneMatch(e -> e.equalsIgnoreCase(finalAnswer))) {
6061
System.out.println("This version does not exist!");
6162
}
@@ -72,7 +73,7 @@ public static void start(ConsoleReader reader) {
7273
*
7374
* @throws Exception If a connection error or something
7475
*/
75-
private static void buildPaperVersion(String version) throws Exception {
76+
private static void buildPaperVersion(String version, Path outputPath) throws Exception {
7677
System.out.println(String.format("Fetching build %s", version));
7778
URLConnection connection = new URL(String.format(API_PROJECT_VERSION_URL, version)).openConnection();
7879
connection.setRequestProperty("User-Agent",
@@ -92,22 +93,22 @@ private static void buildPaperVersion(String version) throws Exception {
9293
Files.createDirectories(buildFolder.toPath());
9394
File paperclip = new File(buildFolder, "paperclip.jar");
9495
if (!paperclip.exists()) {
95-
runPaperClip(connection, buildFolder, paperclip);
96+
runPaperClip(connection, buildFolder, paperclip, outputPath);
9697
} else {
9798
File[] paperclips = buildFolder.listFiles(pathname -> pathname.getName().startsWith("paper"));
9899
if (Objects.requireNonNull(paperclips).length > 0) {
99100
System.out.println("Skipping build");
100101
System.out.println("Copying spigot.jar");
101102
try {
102103
Files.copy(new FileInputStream(Objects.requireNonNull(paperclips)[0]),
103-
Paths.get("local/spigot.jar"),
104+
outputPath,
104105
StandardCopyOption.REPLACE_EXISTING);
105106
} catch (IOException e) {
106107
e.printStackTrace();
107108
}
108109
} else {
109110
SpigotBuilder.deleteBuildFolder(buildFolder);
110-
runPaperClip(connection, buildFolder, paperclip);
111+
runPaperClip(connection, buildFolder, paperclip, outputPath);
111112
}
112113

113114
}
@@ -123,7 +124,7 @@ private static void buildPaperVersion(String version) throws Exception {
123124
*
124125
* @throws IOException Throws if input stream null
125126
*/
126-
private static void runPaperClip(URLConnection connection, File buildFolder, File paperclip) throws IOException {
127+
private static void runPaperClip(URLConnection connection, File buildFolder, File paperclip, Path outputPath) throws IOException {
127128
System.out.println("Downloading Paperclip");
128129
try (InputStream inputStream = connection.getInputStream()) {
129130
Files.copy(inputStream, Paths.get(paperclip.toURI()), StandardCopyOption.REPLACE_EXISTING);
@@ -133,7 +134,7 @@ private static void runPaperClip(URLConnection connection, File buildFolder, Fil
133134

134135
Files.copy(new FileInputStream(Objects.requireNonNull(buildFolder.listFiles(pathname -> pathname.getName()
135136
.startsWith("paperclip")))[0]),
136-
Paths.get("local/spigot.jar"),
137+
outputPath,
137138
StandardCopyOption.REPLACE_EXISTING);
138139
}
139140

cloudnet-cord/cloudnet-setup/src/main/java/de/dytanic/cloudnet/setup/spigot/SetupSpigotVersion.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public void accept(String url) {
3333
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
3434
connection.connect();
3535
try (InputStream inputStream = connection.getInputStream()) {
36-
Files.copy(inputStream, target != null ? target : Paths.get("local/spigot.jar"), StandardCopyOption.REPLACE_EXISTING);
36+
Files.copy(inputStream, SetupSpigotVersion.this.getTarget(), StandardCopyOption.REPLACE_EXISTING);
3737
}
3838
System.out.println("Download was successfully completed!");
3939
} catch (Exception e) {
@@ -144,14 +144,18 @@ public void accept(ConsoleReader reader) {
144144
}
145145
}
146146
case "buildtools":
147-
SpigotBuilder.start(reader);
147+
SpigotBuilder.start(reader, this.getTarget());
148148
break;
149149
case "paper":
150-
PaperBuilder.start(reader);
150+
PaperBuilder.start(reader, this.getTarget());
151151
break;
152152
}
153153
}
154154

155+
public Path getTarget() {
156+
return this.target != null ? this.target : Paths.get("local/spigot.jar");
157+
}
158+
155159
public void setTarget(Path target) {
156160
this.target = target;
157161
}

cloudnet-cord/cloudnet-setup/src/main/java/de/dytanic/cloudnet/setup/spigot/SpigotBuilder.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public final class SpigotBuilder {
2828
*
2929
* @param reader to read the answer
3030
*/
31-
public static void start(final ConsoleReader reader) {
31+
public static void start(final ConsoleReader reader, Path outputPath) {
3232
System.out.println("Fetching Spigot versions");
3333
List<String> versions = loadVersions();
3434
System.out.println("Available Spigot versions:");
@@ -47,7 +47,7 @@ public static void start(final ConsoleReader reader) {
4747
String finalAnswer = name;
4848
if (versions.stream().anyMatch(e -> e.equalsIgnoreCase(finalAnswer))) {
4949
answer = name;
50-
buildSpigot(finalAnswer);
50+
buildSpigot(finalAnswer, outputPath);
5151
} else if (versions.stream().noneMatch(e -> e.equalsIgnoreCase(finalAnswer))) {
5252
System.out.println("This version does not exist!");
5353
}
@@ -83,7 +83,7 @@ private static LinkedList<String> loadVersions() {
8383
*
8484
* @param version the version of spigot
8585
*/
86-
private static void buildSpigot(final String version) {
86+
private static void buildSpigot(final String version, Path outputPath) {
8787
File builder = new File("local/builder/spigot");
8888
File buildFolder = new File(builder, version);
8989
try {
@@ -93,21 +93,21 @@ private static void buildSpigot(final String version) {
9393
}
9494
File buildTools = new File(buildFolder, "buildtools.jar");
9595
if (!buildTools.exists()) {
96-
runBuildTools(version, buildFolder, buildTools);
96+
runBuildTools(version, buildFolder, buildTools, outputPath);
9797
} else {
9898
if (Objects.requireNonNull(buildFolder.listFiles(pathname -> pathname.getName().startsWith("spigot-"))).length > 0) {
9999
System.out.println("Skipping build");
100100
System.out.println("Copying spigot.jar");
101101
try {
102102
Files.copy(new FileInputStream(Objects.requireNonNull(buildFolder.listFiles(pathname -> pathname.getName()
103103
.startsWith("spigot-")))[0]),
104-
Paths.get("local/spigot.jar"),
104+
outputPath,
105105
StandardCopyOption.REPLACE_EXISTING);
106106
} catch (IOException e) {
107107
e.printStackTrace();
108108
}
109109
} else {
110-
runBuildTools(version, buildFolder, buildTools);
110+
runBuildTools(version, buildFolder, buildTools, outputPath);
111111
}
112112
}
113113

@@ -120,7 +120,7 @@ private static void buildSpigot(final String version) {
120120
* @param buildFolder the folder in there are build
121121
* @param buildTools the path of the build tools
122122
*/
123-
private static void runBuildTools(String version, File buildFolder, File buildTools) {
123+
private static void runBuildTools(String version, File buildFolder, File buildTools, Path outputPath) {
124124
try {
125125
long startTime = System.currentTimeMillis();
126126
Files.createDirectories(buildFolder.toPath());
@@ -139,15 +139,15 @@ private static void runBuildTools(String version, File buildFolder, File buildTo
139139
if (Objects.requireNonNull(buildFolder.listFiles(pathname -> pathname.getName().startsWith("spigot-"))).length > 0) {
140140
Files.copy(new FileInputStream(Objects.requireNonNull(buildFolder.listFiles(pathname -> pathname.getName()
141141
.startsWith("spigot-")))[0]),
142-
Paths.get("local/spigot.jar"),
142+
outputPath,
143143
StandardCopyOption.REPLACE_EXISTING);
144144
long endTime = System.currentTimeMillis();
145145
long minutes = ((endTime - startTime) / 1000) / 60;
146146
long seconds = ((endTime - startTime) / 1000) % 60;
147147
System.out.printf("Total Build Time %dMin %dSec\n", minutes, seconds);
148148
} else {
149149
deleteBuildFolder(buildFolder);
150-
buildSpigot(version);
150+
buildSpigot(version, outputPath);
151151
}
152152
} catch (Exception e) {
153153
e.printStackTrace();

0 commit comments

Comments
 (0)