-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathMain.java.patch
More file actions
259 lines (245 loc) · 14.8 KB
/
Main.java.patch
File metadata and controls
259 lines (245 loc) · 14.8 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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
--- a/net/minecraft/server/Main.java
+++ b/net/minecraft/server/Main.java
@@ -64,8 +_,10 @@
@SuppressForbidden(reason = "System.out needed before bootstrap")
@DontObfuscate
- public static void main(String[] args) {
+ public static void main(final OptionSet optionSet) { // CraftBukkit - replaces main(String[] args)
+ io.papermc.paper.log.LogManagerShutdownThread.hook(); // Paper - Improved watchdog support
SharedConstants.tryDetectVersion();
+ /* CraftBukkit start - Replace everything
OptionParser optionParser = new OptionParser();
OptionSpec<Void> optionSpec = optionParser.accepts("nogui");
OptionSpec<Void> optionSpec1 = optionParser.accepts("initSettings", "Initializes 'server.properties' and 'eula.txt', then quits");
@@ -90,41 +_,94 @@
optionParser.printHelpOn(System.err);
return;
}
+ */ // CraftBukkit end
+ try {
- Path path = optionSet.valueOf(optionSpec14);
+ Path path = (Path) optionSet.valueOf("pidFile"); // CraftBukkit
if (path != null) {
writePidFile(path);
}
CrashReport.preload();
- if (optionSet.has(optionSpec13)) {
+ if (optionSet.has("jfrProfile")) { // CraftBukkit
JvmProfiler.INSTANCE.start(Environment.SERVER);
}
+ io.papermc.paper.plugin.PluginInitializerManager.load(optionSet); // Paper
Bootstrap.bootStrap();
Bootstrap.validate();
Util.startTimerHackThread();
Path path1 = Paths.get("server.properties");
- DedicatedServerSettings dedicatedServerSettings = new DedicatedServerSettings(path1);
+ DedicatedServerSettings dedicatedServerSettings = new DedicatedServerSettings(optionSet); // CraftBukkit - CLI argument support
dedicatedServerSettings.forceSave();
RegionFileVersion.configure(dedicatedServerSettings.getProperties().regionFileComression);
Path path2 = Paths.get("eula.txt");
Eula eula = new Eula(path2);
- if (optionSet.has(optionSpec1)) {
+ // Paper start - load config files early for access below if needed
+ org.bukkit.configuration.file.YamlConfiguration bukkitConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) optionSet.valueOf("bukkit-settings"));
+ org.bukkit.configuration.file.YamlConfiguration spigotConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) optionSet.valueOf("spigot-settings"));
+ // Paper end - load config files early for access below if needed
+ if (optionSet.has("initSettings")) { // CraftBukkit
+ // CraftBukkit start - SPIGOT-5761: Create bukkit.yml and commands.yml if not present
+ File configFile = (File) optionSet.valueOf("bukkit-settings");
+ org.bukkit.configuration.file.YamlConfiguration configuration = org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(configFile);
+ configuration.options().copyDefaults(true);
+ configuration.setDefaults(org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(new java.io.InputStreamReader(Main.class.getClassLoader().getResourceAsStream("configurations/bukkit.yml"), java.nio.charset.StandardCharsets.UTF_8)));
+ configuration.save(configFile);
+
+ File commandFile = (File) optionSet.valueOf("commands-settings");
+ org.bukkit.configuration.file.YamlConfiguration commandsConfiguration = org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(commandFile);
+ commandsConfiguration.options().copyDefaults(true);
+ commandsConfiguration.setDefaults(org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(new java.io.InputStreamReader(Main.class.getClassLoader().getResourceAsStream("configurations/commands.yml"), java.nio.charset.StandardCharsets.UTF_8)));
+ commandsConfiguration.save(commandFile);
+ // CraftBukkit end
LOGGER.info("Initialized '{}' and '{}'", path1.toAbsolutePath(), path2.toAbsolutePath());
return;
}
- if (!eula.hasAgreedToEULA()) {
+ // Paper start - eula system property
+ boolean eulaAgreed = Boolean.getBoolean("com.mojang.eula.agree");
+ if (eulaAgreed) {
+ LOGGER.warn("You have used the Paper command line EULA agreement flag.");
+ LOGGER.warn("By using this setting you are indicating your agreement to Mojang's EULA (https://aka.ms/MinecraftEULA).");
+ LOGGER.warn("If you do not agree to the above EULA please stop your server and remove this flag immediately.");
+ }
+ if (!eula.hasAgreedToEULA() && !eulaAgreed) {
+ // Paper end - eula system property
LOGGER.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
return;
}
- File file = new File(optionSet.valueOf(optionSpec9));
- Services services = Services.create(new YggdrasilAuthenticationService(Proxy.NO_PROXY), file);
- String string = Optional.ofNullable(optionSet.valueOf(optionSpec10)).orElse(dedicatedServerSettings.getProperties().levelName);
+ // Paper start - Detect headless JRE
+ String awtException = io.papermc.paper.util.ServerEnvironment.awtDependencyCheck();
+ if (awtException != null) {
+ LOGGER.error("You are using a headless JRE distribution.");
+ LOGGER.error("This distribution is missing certain graphic libraries that the Minecraft server needs to function.");
+ LOGGER.error("For instructions on how to install the non-headless JRE, see https://docs.papermc.io/misc/java-install");
+ LOGGER.error("");
+ LOGGER.error(awtException);
+ return;
+ }
+ // Paper end - Detect headless JRE
+
+ org.spigotmc.SpigotConfig.disabledAdvancements = spigotConfiguration.getStringList("advancements.disabled"); // Paper - fix SPIGOT-5885, must be set early in init
+
+ // Paper start - fix SPIGOT-5824
+ File file;
+ File userCacheFile = new File(Services.USERID_CACHE_FILE);
+ if (optionSet.has("universe")) {
+ file = (File) optionSet.valueOf("universe"); // CraftBukkit
+ userCacheFile = new File(file, Services.USERID_CACHE_FILE);
+ } else {
+ file = new File(bukkitConfiguration.getString("settings.world-container", "."));
+ }
+ // Paper end - fix SPIGOT-5824
+ Services services = Services.create(new com.destroystokyo.paper.profile.PaperAuthenticationService(Proxy.NO_PROXY), file, userCacheFile, optionSet); // Paper - pass OptionSet to load paper config files; override authentication service; fix world-container
+ // CraftBukkit start
+ String string = Optional.ofNullable((String) optionSet.valueOf("world")).orElse(dedicatedServerSettings.getProperties().levelName);
LevelStorageSource levelStorageSource = LevelStorageSource.createDefault(file.toPath());
- LevelStorageSource.LevelStorageAccess levelStorageAccess = levelStorageSource.validateAndCreateAccess(string);
+ LevelStorageSource.LevelStorageAccess levelStorageAccess = levelStorageSource.validateAndCreateAccess(string, LevelStem.OVERWORLD);
+ // CraftBukkit end
Dynamic<?> dataTag;
if (levelStorageAccess.hasWorldData()) {
LevelSummary summary;
@@ -166,12 +_,36 @@
}
Dynamic<?> dynamic = dataTag;
- boolean hasOptionSpec = optionSet.has(optionSpec7);
+ boolean hasOptionSpec = optionSet.has("safeMode"); // CraftBukkit
if (hasOptionSpec) {
LOGGER.warn("Safe mode active, only vanilla datapack will be loaded");
}
PackRepository packRepository = ServerPacksSource.createPackRepository(levelStorageAccess);
+ // CraftBukkit start
+ File bukkitDataPackFolder = new File(levelStorageAccess.getLevelPath(net.minecraft.world.level.storage.LevelResource.DATAPACK_DIR).toFile(), "bukkit");
+ if (!bukkitDataPackFolder.exists()) {
+ bukkitDataPackFolder.mkdirs();
+ }
+ File mcMeta = new File(bukkitDataPackFolder, "pack.mcmeta");
+ try {
+ final var major = SharedConstants.getCurrentVersion().packVersion(net.minecraft.server.packs.PackType.SERVER_DATA).major();
+ final var minor = SharedConstants.getCurrentVersion().packVersion(net.minecraft.server.packs.PackType.SERVER_DATA).minor();
+ com.google.common.io.Files.asCharSink(mcMeta, java.nio.charset.StandardCharsets.UTF_8).write("""
+ {
+ "pack": {
+ "description": "Data pack for resources provided by Bukkit plugins",
+ "min_format": [%d, %d],
+ "max_format": [%d, %d]
+ }
+ }
+ """.formatted(major, minor, major, minor)
+ );
+ } catch (java.io.IOException ex) {
+ throw new RuntimeException("Could not initialize Bukkit datapack", ex);
+ }
+ java.util.concurrent.atomic.AtomicReference<WorldLoader.DataLoadContext> worldLoader = new java.util.concurrent.atomic.AtomicReference<>();
+ // CraftBukkit end
WorldStem worldStem;
try {
@@ -180,6 +_,7 @@
executor -> WorldLoader.load(
initConfig,
context -> {
+ worldLoader.set(context); // CraftBukkit
Registry<LevelStem> registry = context.datapackDimensions().lookupOrThrow(Registries.LEVEL_STEM);
if (dynamic != null) {
LevelDataAndDimensions levelDataAndDimensions = LevelStorageSource.getLevelDataAndDimensions(
@@ -191,7 +_,7 @@
} else {
LOGGER.info("No existing world data, creating new world");
return createNewWorldData(
- dedicatedServerSettings, context, registry, optionSet.has(optionSpec2), optionSet.has(optionSpec3)
+ dedicatedServerSettings, context, registry, optionSet.has("demo"), optionSet.has("bonusChest") // CraftBukkit
);
}
},
@@ -209,6 +_,7 @@
return;
}
+ /*
RegistryAccess.Frozen frozen = worldStem.registries().compositeAccess();
WorldData worldData = worldStem.worldData();
boolean hasOptionSpec1 = optionSet.has(optionSpec6);
@@ -217,22 +_,50 @@
}
levelStorageAccess.saveDataTag(frozen, worldData);
+ */
final DedicatedServer dedicatedServer = MinecraftServer.spin(
thread1 -> {
DedicatedServer dedicatedServer1 = new DedicatedServer(
- thread1, levelStorageAccess, packRepository, worldStem, dedicatedServerSettings, DataFixers.getDataFixer(), services
+ // CraftBukkit start
+ optionSet,
+ worldLoader.get(),
+ thread1,
+ levelStorageAccess,
+ packRepository,
+ worldStem,
+ dedicatedServerSettings,
+ DataFixers.getDataFixer(),
+ services
);
+ /*
dedicatedServer1.setPort(optionSet.valueOf(optionSpec11));
- dedicatedServer1.setDemo(optionSet.has(optionSpec2));
+ */
+ // Paper start
+ if (optionSet.has("serverId")) {
+ dedicatedServer1.setId((String) optionSet.valueOf("serverId"));
+ }
+ dedicatedServer1.setDemo(optionSet.has("demo"));
+ // Paper end
+ /*
dedicatedServer1.setId(optionSet.valueOf(optionSpec12));
- boolean flag = !optionSet.has(optionSpec) && !optionSet.valuesOf(optionSpec15).contains("nogui");
+ */
+ boolean flag = !optionSet.has("nogui") && !optionSet.nonOptionArguments().contains("nogui");
if (flag && !GraphicsEnvironment.isHeadless()) {
dedicatedServer1.showGui();
}
+ // Paper start
+ if (optionSet.has("port")) {
+ int port = (Integer) optionSet.valueOf("port");
+ if (port > 0) {
+ dedicatedServer1.setPort(port);
+ }
+ }
+ // Paper end
return dedicatedServer1;
}
);
+ /* CraftBukkit start
Thread thread = new Thread("Server Shutdown Thread") {
@Override
public void run() {
@@ -241,12 +_,13 @@
};
thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER));
Runtime.getRuntime().addShutdownHook(thread);
+ */ // CraftBukkit end
} catch (Throwable var42) {
LOGGER.error(LogUtils.FATAL_MARKER, "Failed to start the minecraft server", var42);
}
}
- private static WorldLoader.DataLoadOutput<WorldData> createNewWorldData(
+ public static WorldLoader.DataLoadOutput<WorldData> createNewWorldData( // Paper - public
DedicatedServerSettings settings, WorldLoader.DataLoadContext context, Registry<LevelStem> stemRegistry, boolean demo, boolean generateBonusChest
) {
LevelSettings levelSettings;
@@ -314,7 +_,7 @@
RegistryAccess registryAccess,
boolean recreateRegionFiles
) {
- LOGGER.info("Forcing world upgrade!");
+ LOGGER.info("Forcing world upgrade! {}", levelStorage.getLevelId()); // CraftBukkit
try (WorldUpgrader worldUpgrader = new WorldUpgrader(levelStorage, dataFixer, worldData, registryAccess, eraseCache, recreateRegionFiles)) {
Component component = null;