Correct use of custom events

Discussion in 'Plugin Development' started by RcExtract, Apr 20, 2019.

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

    RcExtract

    If I have some methods which make changes to a player programmatically, while player can execute certain commands to achieve that, should I fire events to notify such changes within the method or the command executor?

    For example, I have made a command called /canchat and a method called setCanChat(boolean) which toggle the ability for a player to chat. The /canchat internally calls setCanChat(boolean). I have also made an event called PlayerToggleCanChatEvent. Should I fire the event in
    • setCanChat(boolean) (no matter if the change is done programmatically or by executing commands, the event will be fired) or
    • the command executor for /canchat (the event will only be fired when the change is done by executing commands)?
    Or are there any other better approaches to notify other Listeners about changes without abusing the Bukkit Event API? Thanks.
     
  2. Offline

    Shqep

    Depends on what you want listeners to know.
     
  3. Offline

    RcExtract

    The problem is there are a lot of these situations in my plugin. If i fire events in methods instead of command executors, nearly every method fires an event, which looks abusing. But methods in Bukkit Api like Player.setSprinting and Player.setFlying also fire events.
     
  4. Offline

    timtower Moderator Moderator

    @RcExtract Then call the event in the method that toggles it, outside commands.
     
Thread Status:
Not open for further replies.

Share This Page