callEvent() and following code

Discussion in 'Plugin Development' started by JojoIV, Aug 19, 2018.

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

    JojoIV

    I have a question!

    I was wondering about the behavior of the code after the method callEvent(Event).
    • Does it wait for all listeners to have a chance to handle the event?
    • Or does it just ignore this and move on? (I think it's that one)
    For example:
    Code:
    CommandEvent event = new CommandEvent(sender, cmd, label, args);
    getServer().getPluginManager().callEvent(event);
    return event.isCancelled();
    How do I ensure that it waits for all listeners and THEN returns the cancelled state?

    (I am a total noob at synchronous and asynchronous stuff ... so don't talk to complicated if that's part of the answer)

    Thanks in advance :)
     
  2. Offline

    Zombie_Striker

    @JojoIV
    You should not call any bukkit methods in an async thread. Basically, if you do run this in an async thread, most likely no other events will be called by the time you return.

    If you need to call an event, make sure it is in sync with the main thread.
     
  3. Offline

    JojoIV

    @Zombie_Striker
    Thanks for the reply!
    But how do I do that? As I said I'm a noob at this.
    How do I make sure it is not called in an async thread (the example is placed inside the onCommand() from JavaPlugin)?
    And how would I sync things?

    (And just to be sure: If I call this code in a sync thread then my example should first return when all listeners got a chance on the event?)
     
    Last edited: Aug 20, 2018
  4. Offline

    Zombie_Striker

    @JojoIV
    You would know if you were creating async threads. Unless you are creating a new Thread or using Asyc BukkitRunnables, all other calls are synchronous.
     
Thread Status:
Not open for further replies.

Share This Page