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

Solved Command not working

Comments in 'Plugin Development' started by FlamingGenius, Sep 27, 2015.

  1. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    So i tried but this doesnt work :/ not sure what i did wrong the command is registered but when i try to use it it does nothing

    PHP:
    <?php

    namespace FlamingGenius\MessageSystem;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;

    class 
    main extends PluginBase implements Listener{

    public function 
    onEnable(){
      
    $this->saveDefaultConfig();
      
    $this->getServer()->getPluginManager()->registerEvents($this$this);
    }

    public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args){
      
    $command $cmd->getName();
      if(
    $this->getConfig()->get("enabled") == "true"){
       if(
    strtolower($command == "broadcast")){
        
    $this->getServer()->broadcastMessage("broadcastteat");
       }
      }
      if(
    $this->getConfig()->get("enabled") == "false"){
       
    $sender->sendMessage("Plugin is not enabled");
      }
    }



    }

    ?>
    Last edited: Sep 27, 2015
  2. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    It should be $cmd->getName(), not $this->$cmd->getName(). Please try to acquire more knowledge of PHP before attempting to make a plugin.
    Minecrafter9203 likes this.
  3. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    I fixed that and now im getting this in the log
    2015-09-27 [03:50:49] [Server thread/INFO]: Enabling MessageSystem v1.0.0
    2015-09-27 [03:50:49] [Server thread/NOTICE]: RuntimeException: "Argument 1 passed to pocketmine\plugin\PluginManager::registerEvents() must implement interface pocketmine\event\Listener, instance of FlamingGenius\MessageSystem\main given, called in phar:///usr/local/games/minecraft_pe/1232128/104.156.237.182:19152/plugins/phar_MessageSystem_wpkFWG6qBbcY7RE.phar/src/FlamingGenius/MessageSystem/main.php on line 14 and defined" (E_RECOVERABLE_ERROR) in "/src/pocketmine/plugin/PluginManager" at line 698
    2015-09-27 [03:50:49] [Server thread/INFO]: Disabling MessageSystem v1.0.0
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Read the error. You have to implement Listener interface.
    Minecrafter9203 likes this.
  5. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    Uh...i do not know what this is :(
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    In the class declaration, you have to add `implements Listener`. And add the use statement for pocketmine\event\Listener.
  7. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    If you look at my code u can see i already have this
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Try making it Listener instead of listener?
  9. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    Thats a typo on here the L is capital in my code
  10. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Add command in plugin.yml?
  11. FlamingGenius
    Offline

    FlamingGenius Active Member

    Joined:
    Sep 23, 2015
    Posts:
    173
    Minecraft User:
    FlamingGenius
    Already dOne that my plugin commands looks like this
    PHP:
    commands:
     
    broadcast:
      
    usage: /broadcast <msg>
      
    descriptionBroadcast a msg
      permission
    ms.broadcast
  12. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    OMG it has to be a string.
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    You don't need to use "" in YAML for most cases.
    Legoboy0215 likes this.

Share This Page

Advertisement