Plugin_message_received event triggering multiple times.

Discussion in 'CommandHelper' started by Nolz, Aug 25, 2018.

  1. Nolz

    Nolz New Member

    Greetings!

    I've been working on a way that lets me send messages from one server to another (for things like TP requests and the like), but I ran into a rather odd problem. For whatever reason, whenever I send a plugin message to a player using send_plugin_message(), the event seems to always trigger three times.

    We've already tried;
    • Updating to the latest CommandHelper build (we're now on build 3408)
    • Updating to the latest BungeeCord version (we're now on build 1352)
    • Restarting everything ever.
    We automatically update PaperSpigot every time we launch the server, so we're currently on build 1552.

    The code I'm using is;

    Code (Text):
    proc _pmsgPlayer(@player, @message, @channel){
        @ba = byte_array()
        ba_put_string(@ba, 'ForwardToPlayer')
        ba_put_string(@ba, @player)
        ba_put_string(@ba, @channel)
        ba_put_string(@ba, @message)
        send_plugin_message('BungeeCord', @ba)
    }

    bind(plugin_message_received, null, null, @event,
        @msg = string_from_bytes(@event[bytes])
        @msg = reg_replace('\\p{Cc}',' ',@msg)
        @msg = replace(@msg, "   ", "  ")
        @msg = replace(@msg, "  ", " ")
        @msg = split(" ", @msg)
        array_remove(@msg, 0)
        if(@msg[0] != "tprequest"){
            die()
        }
        array_remove(@msg, 0)
        @msg = array_implode(@msg)
        tmsg(@event[player], @msg)
    )

    register_command("msgtest", array(
        "permission": "commandhelper.*",
        "executor": closure(@cmd, @player, @args,
            _pmsgPlayer(@args[0], "test!", "tprequest")
        )
    ))
    The expected result is that upon running "/msgtest <player>", a single message saying "test!" will be shown to <player>. The actual result is that the message gets shown three times.

    Does anyone have any idea as to what I'm doing wrong?

    Many thanks in advance!
  2. __import__

    __import__ Member

  3. Nolz

    Nolz New Member

    We considered using it a while back actually, but none of us could figure out how it works. Plus, I think that due to the fact that we don't have a fixed amount of servers (they start/stop as needed), using CHServerCommunication would get really complicated, really quickly. I'd say plugin messaging seems to be the best option we have.

    EDIT: Some experimenting later; it turns out that the message was being shown three times because the file that contained the event was being included 3 times. The issue was was solved right away once I fixed that.
    Man, that was one annoying issue.
    Last edited: Aug 28, 2018