sendMessage()'s out of order?

Discussion in 'Plugin Development' started by treestompz, Feb 9, 2013.

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


    Hello Everyone,

    I am making a small plugin to mess with a player when he logs into the server.

    I want to send the player 3 messages and for some reason they are sending out of order.

    @EventHandler(priority = EventPriority.MONITOR)
        public void join(PlayerJoinEvent event)
            Player p = event.getPlayer();
            p.playSound(p.getLocation(), Sound.LEVEL_UP, 10, 1);
            p.sendMessage(ChatColor.GREEN + "Message 1! ");
            p.sendMessage(ChatColor.GREEN + "Message 2!");
            p.sendMessage(ChatColor.RED + "Message 3!");
    Teleporting the player to location always works.

    The sendMessage() methods often sends the messages in a random order. (Ex: instead of 1,2,3 it will send them as 2,3,1) Whenever the messages are out of order, the playSound() method doesn't work, otherwise it does.

    Does anyone know why this is happening?

    Thanks in advance :D
  2. Offline

    ZeusAllMighty11 Retired Staff

    Well since they should all be sent at the same time, it comes down to which one can it send first.
    Try doing a delay when they join of 1 second
    microgeek likes this.
  3. Offline


    I had the same problem. Only solution that worked for me was, concaternating those messages into one single message and using linebreaks to display them one after another.

    It probably or almost surely has to do with the new async chat event that makes such things hard to control.
  4. Offline


    Does grouping them in an array and using one sendMessage() to send them do the same ?
  5. Offline


    Delay it with a scheduler, it takes a couple of seconds from PlayerJoinEvent is called, to they are actually ingame and can see things.
  6. Offline


    Digi: No. And Using sendMessages() instead of sendMessage() will also not solve the problem. I already tried that.
    Using a scheduler is also not a reliable solution. Even if you use a separate scheduler for each message, you can't be sure it will be sent in order, unless you use a high delay. And by doing this, you risk that other messages will come in between your message set.

    I tried to mess with the async chat event, but had no luck in resolving this a more proper way...
  7. Offline


    I don't have this issue, so I honestly don't think that the async caused the issue. His problem (when isolated), was BungeeCord. After removing that, the issue didn't occur.
Thread Status:
Not open for further replies.

Share This Page