Commits
DerFrZocker authored and md_5 committed 6c8a0961188
1 1 | --- a/net/minecraft/server/Main.java |
2 2 | +++ b/net/minecraft/server/Main.java |
3 - | |
3 + | |
4 4 | import net.minecraft.world.level.storage.WorldInfo; |
5 5 | import org.slf4j.Logger; |
6 6 | |
7 7 | +// CraftBukkit start |
8 + | +import com.google.common.base.Charsets; |
9 + | +import java.io.InputStreamReader; |
8 10 | +import java.util.concurrent.atomic.AtomicReference; |
9 11 | +import net.minecraft.SharedConstants; |
10 12 | +import net.minecraft.world.level.dimension.WorldDimension; |
13 + | +import org.bukkit.configuration.file.YamlConfiguration; |
11 14 | +// CraftBukkit end |
12 15 | + |
13 16 | public class Main { |
14 17 | |
15 18 | private static final Logger LOGGER = LogUtils.getLogger(); |
16 - | |
19 + | |
17 20 | public Main() {} |
18 21 | |
19 22 | @DontObfuscate |
20 23 | - public static void main(String[] astring) { |
21 24 | + public static void main(final OptionSet optionset) { // CraftBukkit - replaces main(String[] astring) |
22 25 | SharedConstants.tryDetectVersion(); |
23 26 | + /* CraftBukkit start - Replace everything |
24 27 | OptionParser optionparser = new OptionParser(); |
25 28 | OptionSpec<Void> optionspec = optionparser.accepts("nogui"); |
26 29 | OptionSpec<Void> optionspec1 = optionparser.accepts("initSettings", "Initializes 'server.properties' and 'eula.txt', then quits"); |
27 - | |
30 + | |
28 31 | optionparser.printHelpOn(System.err); |
29 32 | return; |
30 33 | } |
31 34 | + */ // CraftBukkit end |
32 35 | + |
33 36 | + try { |
34 37 | |
35 38 | CrashReport.preload(); |
36 39 | - if (optionset.has(optionspec13)) { |
37 40 | + if (optionset.has("jfrProfile")) { // CraftBukkit |
38 41 | JvmProfiler.INSTANCE.start(Environment.SERVER); |
39 42 | } |
40 43 | |
41 - | |
44 + | |
42 45 | DispenserRegistry.validate(); |
43 46 | SystemUtils.startTimerHackThread(); |
44 47 | Path path = Paths.get("server.properties"); |
45 48 | - DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(path); |
46 49 | + DedicatedServerSettings dedicatedserversettings = new DedicatedServerSettings(optionset); // CraftBukkit - CLI argument support |
47 50 | |
48 51 | dedicatedserversettings.forceSave(); |
49 52 | Path path1 = Paths.get("eula.txt"); |
50 53 | EULA eula = new EULA(path1); |
51 54 | |
52 55 | - if (optionset.has(optionspec1)) { |
53 56 | + if (optionset.has("initSettings")) { // CraftBukkit |
57 + | + // CraftBukkit start - SPIGOT-5761: Create bukkit.yml and commands.yml if not present |
58 + | + File configFile = (File) optionset.valueOf("bukkit-settings"); |
59 + | + YamlConfiguration configuration = YamlConfiguration.loadConfiguration(configFile); |
60 + | + configuration.options().copyDefaults(true); |
61 + | + configuration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(Main.class.getClassLoader().getResourceAsStream("configurations/bukkit.yml"), Charsets.UTF_8))); |
62 + | + configuration.save(configFile); |
63 + | + |
64 + | + File commandFile = (File) optionset.valueOf("commands-settings"); |
65 + | + YamlConfiguration commandsConfiguration = YamlConfiguration.loadConfiguration(commandFile); |
66 + | + commandsConfiguration.options().copyDefaults(true); |
67 + | + commandsConfiguration.setDefaults(YamlConfiguration.loadConfiguration(new InputStreamReader(Main.class.getClassLoader().getResourceAsStream("configurations/commands.yml"), Charsets.UTF_8))); |
68 + | + commandsConfiguration.save(commandFile); |
69 + | + // CraftBukkit end |
54 70 | Main.LOGGER.info("Initialized '{}' and '{}'", path.toAbsolutePath(), path1.toAbsolutePath()); |
55 71 | return; |
56 72 | } |
57 - | |
73 + | |
58 74 | return; |
59 75 | } |
60 76 | |
61 77 | - File file = new File((String) optionset.valueOf(optionspec9)); |
62 78 | + File file = (File) optionset.valueOf("universe"); // CraftBukkit |
63 79 | Services services = Services.create(new YggdrasilAuthenticationService(Proxy.NO_PROXY), file); |
64 80 | - String s = (String) Optional.ofNullable((String) optionset.valueOf(optionspec10)).orElse(dedicatedserversettings.getProperties().levelName); |
65 81 | + // CraftBukkit start |
66 82 | + String s = (String) Optional.ofNullable((String) optionset.valueOf("world")).orElse(dedicatedserversettings.getProperties().levelName); |
67 83 | Convertable convertable = Convertable.createDefault(file.toPath()); |
68 84 | - Convertable.ConversionSession convertable_conversionsession = convertable.createAccess(s); |
69 85 | + Convertable.ConversionSession convertable_conversionsession = convertable.createAccess(s, WorldDimension.OVERWORLD); |
70 86 | WorldInfo worldinfo = convertable_conversionsession.getSummary(); |
71 87 | |
72 88 | if (worldinfo != null) { |
73 - | |
89 + | |
74 90 | } |
75 91 | } |
76 92 | |
77 93 | - boolean flag = optionset.has(optionspec6); |
78 94 | + boolean flag = optionset.has("safeMode"); |
79 95 | |
80 96 | if (flag) { |
81 97 | Main.LOGGER.warn("Safe mode active, only vanilla datapack will be loaded"); |
82 98 | } |
83 99 | |
97 113 | + + "}\n", mcMeta, com.google.common.base.Charsets.UTF_8); |
98 114 | + } catch (java.io.IOException ex) { |
99 115 | + throw new RuntimeException("Could not initialize Bukkit datapack", ex); |
100 116 | + } |
101 117 | + AtomicReference<DataPackConfiguration> config = new AtomicReference<>(); |
102 118 | + AtomicReference<DynamicOps<NBTBase>> ops = new AtomicReference<>(); |
103 119 | + // CraftBukkit end |
104 120 | |
105 121 | WorldStem worldstem; |
106 122 | |
107 - | |
123 + | |
108 124 | return WorldStem.load(worldloader_a, (iresourcemanager, datapackconfiguration1) -> { |
109 125 | IRegistryCustom.e iregistrycustom_e = IRegistryCustom.builtinCopy(); |
110 126 | DynamicOps<NBTBase> dynamicops = RegistryOps.createAndLoad(DynamicOpsNBT.INSTANCE, iregistrycustom_e, iresourcemanager); |
111 127 | + // CraftBukkit start |
112 128 | + config.set(datapackconfiguration1); |
113 129 | + ops.set(dynamicops); |
114 130 | + return Pair.of(null, iregistrycustom_e.freeze()); |
115 131 | + // CraftBukkit end |
116 132 | + /* |
117 133 | SaveData savedata = convertable_conversionsession.getDataTag(dynamicops, datapackconfiguration1, iregistrycustom_e.allElementsLifecycle()); |
118 134 | |
119 135 | if (savedata != null) { |
120 - | |
136 + | |
121 137 | |
122 138 | return Pair.of(worlddataserver, iregistrycustom_e.freeze()); |
123 139 | } |
124 140 | + */ |
125 141 | }, SystemUtils.backgroundExecutor(), executor); |
126 142 | }).get(); |
127 143 | } catch (Exception exception) { |
128 - | |
144 + | |
129 145 | return; |
130 146 | } |
131 147 | |
132 148 | + /* |
133 149 | IRegistryCustom.Dimension iregistrycustom_dimension = worldstem.registryAccess(); |
134 150 | |
135 151 | dedicatedserversettings.getProperties().getWorldGenSettings(iregistrycustom_dimension); |
136 - | |
152 + | |
137 153 | } |
138 154 | |
139 155 | convertable_conversionsession.saveDataTag(iregistrycustom_dimension, savedata); |
140 156 | + */ |
141 157 | final DedicatedServer dedicatedserver = (DedicatedServer) MinecraftServer.spin((thread) -> { |
142 158 | - DedicatedServer dedicatedserver1 = new DedicatedServer(thread, convertable_conversionsession, resourcepackrepository, worldstem, dedicatedserversettings, DataConverterRegistry.getDataFixer(), services, WorldLoadListenerLogger::new); |
143 159 | + DedicatedServer dedicatedserver1 = new DedicatedServer(optionset, config.get(), ops.get(), thread, convertable_conversionsession, resourcepackrepository, worldstem, dedicatedserversettings, DataConverterRegistry.getDataFixer(), services, WorldLoadListenerLogger::new); |
144 160 | |
145 161 | + /* |
146 162 | dedicatedserver1.setSingleplayerProfile(optionset.has(optionspec8) ? new GameProfile((UUID) null, (String) optionset.valueOf(optionspec8)) : null); |
161 177 | + dedicatedserver1.setPort(port); |
162 178 | + } |
163 179 | + } |
164 180 | + |
165 181 | return dedicatedserver1; |
166 182 | }); |
167 183 | + /* CraftBukkit start |
168 184 | Thread thread = new Thread("Server Shutdown Thread") { |
169 185 | public void run() { |
170 186 | dedicatedserver.halt(true); |
171 - | |
187 + | |
172 188 | |
173 189 | thread.setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(Main.LOGGER)); |
174 190 | Runtime.getRuntime().addShutdownHook(thread); |
175 191 | + */ // CraftBukkit end |
176 192 | } catch (Exception exception1) { |
177 193 | Main.LOGGER.error(LogUtils.FATAL_MARKER, "Failed to start the minecraft server", exception1); |
178 194 | } |
179 - | |
195 + | |
180 196 | } |
181 197 | |
182 198 | public static void forceUpgrade(Convertable.ConversionSession convertable_conversionsession, DataFixer datafixer, boolean flag, BooleanSupplier booleansupplier, GeneratorSettings generatorsettings) { |
183 199 | - Main.LOGGER.info("Forcing world upgrade!"); |
184 200 | + Main.LOGGER.info("Forcing world upgrade! {}", convertable_conversionsession.getLevelId()); // CraftBukkit |
185 201 | WorldUpgrader worldupgrader = new WorldUpgrader(convertable_conversionsession, datafixer, generatorsettings, flag); |
186 202 | IChatBaseComponent ichatbasecomponent = null; |
187 203 |