SPIGOT-7465, MC-264979: Fresh installations print NoSuchFileException for server.properties

This commit is contained in:
md_5 2023-08-22 20:51:34 +10:00
parent 8ef7afef65
commit f70a7b68de
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11

View File

@ -1,6 +1,6 @@
--- a/net/minecraft/server/dedicated/PropertyManager.java --- a/net/minecraft/server/dedicated/PropertyManager.java
+++ b/net/minecraft/server/dedicated/PropertyManager.java +++ b/net/minecraft/server/dedicated/PropertyManager.java
@@ -23,13 +23,28 @@ @@ -23,17 +23,37 @@
import net.minecraft.core.IRegistryCustom; import net.minecraft.core.IRegistryCustom;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -30,7 +30,16 @@
} }
public static Properties loadFromFile(Path path) { public static Properties loadFromFile(Path path) {
@@ -97,6 +112,11 @@ 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) { public void store(Path path) {
try { try {
@ -42,7 +51,7 @@
BufferedWriter bufferedwriter = Files.newBufferedWriter(path, StandardCharsets.UTF_8); BufferedWriter bufferedwriter = Files.newBufferedWriter(path, StandardCharsets.UTF_8);
try { try {
@@ -125,7 +145,7 @@ @@ -125,7 +150,7 @@
private static <V extends Number> Function<String, V> wrapNumberDeserializer(Function<String, V> function) { private static <V extends Number> Function<String, V> wrapNumberDeserializer(Function<String, V> function) {
return (s) -> { return (s) -> {
try { try {
@ -51,7 +60,7 @@
} catch (NumberFormatException numberformatexception) { } catch (NumberFormatException numberformatexception) {
return null; return null;
} }
@@ -144,7 +164,7 @@ @@ -144,7 +169,7 @@
@Nullable @Nullable
private String getStringRaw(String s) { private String getStringRaw(String s) {
@ -60,7 +69,7 @@
} }
@Nullable @Nullable
@@ -160,6 +180,16 @@ @@ -160,6 +185,16 @@
} }
protected <V> V get(String s, Function<String, V> function, Function<V, String> function1, V v0) { protected <V> V get(String s, Function<String, V> function, Function<V, String> function1, V v0) {
@ -77,7 +86,7 @@
String s1 = this.getStringRaw(s); String s1 = this.getStringRaw(s);
V v1 = MoreObjects.firstNonNull(s1 != null ? function.apply(s1) : null, v0); V v1 = MoreObjects.firstNonNull(s1 != null ? function.apply(s1) : null, v0);
@@ -172,7 +202,7 @@ @@ -172,7 +207,7 @@
V v1 = MoreObjects.firstNonNull(s1 != null ? function.apply(s1) : null, v0); V v1 = MoreObjects.firstNonNull(s1 != null ? function.apply(s1) : null, v0);
this.properties.put(s, function1.apply(v1)); this.properties.put(s, function1.apply(v1));
@ -86,7 +95,7 @@
} }
protected <V> V get(String s, Function<String, V> function, UnaryOperator<V> unaryoperator, Function<V, String> function1, V v0) { protected <V> V get(String s, Function<String, V> function, UnaryOperator<V> unaryoperator, Function<V, String> function1, V v0) {
@@ -236,7 +266,7 @@ @@ -236,7 +271,7 @@
return properties; return properties;
} }
@ -95,7 +104,7 @@
public class EditableProperty<V> implements Supplier<V> { public class EditableProperty<V> implements Supplier<V> {
@@ -244,7 +274,7 @@ @@ -244,7 +279,7 @@
private final V value; private final V value;
private final Function<V, String> serializer; private final Function<V, String> serializer;
@ -104,7 +113,7 @@
this.key = s; this.key = s;
this.value = object; this.value = object;
this.serializer = function; this.serializer = function;
@@ -258,7 +288,7 @@ @@ -258,7 +293,7 @@
Properties properties = PropertyManager.this.cloneProperties(); Properties properties = PropertyManager.this.cloneProperties();
properties.put(this.key, this.serializer.apply(v0)); properties.put(this.key, this.serializer.apply(v0));