aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower-stripped/net/minecraft/server/dedicated/Settings.java.patch
blob: 35a501511c0b6c31307f67ed4f53c76d8f9b939f (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
--- a/net/minecraft/server/dedicated/Settings.java
+++ b/net/minecraft/server/dedicated/Settings.java
@@ -23,16 +22,38 @@
 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;
+
             try {
                 Properties var13;
                 try (InputStream inputStream = Files.newInputStream(path)) {
@@ -65,10 +116,33 @@
     }
 
     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);
         }
     }
 
@@ -94,7 +169,7 @@
 
     @Nullable
     private String getStringRaw(String key) {
-        return (String)this.properties.get(key);
+        return (String) getOverride(key, this.properties.getProperty(key)); // CraftBukkit
     }
 
     @Nullable
@@ -109,12 +185,23 @@
     }
 
     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);
@@ -181,7 +271,7 @@
         return map;
     }
 
-    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;
@@ -200,9 +290,10 @@
         }
 
         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
         }
     }
 }