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

Multiple SRC Files

Discussion in 'Development' started by Junkdude, Nov 21, 2016.

  1. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    K, I asked this question before, but how do you make multiple src files? I want to have a commands one, main one, and a listener one. Any idea?
     
  2. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Nah, Im having multiple commands, events, etc
     
  3. Reid

    Reid Spider Jockey

    Messages:
    43
    Ohh I see what you mean yeah like I said above just make a new file in in the same directory as your main
     
  4. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    It doesnt register though
     
  5. Tux

    Tux Silverfish

    Messages:
    16
    GitHub:
    minecrafter
    Can you post your code?
     
  6. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Dont have any yet, just wanted to know how
     
  7. Reid

    Reid Spider Jockey

    Messages:
    43
    Let me whip up an example for you really fast
     
  8. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
  9. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Can I have that example now???
     
  10. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You don't make multiple files just because you want to. You ask yourself why you want to do so before you do something. And why, in this situation?
     
    Thunder33345 likes this.
  11. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Organization, make things look neater and easier to clean.
     
  12. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    And are you sure you know the impacts of separating them? You don't simply put them into different files. You make each command its own class, and this is not as simple as "This paragraph is too long; let me start a new paragraph".
     
    Thunder33345 and Jack Noordhuis like this.
  13. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    I know, I'm making a big plugin and I would just like to know.
     
  14. Reid

    Reid Spider Jockey

    Messages:
    43
    Oh dude I'm so sorry for the wait 0.0 I fell asleep but here
    hey.php(non main)
    PHP:
    <?php

    namespace big;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\block\BlockBreakEvent;

    class 
    hey implements Listener{
     
        public function 
    onBreak(BlockBreakEvent $event){
        
    $event->setCancelled();
        }
    }
    then my main Loader.php
    PHP:
    <?php

    namespace big;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\event\entity\EntitySpawnEvent;
    class 
    Loader extends PluginBase implements Listener{

        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getServer()->getPluginManager()->registerEvents(new hey($this), $this);
            
    $this->getLogger()->info(TextFormat::GREEN."big enabled.");
        }
     
        public function 
    onDisable(){
            
    $this->getLogger()->info(TextFormat::RED."big disabled.");
        }
        public function 
    onSpawn(EntitySpawnEvent $event){
      
    $event->getEntity()->setHealth(1);
       }
    }
     
    Last edited: Nov 21, 2016
  15. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Now, could I just make a commands one to using the non maing setup (constructor etc)
     
  16. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Lemme reword that, how would I go about making multiple command files now?
     
  17. Reid

    Reid Spider Jockey

    Messages:
    43
    Similar concept just play with it a bit that is the best way to learn imo
     
  18. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Thank you!
     
    Reid likes this.
  19. Reid

    Reid Spider Jockey

    Messages:
    43
    No problem happy to help :D
     
  20. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    K well i tried to implement commands: all it says is usage:test, and my plugin.yml is correct
    Loader.PHP
    PHP:
    <?php

    namespace CustomItems;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\event\entity\EntitySpawnEvent;
    class 
    Loader extends PluginBase implements Listener{

        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getServer()->getPluginManager()->registerEvents(new ZaRocDamageEvent($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new Commands($this), $this);
            
    $this->getLogger()->info(TextFormat::GREEN."CustomItemsRewrite Enabled!");
            
    $this->getLogger()->info(TextFormat::GREEN."CustomItemsRewrite Enabled!");
        }
     
        public function 
    onDisable(){
            
    $this->getLogger()->info(TextFormat::RED."CustomItemsRewrite Disabled!");
        }
    }
    Commands.PHP
    PHP:
    <?php

    namespace CustomItems;

    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;

    class 
    Commands implements Listener{
        
          public function 
    __construct(Loader $plugin){
              
    $this->plugin $plugin;
    }
        public function 
    onCommand(CommandSender $sender,Command $cmd,$label,array $args){
            if(
    $cmd->getName() == "test"){
                
    $sender->sendPopup("TEST");
            }
        }
    }
     
  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.