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

Return true and false had to be swithced

Comments in 'Plugin Development' started by da123rrell, Dec 20, 2015.

  1. da123rrell
    Offline

    da123rrell Active Member

    Joined:
    Feb 11, 2015
    Posts:
    136
    Minecraft User:
    da123rrell
    Soo i recently mad a plugin to tell you how to do things like buying land but i have something strange
    The return true message and return false message had to be switched
    If i do it like this =
    PHP:
     public function onCommand(CommandSender $sender,command $command$label, array $args) {
            switch(
    $command->getName()){
                case 
    "ILandbuy":
                    
    $sender->sendMessage("Hello ".$sender->getName()."!");
                    
    $sender->sendMessage("thank you for reading the instructions");
                    
    $sender->sendMessage("type /startp on the corner of your land and /endp on the other corner. after that type /landbuy");
                    
    $sender->sendMessage("use landbuy to protect your land from griefers.");
                    return 
    true;
                            default:
                                
    $sender->sendMessage("Acces denied");
                                return 
    false;
                             case 
    "IFactions":
                                
    $sender->sendMessage("Acces denied");
                                return 
    false;
                            default:
                                 
    $sender->sendMessage("Hello ".$sender->getName()."!");
                                    
    $sender->sendMessage("Sorry this instruction is still in progress");
                                    return 
    true;
    Everything will be correct but
    If i do it like this
    PHP:
     public function onCommand(CommandSender $sender,command $command$label, array $args) {
            switch(
    $command->getName()){
                case 
    "ILandbuy":
                    
    $sender->sendMessage("Access denied");
                    return 
    false;
                            default:
                    
    $sender->sendMessage("Hello ".$sender->getName()."!");
                    
    $sender->sendMessage("thank you for reading the instructions");
                    
    $sender->sendMessage("type /startp on the corner of your land and /endp on the other corner. after that type /landbuy");
                    
    $sender->sendMessage("use landbuy to protect your land from griefers.");
                                return 
    true;
                             case 
    "IFactions":
                                
    $sender->sendMessage("Acces denied");
                                return 
    false;
                            default:
                                 
    $sender->sendMessage("Hello ".$sender->getName()."!");
                                    
    $sender->sendMessage("Sorry this instruction is still in progress");
                                    return 
    true;
    The /ILandbuy command will just say Acces denied while the /IFaction command will say the correct message. Why is it like that?
  2. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    You only need one default. Please take a look at the PHP manual and learn about control structures: https://secure.php.net/manual/en/control-structures.switch.php
    PEMapModder likes this.
  3. da123rrell
    Offline

    da123rrell Active Member

    Joined:
    Feb 11, 2015
    Posts:
    136
    Minecraft User:
    da123rrell

Share This Page

Advertisement