diff --git a/patches/minecraft/net/minecraft/server/dedicated/PropertyManager.java.patch b/patches/minecraft/net/minecraft/server/dedicated/PropertyManager.java.patch new file mode 100644 index 0000000000..912daf292a --- /dev/null +++ b/patches/minecraft/net/minecraft/server/dedicated/PropertyManager.java.patch @@ -0,0 +1,11 @@ +--- a/net/minecraft/server/dedicated/PropertyManager.java ++++ b/net/minecraft/server/dedicated/PropertyManager.java +@@ -38,7 +38,7 @@ + + public void func_218970_c(Path p_218970_1_) { + try (OutputStream outputstream = Files.newOutputStream(p_218970_1_)) { +- this.field_73672_b.store(outputstream, "Minecraft server properties"); ++ net.minecraftforge.common.util.SortedProperties.store(field_73672_b, outputstream, "Minecraft server properties"); + } catch (IOException var15) { + field_164440_a.error("Failed to store properties to file: " + p_218970_1_); + } diff --git a/src/main/java/net/minecraftforge/common/util/SortedProperties.java b/src/main/java/net/minecraftforge/common/util/SortedProperties.java new file mode 100644 index 0000000000..d654a42eb5 --- /dev/null +++ b/src/main/java/net/minecraftforge/common/util/SortedProperties.java @@ -0,0 +1,67 @@ +/* + * Minecraft Forge + * Copyright (c) 2016-2019. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +package net.minecraftforge.common.util; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.Collections; +import java.util.Enumeration; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.TreeSet; + +/** + * An Implementation of Properties that is sorted when iterating. + * Made because i got tired of seeing config files written in random orders. + * This is implemented very basically, and thus is not a speedy system. + * This is not recommended for used in high traffic areas, and is mainly intended for writing to disc. + */ +public class SortedProperties extends Properties +{ + private static final long serialVersionUID = -8913480931455982442L; + + @Override + public Set> entrySet() + { + Set> ret = new TreeSet<>((left, right) -> left.getKey().toString().compareTo(right.getKey().toString())); + ret.addAll(super.entrySet()); + return ret; + } + + @Override + public Set keySet() + { + return new TreeSet<>(super.keySet()); + } + + @Override + public synchronized Enumeration keys() + { + return Collections.enumeration(new TreeSet<>(super.keySet())); + } + + public static void store(Properties props, OutputStream stream, String comment) throws IOException + { + SortedProperties sorted = new SortedProperties(); + sorted.putAll(props); + sorted.store(stream, comment); + } +}