--- a/net/minecraft/server/dedicated/DedicatedServerProperties.java +++ b/net/minecraft/server/dedicated/DedicatedServerProperties.java @@ -44,11 +44,16 @@ import net.minecraft.world.level.levelgen.presets.WorldPresets; import org.slf4j.Logger; +// CraftBukkit start +import joptsimple.OptionSet; +// CraftBukkit end + public class DedicatedServerProperties extends Settings { static final Logger LOGGER = LogUtils.getLogger(); private static final Pattern SHA1 = Pattern.compile("^[a-fA-F0-9]{40}$"); private static final Splitter COMMA_SPLITTER = Splitter.on(',').trimResults(); + public final boolean debug = this.get("debug", false); // CraftBukkit public final boolean onlineMode = this.get("online-mode", true); public final boolean preventProxyConnections = this.get("prevent-proxy-connections", false); public final String serverIp = this.get("server-ip", ""); @@ -103,8 +108,10 @@ private final DedicatedServerProperties.WorldDimensionData worldDimensionData; public final WorldOptions worldOptions; - public DedicatedServerProperties(Properties properties) { - super(properties); + // CraftBukkit start + public DedicatedServerProperties(Properties properties, OptionSet optionset) { + super(properties, optionset); + // CraftBukkit end this.difficulty = (Difficulty) this.get("difficulty", dispatchNumberOrString(Difficulty::byId, Difficulty::byName), Difficulty::getKey, Difficulty.EASY); this.gamemode = (GameType) this.get("gamemode", dispatchNumberOrString(GameType::byId, GameType::byName), GameType::getName, GameType.SURVIVAL); this.levelName = this.get("level-name", "world"); @@ -161,23 +168,24 @@ this.initialDataPackConfiguration = getDatapackConfig(this.get("initial-enabled-packs", String.join(",", WorldDataConfiguration.DEFAULT.dataPacks().getEnabled())), this.get("initial-disabled-packs", String.join(",", WorldDataConfiguration.DEFAULT.dataPacks().getDisabled()))); } - public static DedicatedServerProperties fromFile(Path path) { - return new DedicatedServerProperties(loadFromFile(path)); + // CraftBukkit start + public static DedicatedServerProperties fromFile(Path path, OptionSet optionset) { + return new DedicatedServerProperties(loadFromFile(path), optionset); } @Override - @Override - protected DedicatedServerProperties reload(RegistryAccess registryaccess, Properties properties) { - return new DedicatedServerProperties(properties); + protected DedicatedServerProperties reload(RegistryAccess iregistrycustom, Properties properties, OptionSet optionset) { + return new DedicatedServerProperties(properties, optionset); + // CraftBukkit end } @Nullable - private static Component parseResourcePackPrompt(String s) { - if (!Strings.isNullOrEmpty(s)) { + private static Component parseResourcePackPrompt(String json) { + if (!Strings.isNullOrEmpty(json)) { try { - return Component.Serializer.fromJson(s); + return Component.Serializer.fromJson(json); } catch (Exception exception) { - DedicatedServerProperties.LOGGER.warn("Failed to parse resource pack prompt '{}'", s, exception); + DedicatedServerProperties.LOGGER.warn("Failed to parse resource pack prompt '{}'", json, exception); } } @@ -208,7 +216,7 @@ DedicatedServerProperties.LOGGER.warn("Invalid sha1 for resource-pack-sha1"); } - Component component = parseResourcePackPrompt(s4); + Component ichatbasecomponent = parseResourcePackPrompt(s4); UUID uuid; if (s.isEmpty()) { @@ -223,55 +231,55 @@ } } - return Optional.of(new MinecraftServer.ServerResourcePackInfo(uuid, s1, s5, flag, component)); + return Optional.of(new MinecraftServer.ServerResourcePackInfo(uuid, s1, s5, flag, ichatbasecomponent)); } } - private static DataPackConfig getDatapackConfig(String s, String s1) { - List list = DedicatedServerProperties.COMMA_SPLITTER.splitToList(s); - List list1 = DedicatedServerProperties.COMMA_SPLITTER.splitToList(s1); + private static DataPackConfig getDatapackConfig(String initalEnabledPacks, String initialDisabledPacks) { + List list = DedicatedServerProperties.COMMA_SPLITTER.splitToList(initalEnabledPacks); + List list1 = DedicatedServerProperties.COMMA_SPLITTER.splitToList(initialDisabledPacks); return new DataPackConfig(list, list1); } - public WorldDimensions createDimensions(RegistryAccess registryaccess) { - return this.worldDimensionData.create(registryaccess); + public WorldDimensions createDimensions(RegistryAccess registryAccess) { + return this.worldDimensionData.create(registryAccess); } - private static record WorldDimensionData(JsonObject generatorSettings, String levelType) { + public static record WorldDimensionData(JsonObject generatorSettings, String levelType) { private static final Map> LEGACY_PRESET_NAMES = Map.of("default", WorldPresets.NORMAL, "largebiomes", WorldPresets.LARGE_BIOMES); - public WorldDimensions create(RegistryAccess registryaccess) { - Registry registry = registryaccess.registryOrThrow(Registries.WORLD_PRESET); - Holder.Reference holder_reference = (Holder.Reference) registry.getHolder(WorldPresets.NORMAL).or(() -> { - return registry.holders().findAny(); + public WorldDimensions create(RegistryAccess registryAccess) { + Registry iregistry = registryAccess.registryOrThrow(Registries.WORLD_PRESET); + Holder.Reference holder_c = (Holder.Reference) iregistry.getHolder(WorldPresets.NORMAL).or(() -> { + return iregistry.holders().findAny(); }).orElseThrow(() -> { return new IllegalStateException("Invalid datapack contents: can't find default preset"); }); - Optional optional = Optional.ofNullable(ResourceLocation.tryParse(this.levelType)).map((resourcelocation) -> { - return ResourceKey.create(Registries.WORLD_PRESET, resourcelocation); + Optional> optional = Optional.ofNullable(ResourceLocation.tryParse(this.levelType)).map((minecraftkey) -> { // CraftBukkit - decompile error + return ResourceKey.create(Registries.WORLD_PRESET, minecraftkey); }).or(() -> { - return Optional.ofNullable((ResourceKey) DedicatedServerProperties.WorldDimensionData.LEGACY_PRESET_NAMES.get(this.levelType)); + return Optional.ofNullable(DedicatedServerProperties.WorldDimensionData.LEGACY_PRESET_NAMES.get(this.levelType)); // CraftBukkit - decompile error }); - Objects.requireNonNull(registry); - Holder holder = (Holder) optional.flatMap(registry::getHolder).orElseGet(() -> { - DedicatedServerProperties.LOGGER.warn("Failed to parse level-type {}, defaulting to {}", this.levelType, holder_reference.key().location()); - return holder_reference; + Objects.requireNonNull(iregistry); + Holder holder = (Holder) optional.flatMap(iregistry::getHolder).orElseGet(() -> { + DedicatedServerProperties.LOGGER.warn("Failed to parse level-type {}, defaulting to {}", this.levelType, holder_c.key().location()); + return holder_c; }); WorldDimensions worlddimensions = ((WorldPreset) holder.value()).createWorldDimensions(); if (holder.is(WorldPresets.FLAT)) { - RegistryOps registryops = RegistryOps.create(JsonOps.INSTANCE, (HolderLookup.Provider) registryaccess); - DataResult dataresult = FlatLevelGeneratorSettings.CODEC.parse(new Dynamic(registryops, this.generatorSettings())); + RegistryOps registryops = RegistryOps.create(JsonOps.INSTANCE, (HolderLookup.Provider) registryAccess); + DataResult dataresult = FlatLevelGeneratorSettings.CODEC.parse(new Dynamic(registryops, this.generatorSettings())); // CraftBukkit - decompile error Logger logger = DedicatedServerProperties.LOGGER; Objects.requireNonNull(logger); Optional optional1 = dataresult.resultOrPartial(logger::error); if (optional1.isPresent()) { - return worlddimensions.replaceOverworldGenerator(registryaccess, new FlatLevelSource((FlatLevelGeneratorSettings) optional1.get())); + return worlddimensions.replaceOverworldGenerator(registryAccess, new FlatLevelSource((FlatLevelGeneratorSettings) optional1.get())); } }