Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Multiple Files In /scr

Comments in 'Plugin Development' started by Tethered_, Dec 26, 2014.

  1. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    When is it a good idea to break up code into different files in /src, and if I declare variables in one file, how can I access them in other files?
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Pass the variables to the constructor of the other class (file).
    EvolSoft likes this.
  3. Tethered_
    Offline

    Tethered_ Active Member Plugin Developer

    Joined:
    Jun 24, 2014
    Posts:
    178
    Plugins:
    2
    Minecraft User:
    Frostbyte58
    And why would someone want to make multiple files? Does it speed up the server? Are there any benefits?
  4. Praxthisnovcht
    Offline

    Praxthisnovcht Notable Member Plugin Developer

    Joined:
    Mar 10, 2014
    Posts:
    702
    Plugins:
    4
    Minecraft User:
    PraxHellTag
    PHP:
        public function __construct(Main $plugin)
        {
    I personally use a lot of files to find me as I am a novice.

    But I never ask if it optimizes or not =)
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    they don't use more files on purpose. Different files mean different classes, and sometimes you need multiple classes to organize your code, or to make subclasses, like subclasses of PluginTask.
    Tethered_ likes this.
  6. ProjectInfinity
    Offline

    ProjectInfinity Active Member Plugin Developer

    Joined:
    Sep 7, 2014
    Posts:
    112
    Plugins:
    3
    Minecraft User:
    ProjectInfinity
    Maintainability mostly, and some things just have to be separated from the previous class.

    Take a look at ReportRTS, you can see that I (coming from a Java background, where it makes proper sense because of package names) enjoy heavily partitioning the files.
    https://github.com/ProjectInfinity/...ion/tree/master/src/ProjectInfinity/ReportRTS
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Or look at WorldEditArt, where I have one class for each command and register these classes at the main class. I also use classes like Space and Macro to make the server faster by defining data structures rather than with arrays.
  8. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,132
    Plugins:
    4
    Minecraft User:
    iksaku
    Or look at EssentialsPE, we made multiple classes to make the environment work like PocketMine, it is more organized and the commands (that are made per class) are more powerful
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
  10. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    scr...
    PEMapModder likes this.

Share This Page

Advertisement