mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-07 19:12:22 +01:00
769119f918
== AT == public org.spigotmc.SpigotWorldConfig getBoolean(Ljava/lang/String;Z)Z public org.spigotmc.SpigotWorldConfig getDouble(Ljava/lang/String;)D public org.spigotmc.SpigotWorldConfig getDouble(Ljava/lang/String;D)D public org.spigotmc.SpigotWorldConfig getInt(Ljava/lang/String;)I public org.spigotmc.SpigotWorldConfig getInt(Ljava/lang/String;I)I public org.spigotmc.SpigotWorldConfig getList(Ljava/lang/String;Ljava/lang/Object;)Ljava/util/List; public org.spigotmc.SpigotWorldConfig getString(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; public net.minecraft.server.dedicated.DedicatedServerProperties reload(Lnet/minecraft/core/RegistryAccess;Ljava/util/Properties;Ljoptsimple/OptionSet;)Lnet/minecraft/server/dedicated/DedicatedServerProperties; public net.minecraft.world.level.NaturalSpawner SPAWNING_CATEGORIES
136 lines
5.1 KiB
Diff
136 lines
5.1 KiB
Diff
--- a/net/minecraft/server/dedicated/Settings.java
|
|
+++ b/net/minecraft/server/dedicated/Settings.java
|
|
@@ -20,20 +20,40 @@
|
|
import java.util.function.Supplier;
|
|
import java.util.function.UnaryOperator;
|
|
import javax.annotation.Nullable;
|
|
-import net.minecraft.core.RegistryAccess;
|
|
import org.slf4j.Logger;
|
|
|
|
+import joptsimple.OptionSet; // CraftBukkit
|
|
+import net.minecraft.core.RegistryAccess;
|
|
+
|
|
public abstract class Settings<T extends Settings<T>> {
|
|
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
|
public final Properties properties;
|
|
+ // CraftBukkit start
|
|
+ private OptionSet options = null;
|
|
|
|
- public Settings(Properties properties) {
|
|
+ public Settings(Properties properties, final OptionSet options) {
|
|
this.properties = properties;
|
|
+
|
|
+ this.options = options;
|
|
}
|
|
|
|
+ private String getOverride(String name, String value) {
|
|
+ if ((this.options != null) && (this.options.has(name))) {
|
|
+ return String.valueOf(this.options.valueOf(name));
|
|
+ }
|
|
+
|
|
+ return value;
|
|
+ // CraftBukkit end
|
|
+ }
|
|
+
|
|
public static Properties loadFromFile(Path path) {
|
|
try {
|
|
+ // CraftBukkit start - SPIGOT-7465, MC-264979: Don't load if file doesn't exist
|
|
+ if (!path.toFile().exists()) {
|
|
+ return new Properties();
|
|
+ }
|
|
+ // CraftBukkit end
|
|
Properties properties;
|
|
Properties properties1;
|
|
|
|
@@ -97,6 +117,12 @@
|
|
|
|
public void store(Path path) {
|
|
try {
|
|
+ // CraftBukkit start - Don't attempt writing to file if it's read only
|
|
+ if (path.toFile().exists() && !path.toFile().canWrite()) {
|
|
+ Settings.LOGGER.warn("Can not write to file {}, skipping.", path); // Paper - log message file is read-only
|
|
+ return;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
BufferedWriter bufferedwriter = Files.newBufferedWriter(path, StandardCharsets.UTF_8);
|
|
|
|
try {
|
|
@@ -125,7 +151,7 @@
|
|
private static <V extends Number> Function<String, V> wrapNumberDeserializer(Function<String, V> parser) {
|
|
return (s) -> {
|
|
try {
|
|
- return (Number) parser.apply(s);
|
|
+ return (V) parser.apply(s); // CraftBukkit - decompile error
|
|
} catch (NumberFormatException numberformatexception) {
|
|
return null;
|
|
}
|
|
@@ -144,7 +170,7 @@
|
|
|
|
@Nullable
|
|
public String getStringRaw(String key) {
|
|
- return (String) this.properties.get(key);
|
|
+ return (String) this.getOverride(key, this.properties.getProperty(key)); // CraftBukkit
|
|
}
|
|
|
|
@Nullable
|
|
@@ -160,10 +186,20 @@
|
|
}
|
|
|
|
protected <V> V get(String key, Function<String, V> parser, Function<V, String> stringifier, V fallback) {
|
|
- String s1 = this.getStringRaw(key);
|
|
- V v1 = MoreObjects.firstNonNull(s1 != null ? parser.apply(s1) : null, fallback);
|
|
+ // CraftBukkit start
|
|
+ try {
|
|
+ return this.get0(key, parser, stringifier, fallback);
|
|
+ } catch (Exception ex) {
|
|
+ throw new RuntimeException("Could not load invalidly configured property '" + key + "'", ex);
|
|
+ }
|
|
+ }
|
|
|
|
- this.properties.put(key, stringifier.apply(v1));
|
|
+ private <V> V get0(String s, Function<String, V> function, Function<V, String> function1, V v0) {
|
|
+ // CraftBukkit end
|
|
+ String s1 = this.getStringRaw(s);
|
|
+ V v1 = MoreObjects.firstNonNull(s1 != null ? function.apply(s1) : null, v0);
|
|
+
|
|
+ this.properties.put(s, function1.apply(v1));
|
|
return v1;
|
|
}
|
|
|
|
@@ -172,7 +208,7 @@
|
|
V v1 = MoreObjects.firstNonNull(s1 != null ? parser.apply(s1) : null, fallback);
|
|
|
|
this.properties.put(key, stringifier.apply(v1));
|
|
- return new Settings.MutableValue<>(key, v1, stringifier);
|
|
+ return new Settings.MutableValue(key, v1, stringifier); // CraftBukkit - decompile error
|
|
}
|
|
|
|
protected <V> V get(String key, Function<String, V> parser, UnaryOperator<V> parsedTransformer, Function<V, String> stringifier, V fallback) {
|
|
@@ -236,7 +272,7 @@
|
|
return properties;
|
|
}
|
|
|
|
- protected abstract T reload(RegistryAccess registryManager, Properties properties);
|
|
+ protected abstract T reload(RegistryAccess iregistrycustom, Properties properties, OptionSet optionset); // CraftBukkit
|
|
|
|
public class MutableValue<V> implements Supplier<V> {
|
|
|
|
@@ -244,7 +280,7 @@
|
|
private final V value;
|
|
private final Function<V, String> serializer;
|
|
|
|
- MutableValue(final String s, final Object object, final Function function) {
|
|
+ MutableValue(final String s, final V object, final Function function) { // CraftBukkit - decompile error
|
|
this.key = s;
|
|
this.value = object;
|
|
this.serializer = function;
|
|
@@ -258,7 +294,7 @@
|
|
Properties properties = Settings.this.cloneProperties();
|
|
|
|
properties.put(this.key, this.serializer.apply(value));
|
|
- return Settings.this.reload(registryManager, properties);
|
|
+ return Settings.this.reload(registryManager, properties, Settings.this.options); // CraftBukkit
|
|
}
|
|
}
|
|
}
|