From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <Blake.Galbreath@GMail.com>
Date: Tue, 4 Aug 2020 22:08:23 -0500
Subject: [PATCH] Allow anvil colors


diff --git a/src/main/java/net/minecraft/world/inventory/ContainerAnvil.java b/src/main/java/net/minecraft/world/inventory/ContainerAnvil.java
index 1b2d633f3d5d735039f18f27fb1387bd5a74f0d8..77810fbb70bf2e1ad03c28c0d69ceaa63221d94c 100644
--- a/src/main/java/net/minecraft/world/inventory/ContainerAnvil.java
+++ b/src/main/java/net/minecraft/world/inventory/ContainerAnvil.java
@@ -28,6 +28,13 @@ import org.apache.logging.log4j.Logger;
 import org.bukkit.craftbukkit.inventory.CraftInventoryView;
 // CraftBukkit end
 
+// Purpur start
+import io.papermc.paper.adventure.PaperAdventure;
+import net.kyori.adventure.text.Component;
+
+import static net.kyori.adventure.text.format.TextDecoration.ITALIC;
+// Purpur end
+
 public class ContainerAnvil extends ContainerAnvilAbstract {
 
     private static final Logger LOGGER = LogManager.getLogger();
@@ -269,6 +276,17 @@ public class ContainerAnvil extends ContainerAnvilAbstract {
             } else if (!this.renameText.equals(itemstack.getName().getString())) {
                 b1 = 1;
                 i += b1;
+                // Purpur start
+                if (player != null && player.world.purpurConfig.anvilAllowColors && player.getBukkitEntity().hasPermission("purpur.anvil.color")) {
+                    final Component renameTextComponent;
+                    if (renameText.startsWith("&r") && player.getBukkitEntity().hasPermission("purpur.anvil.remove_italics")) {
+                        renameTextComponent = PaperAdventure.LEGACY_AMPERSAND.deserialize(renameText.substring(2)).decoration(ITALIC, false);
+                    } else {
+                        renameTextComponent = PaperAdventure.LEGACY_AMPERSAND.deserialize(renameText);
+                    }
+                    itemstack1.a(PaperAdventure.asVanilla(renameTextComponent));
+                } else
+                // Purpur end
                 itemstack1.a((IChatBaseComponent) (new ChatComponentText(this.renameText)));
             }
 
diff --git a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
index de573b8e09a3ad334991cc313208e0c91990e8a9..1e5dfaac19af7047243b991745a341782850cf20 100644
--- a/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
+++ b/src/main/java/net/pl3x/purpur/PurpurWorldConfig.java
@@ -234,6 +234,11 @@ public class PurpurWorldConfig {
         });
     }
 
+    public boolean anvilAllowColors = false;
+    private void anvilSettings() {
+        anvilAllowColors = getBoolean("blocks.anvil.allow-colors", anvilAllowColors);
+    }
+
     public boolean bedExplode = true;
     public double bedExplosionPower = 5.0D;
     public boolean bedExplosionFire = true;
