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

Plugin Help (Calling Files)

Comments in 'Plugin Development' started by CrazedMiner, May 10, 2015.

  1. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I want to call a file from my Main.php that's inside a folder called Events, inside this folder I have a file called EventsHandler and I have all my different events in separate files and I want to call them from my EventsHandler file, my Problem is I don't know how to call the EventsHandler file every time an Event is called and call the separate event file from EventsHandler.

    I know to call my event files separately to use
    PHP:
    $this->getServer()->getPluginManager()->registerEvents(new Events\JoinEvent($this), $this);
    but I want my EventsHandler file to be the "Middle Man" that is called when an event is and then it goes through all the different event files.

    If you somehow managed to understand my Problem I would greatly appreciate any help you could give :)
  2. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    You mean
    PHP:
    $this->getServer()->getPluginManager()->registerEvents(new Events\EventsHandler\JoinEvent($this), $this);
    ?
    You can just do
    PHP:
    use Folder\Events\EventsHandler\JoinEvents;
    at the beggining and
    PHP:
    $this->getServer()->getPluginManager()->registerEvents(new JoinEvents($this), $this);
    when you call the event
    EvolSoft and CrazedMiner like this.
  3. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    -.-

    Folder\Events\EventsHandler\JoinEvents is a file path that doesn't exist....

    I said that I have my Main.php then I have a folder called Events and in that folder I have EventsHandler.php and JoinEvent.php.
    I want to call EventsHandler from Main.php whenever an event is called and from EventsHandler I want it to call the separate Evnt file (Join.php, Quit.php ect). I want it this way because I'm picky and for easy editing/adding stuff on events :p
  4. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    Do you mean that you want to handle every event on a separate php file?
  5. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Yes, but I want the separate files to be called from the EventsHandler.php file that is called from Main.php
  6. EvolSoft
    Offline

    EvolSoft Notable Member Plugin Developer

    Joined:
    Sep 10, 2014
    Posts:
    821
    Plugins:
    15
    Minecraft User:
    Flavius12
    I think that it's better if you register every event directly on the Main.php script.
    PHP:
    $this->getServer()->getPluginManager()->registerEvents(new JoinEvent($this), $this);
    $this->getServer()->getPluginManager()->registerEvents(new LeaveEvent($this), $this);
    hoyinm14mc likes this.
  7. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Yea, I thought I might end up having to do that :/
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    More precisely, you are putting things at different classes not different files. The main point is to make them all in individual classes. You don't call a file. You load a class, then call member functions inside it. The file is autoloaded when you load the class. Don't get the concept wrong.
    Falk, hoyinm14mc and CrazedMiner like this.
  9. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    I'm picky and I like to have separate files for each event :p
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I am picky too. Call it "classes" not "files".
    Falk likes this.
  11. hoyinm14mc
    Offline

    hoyinm14mc Notable Member Plugin Developer

    Joined:
    Jun 4, 2014
    Posts:
    502
    Plugins:
    9
    Minecraft User:
    hoyinm14mc
    Haha finally I understand what he's talking about

Share This Page

Advertisement