-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.java
202 lines (164 loc) · 8.8 KB
/
Main.java
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package org.bukkit.craftbukkit;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import net.minecraft.server.MinecraftServer;
public class Main {
public static boolean useJline = true;
public static boolean useConsole = true;
public static void main(String[] args) {
// Todo: Installation script
OptionParser parser = new OptionParser() {
{
acceptsAll(asList("?", "help"), "Show the help");
acceptsAll(asList("c", "config"), "Properties file to use")
.withRequiredArg()
.ofType(File.class)
.defaultsTo(new File("server.properties"))
.describedAs("Properties file");
acceptsAll(asList("P", "plugins"), "Plugin directory to use")
.withRequiredArg()
.ofType(File.class)
.defaultsTo(new File("plugins"))
.describedAs("Plugin directory");
acceptsAll(asList("h", "host", "server-ip"), "Host to listen on")
.withRequiredArg()
.ofType(String.class)
.describedAs("Hostname or IP");
acceptsAll(asList("W", "world-dir", "universe", "world-container"), "World container")
.withRequiredArg()
.ofType(File.class)
.describedAs("Directory containing worlds");
acceptsAll(asList("w", "world", "level-name"), "World name")
.withRequiredArg()
.ofType(String.class)
.describedAs("World name");
acceptsAll(asList("p", "port", "server-port"), "Port to listen on")
.withRequiredArg()
.ofType(Integer.class)
.describedAs("Port");
acceptsAll(asList("o", "online-mode"), "Whether to use online authentication")
.withRequiredArg()
.ofType(Boolean.class)
.describedAs("Authentication");
acceptsAll(asList("s", "size", "max-players"), "Maximum amount of players")
.withRequiredArg()
.ofType(Integer.class)
.describedAs("Server size");
acceptsAll(asList("d", "date-format"), "Format of the date to display in the console (for log entries)")
.withRequiredArg()
.ofType(SimpleDateFormat.class)
.describedAs("Log date format");
acceptsAll(asList("log-pattern"), "Specfies the log filename pattern")
.withRequiredArg()
.ofType(String.class)
.defaultsTo("server.log")
.describedAs("Log filename");
acceptsAll(asList("log-limit"), "Limits the maximum size of the log file (0 = unlimited)")
.withRequiredArg()
.ofType(Integer.class)
.defaultsTo(0)
.describedAs("Max log size");
acceptsAll(asList("log-count"), "Specified how many log files to cycle through")
.withRequiredArg()
.ofType(Integer.class)
.defaultsTo(1)
.describedAs("Log count");
acceptsAll(asList("log-append"), "Whether to append to the log file")
.withRequiredArg()
.ofType(Boolean.class)
.defaultsTo(true)
.describedAs("Log append");
acceptsAll(asList("log-strip-color"), "Strips color codes from log file");
acceptsAll(asList("b", "bukkit-settings"), "File for bukkit settings")
.withRequiredArg()
.ofType(File.class)
.defaultsTo(new File("bukkit.yml"))
.describedAs("Yml file");
acceptsAll(asList("C", "commands-settings"), "File for command settings")
.withRequiredArg()
.ofType(File.class)
.defaultsTo(new File("commands.yml"))
.describedAs("Yml file");
acceptsAll(asList("nojline"), "Disables jline and emulates the vanilla console");
acceptsAll(asList("noconsole"), "Disables the console");
acceptsAll(asList("v", "version"), "Show the CraftBukkit Version");
acceptsAll(asList("demo"), "Demo mode");
}
};
OptionSet options = null;
try {
options = parser.parse(args);
} catch (joptsimple.OptionException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage());
}
if ((options == null) || (options.has("?"))) {
try {
parser.printHelpOn(System.out);
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (options.has("v")) {
System.out.println(CraftServer.class.getPackage().getImplementationVersion());
} else {
// Do you love Java using + and ! as string based identifiers? I sure do!
String path = new File(".").getAbsolutePath();
if (path.contains("!") || path.contains("+")) {
System.err.println("Cannot run server in a directory with ! or + in the pathname. Please rename the affected folders and try again.");
return;
}
float javaVersion = Float.parseFloat(System.getProperty("java.class.version"));
if (javaVersion > 55.0) {
System.err.println("Unsupported Java detected (" + javaVersion + "). Only up to Java 11 is supported.");
return;
}
try {
// This trick bypasses Maven Shade's clever rewriting of our getProperty call when using String literals
String jline_UnsupportedTerminal = new String(new char[] {'j','l','i','n','e','.','U','n','s','u','p','p','o','r','t','e','d','T','e','r','m','i','n','a','l'});
String jline_terminal = new String(new char[] {'j','l','i','n','e','.','t','e','r','m','i','n','a','l'});
useJline = !(jline_UnsupportedTerminal).equals(System.getProperty(jline_terminal));
if (options.has("nojline")) {
System.setProperty("user.language", "en");
useJline = false;
}
if (useJline) {
AnsiConsole.systemInstall();
} else {
// This ensures the terminal literal will always match the jline implementation
System.setProperty(jline.TerminalFactory.JLINE_TERMINAL, jline.UnsupportedTerminal.class.getName());
}
if (options.has("noconsole")) {
useConsole = false;
}
if (Main.class.getPackage().getImplementationVendor() != null && System.getProperty("IReallyKnowWhatIAmDoingISwear") == null) {
Date buildDate = new SimpleDateFormat("yyyyMMdd-HHmm").parse(Main.class.getPackage().getImplementationVendor());
Calendar deadline = Calendar.getInstance();
deadline.add(Calendar.DAY_OF_YEAR, -3);
if (buildDate.before(deadline.getTime())) {
System.err.println("*** Error, this build is outdated ***");
System.err.println("*** Please download a new build as per instructions from https://www.spigotmc.org/ ***");
System.err.println("*** Server will start in 15 seconds ***");
Thread.sleep(TimeUnit.SECONDS.toMillis(15));
}
}
System.err.println("*** WARNING: This is a development build. It is not meant for production server usage! Please keep backups and update frequently.");
System.out.println("Loading libraries, please wait...");
MinecraftServer.main(options);
} catch (Throwable t) {
t.printStackTrace();
}
}
}
private static List<String> asList(String... params) {
return Arrays.asList(params);
}
}