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/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index abe8670ec7b0ef4a93418a5e9cf23a1a536cbc96..cdc559a8330d804a269f942f5bcba84ab9ea4289 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -1449,6 +1449,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/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index be29ecfa00d53ad2067015a5261184b4157c604b..4d0dcbcc00e44c4912302dd0e7331471f33cb370 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -2902,6 +2902,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/server/TileEntitySign.java b/src/main/java/net/minecraft/server/TileEntitySign.java
index 1e6bb566c0a718bba289b2e727a832e0aa6b7f15..cbbaf8ca4b6425e2ce58e500b13b3b5269704c3c 100644
--- a/src/main/java/net/minecraft/server/TileEntitySign.java
+++ b/src/main/java/net/minecraft/server/TileEntitySign.java
@@ -2,6 +2,7 @@ package net.minecraft.server;
 
 import com.mojang.brigadier.exceptions.CommandSyntaxException;
 import javax.annotation.Nullable;
+import io.papermc.paper.adventure.PaperAdventure; // Purpur
 
 public class TileEntitySign extends TileEntity implements ICommandListener { // CraftBukkit - implements
 
@@ -92,6 +93,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 8393a0253ac16a8f15f78288d6cc31f8688c403c..484da2bf267cab4e4569c98111398af64c834eed 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);
     }
 
