-
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathMain.java
More file actions
82 lines (68 loc) · 2.56 KB
/
Main.java
File metadata and controls
82 lines (68 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* Paperclip - Paper Minecraft launcher
*
* Copyright (c) 2019 Kyle Wood (DemonWav)
* https://github.com/PaperMC/Paperclip
*
* MIT License
*/
package io.papermc.paperclip;
import com.eclipsesource.json.Json;
import com.eclipsesource.json.JsonObject;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Method;
public final class Main {
private static final JsonObject VERSION = readJsonFile();
private static JsonObject readJsonFile() {
final JsonObject object;
InputStreamReader reader = null;
try {
reader = new InputStreamReader(Main.class.getClassLoader().getResourceAsStream("version.json"), "UTF_8");
object = Json.parse(reader).asObject();
} catch (final IOException exc) {
throw new RuntimeException("Failed to read version.json", exc);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
return object;
}
public static void main(final String[] args) {
final int javaVersion = VERSION.getInt("java_version", 17);
final String minecraftVersion = VERSION.getString("name", "Unknown");
if (getJavaVersion() < javaVersion) {
System.err.printf("Minecraft %s requires running the server with Java %s or above. " +
"Download Java %s (or above) from https://adoptium.net/", minecraftVersion, javaVersion, javaVersion);
System.exit(1);
}
try {
final Class<?> paperclipClass = Class.forName("io.papermc.paperclip.Paperclip");
final Method mainMethod = paperclipClass.getMethod("main", String[].class);
mainMethod.invoke(null, (Object) args);
} catch (final Exception e) {
e.printStackTrace();
}
}
private static int getJavaVersion() {
final String version = System.getProperty("java.specification.version");
final String[] parts = version.split("\\.");
final String errorMsg = "Could not determine version of the current JVM";
if (parts.length == 0) {
throw new IllegalStateException(errorMsg);
}
if (parts[0].equals("1")) {
if (parts.length < 2) {
throw new IllegalStateException(errorMsg);
}
return Integer.parseInt(parts[1]);
} else {
return Integer.parseInt(parts[0]);
}
}
}