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 plugin

Comments in 'Plugin Development' started by IcePL, May 27, 2016.

  1. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    Hi, how to add a multiple files in plugin?
    Ex. Main class and command.php
  2. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Supposing that both are classes, add a content to "Command.php" and create new class instance on Main.php
    I suppose that you're trying to add a command in Command.php, so simply extend Command (you should use the PocketMine Command class with an aliase, both cannot have the same name) and add all the command stuff.
    You can register a command class in the main file with:
    PHP:
    $this->getServer()->getCommandMap()->register("command", new Command());
    Last edited: May 27, 2016
    IcePL likes this.
  3. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    Ok thanks.
    And how to make multiple files with ex. event (blockplaceevent)
    Last edited: May 27, 2016
  4. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    Please any help me? :(
  5. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    Or how to use __construct?
  6. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    We cannot explain everything of PHP to you, this is the PocketMine forum, not a PHP one. Please learn PHP before you start with PocketMine plugins.
    KubixQ and applqpak like this.
  7. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    This is my main.php:

    PHP:
    <?php

    namespace test;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;

    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\command\ConsoleCommandSender;

    use 
    pocketmine\item\Item;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pockemine\inventory\Inventory;
    use 
    pocketmine\event\player\PlayerJoinEvent;

    class 
    main extends PluginBase implements Listener{
           
       
        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getLogger()->info("plugin testowy został załadowany");
            }
        }
    And test.php:
    PHP:
    <?php

    namespace test;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\player\PlayerJoinEvent;

    use 
    test\main;

    use 
    pocketmine\Player;

    class 
    test extends PluginBase implements Listener{
         
          public function 
    __construct(main $plugin){
              
    $this->plugin $plugin;
        }
       
        public function 
    onJoin(PlayerJoinEvent $event){
        
    $player $event->getPlayer();
        
    $player->sendMessage("TESTSSSSSTSTSTST");
        }
    }
    But this plugin not work
  8. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    Ok xd, now this plugin work.
    Sorry for my englisch
  9. BlubberBoy333
    Offline

    BlubberBoy333 Active Member

    Joined:
    Aug 31, 2014
    Posts:
    177
    Minecraft User:
    Blubberboy333
    You're making two main files, which won't work
  10. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    I'm add code to load events from test.php class
  11. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    But i have error when i'm register the command:
    Code:
    [Server] Fatal error: Call to undefined function test\new TestCommand() in myzip:///storage/sdcard0/PocketMine/plugins/test.zip#src/test/Main.php on line 16
    [Server] [12:59:08] [EMERGENCY]: An unrecoverable error has occurred and the server has crashed. Creating a crash dump
    [Server] [12:59:08] [EMERGENCY]: Please upload the "/storage/sdcard0/PocketMine/CrashDump_Fri_May_27-12.59.08-UTC_2016.log" file to the Crash Archive and submit the link to the Bug Reporting page. Give as much info as you can.
    
    My Main class
    PHP:
    <?php

    namespace test;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Server;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandExecutor;
    use 
    test\command\TestCommand;

    class 
    Main extends PluginBase implements Listener{
           
       
        public function 
    onEnable(){
        
    $this->getCommand('test')->setExecutor(new TestCommand());
            
    $this->getServer()->getPluginManager()->registerEvents(new EventListener($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new TestCommand($this), $this);
            
    $this->getLogger()->info("plugin testowy został załadowany");
            }
        }
    And TestCommand:
    PHP:
    <?php

    namespace test\command;

    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandExecutor;

    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    test\Main;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\PluginBase;

    use 
    pocketmine\event\player\PlayerJoinEvent;

    class 
    TestCommand implements CommandExecutor{

               public function 
    __construct(Main $plugin){
              
    $this->plugin $plugin;
        }
       
              public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){   
           
    $name $sender->getPlayer()->getName();
                if(
    strtolower($command->getName('test'))) {
                    if(empty(
    $args)) {
                        
    $sender->sendMessage("test");
                        return 
    true;
                        }
                         if(
    $args[0] == "test1") {
               }
               if(
    $args[0] == "test2") {

       
                 }
                   }
                   if(
    $args[0] == "test3") {
                    }
               
              }
        }
  12. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    Can any help me?
  13. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    If you want register an event in only one class you should use registerEvent method instead registerEvents.
  14. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Please learn OOP and better PHP. Before you attempt to make complex pocketmine plugins.
  15. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
  16. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
  17. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    And what is the reason of creating a file for the plugin? If you just want to have another file in the plugin, the link I sent you already explains how. Can you first explain why you want to create multiple files?
  18. IcePL
    Offline

    IcePL New Member

    Joined:
    Feb 16, 2016
    Posts:
    73
    Minecraft User:
    IcePL
    but I ask you to do a few classes in the plugin and you give me a guide on how to do a new file in windows ... !
  19. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Oh right. In the new file add this:
    PHP:
    <?php
    class Clazz{
    }
    New class added. Happy?

    If you can't even explain what you want a new class for, how can we answer you?

Share This Page

Advertisement