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

registering commands

Comments in 'Plugin Development' started by CreeperFace001, Jun 30, 2015.

Thread Status:
Not open for further replies.
  1. CreeperFace001
    Offline

    CreeperFace001 Banned

    Joined:
    Jun 29, 2015
    Posts:
    11
    Minecraft User:
    Creeperface001
    first question: can i have onCommand() function in more classes? if yes so why thi desn´t work?
    command file:
    PHP:
    <?php

    namespace ColorMatch;

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

    abstract class 
    CommandBase implements CommandExecutor{
      
        public 
    $plugin;
      
        public function 
    __construct($plugin){
            
    $this->plugin $plugin;
        }
      
        public function 
    registerCmd($cmd$data){
            
    $pc = new PluginCommand($cmd$this->plugin);
            
    $pc->setDescription($data["description"]);
            
    $pc->setUsage($data["usage"]);
            
    $pc->setPermission($data["permission"]);
            
    $pc->setExecutor($this);
            
    $this->plugin->getServer()->getCommandMap()->register($this->plugin->getDescription()->getName(),$pc);
        }
    }
    file with onCommand() function
    PHP:
    <?php

    namespace ColorMatch\Arena;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\player\PlayerRespawnEvent;
    use 
    pocketmine\event\player\PlayerDeathEvent;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\event\player\PlayerKickEvent;
    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\event\player\PlayerDropItemEvent;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\block\BlockPlaceEvent;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\inventory\PlayerInventory;
    use 
    pocketmine\Player;
    use 
    ColorMatch\ColorMatch;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\CommandExecutor;
    use 
    ColorMatch\CommandBase;

    class 
    Arena extends CommandBase implements Listener{
    public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args){
    //some code
    }
    }
    in main file:
    PHP:
    $game = new Arena($name$this);
      
    $game->enableScheduler();
      
    $game->registerCmd("cm", ['description' => "main command"'usage' => "/cm help"'permission' => "cm.command"]);
      
    $this->getServer()->getPluginManager()->registerEvents($game$this);
    and second onComand function is in main file but it works.
  2. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    Example...
    PHP:
        public function onCommand(CommandSender $senderCommand $command$label, array $args)
        {
            
    $cmd strtolower($command->getName());
            switch (
    $cmd) {
                case 
    "be":
                    
    $sender->sendMessage(TextFormat::GREEN "Place block of emerald block and step on it!");
            }
        }
    I use this to make commands...
  3. CreeperFace001
    Offline

    CreeperFace001 Banned

    Joined:
    Jun 29, 2015
    Posts:
    11
    Minecraft User:
    Creeperface001
    i know how to works with command i have a probem with registering it
  4. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    I wonder what you mean by register + sorry for not understanding xD ( can u tell me what u trying to do? )
  5. CreeperFace001
    Offline

    CreeperFace001 Banned

    Joined:
    Jun 29, 2015
    Posts:
    11
    Minecraft User:
    Creeperface001
    register command in another class
  6. iDirtPlayzMC
    Offline

    iDirtPlayzMC Active Member

    Joined:
    Apr 10, 2015
    Posts:
    264
    Minecraft User:
    iZenith_xPr
    um sorry no ideas
Thread Status:
Not open for further replies.

Share This Page

Advertisement