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

Enable/disable classes?

Discussion in 'Facepalm' started by WreckagePE / ZAYD, May 1, 2017.

  1. WreckagePE / ZAYD

    WreckagePE / ZAYD Slime

    Messages:
    82
    I was coding a UHC plugin. UHC has stuff called 'Scenarios'. An example of a scenario is NoFall. NoFall basically makes it so you cannot take damage from fall...


    I can setup this class and it's code correctly, but how can I enable the code inside it to be active/unactivate it within a command?
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    Lowkey likes this.
  3. Lowkey

    Lowkey Slime

    Messages:
    94
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    just dont register that class as an event listener
    even if it implements it, if you dont register it nothing should happen
     
  5. Intyre

    Intyre Administrator Staff Member PMMP Team

    Messages:
    81
    GitHub:
    Intyre
    PHP:
    if($disabled){return;}
     
  6. WreckagePE / ZAYD

    WreckagePE / ZAYD Slime

    Messages:
    82
    Can you like uhh say more? I don't understand
     
  7. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    PHP:
    if($this->disabled){return;}
    basically if the property disabled is true, return(i hope you KNOW what return meant)
    even tho i recommend just dont even register events in the first place
     
    Last edited by a moderator: May 1, 2017
  8. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    I don't think anyone ever mentioned Event Listeners.
    He is implying that you can use a simple attribute in your class(Although it's technically an object) set to a boolean value that indicates whether the code in that class should be executed or not. It would really help if you explained how your CutClean class works. Does it implement pocketmine\event\Listener, and handle events itself? Or does the plugin's main Listener(I assume it has one) execute methods in the CutClean class on an event?
     
  9. WreckagePE / ZAYD

    WreckagePE / ZAYD Slime

    Messages:
    82
    It's a class by itself which implements PluginBase. It just setDrops of ores to ingots.

    I need an example code to study...
     
  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.