package com.jumanjicraft.BungeeChatClient;

import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;

public class BungeeChatSender {

    private final BungeeChatClient plugin;

    /**
     *
     * @param plugin
     */
    public BungeeChatSender(BungeeChatClient plugin) {
        this.plugin = plugin;
        register();
    }
    
    private void register() {
        plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord");
    }    
    
    /**
     *
     * @param cm
     */
    public void TransmitChatMessage(ChatMessage cm) {
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        
        /* My custom tag */
        out.writeUTF("PurpleBungeeIRC");
        
        /* Herochat tokens */
        out.writeUTF(cm.getChannel());
        out.writeUTF(cm.getMessage());
        out.writeUTF(cm.getSender());
        out.writeUTF(cm.getHeroColor());
        out.writeUTF(cm.getHeroNick());
        
        /* Vault tokens */
        out.writeUTF(cm.getPlayerPrefix());
        out.writeUTF(cm.getPlayerSuffix());
        out.writeUTF(cm.getGroupPrefix());
        out.writeUTF(cm.getGroupSuffix());
        out.writeUTF(cm.getPlayerGroup());
        
        plugin.getServer().sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
    }

}

@@ -54,118 +54,358 @@
 com.
-google.common.io.ByteArrayDataOutput;%0D%0Aimport com.google.common.io.ByteStreams;%0D%0A%0D%0Apublic class BungeeChatSend
+dthielke.Herochat;%0D%0Aimport com.dthielke.api.Channel;%0D%0Aimport com.google.common.io.ByteArrayDataInput;%0D%0Aimport com.google.common.io.ByteArrayDataOutput;%0D%0Aimport com.google.common.io.ByteStreams;%0D%0Aimport org.bukkit.entity.Player;%0D%0Aimport org.bukkit.plugin.messaging.PluginMessageListener;%0D%0A%0D%0Apublic class BungeeChatSender implements PluginMessageListen
 er %7B
@@ -617,20 +617,16 @@
 %0A    %7D%0D%0A
-    
 %0D%0A    pr
@@ -704,13 +704,13 @@
 ster
-Outgo
+Incom
 ingP
@@ -742,20 +742,26 @@
 geeC
-ord%22
+hat%22, this
 );%0D%0A    
 %7D   
@@ -760,19 +760,107 @@
     
-%7D
     
+plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, %22BungeeChat%22);
 %0D%0A    
+%7D%0D%0A
 %0D%0A  
@@ -1016,32 +1016,24 @@
 aOutput();%0D%0A
-        
 %0D%0A        /*
@@ -1089,32 +1089,24 @@
 ngeeIRC%22);%0D%0A
-        
 %0D%0A        /*
@@ -1324,32 +1324,24 @@
 roNick());%0D%0A
-        
 %0D%0A        /*
@@ -1580,24 +1580,16 @@
 up());%0D%0A
-        
 %0D%0A      
@@ -1647,11 +1647,11 @@
 geeC
-ord
+hat
 %22, o
@@ -1679,11 +1679,648 @@
    %7D%0D%0A%0D%0A
+    @Override%0D%0A    public void onPluginMessageReceived(String tag, Player player, byte%5B%5D data) %7B%0D%0A        if (!tag.equalsIgnoreCase(%22BungeeChat%22)) %7B%0D%0A            return;%0D%0A        %7D%0D%0A        ByteArrayDataInput in = ByteStreams.newDataInput(data);%0D%0A        String chatchannel = in.readUTF();%0D%0A        String message = in.readUTF();%0D%0A        plugin.logDebug(%22chatChannel: %22 + chatchannel);%0D%0A        plugin.logDebug(%22message: %22 + message);%0D%0A        Channel channel = Herochat.getChannelManager().getChannel(chatchannel);%0D%0A        if (channel == null) %7B%0D%0A            return;%0D%0A        %7D%0D%0A%0D%0A        channel.sendRawMessage(message);%0D%0A%0D%0A    %7D%0D%0A%0D%0A
 %7D%0D%0A

Fix irc -> herochat