aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower-stripped/net/minecraft/server/Main.java.patch
blob: 9a3e9694d6457412be1cccd74b69e4ef4e333096 (plain)
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
--- a/net/minecraft/server/Main.java
+++ b/net/minecraft/server/Main.java
@@ -59,28 +60,37 @@
 import net.minecraft.world.level.storage.WorldData;
 import org.slf4j.Logger;
 
+// CraftBukkit start
+import com.google.common.base.Charsets;
+import java.io.InputStreamReader;
+import java.util.concurrent.atomic.AtomicReference;
+import net.minecraft.SharedConstants;
+import org.bukkit.configuration.file.YamlConfiguration;
+// CraftBukkit end
+
 public class Main {
     private static final Logger LOGGER = LogUtils.getLogger();
 
     @DontObfuscate
-    public static void main(String[] args) {
+    public static void main(final OptionSet optionset) { // CraftBukkit - replaces main(String[] astring)
         SharedConstants.tryDetectVersion();
-        OptionParser optionParser = new OptionParser();
-        OptionSpec<Void> optionSpec = optionParser.accepts("nogui");
-        OptionSpec<Void> optionSpec1 = optionParser.accepts("initSettings", "Initializes 'server.properties' and 'eula.txt', then quits");
-        OptionSpec<Void> optionSpec2 = optionParser.accepts("demo");
-        OptionSpec<Void> optionSpec3 = optionParser.accepts("bonusChest");
-        OptionSpec<Void> optionSpec4 = optionParser.accepts("forceUpgrade");
-        OptionSpec<Void> optionSpec5 = optionParser.accepts("eraseCache");
-        OptionSpec<Void> optionSpec6 = optionParser.accepts("safeMode", "Loads level with vanilla datapack only");
-        OptionSpec<Void> optionSpec7 = optionParser.accepts("help").forHelp();
-        OptionSpec<String> optionSpec8 = optionParser.accepts("universe").withRequiredArg().defaultsTo(".");
-        OptionSpec<String> optionSpec9 = optionParser.accepts("world").withRequiredArg();
-        OptionSpec<Integer> optionSpec10 = optionParser.accepts("port").withRequiredArg().ofType(Integer.class).defaultsTo(-1);
-        OptionSpec<String> optionSpec11 = optionParser.accepts("serverId").withRequiredArg();
-        OptionSpec<Void> optionSpec12 = optionParser.accepts("jfrProfile");
-        OptionSpec<Path> optionSpec13 = optionParser.accepts("pidFile").withRequiredArg().withValuesConvertedBy(new PathConverter());
-        OptionSpec<String> optionSpec14 = optionParser.nonOptions();
+        /* 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");
+        OptionSpec<Void> optionspec2 = optionparser.accepts("demo");
+        OptionSpec<Void> optionspec3 = optionparser.accepts("bonusChest");
+        OptionSpec<Void> optionspec4 = optionparser.accepts("forceUpgrade");
+        OptionSpec<Void> optionspec5 = optionparser.accepts("eraseCache");
+        OptionSpec<Void> optionspec6 = optionparser.accepts("safeMode", "Loads level with vanilla datapack only");
+        OptionSpec<Void> optionspec7 = optionparser.accepts("help").forHelp();
+        OptionSpec<String> optionspec8 = optionparser.accepts("universe").withRequiredArg().defaultsTo(".", new String[0]);
+        OptionSpec<String> optionspec9 = optionparser.accepts("world").withRequiredArg();
+        OptionSpec<Integer> optionspec10 = optionparser.accepts("port").withRequiredArg().ofType(Integer.class).defaultsTo(-1, new Integer[0]);
+        OptionSpec<String> optionspec11 = optionparser.accepts("serverId").withRequiredArg();
+        OptionSpec<Void> optionspec12 = optionparser.accepts("jfrProfile");
+        OptionSpec<Path> optionspec13 = optionparser.accepts("pidFile").withRequiredArg().withValuesConvertedBy(new PathConverter(new PathProperties[0]));
+        NonOptionArgumentSpec nonoptionargumentspec = optionparser.nonOptions();
 
         try {
             OptionSet optionSet = optionParser.parse(args);
@@ -88,14 +102,18 @@
                 optionParser.printHelpOn(System.err);
                 return;
             }
+            */ // CraftBukkit end
 
-            Path path = optionSet.valueOf(optionSpec13);
+        try {
+
+            Path path = (Path) optionset.valueOf("pidFile"); // CraftBukkit
+
             if (path != null) {
                 writePidFile(path);
             }
 
             CrashReport.preload();
-            if (optionSet.has(optionSpec12)) {
+            if (optionset.has("jfrProfile")) { // CraftBukkit
                 JvmProfiler.INSTANCE.start(Environment.SERVER);
             }
 
@@ -103,12 +121,27 @@
             Bootstrap.validate();
             Util.startTimerHackThread();
             Path path1 = Paths.get("server.properties");
-            DedicatedServerSettings dedicatedServerSettings = new DedicatedServerSettings(path1);
-            dedicatedServerSettings.forceSave();
+            DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(optionset); // CraftBukkit - CLI argument support
+
+            dedicatedserversettings.forceSave();
             Path path2 = Paths.get("eula.txt");
             Eula eula = new Eula(path2);
-            if (optionSet.has(optionSpec1)) {
-                LOGGER.info("Initialized '{}' and '{}'", path1.toAbsolutePath(), path2.toAbsolutePath());
+
+            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");
+                YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile);
+                configuration.options().copyDefaults(true);
+                configuration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(Main.class.getClassLoader().getResourceAsStream("configurations/bukkit.yml"), Charsets.UTF_8)));
+                configuration.save(configFile);
+
+                File commandFile = (File) optionset.valueOf("commands-settings");
+                YamlConfiguration commandsConfiguration = YamlConfiguration.loadConfiguration(commandFile);
+                commandsConfiguration.options().copyDefaults(true);
+                commandsConfiguration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(Main.class.getClassLoader().getResourceAsStream("configurations/commands.yml"), Charsets.UTF_8)));
+                commandsConfiguration.save(commandFile);
+                // CraftBukkit end
+                Main.LOGGER.info("Initialized '{}' and '{}'", path1.toAbsolutePath(), path2.toAbsolutePath());
                 return;
             }
 
@@ -117,14 +150,18 @@
                 return;
             }
 
-            File file = new File(optionSet.valueOf(optionSpec8));
+            File file = (File) optionset.valueOf("universe"); // CraftBukkit
             Services services = Services.create(new YggdrasilAuthenticationService(Proxy.NO_PROXY), file);
-            String string = Optional.ofNullable(optionSet.valueOf(optionSpec9)).orElse(dedicatedServerSettings.getProperties().levelName);
-            LevelStorageSource levelStorageSource = LevelStorageSource.createDefault(file.toPath());
-            LevelStorageSource.LevelStorageAccess levelStorageAccess = levelStorageSource.validateAndCreateAccess(string);
-            Dynamic<?> dataTag;
-            if (levelStorageAccess.hasWorldData()) {
-                LevelSummary summary;
+            // CraftBukkit start
+            String s = (String) Optional.ofNullable((String) optionset.valueOf("world")).orElse(dedicatedserversettings.getProperties().levelName);
+            LevelStorageSource convertable = LevelStorageSource.createDefault(file.toPath());
+            LevelStorageSource.LevelStorageAccess convertable_conversionsession = convertable.validateAndCreateAccess(s, LevelStem.OVERWORLD);
+            // CraftBukkit end
+            Dynamic dynamic;
+
+            if (convertable_conversionsession.hasWorldData()) {
+                LevelSummary worldinfo;
+
                 try {
                     dataTag = levelStorageAccess.getDataTag();
                     summary = levelStorageAccess.getSummary(dataTag);
@@ -162,72 +196,73 @@
                 dataTag = null;
             }
 
-            Dynamic<?> dynamic = dataTag;
-            boolean hasOptionSpec = optionSet.has(optionSpec6);
-            if (hasOptionSpec) {
-                LOGGER.warn("Safe mode active, only vanilla datapack will be loaded");
+            Dynamic<?> dynamic1 = dynamic;
+            boolean flag = optionset.has("safeMode"); // CraftBukkit
+
+            if (flag) {
+                Main.LOGGER.warn("Safe mode active, only vanilla datapack will be loaded");
             }
 
-            PackRepository packRepository = ServerPacksSource.createPackRepository(levelStorageAccess);
+            PackRepository resourcepackrepository = ServerPacksSource.createPackRepository(convertable_conversionsession);
+            // CraftBukkit start
+            File bukkitDataPackFolder = new File(convertable_conversionsession.getLevelPath(LevelResource.DATAPACK_DIR).toFile(), "bukkit");
+            if (!bukkitDataPackFolder.exists()) {
+                bukkitDataPackFolder.mkdirs();
+            }
+            File mcMeta = new File(bukkitDataPackFolder, "pack.mcmeta");
+            try {
+                com.google.common.io.Files.write("{\n"
+                        + "    \"pack\": {\n"
+                        + "        \"description\": \"Data pack for resources provided by Bukkit plugins\",\n"
+                        + "        \"pack_format\": " + SharedConstants.getCurrentVersion().getPackVersion(PackType.SERVER_DATA) + "\n"
+                        + "    }\n"
+                        + "}\n", mcMeta, com.google.common.base.Charsets.UTF_8);
+            } catch (java.io.IOException ex) {
+                throw new RuntimeException("Could not initialize Bukkit datapack", ex);
+            }
+            AtomicReference<WorldLoader.a> worldLoader = new AtomicReference<>();
+            // CraftBukkit end
 
             WorldStem worldStem;
             try {
-                WorldLoader.InitConfig initConfig = loadOrCreateConfig(dedicatedServerSettings.getProperties(), dynamic, hasOptionSpec, packRepository);
-                worldStem = Util.<WorldStem>blockUntilDone(
-                        executor -> WorldLoader.load(
-                                initConfig,
-                                context -> {
-                                    Registry<LevelStem> registry = context.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM);
-                                    if (dynamic != null) {
-                                        LevelDataAndDimensions levelDataAndDimensions = LevelStorageSource.getLevelDataAndDimensions(
-                                            dynamic, context.dataConfiguration(), registry, context.datapackWorldgen()
-                                        );
-                                        return new WorldLoader.DataLoadOutput<>(
-                                            levelDataAndDimensions.worldData(), levelDataAndDimensions.dimensions().dimensionsRegistryAccess()
-                                        );
-                                    } else {
-                                        LOGGER.info("No existing world data, creating new world");
-                                        LevelSettings levelSettings;
-                                        WorldOptions worldOptions;
-                                        WorldDimensions worldDimensions;
-                                        if (optionSet.has(optionSpec2)) {
-                                            levelSettings = MinecraftServer.DEMO_SETTINGS;
-                                            worldOptions = WorldOptions.DEMO_OPTIONS;
-                                            worldDimensions = WorldPresets.createNormalWorldDimensions(context.datapackWorldgen());
-                                        } else {
-                                            DedicatedServerProperties properties = dedicatedServerSettings.getProperties();
-                                            levelSettings = new LevelSettings(
-                                                properties.levelName,
-                                                properties.gamemode,
-                                                properties.hardcore,
-                                                properties.difficulty,
-                                                false,
-                                                new GameRules(),
-                                                context.dataConfiguration()
-                                            );
-                                            worldOptions = optionSet.has(optionSpec3) ? properties.worldOptions.withBonusChest(true) : properties.worldOptions;
-                                            worldDimensions = properties.createDimensions(context.datapackWorldgen());
-                                        }
-            
-                                        WorldDimensions.Complete complete = worldDimensions.bake(registry);
-                                        Lifecycle lifecycle = complete.lifecycle().add(context.datapackWorldgen().allRegistriesLifecycle());
-                                        return new WorldLoader.DataLoadOutput<>(
-                                            new PrimaryLevelData(levelSettings, worldOptions, complete.specialWorldProperty(), lifecycle),
-                                            complete.dimensionsRegistryAccess()
-                                        );
-                                    }
-                                },
-                                WorldStem::new,
-                                Util.backgroundExecutor(),
-                                executor
-                            )
-                    )
-                    .get();
-            } catch (Exception var37) {
-                LOGGER.warn(
-                    "Failed to load datapacks, can't proceed with server load. You can either fix your datapacks or reset to vanilla with --safeMode",
-                    (Throwable)var37
-                );
+                WorldLoader.c worldloader_c = loadOrCreateConfig(dedicatedserversettings.getProperties(), dynamic1, flag, resourcepackrepository);
+
+                worldstem = (WorldStem) Util.blockUntilDone((executor) -> {
+                    return WorldLoader.load(worldloader_c, (worldloader_a) -> {
+                        worldLoader.set(worldloader_a); // CraftBukkit
+                        Registry<LevelStem> iregistry = worldloader_a.datapackDimensions().registryOrThrow(Registries.LEVEL_STEM);
+
+                        if (dynamic1 != null) {
+                            LevelDataAndDimensions leveldataanddimensions = LevelStorageSource.getLevelDataAndDimensions(dynamic1, worldloader_a.dataConfiguration(), iregistry, worldloader_a.datapackWorldgen());
+
+                            return new WorldLoader.b<>(leveldataanddimensions.worldData(), leveldataanddimensions.dimensions().dimensionsRegistryAccess());
+                        } else {
+                            Main.LOGGER.info("No existing world data, creating new world");
+                            LevelSettings worldsettings;
+                            WorldOptions worldoptions;
+                            WorldDimensions worlddimensions;
+
+                            if (optionset.has("demo")) { // CraftBukkit
+                                worldsettings = MinecraftServer.DEMO_SETTINGS;
+                                worldoptions = WorldOptions.DEMO_OPTIONS;
+                                worlddimensions = WorldPresets.createNormalWorldDimensions(worldloader_a.datapackWorldgen());
+                            } else {
+                                DedicatedServerProperties dedicatedserverproperties = dedicatedserversettings.getProperties();
+
+                                worldsettings = new LevelSettings(dedicatedserverproperties.levelName, dedicatedserverproperties.gamemode, dedicatedserverproperties.hardcore, dedicatedserverproperties.difficulty, false, new GameRules(), worldloader_a.dataConfiguration());
+                                worldoptions = optionset.has("bonusChest") ? dedicatedserverproperties.worldOptions.withBonusChest(true) : dedicatedserverproperties.worldOptions; // CraftBukkit
+                                worlddimensions = dedicatedserverproperties.createDimensions(worldloader_a.datapackWorldgen());
+                            }
+
+                            WorldDimensions.b worlddimensions_b = worlddimensions.bake(iregistry);
+                            Lifecycle lifecycle = worlddimensions_b.lifecycle().add(worldloader_a.datapackWorldgen().allRegistriesLifecycle());
+
+                            return new WorldLoader.b<>(new PrimaryLevelData(worldsettings, worldoptions, worlddimensions_b.specialWorldProperty(), lifecycle), worlddimensions_b.dimensionsRegistryAccess());
+                        }
+                    }, WorldStem::new, Util.backgroundExecutor(), executor);
+                }).get();
+            } catch (Exception exception) {
+                Main.LOGGER.warn("Failed to load datapacks, can't proceed with server load. You can either fix your datapacks or reset to vanilla with --safeMode", exception);
                 return;
             }
 
@@ -262,7 +300,10 @@
     
                     return dedicatedServer1;
                 }
-            );
+
+                return dedicatedserver1;
+            });
+            /* CraftBukkit start
             Thread thread = new Thread("Server Shutdown Thread") {
                 @Override
                 public void run() {
@@ -271,8 +312,9 @@
             };
             thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER));
             Runtime.getRuntime().addShutdownHook(thread);
-        } catch (Exception var40) {
-            LOGGER.error(LogUtils.FATAL_MARKER, "Failed to start the minecraft server", (Throwable)var40);
+            */ // CraftBukkit end
+        } catch (Exception exception1) {
+            Main.LOGGER.error(LogUtils.FATAL_MARKER, "Failed to start the minecraft server", exception1);
         }
     }
 
@@ -303,16 +348,10 @@
         return new WorldLoader.InitConfig(packConfig, Commands.CommandSelection.DEDICATED, dedicatedServerProperties.functionPermissionLevel);
     }
 
-    private static void forceUpgrade(
-        LevelStorageSource.LevelStorageAccess levelStorage,
-        DataFixer dataFixer,
-        boolean eraseCache,
-        BooleanSupplier upgradeWorld,
-        Registry<LevelStem> dimesions
-    ) {
-        LOGGER.info("Forcing world upgrade!");
-        WorldUpgrader worldUpgrader = new WorldUpgrader(levelStorage, dataFixer, dimesions, eraseCache);
-        Component component = null;
+    public static void forceUpgrade(LevelStorageSource.LevelStorageAccess levelStorage, DataFixer dataFixer, boolean eraseCache, BooleanSupplier upgradeWorld, Registry<LevelStem> dimesions) {
+        Main.LOGGER.info("Forcing world upgrade! {}", levelStorage.getLevelId()); // CraftBukkit
+        WorldUpgrader worldupgrader = new WorldUpgrader(levelStorage, dataFixer, dimesions, eraseCache);
+        Component ichatbasecomponent = null;
 
         while (!worldUpgrader.isFinished()) {
             Component status = worldUpgrader.getStatus();