Having issues receiving player lists form Plugin Channels. Please Help!

Discussion in 'Plugin Development' started by GODofCRAFTERS, Apr 13, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    GODofCRAFTERS

    I'm using the BungeeCord plugin. But I don't know why I'm getting the error that I'm getting.
    Here's the variable declarations:
    Code:
    public static String server = null;
    public static String[] playerList = null;
    Here's the registering of Outgoing and Incoming Plugin channels in the onEnable method:
    Code:
    Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
            Bukkit.getMessenger().registerIncomingPluginChannel(this, "BungeeCord", this);
    Here'e the onPluginMessageReceived method:
    Code:
    @Override
        public void onPluginMessageReceived(String channel, Player player, byte[] message){
               ByteArrayDataInput i = ByteStreams.newDataInput(message);
               String subchannel = i.readUTF();
            if (subchannel.equals("PlayerList")) {
                server = i.readUTF();
                playerList = i.readUTF().split(", ");
                player.sendMessage("so far so good");
            }
        }
    Here's where I give the output stream and call the subchannel:
    Code:
    String msg = new String("string");
            
                ByteArrayDataOutput out = ByteStreams.newDataOutput();
            
                out.writeUTF("PlayerList");
                out.writeUTF("ALL");
            
                for(String staff : playerList){
                    if(player.hasPermission("requests.recieve")){
                    
                        try{
                            out.writeUTF("Message");
                            out.writeUTF(staff);
                            out.writeUTF(msg);
                        }catch(Exception e){}
                    }
                }
    It gives me a NullPointerException at the line that contains the "for" loop. Probably because playerList is empty. But I don't know why it's empty. Please help.
     
  2. Online

    timtower Administrator Administrator Moderator

    Locked.
    Offline mode is not supported
     
Thread Status:
Not open for further replies.

Share This Page