-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathMain.java.patch
More file actions
291 lines (277 loc) · 16.5 KB
/
Main.java.patch
File metadata and controls
291 lines (277 loc) · 16.5 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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
--- a/net/minecraft/server/Main.java
+++ b/net/minecraft/server/Main.java
@@ -63,8 +_,10 @@
private static final Logger LOGGER = LogUtils.getLogger();
@SuppressForbidden(reason = "System.out needed before bootstrap")
- public static void main(final String[] args) {
+ public static void main(final OptionSet options) { // CraftBukkit - replaces main(String[] args)
+ io.papermc.paper.log.LogManagerShutdownThread.hook(); // Paper - Improved watchdog support
SharedConstants.tryDetectVersion();
+ /* CraftBukkit start - Replace everything
OptionParser parser = new OptionParser();
OptionSpec<Void> nogui = parser.accepts("nogui");
OptionSpec<Void> initSettings = parser.accepts("initSettings", "Initializes 'server.properties' and 'eula.txt', then quits");
@@ -89,39 +_,96 @@
parser.printHelpOn(System.err);
return;
}
+ */ // CraftBukkit end
+ try {
- Path pidFilePath = options.valueOf(pidFile);
+ Path pidFilePath = (Path) options.valueOf("pidFile"); // CraftBukkit
if (pidFilePath != null) {
writePidFile(pidFilePath);
}
CrashReport.preload();
- if (options.has(jfrProfilingOption)) {
+ if (options.has("jfrProfile")) { // CraftBukkit
JvmProfiler.INSTANCE.start(Environment.SERVER);
}
+ io.papermc.paper.plugin.PluginInitializerManager.load(options); // Paper
Bootstrap.bootStrap();
Bootstrap.validate();
Util.startTimerHackThread();
Path settingsFile = Paths.get("server.properties");
- DedicatedServerSettings settings = new DedicatedServerSettings(settingsFile);
+ DedicatedServerSettings settings = new DedicatedServerSettings(options); // CraftBukkit - CLI argument support
settings.forceSave();
+ // Paper start
+ if (options.has("forceUpgrade") || options.has("recreateRegionFiles")) {
+ LOGGER.error("World upgrade and region file recreation are not yet implemented in Paper 26.1.");
+ return;
+ }
+ // Paper end
RegionFileVersion.configure(settings.getProperties().regionFileComression);
Path eulaFile = Paths.get("eula.txt");
Eula eula = new Eula(eulaFile);
- if (options.has(initSettings)) {
+ // Paper start - load config files early for access below if needed
+ org.bukkit.configuration.file.YamlConfiguration bukkitConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) options.valueOf("bukkit-settings"));
+ org.bukkit.configuration.file.YamlConfiguration spigotConfiguration = io.papermc.paper.configuration.PaperConfigurations.loadLegacyConfigFile((File) options.valueOf("spigot-settings"));
+ // Paper end - load config files early for access below if needed
+ if (options.has("initSettings")) { // CraftBukkit
+ // CraftBukkit start - SPIGOT-5761: Create bukkit.yml and commands.yml if not present
+ File configFile = (File) options.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) options.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 '{}'", settingsFile.toAbsolutePath(), eulaFile.toAbsolutePath());
return;
}
- if (!eula.hasAgreedToEULA()) {
+ // Spigot start
+ boolean eulaAgreed = Boolean.getBoolean("com.mojang.eula.agree");
+ if (eulaAgreed) {
+ LOGGER.error("You have used the Spigot command line EULA agreement flag.");
+ LOGGER.error("By using this setting you are indicating your agreement to Mojang's EULA (https://aka.ms/MinecraftEULA).");
+ LOGGER.error("If you do not agree to the above EULA please stop your server and remove this flag immediately.");
+ }
+ if (!eula.hasAgreedToEULA() && !eulaAgreed) {
+ // Spigot end
LOGGER.info("You need to agree to the EULA in order to run the server. Go to eula.txt for more info.");
return;
}
- File universePath = new File(options.valueOf(universe));
- Services services = Services.create(new YggdrasilAuthenticationService(Proxy.NO_PROXY), universePath);
- String levelName = Optional.ofNullable(options.valueOf(worldName)).orElse(settings.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 universePath;
+ File userCacheFile = new File(Services.USERID_CACHE_FILE);
+ if (options.has("universe")) {
+ universePath = (File) options.valueOf("universe"); // CraftBukkit
+ userCacheFile = new File(universePath, Services.USERID_CACHE_FILE);
+ } else {
+ universePath = 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), universePath, userCacheFile, options); // Paper - pass OptionSet to load paper config files; override authentication service; fix world-container
+ String levelName = Optional.ofNullable((String) options.valueOf("world")).orElse(settings.getProperties().levelName); // CraftBukkit
LevelStorageSource levelStorageSource = LevelStorageSource.createDefault(universePath.toPath());
LevelStorageSource.LevelStorageAccess access = levelStorageSource.validateAndCreateAccess(levelName);
Dynamic<?> levelDataTag;
@@ -149,13 +_,38 @@
} else {
levelDataTag = null;
}
+ io.papermc.paper.world.migration.WorldFolderMigration.didInitialLoad = true; // Paper
- boolean safeModeEnabled = options.has(safeMode);
+ boolean safeModeEnabled = options.has("safeMode"); // CraftBukkit
if (safeModeEnabled) {
LOGGER.warn("Safe mode active, only vanilla datapack will be loaded");
}
PackRepository packRepository = ServerPacksSource.createPackRepository(access);
+ // CraftBukkit start
+ File bukkitDataPackFolder = new File(access.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 {
@@ -164,17 +_,31 @@
executor -> WorldLoader.load(
worldLoadConfig,
context -> {
+ worldLoader.set(context); // CraftBukkit
Registry<LevelStem> datapackDimensions = context.datapackDimensions().lookupOrThrow(Registries.LEVEL_STEM);
if (levelDataTag != null) {
+ // Paper start - migrate startup world
+ try {
+ io.papermc.paper.world.migration.WorldFolderMigration.migrateStartupWorld(
+ access,
+ context.datapackWorldgen(),
+ levelName,
+ LevelStem.OVERWORLD,
+ io.papermc.paper.world.PaperWorldLoader.dimensionKey(LevelStem.OVERWORLD)
+ );
+ } catch (final IOException ex) {
+ throw new UncheckedIOException("Failed to migrate world storage for " + LevelStem.OVERWORLD.identifier(), ex);
+ }
+ // Paper end - migrate startup world
LevelDataAndDimensions worldData = LevelStorageSource.getLevelDataAndDimensions(
- access, levelDataTag, context.dataConfiguration(), datapackDimensions, context.datapackWorldgen()
+ access, levelDataTag, context.dataConfiguration(), datapackDimensions, context.datapackWorldgen(), net.minecraft.world.level.Level.OVERWORLD // Paper
);
return new WorldLoader.DataLoadOutput<>(
worldData.worldDataAndGenSettings(), worldData.dimensions().dimensionsRegistryAccess()
);
} else {
LOGGER.info("No existing world data, creating new world");
- return createNewWorldData(settings, context, datapackDimensions, options.has(demo), options.has(bonusChest));
+ return createNewWorldData(settings, context, datapackDimensions, options.has("demo"), options.has("bonusChest")); // CraftBukkit
}
},
WorldStem::new,
@@ -191,6 +_,7 @@
return;
}
+ /*
RegistryAccess.Frozen registryHolder = worldStem.registries().compositeAccess();
WorldData data = worldStem.worldDataAndGenSettings().data();
boolean recreateRegionFilesValue = options.has(recreateRegionFiles);
@@ -199,22 +_,51 @@
}
access.saveDataTag(data);
+ */
final DedicatedServer dedicatedServer = MinecraftServer.spin(
thread -> {
DedicatedServer server = new DedicatedServer(
- thread, access, packRepository, worldStem, Optional.empty(), settings, DataFixers.getDataFixer(), services
+ // CraftBukkit start
+ options,
+ worldLoader.get(),
+ thread,
+ access,
+ packRepository,
+ worldStem,
+ Optional.empty(),
+ settings,
+ DataFixers.getDataFixer(),
+ services
);
+ /*
server.setPort(options.valueOf(port));
- server.setDemo(options.has(demo));
+ */
+ // Paper start
+ if (options.has("serverId")) {
+ server.setId((String) options.valueOf("serverId"));
+ }
+ server.setDemo(options.has("demo"));
+ // Paper end
+ /*
server.setId(options.valueOf(serverId));
- boolean gui = !options.has(nogui) && !options.valuesOf(nonOptions).contains("nogui");
+ */
+ boolean gui = !options.has("nogui") && !options.nonOptionArguments().contains("nogui");
if (gui && !GraphicsEnvironment.isHeadless()) {
server.showGui();
}
+ // Paper start
+ if (options.has("port")) {
+ int port = (Integer) options.valueOf("port");
+ if (port > 0) {
+ server.setPort(port);
+ }
+ }
+ // Paper end
return server;
}
);
+ /* CraftBukkit start
Thread shutdownThread = new Thread("Server Shutdown Thread") {
@Override
public void run() {
@@ -223,12 +_,13 @@
};
shutdownThread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER));
Runtime.getRuntime().addShutdownHook(shutdownThread);
+ */ // CraftBukkit end
} catch (Throwable var40) {
LOGGER.error(LogUtils.FATAL_MARKER, "Failed to start the minecraft server", var40);
}
}
- private static WorldLoader.DataLoadOutput<LevelDataAndDimensions.WorldDataAndGenSettings> createNewWorldData(
+ public static WorldLoader.DataLoadOutput<LevelDataAndDimensions.WorldDataAndGenSettings> createNewWorldData( // Paper - public
final DedicatedServerSettings settings,
final WorldLoader.DataLoadContext context,
final Registry<LevelStem> datapackDimensions,
@@ -299,7 +_,11 @@
final RegistryAccess registryAccess,
final boolean recreateRegionFiles
) {
- LOGGER.info("Forcing world upgrade!");
+ throw new UnsupportedOperationException(
+ "World upgrade and region file recreation are not yet implemented in Paper 26.1."
+ );
+ /*
+ LOGGER.info("Forcing world upgrade! {}", storageSource.getLevelId()); // CraftBukkit
try (WorldUpgrader upgrader = new WorldUpgrader(storageSource, fixerUpper, registryAccess, eraseCache, recreateRegionFiles)) {
Component lastStatus = null;
@@ -327,5 +_,6 @@
}
}
}
+ */
}
}