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

Register command in main PHP

Comments in 'Plugin Development' started by Lexo, Feb 18, 2016.

  1. Lexo
    Offline

    Lexo New Member

    Joined:
    May 25, 2015
    Posts:
    19
    Minecraft User:
    Lexo
    Hi. I want to create plugin, and for this I need one thing. I want to register command in main PHP script, not in "plugin.yml". What I must do for that? After I register the command, where I will have to write the executable code to it?
  2. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    You must register your commands in the plugin.yml.
    You put the code for the commands in what class u desire.
    applqpak likes this.
  3. Lexo
    Offline

    Lexo New Member

    Joined:
    May 25, 2015
    Posts:
    19
    Minecraft User:
    Lexo
    But what about Essentials PE? It's don't register commands in "plugin.yml" +_-
  4. amiremad
    Offline

    amiremad Active Member

    Joined:
    Sep 8, 2015
    Posts:
    192
    Minecraft User:
    amir107
    dont compare essentials pe with any plugin

    1- it is featured

    2- it has been made by the most professional devs
  5. Lexo
    Offline

    Lexo New Member

    Joined:
    May 25, 2015
    Posts:
    19
    Minecraft User:
    Lexo
    I know, it's possible to register command without "plugin.yml". BUT HOW?
  6. KubixQ
    Offline

    KubixQ Active Member

    Joined:
    Sep 13, 2015
    Posts:
    85
    Minecraft User:
    KubixQ
    You must register commands in main.php and plugin.yml -,-
    applqpak likes this.
  7. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Then why don't you just look into the source of it?
    applqpak likes this.
  8. minebuilder0110
    Offline

    minebuilder0110 Notable Member

    Joined:
    Dec 8, 2014
    Posts:
    485
    Minecraft User:
    Apparitional
    You might want to look at @aliuly's plugins, he have some unique style where he literally handles all the plugin.yml and config.yml stuff in the plugin itself.
  9. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    No, you can register commands with a main php file too.
  10. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Why he shouldnt? I dont understand the sense of your post?
  11. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    He mustnt, he can do it in a php file too
  12. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    Stop spamming! You can use a single reply to answer 3 posts.
    Loader.php:
    PHP:
    <?php
    namespace plugin\hey;
    class 
    Loader extends PluginBase{
    public function 
    onEnable(){//when plugin enables
    $this->getServer()->getCommandMap()->register("hey", new hey($this));//register the command 'hey' in the 'hey' class
    }
    }
    hey.php:
    PHP:
    <?php
    namespace plugin\hey;


    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\PluginIdentifiableCommand;
    use 
    pocketmine\Player;
    use 
    pocketmine\utils\TextFormat;
    class 
    hey extends Command implements PluginIdentifiableCommand{
        private 
    $hey;
        public function 
    __construct(Loader $plugin){
            
    parent::__construct("hey""send hey message""/hey <message>", ["h","hello","sup"]);//register command usage, alias, etc.
            
    $this->setPermission("hey");//set permission for command
            
    $this->hey $plugin;
        }
        public function 
    execute(CommandSender $sender$alias, array $args){//when sender executes command hey
            
    $this->hey->getServer()->broadcastMessage(TextFormat::AQUA.implode(" "$args));//send message when someone does '/hey <message>' AKA '/hey <$args>'
    }
    Last edited: Feb 18, 2016
  13. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Hey! you are trying to convert an array into a string...
    Vaivez66 likes this.
  14. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    It's just an example (he could implode that if he wants) :p. Actually, he had typo on TextFormat too...
    PocketKiller likes this.
  15. xBeastMode
    Offline

    xBeastMode Active Member

    Joined:
    Nov 27, 2015
    Posts:
    292
    I usually forget something cause I'm obviously a human not a robot. :cool:
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    • It is not a must to register commands in plugin.yml
    • And your main class is not necessarily called main.php
    • And commands don't need to be registered in the main class
    • And commands actually don't even need to be registered on startup. If you have a reason, register it at the middle of server runtime is also OK.
    amiremad and PocketKiller like this.

Share This Page

Advertisement