No BungeeCord PluginMessage on Join?

Discussion in 'BungeeCord Plugin Development' started by Dark4ty, Jun 10, 2015.

  1. Hey guys, I need your help. I'm new at BungeeCord and I'm a bit confused now.
    Code (Text):
          @Override
          public void onPluginMessageReceived(String channel, Player player, byte[] message) {
         
              System.out.println("recived : " + channel);
           
             if (!channel.equals("BungeeCord")) {
              return;
            }
            ByteArrayDataInput in = ByteStreams.newDataInput(message);
            String subchannel = in.readUTF();
            if (subchannel.equals("GetServer")) {
                String servername = in.readUTF();
                System.out.println("Player" + player.getName() + " is on Server " + servername);
                player.sendMessage("§8>> §aYou are on server §8" + servername);
            }
          }
    Code (Text):
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
     
            if(commandLabel.equalsIgnoreCase("usc")){
             
                ByteArrayOutputStream b = new ByteArrayOutputStream();
                DataOutputStream out = new DataOutputStream(b);
             
                try {
                    out.writeUTF("GetServer");
                } catch (IOException e) {
                    e.printStackTrace();
                }

             
                ((Player) sender).sendPluginMessage(plugin, "BungeeCord", b.toByteArray());
             
                return true;
            }
         
         
         
            return false;
     
        }
    Code (Text):
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
     
         //Update the ServerAddres with BungeeCord!    -> replace method sp.setServer();
        ByteArrayOutputStream b = new ByteArrayOutputStream();
        DataOutputStream out = new DataOutputStream(b);
     
        try {
            out.writeUTF("GetServer");
        } catch (IOException e1) {
            e1.printStackTrace();
        }

     
        e.getPlayer().sendPluginMessage(plugin, "BungeeCord", b.toByteArray());
        //Bungeecord ends here!
     
     
     
        }


    The /usc command does work perfect, but the join event doesn't. Where's my mistake?
     
  2. Any errors on join?
     
  3. PlayerJoinEvent is only triggered once the player joins, not after the player joined (if I am correct). You should try using the PostLoginEvent, that should work.
     
  4. It looks like he is writing a spigot plugin, so no PostLoginEvent available. Try to delay the plugin message sending some ticks.
     
  5. Ah, I got a little confused with him being in the Bungeecord section, he should, if that is the case, go to the Spigot help section, not the bungeecord one though, right?
     
    • Agree Agree x 1
  6. I'll try, thanks
    mhm.. It has to do with BungeeCord too, but yeah I think you're right.