Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/Spigot-Server-Patches/0337-Strip-private-area-unicode-characters-from-signs.patch

95 Zeilen
4.0 KiB
Diff

2019-05-06 04:58:04 +02:00
From 710758c98f59d5b99d69a98b5d3a6d3462d6581d Mon Sep 17 00:00:00 2001
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
2019-05-06 04:58:04 +02:00
index 9de03a24cf..4165c6d11a 100644
--- a/src/main/java/net/minecraft/server/TileEntitySign.java
+++ b/src/main/java/net/minecraft/server/TileEntitySign.java
2019-05-05 13:12:32 +02:00
@@ -14,6 +14,11 @@ public class TileEntitySign extends TileEntity implements ICommandListener { //
private final String[] k = new String[4];
private EnumColor l;
+ // 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-05 13:12:32 +02:00
this.l = EnumColor.BLACK;
@@ -36,6 +41,13 @@ public class TileEntitySign extends TileEntity implements ICommandListener { //
// CraftBukkit end
2019-05-05 13:12:32 +02:00
nbttagcompound.setString("Color", this.l.b());
+
+ // Paper start - Only remove private area unicode once
+ if (this.privateUnicodeRemoved) {
+ nbttagcompound.setBoolean("Paper.RemovedPrivateUnicode", true);
+ }
+ // Paper end
+
return nbttagcompound;
}
2019-05-05 13:12:32 +02:00
@@ -45,6 +57,11 @@ public class TileEntitySign extends TileEntity implements ICommandListener { //
super.load(nbttagcompound);
2019-05-05 13:12:32 +02:00
this.l = EnumColor.a(nbttagcompound.getString("Color"), EnumColor.BLACK);
+ // 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-05-05 13:12:32 +02:00
@@ -57,6 +74,19 @@ public class TileEntitySign extends TileEntity implements ICommandListener { //
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 {
//IChatBaseComponent ichatbasecomponent = IChatBaseComponent.ChatSerializer.a(s); // Paper - move down - the old format might throw a json error
2019-05-05 13:12:32 +02:00
@@ -83,6 +113,7 @@ public class TileEntitySign extends TileEntity implements ICommandListener { //
this.k[i] = null;
}
+ if (ranUnicodeRemoval) this.privateUnicodeRemoved = true; // Paper - Flag to write NBT
}
public void a(int i, IChatBaseComponent ichatbasecomponent) {
--
2019-05-05 13:32:20 +02:00
2.21.0