aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-spigotflower-stripped/net/minecraft/server/dedicated/Settings.java.patch
blob: d784dbc38c02a8252ce580496ef54fe2a22bbac7 (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
--- 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
         }
     }
 }