2021-08-03 09:35:02 +02:00
|
|
|
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
|
2023-08-28 13:05:48 +02:00
|
|
|
index ca23639f15107ccd43b874ae38fa37279b827a8f..faca42b2b5b20559f98c300b7011b67165391a0d 100644
|
2021-08-03 09:35:02 +02:00
|
|
|
--- 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>> {
|
2021-08-03 09:35:02 +02:00
|
|
|
|
2022-03-01 06:43:03 +01:00
|
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
2021-08-03 09:35:02 +02:00
|
|
|
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;
|
|
|
|
|
2023-08-28 13:05:48 +02:00
|
|
|
@@ -123,7 +124,46 @@ public abstract class Settings<T extends Settings<T>> {
|
2023-06-08 19:48:28 +02:00
|
|
|
return;
|
2021-08-03 09:35:02 +02:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2023-06-08 19:48:28 +02:00
|
|
|
- BufferedWriter bufferedwriter = Files.newBufferedWriter(path, StandardCharsets.UTF_8);
|
2021-08-03 09:35:02 +02:00
|
|
|
+ // Paper start - disable writing comments to properties file
|
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) {
|
2021-08-03 09:35:02 +02:00
|
|
|
+ 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 {
|
2021-08-04 09:48:15 +02:00
|
|
|
+ this.write(b, 0, b.length);
|
2021-08-03 09:35:02 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
2022-03-01 06:43:03 +01:00
|
|
|
+ public void write(@org.jetbrains.annotations.NotNull byte[] bbuf, int off, int len) throws IOException {
|
2021-08-03 09:35:02 +02:00
|
|
|
+ int latest_offset = off; // The latest offset, updated when comment ends
|
|
|
|
+ for (int index = off; index < off + len; ++index ) {
|
2021-08-04 09:48:15 +02:00
|
|
|
+ byte c = bbuf[index];
|
2021-08-03 09:35:02 +02:00
|
|
|
+ boolean isNewline = (c == '\n' || c == '\r');
|
2023-06-08 19:48:28 +02:00
|
|
|
+ if (isNewline && this.isComment) {
|
2021-08-03 09:35:02 +02:00
|
|
|
+ // Comment has ended
|
2023-06-08 19:48:28 +02:00
|
|
|
+ this.isComment = false;
|
2021-08-03 09:35:02 +02:00
|
|
|
+ latest_offset = index+1;
|
|
|
|
+ }
|
2023-06-08 19:48:28 +02:00
|
|
|
+ if (c == '#' && this.isRightAfterNewline) {
|
|
|
|
+ this.isComment = true;
|
2021-08-03 09:35:02 +02:00
|
|
|
+ if (index != latest_offset) {
|
|
|
|
+ // We got some non-comment data earlier
|
2021-08-04 09:48:15 +02:00
|
|
|
+ super.write(bbuf, latest_offset, index-latest_offset);
|
2021-08-03 09:35:02 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
2023-06-08 19:48:28 +02:00
|
|
|
+ this.isRightAfterNewline = isNewline; // Store for next iteration
|
2021-08-03 09:35:02 +02:00
|
|
|
+
|
|
|
|
+ }
|
2023-06-08 19:48:28 +02:00
|
|
|
+ if (latest_offset < off+len && !this.isComment) {
|
2021-08-03 09:35:02 +02:00
|
|
|
+ // We have some unwritten data, that isn't part of a comment
|
2021-08-04 09:48:15 +02:00
|
|
|
+ super.write(bbuf, latest_offset, (off + len) - latest_offset);
|
2021-08-03 09:35:02 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
2023-06-08 19:48:28 +02:00
|
|
|
+ BufferedWriter bufferedwriter = new BufferedWriter(new java.io.OutputStreamWriter(bufferedOutputStream, java.nio.charset.StandardCharsets.UTF_8.newEncoder()));
|
2021-08-03 09:35:02 +02:00
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
try {
|
2023-06-08 19:48:28 +02:00
|
|
|
this.properties.store(bufferedwriter, "Minecraft server properties");
|