Send Plugin Message

Discussion in 'BungeeCord Plugin Development' started by SKAH, Jan 14, 2020.

  1. Hello, i have 2 servers and i would like send plugin message when player was disconnected on the server 1 to switch on server 2, but i want send my message by spigot server

    my code:


    Code (Java):
    @EventHandler
        public void playerQuit(PlayerQuitEvent event)
        {
            Player player = event.getPlayer();
            Utils.getInst().sendData("invest", "invest", "get", player.getName(), (int)Utils.getInst().getMoney(player.getName()));
        }
    Code (Java):
       public void sendData(String sendServer, String channelName, String subChannelName, String stringData, int data) {
       
            ByteArrayDataOutput o = ByteStreams.newDataOutput();
         
            o.writeUTF("Forward");
            o.writeUTF(sendServer);
         
            o.writeUTF(subChannelName);
            o.writeUTF(stringData);
            o.writeInt(data);
            Bukkit.getServer().sendPluginMessage(plugin, channelName, o.toByteArray());
         
            System.out.println("Envoy√© !");
            System.out.println("PlayerName " + stringData);
            System.out.println("Money " + data);
        }
     
  2. I have tried
    Code (Java):
     public void sendData(Player player, String sendServer, String channelName, String subChannelName, String stringData, int data) {
         
            ByteArrayDataOutput o = ByteStreams.newDataOutput();
         
            o.writeUTF("Forward");
            o.writeUTF(sendServer);
         
            o.writeUTF(subChannelName);
            o.writeUTF(stringData);
            o.writeInt(data);
            player.getServer().sendPluginMessage(plugin, channelName, o.toByteArray());
           
            System.out.println("Envoy√© !");
            System.out.println("PlayerName " + stringData);
            System.out.println("Money " + data);
        }
    Println are displayed but message not send
     
  3. Maybe it doesn't send because the player has already disconnected from the server
     
  4. You need an existent connection for send this type of messages, try using one connected player, if your server doesn't have connected players you can't send messages, for that you can use sockets
     
    • Like Like x 1