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
|
2021-11-25 00:46:26 +01:00
|
|
|
index 71767307062e99262afb994016720e1f1555b820..b285e8f6172154af1aa942ab164d73bc885c5fa4 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
|
2021-08-04 09:48:15 +02:00
|
|
|
@@ -1,6 +1,8 @@
|
2021-08-03 09:35:02 +02:00
|
|
|
package net.minecraft.server.dedicated;
|
|
|
|
|
|
|
|
import com.google.common.base.MoreObjects;
|
2021-08-04 09:48:15 +02:00
|
|
|
+
|
|
|
|
+import java.io.BufferedOutputStream; // Paper
|
2021-08-03 09:35:02 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
@@ -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<T extends Settings<T>> {
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2021-08-04 09:48:15 +02:00
|
|
|
@@ -79,9 +83,47 @@ public abstract class Settings<T extends Settings<T>> {
|
2021-08-03 09:35:02 +02:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
OutputStream outputstream = Files.newOutputStream(path);
|
|
|
|
+ // Paper start - disable writing comments to properties file
|
2021-08-04 09:48:15 +02:00
|
|
|
+ BufferedOutputStream bufferedOutputStream = !skipComments ? new BufferedOutputStream(outputstream) : new 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
|
2021-08-04 09:48:15 +02:00
|
|
|
+ public void write(@NotNull byte[] b) throws IOException {
|
|
|
|
+ this.write(b, 0, b.length);
|
2021-08-03 09:35:02 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
2021-08-04 09:48:15 +02:00
|
|
|
+ public void write(@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');
|
|
|
|
+ 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
|
2021-08-04 09:48:15 +02:00
|
|
|
+ super.write(bbuf, latest_offset, index-latest_offset);
|
2021-08-03 09:35:02 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ isRightAfterNewline = isNewline; // Store for next iteration
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ if (latest_offset < off+len && !isComment) {
|
|
|
|
+ // 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
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ // Paper end
|
|
|
|
|
|
|
|
try {
|
|
|
|
- this.properties.store(outputstream, "Minecraft server properties");
|
2021-08-04 09:48:15 +02:00
|
|
|
+ this.properties.store(bufferedOutputStream, "Minecraft server properties"); // Paper - use bufferedOutputStream
|
2021-08-03 09:35:02 +02:00
|
|
|
} catch (Throwable throwable) {
|
|
|
|
if (outputstream != null) {
|
|
|
|
try {
|