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

loader class Sos

Comments in 'Plugin Development' started by rinkuno, Jul 19, 2016.

  1. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    PHP:
    <?php
    namespace mcpe\plugin;

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

    class 
    Op extends Command implements \pocketmine\command\PluginIdentifiableCommand {
        
    /** @var Main $plugin */
           
    private $plugin;
        public function 
    __construct(MainBase $plugin){
            
    parent::__construct("cmd""description"null, ["cmds"]);
            
    $this->plugin $plugin;
            
    $this->setPermission("plugin.help");
        }
        public function 
    execute(CommandSender $sender$currentAlias, array $args){ // will be done by running the command
          
    foreach($this->plugin->getServer()->getOnlinePlayers() as $player){
          
    $player->sendMessage("hi");
        }
      }
  2. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    How can I fix that code
  3. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    What do you mean by fixing?
  4. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    Like the command
  5. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    Error Unknown command
  6. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    So what can I do
  7. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    Any one there I nead help
  8. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    Like @SOFe already said you can use onCommand() in your main file directly, like this:
    PHP:
    public function onCommand(CommandSender $senderCommand $command$label, array $args){
            switch (
    strtolower($command->getName())) {
                case 
    "command":
                        if(!(isset(
    $args[0]))) {
                            
    $sender->sendMessage("Hi");
                            }
                        }
                        
    $arg array_shift($args);
                        switch (
    $arg) {                           
                   case 
    "sub":
    $sender->sendMessage("Sub-cmd1");
                    break;
                   case 
    "sub2":
    $sender->sendMessage("Sub-cmd2");
                    break;
                   default:
    $sender->sendMessage("Sub-command not found");
                   break;
    }
    }
    This includes sub-commands, for example running command sub. 'default' will be done if the sub-command doesn't exists.
    applqpak likes this.
  9. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    can I get a plugins example of this
  10. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    He just did. If you want to make a plugin, learn php first.
    applqpak likes this.
  11. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
  12. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    Where
  13. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    When I use /cmd (my plugin) it won't work it makes a blank line //noting
  14. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    PHP:
    <?php
    namespace mcpe\plugin;

    use 
    pocketmine\plugin\PluginBase as base;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\utils\TextFormat as §;

    class 
    MainBase extends base{
         public function 
    onEnable(){
            
    $this->getLogger()->info("onEnable() has been called!");
        }

        public function 
    onDisable(){
            
    $this->getLogger()->info("onDisable() has been called!");
        }
       
       
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){
        if(
    strtolower($command->getName()) === "cmd"){
            
    $sender->sendMessage(§::RED "WIP");
            return 
    true;
        }

        return 
    false;
    }
    }
  15. SOFe
    Offline

    SOFe Banned

    Joined:
    May 28, 2016
    Posts:
    386
    Minecraft User:
    Herobrine
    Did you register commands in plugin.yml?

    Also, do not use "mcpe" as the top level namespace. Namespaces starting with `minecraft`, `mojang` and `pocketmine`, are directly prohibited (won't be loaded), so it is reasonable to believe that `mcpe` is discouraged as well.
  16. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    Yo my so I figured out its the usage how can I remove it
  17. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    The usage can be set in the plugin.yml (recommended) or in onCommand() with $this->setUsage($usage)
  18. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    No I just want it to use the command not usage
  19. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    then add return true;
  20. rinkuno
    Offline

    rinkuno Active Member

    Joined:
    Oct 8, 2014
    Posts:
    59
    Minecraft User:
    rinku
    Gives a error

Share This Page

Advertisement