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
|
--- a/net/minecraft/server/dedicated/PropertyManager.java
+++ b/net/minecraft/server/dedicated/PropertyManager.java
@@ -23,17 +23,37 @@
import net.minecraft.core.IRegistryCustom;
import org.slf4j.Logger;
+import joptsimple.OptionSet; // CraftBukkit
+
public abstract class PropertyManager<T extends PropertyManager<T>> {
private static final Logger LOGGER = LogUtils.getLogger();
public final Properties properties;
+ // CraftBukkit start
+ private OptionSet options = null;
- public PropertyManager(Properties properties) {
+ public PropertyManager(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,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 {
@@ -125,7 +150,7 @@
private static <V extends Number> Function<String, V> wrapNumberDeserializer(Function<String, V> function) {
return (s) -> {
try {
- return (Number) function.apply(s);
+ return (V) function.apply(s); // CraftBukkit - decompile error
} catch (NumberFormatException numberformatexception) {
return null;
}
@@ -144,7 +169,7 @@
@Nullable
private String getStringRaw(String s) {
- return (String) this.properties.get(s);
+ return (String) getOverride(s, this.properties.getProperty(s)); // CraftBukkit
}
@Nullable
@@ -160,6 +185,16 @@
}
protected <V> V get(String s, Function<String, V> function, Function<V, String> function1, V v0) {
+ // CraftBukkit start
+ try {
+ return get0(s, function, function1, v0);
+ } catch (Exception ex) {
+ throw new RuntimeException("Could not load invalidly configured property '" + s + "'", 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);
@@ -172,7 +207,7 @@
V v1 = MoreObjects.firstNonNull(s1 != null ? function.apply(s1) : null, v0);
this.properties.put(s, function1.apply(v1));
- return new PropertyManager.EditableProperty<>(s, v1, function1);
+ return new PropertyManager.EditableProperty(s, v1, function1); // CraftBukkit - decompile error
}
protected <V> V get(String s, Function<String, V> function, UnaryOperator<V> unaryoperator, Function<V, String> function1, V v0) {
@@ -236,7 +271,7 @@
return properties;
}
- protected abstract T reload(IRegistryCustom iregistrycustom, Properties properties);
+ protected abstract T reload(IRegistryCustom iregistrycustom, Properties properties, OptionSet optionset); // CraftBukkit
public class EditableProperty<V> implements Supplier<V> {
@@ -244,7 +279,7 @@
private final V value;
private final Function<V, String> serializer;
- EditableProperty(String s, Object object, Function function) {
+ EditableProperty(String s, V object, Function function) { // CraftBukkit - decompile error
this.key = s;
this.value = object;
this.serializer = function;
@@ -258,7 +293,7 @@
Properties properties = PropertyManager.this.cloneProperties();
properties.put(this.key, this.serializer.apply(v0));
- return PropertyManager.this.reload(iregistrycustom, properties);
+ return PropertyManager.this.reload(iregistrycustom, properties, PropertyManager.this.options); // CraftBukkit
}
}
}
|