From 0fc6213f9cfc9e492dd5d394bbb587e026bc374b Mon Sep 17 00:00:00 2001 From: Prof-Bloodstone <46570876+Prof-Bloodstone@users.noreply.github.com> Date: Tue, 3 Aug 2021 09:35:02 +0200 Subject: [PATCH] Allow skipping writing of comments to server.properties (#6251) Makes less git noise, as it won't update the date every single time Use -DPaper.skipServerPropertiesComments=true flag to disable writing it --- ...riting-of-comments-to-server.propert.patch | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 patches/server/0738-Allow-skipping-writing-of-comments-to-server.propert.patch diff --git a/patches/server/0738-Allow-skipping-writing-of-comments-to-server.propert.patch b/patches/server/0738-Allow-skipping-writing-of-comments-to-server.propert.patch new file mode 100644 index 0000000000..973aa00abd --- /dev/null +++ b/patches/server/0738-Allow-skipping-writing-of-comments-to-server.propert.patch @@ -0,0 +1,95 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Professor Bloodstone +Date: Fri, 23 Jul 2021 02:32:04 +0200 +Subject: [PATCH] Allow skipping writing of comments to server.properties + +Makes less git noise, as it won't update the date every single time + +Use -DPaper.skipServerPropertiesComments=true flag to disable writing it + +diff --git a/src/main/java/net/minecraft/server/dedicated/Settings.java b/src/main/java/net/minecraft/server/dedicated/Settings.java +index 745a6735fba8343329ec31723da914fad16ae134..2713d9acc51c6c5cc51bdbbe63477343ecb29154 100644 +--- a/src/main/java/net/minecraft/server/dedicated/Settings.java ++++ b/src/main/java/net/minecraft/server/dedicated/Settings.java +@@ -1,9 +1,11 @@ + package net.minecraft.server.dedicated; + + import com.google.common.base.MoreObjects; ++import java.io.BufferedWriter; // Paper + import java.io.IOException; + import java.io.InputStream; + import java.io.OutputStream; ++import java.io.OutputStreamWriter; // Paper + import java.nio.file.Files; + import java.nio.file.Path; + import java.util.Objects; +@@ -18,11 +20,13 @@ import org.apache.logging.log4j.Logger; + + import joptsimple.OptionSet; // CraftBukkit + import net.minecraft.core.RegistryAccess; ++import org.jetbrains.annotations.NotNull; // Paper + + public abstract class Settings> { + + private static final Logger LOGGER = LogManager.getLogger(); + public final Properties properties; ++ private static final boolean skipComments = Boolean.getBoolean("Paper.skipServerPropertiesComments"); // Paper - allow skipping server.properties comments + // CraftBukkit start + private OptionSet options = null; + +@@ -79,9 +83,54 @@ public abstract class Settings> { + } + // CraftBukkit end + OutputStream outputstream = Files.newOutputStream(path); ++ // Paper start - disable writing comments to properties file ++ OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputstream); ++ BufferedWriter bufferedwriter = !skipComments ? new BufferedWriter(outputStreamWriter) : new BufferedWriter(outputStreamWriter) { ++ private boolean isRightAfterNewline = true; // If last written char was newline ++ private boolean isComment = false; // Are we writing comment currently? ++ ++ @Override ++ public void write(@NotNull String str) throws IOException { ++ char[] ch = str.toCharArray(); ++ this.write(ch); ++ } ++ ++ @Override ++ public void write(@NotNull char[] cbuf) throws IOException { ++ this.write(cbuf, 0, cbuf.length); ++ } ++ ++ @Override ++ public void write(@NotNull char[] cbuf, int off, int len) throws IOException { ++ int latest_offset = off; // The latest offset, updated when comment ends ++ for (int index = off; index < off + len; ++index ) { ++ char c = cbuf[index]; ++ boolean isNewline = (c == '\n' || c == '\r'); ++ if (isNewline && isComment) { ++ // Comment has ended ++ isComment = false; ++ latest_offset = index+1; ++ } ++ if (c == '#' && isRightAfterNewline) { ++ isComment = true; ++ if (index != latest_offset) { ++ // We got some non-comment data earlier ++ super.write(cbuf, latest_offset, index-latest_offset); ++ } ++ } ++ isRightAfterNewline = isNewline; // Store for next iteration ++ ++ } ++ if (latest_offset < off+len && !isComment) { ++ // We have some unwritten data, that isn't part of a comment ++ super.write(cbuf, latest_offset, (off + len) - latest_offset); ++ } ++ } ++ }; ++ // Paper end + + try { +- this.properties.store(outputstream, "Minecraft server properties"); ++ this.properties.store(bufferedwriter, "Minecraft server properties"); // Paper - use bufferedwriter + } catch (Throwable throwable) { + if (outputstream != null) { + try {