aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/server/dedicated/Settings.java.patch
blob: 1cc83808593aa59acf2a926a5d70d07fc80a14ef (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
--- a/net/minecraft/server/dedicated/Settings.java
+++ b/net/minecraft/server/dedicated/Settings.java
@@ -2,11 +2,11 @@
 
 import com.google.common.base.MoreObjects;
 import com.mojang.logging.LogUtils;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.io.Reader;
-import java.io.Writer;
 import java.nio.charset.CharacterCodingException;
 import java.nio.charset.CharsetDecoder;
 import java.nio.charset.CodingErrorAction;
@@ -20,112 +20,201 @@
 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();
-    protected final Properties properties;
+    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;
+
             try {
-                Properties var13;
-                try (InputStream inputStream = Files.newInputStream(path)) {
-                    CharsetDecoder charsetDecoder = StandardCharsets.UTF_8
-                        .newDecoder()
-                        .onMalformedInput(CodingErrorAction.REPORT)
-                        .onUnmappableCharacter(CodingErrorAction.REPORT);
-                    Properties map = new Properties();
-                    map.load(new InputStreamReader(inputStream, charsetDecoder));
-                    var13 = map;
+                InputStream inputstream = Files.newInputStream(path);
+
+                try {
+                    CharsetDecoder charsetdecoder = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);
+
+                    properties = new Properties();
+                    properties.load(new InputStreamReader(inputstream, charsetdecoder));
+                    properties1 = properties;
+                } catch (Throwable throwable) {
+                    if (inputstream != null) {
+                        try {
+                            inputstream.close();
+                        } catch (Throwable throwable1) {
+                            throwable.addSuppressed(throwable1);
+                        }
+                    }
+
+                    throw throwable;
                 }
 
-                return var13;
-            } catch (CharacterCodingException var9) {
-                LOGGER.info("Failed to load properties as UTF-8 from file {}, trying ISO_8859_1", path);
+                if (inputstream != null) {
+                    inputstream.close();
+                }
 
-                Properties var4;
-                try (Reader bufferedReader = Files.newBufferedReader(path, StandardCharsets.ISO_8859_1)) {
-                    Properties map = new Properties();
-                    map.load(bufferedReader);
-                    var4 = map;
+                return properties1;
+            } catch (CharacterCodingException charactercodingexception) {
+                Settings.LOGGER.info("Failed to load properties as UTF-8 from file {}, trying ISO_8859_1", path);
+                BufferedReader bufferedreader = Files.newBufferedReader(path, StandardCharsets.ISO_8859_1);
+
+                try {
+                    properties = new Properties();
+                    properties.load(bufferedreader);
+                    properties1 = properties;
+                } catch (Throwable throwable2) {
+                    if (bufferedreader != null) {
+                        try {
+                            bufferedreader.close();
+                        } catch (Throwable throwable3) {
+                            throwable2.addSuppressed(throwable3);
+                        }
+                    }
+
+                    throw throwable2;
                 }
 
-                return var4;
+                if (bufferedreader != null) {
+                    bufferedreader.close();
+                }
+
+                return properties1;
             }
-        } catch (IOException var10) {
-            LOGGER.error("Failed to load properties from file: {}", path, var10);
+        } catch (IOException ioexception) {
+            Settings.LOGGER.error("Failed to load properties from file: {}", path, ioexception);
             return new Properties();
         }
     }
 
     public void store(Path path) {
-        try (Writer bufferedWriter = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
-            this.properties.store(bufferedWriter, "Minecraft server properties");
-        } catch (IOException var7) {
-            LOGGER.error("Failed to store properties to file: {}", 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 {
+                this.properties.store(bufferedwriter, "Minecraft server properties");
+            } catch (Throwable throwable) {
+                if (bufferedwriter != null) {
+                    try {
+                        bufferedwriter.close();
+                    } catch (Throwable throwable1) {
+                        throwable.addSuppressed(throwable1);
+                    }
+                }
+
+                throw throwable;
+            }
+
+            if (bufferedwriter != null) {
+                bufferedwriter.close();
+            }
+        } catch (IOException ioexception) {
+            Settings.LOGGER.error("Failed to store properties to file: {}", path);
         }
+
     }
 
     private static <V extends Number> Function<String, V> wrapNumberDeserializer(Function<String, V> parseFunc) {
-        return string -> {
+        return (s) -> {
             try {
-                return parseFunc.apply(string);
-            } catch (NumberFormatException var3) {
+                return (V) parseFunc.apply(s); // CraftBukkit - decompile error
+            } catch (NumberFormatException numberformatexception) {
                 return null;
             }
         };
     }
 
     protected static <V> Function<String, V> dispatchNumberOrString(IntFunction<V> byId, Function<String, V> byName) {
-        return string -> {
+        return (s) -> {
             try {
-                return byId.apply(Integer.parseInt(string));
-            } catch (NumberFormatException var4) {
-                return byName.apply(string);
+                return byId.apply(Integer.parseInt(s));
+            } catch (NumberFormatException numberformatexception) {
+                return byName.apply(s);
             }
         };
     }
 
     @Nullable
     private String getStringRaw(String key) {
-        return (String)this.properties.get(key);
+        return (String) getOverride(key, this.properties.getProperty(key)); // CraftBukkit
     }
 
     @Nullable
     protected <V> V getLegacy(String key, Function<String, V> mapper) {
-        String stringRaw = this.getStringRaw(key);
-        if (stringRaw == null) {
+        String s1 = this.getStringRaw(key);
+
+        if (s1 == null) {
             return null;
         } else {
             this.properties.remove(key);
-            return mapper.apply(stringRaw);
+            return mapper.apply(s1);
         }
     }
 
     protected <V> V get(String key, Function<String, V> mapper, Function<V, String> toString, V value) {
-        String stringRaw = this.getStringRaw(key);
-        V object = MoreObjects.firstNonNull(stringRaw != null ? mapper.apply(stringRaw) : null, value);
-        this.properties.put(key, toString.apply(object));
-        return object;
+        // 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);
+
+        this.properties.put(s, function1.apply(v1));
+        return v1;
+    }
+
     protected <V> Settings<T>.MutableValue<V> getMutable(String key, Function<String, V> mapper, Function<V, String> toString, V value) {
-        String stringRaw = this.getStringRaw(key);
-        V object = MoreObjects.firstNonNull(stringRaw != null ? mapper.apply(stringRaw) : null, value);
-        this.properties.put(key, toString.apply(object));
-        return new Settings<T>.MutableValue<>(key, object, toString);
+        String s1 = this.getStringRaw(key);
+        V v1 = MoreObjects.firstNonNull(s1 != null ? mapper.apply(s1) : null, value);
+
+        this.properties.put(key, toString.apply(v1));
+        return new Settings.MutableValue(key, v1, toString); // CraftBukkit - decompile error
     }
 
-    protected <V> V get(String key, Function<String, V> mapper, UnaryOperator<V> unaryOperator, Function<V, String> toString, V value) {
-        return this.get(key, string -> {
-            V object = mapper.apply(string);
-            return object != null ? unaryOperator.apply(object) : null;
+    protected <V> V get(String key, Function<String, V> mapper, UnaryOperator<V> unaryoperator, Function<V, String> toString, V value) {
+        return this.get(key, (s1) -> {
+            V v1 = mapper.apply(s1);
+
+            return v1 != null ? unaryoperator.apply(v1) : null;
         }, toString, value);
     }
 
@@ -138,32 +227,32 @@
     }
 
     protected String get(String key, String value) {
-        return this.get(key, Function.identity(), Function.identity(), value);
+        return (String) this.get(key, Function.identity(), Function.identity(), value);
     }
 
     @Nullable
     protected String getLegacyString(String key) {
-        return this.getLegacy(key, Function.identity());
+        return (String) this.getLegacy(key, Function.identity());
     }
 
     protected int get(String key, int value) {
-        return this.get(key, wrapNumberDeserializer(Integer::parseInt), Integer.valueOf(value));
+        return (Integer) this.get(key, wrapNumberDeserializer(Integer::parseInt), value);
     }
 
     protected Settings<T>.MutableValue<Integer> getMutable(String key, int value) {
         return this.getMutable(key, wrapNumberDeserializer(Integer::parseInt), value);
     }
 
-    protected int get(String key, UnaryOperator<Integer> unaryOperator, int value) {
-        return this.get(key, wrapNumberDeserializer(Integer::parseInt), unaryOperator, Objects::toString, value);
+    protected int get(String key, UnaryOperator<Integer> unaryoperator, int value) {
+        return (Integer) this.get(key, wrapNumberDeserializer(Integer::parseInt), unaryoperator, Objects::toString, value);
     }
 
     protected long get(String key, long value) {
-        return this.get(key, wrapNumberDeserializer(Long::parseLong), value);
+        return (Long) this.get(key, wrapNumberDeserializer(Long::parseLong), value);
     }
 
     protected boolean get(String key, boolean value) {
-        return this.get(key, Boolean::valueOf, value);
+        return (Boolean) this.get(key, Boolean::valueOf, value);
     }
 
     protected Settings<T>.MutableValue<Boolean> getMutable(String key, boolean value) {
@@ -172,37 +261,39 @@
 
     @Nullable
     protected Boolean getLegacyBoolean(String key) {
-        return this.getLegacy(key, Boolean::valueOf);
+        return (Boolean) this.getLegacy(key, Boolean::valueOf);
     }
 
     protected Properties cloneProperties() {
-        Properties map = new Properties();
-        map.putAll(this.properties);
-        return map;
+        Properties properties = new Properties();
+
+        properties.putAll(this.properties);
+        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> {
+
         private final String key;
         private final V value;
         private final Function<V, String> serializer;
 
-        MutableValue(String key, V value, Function<V, String> serializer) {
-            this.key = key;
-            this.value = value;
-            this.serializer = serializer;
+        MutableValue(String s, V object, Function function) { // CraftBukkit - decompile error
+            this.key = s;
+            this.value = object;
+            this.serializer = function;
         }
 
-        @Override
         public V get() {
             return this.value;
         }
 
         public T update(RegistryAccess registryAccess, V newValue) {
-            Properties map = Settings.this.cloneProperties();
-            map.put(this.key, this.serializer.apply(newValue));
-            return Settings.this.reload(registryAccess, map);
+            Properties properties = Settings.this.cloneProperties();
+
+            properties.put(this.key, this.serializer.apply(newValue));
+            return Settings.this.reload(registryAccess, properties, Settings.this.options); // CraftBukkit
         }
     }
 }