Paper/patches/server/0564-Allow-skipping-writing-of-comments-to-server.propert.patch

70 lines
3.9 KiB
Diff
Raw Permalink Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Professor Bloodstone <git@bloodstone.dev>
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
2024-04-24 17:27:28 +02:00
index 0ec3b546db0cf3858dd9cd9ea067d1d6713a8491..d7bd235ef2815890e038091dd625177049d253a5 100644
--- a/src/main/java/net/minecraft/server/dedicated/Settings.java
+++ b/src/main/java/net/minecraft/server/dedicated/Settings.java
2023-06-08 19:48:28 +02:00
@@ -29,6 +29,7 @@ public abstract class Settings<T extends Settings<T>> {
2022-03-01 06:43:03 +01:00
private static final Logger LOGGER = LogUtils.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;
@@ -123,7 +124,46 @@ public abstract class Settings<T extends Settings<T>> {
2023-06-08 19:48:28 +02:00
return;
}
// CraftBukkit end
2023-06-08 19:48:28 +02:00
- BufferedWriter bufferedwriter = Files.newBufferedWriter(path, StandardCharsets.UTF_8);
+ // Paper start - allow skipping server.properties comments
2023-06-08 19:48:28 +02:00
+ java.io.OutputStream outputstream = Files.newOutputStream(path);
2022-03-01 06:43:03 +01:00
+ java.io.BufferedOutputStream bufferedOutputStream = !skipComments ? new java.io.BufferedOutputStream(outputstream) : new java.io.BufferedOutputStream(outputstream) {
+ private boolean isRightAfterNewline = true; // If last written char was newline
+ private boolean isComment = false; // Are we writing comment currently?
+
+ @Override
2022-03-01 06:43:03 +01:00
+ public void write(@org.jetbrains.annotations.NotNull byte[] b) throws IOException {
+ this.write(b, 0, b.length);
+ }
+
+ @Override
2022-03-01 06:43:03 +01:00
+ public void write(@org.jetbrains.annotations.NotNull byte[] bbuf, 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 ) {
+ byte c = bbuf[index];
+ boolean isNewline = (c == '\n' || c == '\r');
2023-06-08 19:48:28 +02:00
+ if (isNewline && this.isComment) {
+ // Comment has ended
2023-06-08 19:48:28 +02:00
+ this.isComment = false;
+ latest_offset = index+1;
+ }
2023-06-08 19:48:28 +02:00
+ if (c == '#' && this.isRightAfterNewline) {
+ this.isComment = true;
+ if (index != latest_offset) {
+ // We got some non-comment data earlier
+ super.write(bbuf, latest_offset, index-latest_offset);
+ }
+ }
2023-06-08 19:48:28 +02:00
+ this.isRightAfterNewline = isNewline; // Store for next iteration
+
+ }
2023-06-08 19:48:28 +02:00
+ if (latest_offset < off+len && !this.isComment) {
+ // We have some unwritten data, that isn't part of a comment
+ super.write(bbuf, latest_offset, (off + len) - latest_offset);
+ }
+ }
+ };
2023-06-08 19:48:28 +02:00
+ BufferedWriter bufferedwriter = new BufferedWriter(new java.io.OutputStreamWriter(bufferedOutputStream, java.nio.charset.StandardCharsets.UTF_8.newEncoder()));
+ // Paper end - allow skipping server.properties comments
try {
2023-06-08 19:48:28 +02:00
this.properties.store(bufferedwriter, "Minecraft server properties");