--- a/net/minecraft/server/dedicated/PropertyManager.java +++ b/net/minecraft/server/dedicated/PropertyManager.java @@ -17,15 +17,30 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import joptsimple.OptionSet; // CraftBukkit + public abstract class PropertyManager> { private static final Logger LOGGER = LogManager.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 loadPropertiesFile(Path path) { Properties properties = new Properties(); @@ -61,6 +76,11 @@ public void savePropertiesFile(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 OutputStream outputstream = Files.newOutputStream(path); Throwable throwable = null; @@ -92,7 +112,7 @@ private static Function a(Function function) { return (s) -> { try { - return (Number) function.apply(s); + return (V) function.apply(s); // CraftBukkit - decompile error } catch (NumberFormatException numberformatexception) { return null; } @@ -111,7 +131,7 @@ @Nullable private String c(String s) { - return (String) this.properties.get(s); + return (String) getOverride(s, this.properties.getProperty(s)); // CraftBukkit } @Nullable @@ -139,7 +159,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 a(String s, Function function, UnaryOperator unaryoperator, Function function1, V v0) { @@ -168,7 +188,7 @@ } protected int getInt(String s, int i) { - return (Integer) this.a(s, a(Integer::parseInt), (Object) i); + return (Integer) this.a(s, a(Integer::parseInt), i); // CraftBukkit - decompile error } protected PropertyManager.EditableProperty b(String s, int i) { @@ -180,7 +200,7 @@ } protected long getLong(String s, long i) { - return (Long) this.a(s, a(Long::parseLong), (Object) i); + return (Long) this.a(s, a(Long::parseLong), i); // CraftBukkit - decompile error } protected boolean getBoolean(String s, boolean flag) { @@ -203,7 +223,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 implements Supplier { @@ -211,7 +231,7 @@ private final V c; private final Function d; - private EditableProperty(String s, Object object, Function function) { + private EditableProperty(String s, V object, Function function) { // CraftBukkit - decompile error this.b = s; this.c = object; this.d = function; @@ -225,7 +245,7 @@ Properties properties = PropertyManager.this.a(); properties.put(this.b, this.d.apply(v0)); - return PropertyManager.this.reload(iregistrycustom, properties); + return PropertyManager.this.reload(iregistrycustom, properties, PropertyManager.this.options); // CraftBukkit } } }