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

Set a command executor.

Comments in 'Plugin Development' started by AndrewBit, Feb 13, 2016.

  1. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Hi, I'm having a small mistake in a plugin.
    I'm trying to set a custom executor, but it doesn't work...

    My main class OnEnable:
    PHP:
     public function OnEnable()
        {
            
    $this->getServer()->getPluginManager()->registerEvents(new EvListener($this),$this);
            @
    mkdir($this->getDataFolder());
            @
    mkdir($this->getDataFolder() . "players/");

            
    $command = new PluginCommand("mc",$this);
            
    $command->setExecutor(new Mc($this));
            
    $this->getServer()->getCommandMap()->register("mc",$command);

            
    $this->saveResource("settings.yml");
            
    $this->saveResource("groups.yml");
            
    $this->getLogger()->info(TextFormat::GREEN "MagicChat " MagicChat::VERSION " by @AndrewBit4 enabled.");

            if(
    $this->getConf("Broadcaster")[0]){
                
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new Broadcaster($this),$this->getConf("Broadcaster")[1] * 20);
            }
            if(
    $this->getConf("Popup")[0]){
                
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new PopupTask($this),$this->getConf("Popup")[1] * 20);
            }
        }
    My command executor:
    PHP:
    <?php

    namespace andrew\Commands;

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

    use 
    andrew\MagicChat;

    class 
    Mc implements CommandExecutor {

        private 
    $plugin;

        public function 
    __construct(MagicChat $plugin){
            
    $this->plugin $plugin;
        }

        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args) {
            
    $fcmd $cmd->getName();
            if(
    strtolower($fcmd) === "mc"){
                
    $sender->sendMessage("Mc works!");
            }
        }
    }
    ?>
    Plugin yaml:
    PHP:
    nameMagicChat
    main
    andrew\MagicChat
    version
    "0.1"
    api: [1.12.0]
    authorAndrewBit4
    description
    Manage your chat like never before!
    websitehttp://twitter.com/AndrewBit4
    commands:
    mc:
      
    aliases: [magicchat]
      
    descriptionMagic chat commands.
      default: 
    op
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What happens when you execute the command?
  3. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Nothing, it doesn't send any message...
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Not even command not exist? That's odd. Does a new command exist in /help?
  5. MichaelM04
    Offline

    MichaelM04 Active Member Plugin Developer

    Joined:
    Nov 12, 2015
    Posts:
    213
    Plugins:
    1
    Minecraft User:
    Michael
    Is there any errors on load? Any errors at all? More info would be better crashes in the background when you execute the command
  6. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    Plugin.yml: missing space after before mc:
    AndrewBit likes this.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Oh wait. You are registering twice. either register it in plugin.yml then use $this->getCommand() to get the instance, or just delete the registering in plugin.yml and setup the data in code entirely.
    Vaivez66, AndrewBit and PocketKiller like this.

Share This Page

Advertisement