From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Thu, 6 Jun 2019 17:40:30 -0500
Subject: [PATCH] Signs allow color codes


diff --git a/src/main/java/net/minecraft/server/level/EntityPlayer.java b/src/main/java/net/minecraft/server/level/EntityPlayer.java
index e875671ce985199bc37de131280935a859253954..ba71636527f173dfc5ddae9ef0f7c73d0423d9b3 100644
--- a/src/main/java/net/minecraft/server/level/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/level/EntityPlayer.java
@@ -1579,6 +1579,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
 
     @Override
     public void openSign(TileEntitySign tileentitysign) {
+        if (world.purpurConfig.signAllowColors) this.playerConnection.sendPacket(tileentitysign.getTranslatedUpdatePacket()); // Purpur
         tileentitysign.a((EntityHuman) this);
         this.playerConnection.sendPacket(new PacketPlayOutOpenSignEditor(tileentitysign.getPosition()));
     }
diff --git a/src/main/java/net/minecraft/server/network/PlayerConnection.java b/src/main/java/net/minecraft/server/network/PlayerConnection.java
index 1e7ae4a3947f2714159a6b93ef7d79541a6e070d..d2896d49b4b3cb0a6cf64ee29233ff59b8fba45d 100644
--- a/src/main/java/net/minecraft/server/network/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/network/PlayerConnection.java
@@ -3072,6 +3072,15 @@ public class PlayerConnection implements PacketListenerPlayIn {
                     }
                 }
                 // Paper end
+                // Purpur start
+                if (worldserver.purpurConfig.signAllowColors) {
+                    final org.bukkit.entity.Player bukkitPlayer = player.getBukkitEntity();
+                    if (bukkitPlayer.hasPermission("purpur.sign.color")) currentLine = currentLine.replaceAll("(?i)&([0-9a-fr])", "\u00a7$1");
+                    if (bukkitPlayer.hasPermission("purpur.sign.style")) currentLine = currentLine.replaceAll("(?i)&([l-or])", "\u00a7$1");
+                    if (bukkitPlayer.hasPermission("purpur.sign.magic")) currentLine = currentLine.replaceAll("(?i)&([kr])", "\u00a7$1");
+                    lines.add(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(currentLine));
+                } else
+                // Purpur end
                 lines.add(net.kyori.adventure.text.Component.text(SharedConstants.filterAllowedChatCharacters(currentLine))); // Paper - Replaced with anvil color stripping method to stop exploits that allow colored signs to be created.
             }
             SignChangeEvent event = new SignChangeEvent(org.bukkit.craftbukkit.block.CraftBlock.at(worldserver, blockposition), this.getPlayer(), lines);
diff --git a/src/main/java/net/minecraft/world/level/block/entity/TileEntitySign.java b/src/main/java/net/minecraft/world/level/block/entity/TileEntitySign.java
index 96d0524482281f8570464962c0fd5319199440d7..a87a2fa507dc3bd6d9979db5868e7ef6ea1eddbd 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/TileEntitySign.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/TileEntitySign.java
@@ -1,6 +1,7 @@
 package net.minecraft.world.level.block.entity;
 
 import com.mojang.brigadier.exceptions.CommandSyntaxException;
+import io.papermc.paper.adventure.PaperAdventure; // Purpur
 import javax.annotation.Nullable;
 import net.minecraft.commands.CommandListenerWrapper;
 import net.minecraft.commands.ICommandListener;
@@ -112,6 +113,18 @@ public class TileEntitySign extends TileEntity implements ICommandListener { //
         this.g[i] = null;
     }
 
+    // Purpur start
+    public PacketPlayOutTileEntityData getTranslatedUpdatePacket() {
+        NBTTagCompound nbt = save(new NBTTagCompound());
+        for (int i = 0; i < 4; ++i) {
+            String line = PaperAdventure.LEGACY_AMPERSAND.serialize(PaperAdventure.asAdventure(lines[i]));
+            nbt.setString("Text" + (i + 1), net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().serialize(net.kyori.adventure.text.Component.text(line)));
+        }
+        nbt.setString("PurpurEditor", "true");
+        return new PacketPlayOutTileEntityData(position, 9, nbt);
+    }
+    // Purpur end
+
     @Nullable
     @Override
     public PacketPlayOutTileEntityData getUpdatePacket() {
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index ea95a4116371d58eb36be51093af7f0fa28e3dfd..b67f87f38d0ff99ff62d2103ecc737317a435102 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -109,8 +109,10 @@ public class PurpurWorldConfig {
         });
     }
 
+    public boolean signAllowColors = false;
     public boolean signRightClickEdit = false;
     private void signSettings() {
+        signAllowColors = getBoolean("blocks.sign.allow-colors", signAllowColors);
         signRightClickEdit = getBoolean("blocks.sign.right-click-edit", signRightClickEdit);
     }
 
