mirror of https://github.com/PaperMC/Paper.git
103 lines
3.5 KiB
Diff
103 lines
3.5 KiB
Diff
--- a/net/minecraft/server/dedicated/Settings.java
|
|
+++ b/net/minecraft/server/dedicated/Settings.java
|
|
@@ -23,17 +22,36 @@
|
|
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();
|
|
- protected final Properties properties;
|
|
+ public final Properties properties;
|
|
+ // CraftBukkit start
|
|
+ private OptionSet options = null;
|
|
|
|
public Settings(Properties properties) {
|
|
this.properties = properties;
|
|
}
|
|
|
|
+ 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,11 @@
|
|
|
|
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()) {
|
|
+ return;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
BufferedWriter bufferedwriter = Files.newBufferedWriter(path, StandardCharsets.UTF_8);
|
|
|
|
try {
|
|
@@ -143,8 +168,8 @@
|
|
}
|
|
|
|
@Nullable
|
|
- private String getStringRaw(String s) {
|
|
- return (String) this.properties.get(s);
|
|
+ private String getStringRaw(String key) {
|
|
+ return (String) getOverride(key, this.properties.getProperty(key)); // CraftBukkit
|
|
}
|
|
|
|
@Nullable
|
|
@@ -159,7 +184,17 @@
|
|
}
|
|
}
|
|
|
|
- protected <V> V get(String s, Function<String, V> function, Function<V, String> function1, V v0) {
|
|
+ protected <V> V get(String key, Function<String, V> mapper, Function<V, String> toString, V value) {
|
|
+ // CraftBukkit start
|
|
+ try {
|
|
+ return get0(key, mapper, toString, value);
|
|
+ } catch (Exception ex) {
|
|
+ throw new RuntimeException("Could not load invalidly configured property '" + key + "'", ex);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ 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);
|
|
|
|
@@ -236,7 +271,7 @@
|
|
return properties;
|
|
}
|
|
|
|
- protected abstract T reload(RegistryAccess registryAccess, Properties properties);
|
|
+ protected abstract T reload(RegistryAccess iregistrycustom, Properties properties, OptionSet optionset); // CraftBukkit
|
|
|
|
public class MutableValue<V> implements Supplier<V> {
|
|
|
|
@@ -258,8 +292,8 @@
|
|
public T update(RegistryAccess registryaccess, V v0) {
|
|
Properties properties = Settings.this.cloneProperties();
|
|
|
|
- properties.put(this.key, this.serializer.apply(v0));
|
|
- return Settings.this.reload(registryaccess, properties);
|
|
+ properties.put(this.key, this.serializer.apply(newValue));
|
|
+ return Settings.this.reload(registryAccess, properties, Settings.this.options); // CraftBukkit
|
|
}
|
|
}
|
|
}
|