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

Solved Command Aren't being pprocess

Comments in 'Plugin Development' started by andre_the_gamer, Oct 30, 2015.

?

Will this plugin be useful

  1. Yea, it will xD

    40.0%
  2. No, it won't :P

    60.0%
  1. andre_the_gamer
    Offline

    andre_the_gamer Active Member

    Joined:
    Feb 5, 2015
    Posts:
    112
    Minecraft User:
    Andre_The_Gamer
    Hi, im working on a pocketmine plugin which is called: MyHelper (Will be submitted to pocketmine when done) it would allows users to customized /helper command with their own custom message. They will be able to add anything like where user's can buy vip for their server.. ect All of that will be able to edit on the Config.yml

    While i was running it to make sure no errors are found , so far there was not, but i registered a command and it doesn't work (when i run /helper on the local server). Please help i've added some pictures if you wanna help and point me out some mistakes.

    MyHelper.php
    PHP:
    <?php

    #########################
    # MyHelper Was Created By: Andre_The_Gamer
    #########################
    # ===================================
    namespace Andre;
    #
    #######################
    # EVERYTHING THE PLUGIN WILL USED.
    ######################

    use pocketmine\Server;
    use 
    pocketmine\event\server\ServerCommandEvent;
    use 
    pocketmine\command\defaults\HelpCommand;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\PluginCommand;
    use 
    pocketmine\plugin\PluginLogger;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\event\player\PlayerLoginEvent;
    use 
    pocketmine\command\defaults\KickCommand;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\CommandReader;
    use 
    pocketmine\event\player;
    use 
    pocketmine\event\player\PlayerPreLoginEvent;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\network\protocol\LevelEventPacket;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\command\Command;

    ########################################

    #################################
    # Basic Start Up Things
    ###################################

    class MyHelper extends PluginBase{
         public function 
    onEnable(){
         
       
    $this->config = (new Config($this->getDataFolder()."config.yml"Config::YAML))->getAll();
           
    $this->saveDefaultConfig();
            
    $this->reloadConfig();
            
    $this->getConfig()->getAll();

        }

        public function 
    onDisable(){
            
    $this->getLogger()->info("onDisable() MyHelper Is Disable");
    }
    public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){
        
    $commandName $command->getName();
        if(
    $commandName === "helper"){ // Doesn't work when i try /help In local server
          
    $sender->sendMessage(" Testing"); // This will get line1 from config :p , But i've haven't work on it yet.
          
    return true;
        }
        return 
    false;
      }
    }
    Config.yml:
    PHP:
    ############################
    #   MY HELPER              #
    ############################
    # - Custom /helper command with custom message
    # Made By: Andre_The_Gamer  // Do Not Modify Without My Permission! :D
    # Website: www.insanepe.net
    #####


    ### No Permission Message
    No-PermissionYou don't have permission to use this command


    # ===== Messages ===== #

    line1: +=My Helper=+
    line2:  Add Anything here
    line3: Add Anything here
    line4: Add Anything here
    line5: Add Anything here
    line6: Add Anything here
    line7: Add Anything here
    line8: Add Anything here
    line9: += <> <> =+

    Plugin.yml:
    PHP:
    nameMyHelper
    main
    Andre\MyHelper
    version
    1.0.0
    api
    1.0.0
    author
    Andre_The_Gamer
    descrption
    Set your own custom help page
    website
    https://www.insanepe.net


    Commands:
        
    helper:
            
    descriptionshow the help page to user
            permission
    myhelper.use

    Permissions:
        
    myhelper.use:
            default: 
    true
            description
    allows player to use the /helper command
          


    I started with this project today. xD This plugin will be useful for all server's owner cause they will be able to customized the /helper command. I just need help to register the /helper command and ill be good to do. :p
    Last edited: Oct 30, 2015
  2. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    Firstly the command would be /helper and not/help. Secondly, it wouldn't display the messages to the players as, you haven't linked the configs to sendMessage(). So basically, when you would do /helper, it would send: Testing, and you forgot to register events. so in public function onEnable(), please add:
    PHP:
    $this->getServer()->getPluginManager()->registerEvents($this$this);
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    BTW, $this->getConfig()->getAll(); won't do anything.

    We need plugin.yml, not config.yml
  4. andre_the_gamer
    Offline

    andre_the_gamer Active Member

    Joined:
    Feb 5, 2015
    Posts:
    112
    Minecraft User:
    Andre_The_Gamer
    I know., i didn't link the comfig. But when i do /helper (In local server) it would send: Testing" but it didn't
  5. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    I recommend, that you firstly make a command without using the concept of configs, so you can get a understand of how the commands work.

    Example of a simple command that sends player a message:

    PHP:
    public function onCommand(CommandSender $senderCommand $command$label, array $args){
        
    $cmd strtolower($command->getName());
        if(
    $cmd === "h"){
          
    $sender->sendMessage("Welcome " .  $sender->getName() . " !");
          
    $sender->sendMessage("Please use the warps");
          return 
    true;
        }
    return 
    false
    }
  6. andre_the_gamer
    Offline

    andre_the_gamer Active Member

    Joined:
    Feb 5, 2015
    Posts:
    112
    Minecraft User:
    Andre_The_Gamer
    It has been added to the thread look above :p
    Legoboy0215 likes this.
  7. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Why register events? Has nothing to do with commands :p
    PEMapModder and andre_the_gamer like this.
  8. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Why? There's no event being used, why register them?
    You should add "usage" to the command in the plugin.yml.
  9. andre_the_gamer
    Offline

    andre_the_gamer Active Member

    Joined:
    Feb 5, 2015
    Posts:
    112
    Minecraft User:
    Andre_The_Gamer
    Alright, thanks im adding it.

    EDIT: Still didn't work :p
    Last edited: Oct 30, 2015
  10. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    do 'permissions' instead of 'Permissions' and 'Commands' to - 'commands'

    Dont wanna be mean, but you have bad coding style, practise more ;)
  11. andre_the_gamer
    Offline

    andre_the_gamer Active Member

    Joined:
    Feb 5, 2015
    Posts:
    112
    Minecraft User:
    Andre_The_Gamer
    Thanks, but my codding style is alright. It's not messy :p . Look before you judge ;) :p

    Ok, it works. Thanks alot. Im gonna start working on config now.. Thanks alot :)
  12. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    applqpak likes this.
  13. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    plugin.yml
    Code:
    name: MyHelper
    api: 1.0.0
    version: 1.0.0
    main: Andre\MyHelper
    description: 'Useless plugin :)'
    
    commands:
     helper
      usage: '/helper'
      permission: myhelper.command.helper
     
    permissions:
     myhelper.*:
      default: false
      description: ''
      children:
       myhelper.command.*
        default: false
        description: ''
        children:
         myhelper.command.helper
          default: true
          description: ''
    
    MyHelper.php
    PHP:
    <?php
    namespace Andre;

    use 
    pocketmine\plugin\PluginBase;

    use 
    pocketmine\Player;

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

    use 
    pocketmine\utils\TextFormat;

    class 
    MyHelper extends PluginBase {
       
       public function 
    onLoad()
       {
         
    $this->getLogger()->info('['.$this->getDescription()->getName().'] Loading...');
       }
       
       public function 
    onEnable()
       {
         
    $this->saveDefaultConfig();
         
    $this->getLogger()->info(TextFormat::GREEN.'Activated.');
       }
       
       public function 
    onDisable()
       {
         
    $this->getLogger()->info(TextFormat::GREEN.'Deactivated.');
       }
       
       
    /**
       * @param CommandSender $sender
       * @param Command $command
       * @param string $label
       * @param array $args
       *
       * @return bool
       */
       
    public function onCommand(CommandSender $senderCommand $command$label, array $args)
       {
         
         if(
    strtolower($command->getName()) === 'helper'){
             if(!
    $sender instanceof Player){
                 
    $sender->sendMessage('Run this command in-game');
                 return 
    true;
             }
             foreach(
    $this->getConfig()->get('content') as $i => $msg)
             {
               
    $sender->sendMessage($msg);
             }
         }
         
       }
       
    }
    config.yml
    Code:
    ---
    content:
     - 'Line 1'
     - 'Line 2'
     - 'Line 3'
     - 'And so on'
    ...
    
  14. andre_the_gamer
    Offline

    andre_the_gamer Active Member

    Joined:
    Feb 5, 2015
    Posts:
    112
    Minecraft User:
    Andre_The_Gamer
    It's already has been solved!! But anyway thanks.
  15. andre_the_gamer
    Offline

    andre_the_gamer Active Member

    Joined:
    Feb 5, 2015
    Posts:
    112
    Minecraft User:
    Andre_The_Gamer
    Thanks, everyone that helped "MyHelper" Is done and has been submitetd to pocketmine. Thanks for helping. i hope it get's accepted! :)
  16. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    I Doubt. It's too simple, but from other side its original and unique

Share This Page

Advertisement