Sort server.properties while writing.

This commit is contained in:
LexManos 2019-08-20 15:27:31 -07:00
parent b0787e9f40
commit 0c1c1b65e1
2 changed files with 78 additions and 0 deletions

View file

@ -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_);
}

View file

@ -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<Map.Entry<Object, Object>> entrySet()
{
Set<Map.Entry<Object, Object>> ret = new TreeSet<>((left, right) -> left.getKey().toString().compareTo(right.getKey().toString()));
ret.addAll(super.entrySet());
return ret;
}
@Override
public Set<Object> keySet()
{
return new TreeSet<>(super.keySet());
}
@Override
public synchronized Enumeration<Object> 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);
}
}