1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

PQRS Addition: Check if plugin is enabled in execute()

Discussion in 'General discussion' started by SalmonDE, Mar 7, 2018.

  1. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Hello!

    I often see people overriding PluginCommand::execute() but many of them forget calling the parent method at the beginning.
    Personally, I prefer to implement CommandExecutor in my commands so I never get in this situation, but that's irrelevant.

    Anyway, my point is that within PluginCommand::execute() there is a check whether the owning plugin is still enabled or not.
    If the plugin gets disabled after the command was registered and the server doesn't stop, it's possible that the command still gets executed which therefore could result into some unexpected behaviour, because for instance the plugin would fail starting a task.

    You may think that PMMP unregisters the commands of a plugin when disabled, but as far as I can tell it doesn't.

    Although I'd suggest to think about adding a clause for this into the PQRS, I'm not sure if it suits the aim of the document so I'm open for thoughts about this entire topic.

    Additionally I've added a example plugin which adds the command /examplecommand. When the server enables the plugin it registers the command and disables itself again.
     

    Attached Files:

    SOFe, notapplqpak, Palente and 3 others like this.
  2. EdwardHamHam

    EdwardHamHam Skeleton

    Messages:
    962
    GitHub:
    edwardhamham
    Strange. I never realised this.
     
    0x15f likes this.
  3. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
    Yeah it usually never happens. Even I didn't think of it as something important.
    I first encountered this last year when I tested a plugin of someone. Eventually I dropped it because it never concerned me but it started to bug me again lately so I brought it up here.
     
  4. 0x15f

    0x15f Baby Zombie

    Messages:
    145
    GitHub:
    0x15f
    Me either... my whole life is a lie 0.o
     
  5. SalmonDE

    SalmonDE Zombie Pigman

    Messages:
    739
    GitHub:
    SalmonDE
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.