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

Usage: /command - Please look!

Comments in 'Plugin Development' started by Andrey Nazarchuk, Jun 4, 2015.

  1. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Ok so I am making a plugin and every time I try to use a command it says:
    Code:
    Usage: /command that I put in
    Here is my command code:
    PHP:
      public function onCmd(Command $cmdCommandSender $sender$label, array $args){

       
    $cmd strtolower($cmd->getName());
        switch(
    $cmd){
            case 
    "sw":
                if(
    $sender->hasPermission("matrixpe.command.sw") or $sender->hasPermission("matrixpe.command") or $sender->hasPermission("matrixpe")){
                    
    $sender->sendMessage($swm->get("prefix") . $swm->get("info"));
                }
                else{ 
    $sender->sendMessage($swm->get("prefix") . $swm->get("no-perm"));
                }
                break;
           
            case 
    "sl":
                if(
    $sender->hasPermission("matrixpe.command.sl") or $sender->hasPermission("matrixpe.command") or $sender->hasPermission("matrixpe")){
                
    $x $sender->getFloorX();
                
    $y $sender->getFloorY();
                
    $z $sender->getFloorZ();
                
    $lvl $sender->getLevel()->getName();
               
                
    $this->getConfig()->set("lobby", array($x$y$z$lvl));
                
    $this->getConfig()->save();
               
                
    $sender->sendMessage($swm->get("prefix") . $swm->get("lobby-set") . "$x"$y"$z"level:" "$sender->getLevel()->getName()");
                return 
    true;
                }
                else{ 
    $sender->sendMessage($swm->get("no-perm"));
                }
                break;
           
            case 
    "leave":
                if(
    $sender->hasPermission("matrixpe.command.leave") or $sender->hasPermission("matrixpe.command") or $sender->hasPermission("matrixpe")){
                    if(
    $sender->getLevel()->getName() == $this->getConfig()->get('arenaworld')){
                        
    $this->arenaplayers $this->arenaplayers 1;
                        
    $sender->sendMessage($swm->get("Leave-message"));
                        
    $sender->teleport($this->getServer()->getLevelByName($this->getConfig()>get('lobby'))->getSafeSpawn());
                            if(
    $this->arenaplayers <= 1){
                                foreach(
    $this->getServer()->getLevelByName($this->getConfig()->get('arenaworld'))->getPlayers() as $p){
                                    if(
    $p->getGameMode() == 0){
                                        
    $p->teleport($this->getServer()->getLevelByName($this->config->get('lobby'))->getSafeSpawn());
                                        
    $points $this->points->get($p)[2] + $this->getConfig($stats/*Is this correct?*/)->get('points-per-match');
                                        
    $deaths $this->points->get($player)[0];
                                          
    $kills $this->points->get($player)[1];
                                        
    $this->getConfig($stats/*Is this correct?*/)->set($p, array($deaths$kills$points));
                                        
    $p->sendMessage($swm->get("won"));
                                        
    $p->sendMessage($swm->get("won2"));
                                        
    $p->sendMessage($swm->get("You have: ".$deaths." deaths, ".$kills." kills and ".$points." points."));
                                        
    $p->sendMessage($swm->get("Leave-message"));
                                        
    $this->cleanupMemory($p);
                                    }else{
                                        
    $p->sendMessage($swm->get("Match-done"));
                                        
    $p->teleport($this->getServer()->getLevelByName($this->getConfig()->get('lobby'))->getSafeSpawn());
                                        
    $p->setGameMode(0);
                                        
    $this->cleanupMemory($p);
                                    }
                                    
    $this->stopGame($this->getConfig->getNested()->get('arenaworld')); //DANGER, Please make this stop game only in this world.
                                
    }
                            }
                            return 
    true;
                        }else{
                            
    $sender->sendMessage("§cYou are not in a SkyWars match.");
                            return 
    true;
                        }
                    }else{
                        
    $sender->sendMessage("no-perm");
                        return 
    true;
                    }
                break;
           
            case 
    "stat":
                if(
    $sender->hasPermission("matrixpe.command.stat") or $sender->hasPermission("matrixpe.command") or $sender->hasPermission("matrixpe")){
                    if(!(isset(
    $args[1]))){
                        
    $player $sender->getName();//right or wrong?
                        
    $deaths $this->stats->get($player)[0];//this?
                        
    $kills $this->stats->get($player)[1];//this?
                        
    $points $this->stats->get($player)[2];//this?
                        
    $sender->sendMessage("You have: ".$deaths." deaths, ".$kills." kills and ".$points." points.");
                        return 
    true;
                    }else{
                        
    $player $args[1];//all of these also
                        
    $deaths $this->stats->get($player)[0];
                        
    $kills $this->stats->get($player)[1];
                        
    $points $this->stats->get($player)[2];
                        
    $sender->sendMessage($player." has ".$deaths." deaths, ".$kills." kills and ".$points." points.");
                        return 
    true;
                    }
                    }else{
                        
    $sender->sendMessage("no-perm");
                        return 
    true;
                    }
                break;
           
            case 
    "sp"://Spectator spawn, Please check!
                
    if($sender->hasPermission("matrixpe.command.sp") or $sender->hasPermission("matrixpe.command") or $sender->hasPermission("matrixpe")){
                
    $x $sender->getFloorX();
                
    $y $sender->getFloorY();
                
    $z $sender->getFloorZ();
                switch(
    $args[1]){
                }
                
    $slotname $args[1];
                
    $this->getConfig()->set(new Config("$slotname", array($x$y$z)));
                
    $this->getConfig()->save();
                
    $sender->sendMessage($swm->get("prefix") . $swm->get("spec-set"));
                return 
    true;
                }
                else{ 
    $sender->sendMessage($swm->get("prefix") . $swm->get("no-perm"));
                }
                break;
           
            case 
    "ss"://Player spawn
                
    if($sender->hasPermission("matrixpe.command.ss") or $sender->hasPermission("matrixpe.command") or $sender->hasPermission("matrixpe")){
                
    $x $sender->getFloorX();
                
    $y $sender->getFloorY();
                
    $z $sender->getFloorZ();
                switch(
    $args[1]){
                }
                
    $slotname $args[1];
               
                
    $this->getConfig()->set(new Config("$slotname", array($x$y$z)));
                
    $this->getConfig()->save();
               
                
    $sender->sendMessage($swm->get("prefix") . $swm->get("player-set"));
                return 
    true;
                }
                else{ 
    $sender->sendMessage($swm->get("prefix") . $swm->get("no-perm"));
                }
                break;
           
            case 
    "play":
                if(
    $sender->hasPermission("matrixpe.command.play") or $sender->hasPermission("matrixpe.command") or $sender->hasPermission("matrixpe")){
                    if(
    $this->arenaplayers >= $this->getConfig()->get('neededplayers') and $this->play == false){
                        
    $sender->sendMessage($swm->get("full"));
                    return 
    true;
                    }elseif(
    $this->arenaplayers $this->getConfig()->get('neededplayers') and $this->play == false){
                        
    $spawn $this->getConfig()->get('player-spawns')[$this->arenaplayers]; //Make this put each player in a different spawn
                        
    $sender->teleport(new Position($spawn[0], $spawn[1], $spawn[2], $this->getServer()->getLevelByName($this->getConfig()->get('arenaworld'))));
                        
    $this->arenaplayers $this->arenaplayers 1;
                        
    $sender->sendMessage($swm->get("Join-message"));
                              if(
    $this->arenaplayers == $this->getConfig()->get('neededplayers')){
                                  
    $this->startGame($this->getConfig()>get('arenaworld'));
                              }
                              return 
    true;
                                }elseif(
    $this->play == true){
                                    
    $sender->sendMessage($swm->get("started"));
                                return 
    true;
                                }
                            }else{
                                
    $sender->sendMessage($swm->get("no-perm"));
                                return 
    true;
                            }
                        break;
           
            case 
    "help":
                if(
    $sender->hasPermission("matrixpe.command.help") or $sender->hasPermission("matrixpe.command") or $sender->hasPermission("matrixpe")){
                    
    $command explode(" "strtolower($event->getMessage()));
                            
    $event->setCancelled(true);
                                
    $sender->sendMessage("§6=-=-=-=-= §f§lSky§4§lWars §6=-=-=-=-=");
                                
    $sender->sendMessage("§e/leave §8§l-- §r§bLeaves the match.");
                                
    $sender->sendMessage("§e/stat §8§l-- §r§bSee your statistics.");
                                
    $sender->sendMessage("§e/help §8§l-- §r§bShows the help§7[This Page].");
                                    if(
    $sender->hasPermission("matrixpe.") or $sender->hasPermission("matrixpe.command") or $sender->hasPermission("matrixpe.build")){
                                        
    $sender->sendMessage("§4/ss §8§l-- §r§bSets a Player Spawn.");
                                        
    $sender->sendMessage("§4/sl §8§l-- §r§bSets Lobby Spawn.");
                                        
    $sender->sendMessage("§4/spec §8§l-- §r§bSets spectator spawn.");
                                        
    $sender->sendMessage("§4/sw §8§l-- §r§bShows Info screen.");
                                    }
                                    return 
    true;
                                }
                else{ 
    $sender->sendMessage($swm->get("prefix") . $swm->get("no-perm"));
                }
                break;
            }
           
        }

    Here is my plugin.yml:
    Code:
    name: SkyWarsPE
    version: 0.1
    api: 1.12.0
    main: SkyWarsPE\Main
    author: [MatrixPE Devs(Andrey, CraftYourBukkit, Mak Ho Yin, optrusty)]
    description: SkyWarsPE, Custom SkyWars plugin
    website: matrixpe.net
    commands:
    sw:
      description: "Info"
      usage: "/sw"
      permission: matrixpe.command.sw
    ss:
      description: "Set a Player spawn"
      usage: "/ss"
      permission: matrixpe.command.ss
    sl:
      description: "Sets lobby spawnpoint"
      usage: "/sl <x> <y> <z>"
      permission: matrixpe.command.sl
    spec:
      description: "Sets spectator spawnpoint"
      usage: "/spec"
      permission: matrixpe.command.spec
    leave:
      description: "Leaves the match"
      usage: "/leave"
      permission: matrixpe.command.leave
    play:
      description: "Joins a match"
      usage: "/play"
      permission: matrixpe.command.play
    help:
      description: "Shows help"
      usage: /help
      permission: matrixpe.command.help
    stat:
      description: "Shows statistics"
      usage: /stat <playername>
      permission: matrixpe.command.stat
    permissions:
    matrixpe:
      description: "Allows accsess to all MatrixPE features"
      default: op
      children:
       matrixpe.build:
        description: "Allows Building/Breaking"
        default: op
       matrixpe.command:
        description: "Allows accsess to all MatrixPE commands"
        default: op
        children:
         matrixpe.command.sw:
          description: "Shows the Info"
          default: true
         matrixpe.command.ss:
          description: "Set a Player spawn"
          default: op
         matrixpe.command.sl:
          description: "Sets the Lobby"
          default: op
         matrixpe.command.spec:
          description: "Sets the spectator spawn"
          default: op
         matrixpe.command.leave:
          description: "Leaves the match"
          default: true
         matrixpe.command.play:
          description: "Joins a match"
          default: true
         matrixpe.command.help:
          description: "Shows help"
          default: true
         matrixpe.command.stat:
          description: "Shows statistics"
          default: true
    

    Please tell me whats wrong, Thank You! :D
    Last edited: Jun 4, 2015
  2. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Ok,
    Then at least provide a link to the thread that explains this because I saw it once but lost it and do not remember the name.
  3. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,706
    Plugins:
    22
    Minecraft User:
    Falkirknh
    If your function doesn't return true the usage method will be shown.
  4. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Thank you, should I put it before or after break;?
  5. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    before
    Andrey Nazarchuk likes this.
  6. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Thank you!
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Andrey Nazarchuk and Creeperface like this.
  8. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    We don't have time to help you if you don't have time to learn.
  10. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Do your own brain work.
  11. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    OK thank you and sorry everyone, it works now.

Share This Page

Advertisement