package io.github.aquerr.eaglefactions.listeners;

import io.github.aquerr.eaglefactions.logic.FactionLogic;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.filter.cause.Root;
import org.spongepowered.api.event.message.MessageChannelEvent;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.TextRepresentable;
import org.spongepowered.api.text.format.TextColors;

public class ChatMessageListener
{
    @Listener
    public void onChatMessage(MessageChannelEvent.Chat event, @Root Player player)
    {
        if(FactionLogic.getFactionName(player.getUniqueId()) != null)
        {
            String message = event.getMessage().toPlain();

            String fullMessage[] = message.split(":");

            String head = fullMessage[0];
            String body = fullMessage[1];

            head = head.replace(player.getName(), "");

            String factionTag = FactionLogic.getFactionTag(FactionLogic.getFactionName(player.getUniqueId()));
            if(factionTag != null)
            {
                TextRepresentable header = Text.of(head + "[", TextColors.GREEN, factionTag, TextColors.RESET, "]" + player.getName() + ":");
                TextRepresentable textRepresentable = Text.of(body);

                event.setMessage(header,textRepresentable);
            }
        }

        return;
    }
}

@@ -691,32 +691,34 @@
    %7B%0A           
+//
  String message 
@@ -749,16 +749,18 @@
 lain();%0A
+//
 %0A       
@@ -755,32 +755,34 @@
 ;%0A//%0A           
+//
  String fullMess
@@ -805,24 +805,26 @@
 split(%22:%22);%0A
+//
 %0A           
@@ -815,32 +815,34 @@
 ;%0A//%0A           
+//
  String head = f
@@ -859,32 +859,34 @@
 %5B0%5D;%0A           
+//
  String body = f
@@ -900,16 +900,18 @@
 age%5B1%5D;%0A
+//
 %0A       
@@ -914,16 +914,18 @@
         
+//
  head = 
@@ -960,16 +960,18 @@
 ), %22%22);%0A
+//
 %0A       
@@ -974,16 +974,18 @@
         
+//
  String 
@@ -1083,24 +1083,26 @@
 %0A           
+//
  if(factionT
@@ -1120,24 +1120,26 @@
 %0A           
+//
  %7B%0A         
@@ -1132,32 +1132,34 @@
 // %7B%0A           
+//
      TextReprese
@@ -1280,24 +1280,26 @@
 %0A           
+//
      TextRep
@@ -1344,16 +1344,18 @@
 (body);%0A
+//
 %0A       
@@ -1354,24 +1354,26 @@
 %0A           
+//
      event.s
@@ -1420,18 +1420,336 @@
         
- %7D
+// %7D%0A%0A            Text text = Text.builder()%0A                    .append(Text.of(%22%5B%22,TextColors.GREEN, FactionLogic.getFactionTag(FactionLogic.getFactionName(player.getUniqueId())), TextColors.RESET, %22%5D%22))%0A                    .append(event.getMessage())%0A                    .build();%0A%0A            event.setMessage(text);
 %0A       

Change style of displaying tags