Repository: kyoripowered/adventure
Issue: Legacy color code parsing

When more than one color code is specified consecutively, the one which appears first is used, rather than the last.

For example, `&a&9foo` is parsed to `foo` with color `green` as opposed to `foo` with color `blue`.

Test case:
```java
@Test
public void testFromColor() {
  final TextComponent component = TextComponent.builder("")
    .append(TextComponent.of("foo").color(TextColor.BLUE))
    .build();

  assertEquals(component, ComponentSerializers.LEGACY.deserialize("&a&9foo", '&'));
}
```

```
java.lang.AssertionError: 
Expected :TextComponent{content=, children=[TextComponent{content=foo, children=[], color=blue, obfuscated=null, bold=null, strikethrough=null, underlined=null, italic=null, clickEvent=null, hoverEvent=null, insertion=null}], color=null, obfuscated=null, bold=null, strikethrough=null, underlined=null, italic=null, clickEvent=null, hoverEvent=null, insertion=null}
Actual   :TextComponent{content=, children=[TextComponent{content=foo, children=[], color=green, obfuscated=null, bold=null, strikethrough=null, underlined=null, italic=null, clickEvent=null, hoverEvent=null, insertion=null}], color=null, obfuscated=null, bold=null, strikethrough=null, underlined=null, italic=null, clickEvent=null, hoverEvent=null, insertion=null}
```

I've tried playing around with `LegacyComponentSerializer` to work out a fix. I assume this is happening because the string is being parsed in reverse, meaning the first color code in the string is being read after the color code later in the string - hence overriding the last.

Changed files:
src/test/java/net/kyori/text/serializer/ComponentSerializerTest.java, src/main/java/net/kyori/text/BuildableComponent.java, src/main/java/net/kyori/text/serializer/LegacyComponentSerializerImpl.java, src/main/java/net/kyori/text/AbstractBuildableComponent.java

diff --git a/src/main/java/net/kyori/text/AbstractBuildableComponent.java b/src/main/java/net/kyori/text/AbstractBuildableComponent.java
index 949ebfe1..904274a7 100644
--- a/src/main/java/net/kyori/text/AbstractBuildableComponent.java
+++ b/src/main/java/net/kyori/text/AbstractBuildableComponent.java
@@ -215,6 +215,15 @@ public abstract class AbstractBuildableComponent<C extends BuildableComponent<C,
       return (B) this;
     }
 
+    @NonNull
+    @Override
+    public B colorIfAbsent(@Nullable final TextColor color) {
+      if(this.color == null) {
+        this.color = color;
+      }
+      return (B) this;
+    }
+
     @NonNull
     @Override
     public B decoration(@NonNull final TextDecoration decoration, @NonNull final TextDecoration.State state) {
diff --git a/src/main/java/net/kyori/text/BuildableComponent.java b/src/main/java/net/kyori/text/BuildableComponent.java
index 4cb74fec..168fcabb 100644
--- a/src/main/java/net/kyori/text/BuildableComponent.java
+++ b/src/main/java/net/kyori/text/BuildableComponent.java
@@ -125,6 +125,15 @@ public interface BuildableComponent<C extends BuildableComponent<C, B>, B extend
     @NonNull
     B color(@Nullable final TextColor color);
 
+    /**
+     * Sets the color of this component if there isn't one set already.
+     *
+     * @param color the color
+     * @return this builder
+     */
+    @NonNull
+    B colorIfAbsent(@Nullable final TextColor color);
+
     /**
      * Sets the state of a decoration on this component.
      *
diff --git a/src/main/java/net/kyori/text/serializer/LegacyComponentSerializerImpl.java b/src/main/java/net/kyori/text/serializer/LegacyComponentSerializerImpl.java
index cf776c30..85df3668 100644
--- a/src/main/java/net/kyori/text/serializer/LegacyComponentSerializerImpl.java
+++ b/src/main/java/net/kyori/text/serializer/LegacyComponentSerializerImpl.java
@@ -109,7 +109,7 @@ class LegacyComponentSerializerImpl implements LegacyComponentSerializer {
 
   private static boolean applyFormat(@NonNull final TextComponent.Builder builder, @NonNull final TextFormat format) {
     if(format instanceof TextColor) {
-      builder.color((TextColor) format);
+      builder.colorIfAbsent((TextColor) format);
       return true;
     } else if(format instanceof TextDecoration) {
       builder.decoration((TextDecoration) format, TextDecoration.State.TRUE);
diff --git a/src/test/java/net/kyori/text/serializer/ComponentSerializerTest.java b/src/test/java/net/kyori/text/serializer/ComponentSerializerTest.java
index d46696ef..5a80917c 100644
--- a/src/test/java/net/kyori/text/serializer/ComponentSerializerTest.java
+++ b/src/test/java/net/kyori/text/serializer/ComponentSerializerTest.java
@@ -47,6 +47,15 @@ public class ComponentSerializerTest {
     assertEquals(component, ComponentSerializers.LEGACY.deserialize("&a&lfoo&9bar", '&'));
   }
 
+  @Test
+  public void testFromColorOverride() {
+    final TextComponent component = TextComponent.builder("")
+      .append(TextComponent.of("foo").color(TextColor.BLUE))
+      .build();
+
+    assertEquals(component, ComponentSerializers.LEGACY.deserialize("&a&9foo", '&'));
+  }
+
   @Test
   public void testToLegacy() {
     final TextComponent c1 = TextComponent.builder("hi")