Messaging Channel doesn't work?

Discussion in 'BungeeCord Plugin Development' started by nullUser, Mar 23, 2013.

  1. Hi, is there any way would pick a message from message channel?
    I try this make like that but doesn't work :(
    Code:
    test.java
    Code (Text):
    package com.test.test.digitalix;
     
    import java.io.ByteArrayOutputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
     
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
     
    public class test extends JavaPlugin implements Listener{
     
        public void onEnable(){Event();BungeeCord();}
       
        public void Event(){
            getServer().getPluginManager().registerEvents(this, this);
        }
       
        public void BungeeCord(){
           
            Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
            Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", new mListener(this));
           
        }
       
        @EventHandler(priority=EventPriority.HIGH)
        public void send(PlayerJoinEvent e) throws IOException{
     
            Player p = e.getPlayer();
     
            String msg = "Hi! This works!";
           
            ByteArrayOutputStream bao = new ByteArrayOutputStream();
            DataOutputStream msgData = new DataOutputStream(bao);
            msgData.writeUTF("Forward");
            msgData.writeUTF("lobby");
            msgData.writeUTF("MCW");
            msgData.writeShort(msg.length());
            msgData.writeBytes(msg);
            p.sendPluginMessage(this, "BungeeCord", bao.toByteArray());
     
        }
       
    }
    and mListener.java
    Code (Text):
    package com.test.test.digitalix;
     
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.messaging.PluginMessageListener;
     
    public class mListener implements PluginMessageListener {
     
        private test plugin;
     
        public mListener(test test) {
            // TODO Auto-generated constructor stub
            this.plugin = test;
        }
     
        @Override
        public void onPluginMessageReceived(String arg0, Player arg1, byte[] arg2) {
            // TODO Auto-generated method stub
            System.out.print("MSG!");
           
     
            this.plugin.getLogger().info("Got Plugin Message on " + arg0 + " from " + arg1.getName() + " messge was: " + arg2.toString());
     
        }
     
    }
     
    Why this dosen't work?
     
  2. md_5

    Administrator Developer

    Can't send plugin messages on player join, schedule a sync delayed task for one tick later.