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

Solved Commands and Args in Multi Files

Discussion in 'Development' started by Teamblocket, Jan 1, 2018.

  1. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    Ok so i was wondering how i can make each of my $args[0] in a different file , its for a faction plugin so theirs going be a lot of $args[0] usage so i want to sperate them to its own file.
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    You arent suppose to do that unless you know how to do it or else it just causes more hassle
     
    HyGlobalHD likes this.
  3. HyGlobalHD

    HyGlobalHD Spider Jockey

    Messages:
    25
    GitHub:
    HyGlobalHD
    What Thunder Said is True.

    It Only Be More Complicated.
     
  4. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    Can someone just show me the correct way todo this? I don't care if its complicated or its more of a hassle.
     
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    The question is not in whether it's complicated or whether you know how to, but in why you want to do it.

    If you simply think multi files "looks cool": Just forget it. It looks even cooler if you manage a large plugin in a single file.

    If you want to separate your code into separate files to make it easier to manage, just create "utility classes" that declare static methods. Create a class of any (valid) name you like, declare a static function with the required parameters (e.g. $main, $args, $sender, etc.) and call the static function from your original command handler, moving your code over there. You don't even need to create useless stuff like class properties and constructors.

    If you truly have reasons related to OOP that makes you want to separate files... you should know how anyway.
     
    Teamblocket likes this.
  6. Irish

    Irish Baby Zombie

    Messages:
    156
    GitHub:
    irishpacks
    A SubCommand class would probably be what you're looking for, but I'd look into OOP(Object Oriented Programming) before trying to do it. In the long run, it'd be good to know OOP anyways.
     
  7. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    Ill go with your idea then since i can do that and its easier to manage, thanks.:)
     
  8. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    I have seen so many people registering commands with custom classes without an explicit reason to. What they do is just to complicate a single plugin by rewriting what is in the PluginCommand class. This gets more ironic when your command only has a few lines that actually execute something, and you're writing several tens of lines in several files, redirecting calls everywhere just to execute a few lines.
    Admittedly, it is good when your plugin gets big in the future. But you could as well implement the onCommand() method in PluginBase and make calls to static methods in other classes. Generally, you don't need to register custom command classes unless your commands are highly dynamic (e.g. you register new commands according to settings in a config, not hardcoded commands).
     
    Jack Noordhuis and HimbeersaftLP like this.
  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.