2020-01-22 03:02:07 +01:00
From 5509fa75cffe5764dab30e4ad1745d5bd8e95c5d Mon Sep 17 00:00:00 2001
2018-10-24 02:59:08 +02:00
From: Zach Brown <zach@zachbr.io>
Date: Tue, 23 Oct 2018 20:53:43 -0400
Subject: [PATCH] Strip private area unicode characters from signs
It is not immediately clear how these characters ended up on signs in
previous versions. It is clear, however, that they now render as empty
unicode boxes in 1.13, whereas previously they rendered as invisible
characters.
When these signs are loaded in versions after this commit, these
characters from the private use area of the Unicode block will be
stripped. The sign will then be marked to ensure this conversion only
runs once.
There is a flag -DPaper.keepInvalidUnicode=true that can be used if you
do not want us to strip these characters from your signs, though I can
think of no reason to use it.
Fixes GH-1571
diff --git a/src/main/java/net/minecraft/server/TileEntitySign.java b/src/main/java/net/minecraft/server/TileEntitySign.java
2020-01-22 03:02:07 +01:00
index 03f6ddf00..4c2273497 100644
2018-10-24 02:59:08 +02:00
--- a/src/main/java/net/minecraft/server/TileEntitySign.java
+++ b/src/main/java/net/minecraft/server/TileEntitySign.java
2019-12-12 17:20:43 +01:00
@@ -11,6 +11,11 @@ public class TileEntitySign extends TileEntity implements ICommandListener { //
private final String[] g = new String[4];
2019-05-14 04:20:58 +02:00
private EnumColor color;
2018-10-24 02:59:08 +02:00
+ // Paper start - Strip invalid unicode from signs on load
+ private static final boolean keepInvalidUnicode = Boolean.getBoolean("Paper.keepInvalidUnicode"); // Allow people to keep their bad unicode if they really want it
+ private boolean privateUnicodeRemoved = false;
+ // Paper end
+
public TileEntitySign() {
super(TileEntityTypes.SIGN);
2019-05-14 04:20:58 +02:00
this.color = EnumColor.BLACK;
2019-12-12 17:20:43 +01:00
@@ -33,6 +38,12 @@ public class TileEntitySign extends TileEntity implements ICommandListener { //
2018-10-24 02:59:08 +02:00
// CraftBukkit end
2019-05-14 04:20:58 +02:00
nbttagcompound.setString("Color", this.color.b());
+ // Paper start - Only remove private area unicode once // TODO - this doesn't need to run for every sign, check data ver
2018-10-24 02:59:08 +02:00
+ if (this.privateUnicodeRemoved) {
+ nbttagcompound.setBoolean("Paper.RemovedPrivateUnicode", true);
+ }
+ // Paper end
+
return nbttagcompound;
}
2019-12-12 17:20:43 +01:00
@@ -42,6 +53,11 @@ public class TileEntitySign extends TileEntity implements ICommandListener { //
2018-10-24 02:59:08 +02:00
super.load(nbttagcompound);
2019-05-14 04:20:58 +02:00
this.color = EnumColor.a(nbttagcompound.getString("Color"), EnumColor.BLACK);
2018-10-24 02:59:08 +02:00
+ // Paper start - Keep track, only do it once per sign
+ this.privateUnicodeRemoved = nbttagcompound.getBoolean("Paper.RemovedPrivateUnicode");
+ boolean ranUnicodeRemoval = false;
+ // Paper end
+
// CraftBukkit start - Add an option to convert signs correctly
// This is done with a flag instead of all the time because
// we have no way to tell whether a sign is from 1.7.10 or 1.8
2019-12-12 17:20:43 +01:00
@@ -54,6 +70,19 @@ public class TileEntitySign extends TileEntity implements ICommandListener { //
2018-10-24 02:59:08 +02:00
s = "\"\"";
}
+ // Paper start - Strip private use area unicode from signs
+ if (s != null && !keepInvalidUnicode && !this.privateUnicodeRemoved) {
+ StringBuilder builder = new StringBuilder();
+ for (char character : s.toCharArray()) {
+ if (Character.UnicodeBlock.of(character) != Character.UnicodeBlock.PRIVATE_USE_AREA) {
+ builder.append(character);
+ }
+ }
+ s = builder.toString();
+ ranUnicodeRemoval = true;
+ }
+ // Paper end
+
try {
2019-05-14 04:20:58 +02:00
//IChatBaseComponent ichatbasecomponent = IChatBaseComponent.ChatSerializer.a(s.isEmpty() ? "\"\"" : s); // Paper - move down - the old format might throw a json error
2018-10-24 02:59:08 +02:00
2019-12-12 17:20:43 +01:00
@@ -80,6 +109,7 @@ public class TileEntitySign extends TileEntity implements ICommandListener { //
this.g[i] = null;
2018-10-24 02:59:08 +02:00
}
+ if (ranUnicodeRemoval) this.privateUnicodeRemoved = true; // Paper - Flag to write NBT
}
public void a(int i, IChatBaseComponent ichatbasecomponent) {
--
2020-01-22 03:02:07 +01:00
2.25.0.windows.1
2018-10-24 02:59:08 +02:00