Send a plugin message when a player quit the server

Discussion in 'Spigot Plugin Development' started by Frivec, Aug 26, 2019.

  1. Hi

    I would like to send a plugin message to bungeecord when a player quit the server but it doesn't works

    There's no pre quit event so how can i send this message please ?
  2. @EventHandler
    public void onDc(PlayerQuitEvent e){
    //send message
  3. That's what i tried ;)

    The plugin message isn't sent at all. The bungeecord will never receive the plugin message and idk why :/ It works with the join event but not with the quit event.
  4. I'm not very familiar with BungeeCord, have you tried using the playerquitevent for something other than bungeecord, just to see if it would work with other stuff?
  5. Can you show your code?
  6. I tried with something else and it works, so the problem is probably the plugin message. Thanks anyway for your help :).

    If you want, but it's kind of classic:

    Code (Java):
        public void onQuit(final PlayerQuitEvent e) {
            final Player player = e.getPlayer();
            final HubPlayer hubPlayer = HubPlayer.get(player.getUniqueId());  

            final ByteArrayDataOutput out = ByteStreams.newDataOutput();
            sendPluginMessage(player, Utils.pmHubChannel, out.toByteArray());

    • Friendly Friendly x 1
  7. The sendPluginMessage method would also be interesting to see.
  8. Ok, here it is:

    Code (Java):
        public static void sendPluginMessage(final Player player, final String channel, final byte[] bytes) {
            Bukkit.getScheduler().scheduleSyncDelayedTask(Hub.getInstance(), new Runnable() {
                public void run() {
                    if(player != null)
                        player.getServer().sendPluginMessage(Hub.getInstance(), channel, bytes);
                        Bukkit.getServer().sendPluginMessage(Hub.getInstance(), channel, bytes);
            }, 3L);
  9. Don't delay the plugin message send.
  10. The delay is necessary because of the player join event. Without the delay, the messages isn't sent.

    I'll try to remove it for the quit event :)


    It doesn't works :/
    #10 Frivec, Aug 26, 2019
    Last edited: Aug 26, 2019
  11. I think it's because spigot send message to bungeecord with player's connection
  12. I found why the plugin message isn't received by bungeecord. It's because a player has to be connect at the moment of the receive.

    When the plugin message is received by the bungeecord, there's no player connected, so it doesn't works :/

    Thanks for your help :)
  13. You can use sockets if you want it to work without players.
  14. I'll try :) Thanks for your help
  15. Wouldn't it be better to store these values in a SQL database?
  16. Yeah, an SQL database would probably be the way to go. Don't dive into the hassle of sockets when there are easier ways.
  17. Are implement bungeecord in and output in a main class?
  18. I use a sql database to store these values.

    The plugin wich use the plugin messages isn't connected to my database, only Bungeecord is. I wanted to use the plugin messages to send the informations to the bungeecord proxy then save them into the database.

    It's a way to avoid having too many connections to the database.