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

Changing all letters to lower case

Comments in 'Plugin Development' started by Deathcrow, Sep 17, 2015.

  1. Deathcrow
    Offline

    Deathcrow Active Member

    Joined:
    Aug 20, 2015
    Posts:
    61
    Minecraft User:
    Deathcrow
    I wanna let the user run the command weather they put it all caps or all lower im sure it could be accomplished with strtolower but what abt upper? And using both?
    Code:
    public function onCommand(CommandSender $sender,Command $command,$commandLabel, array $args){
    $item = $this->getConfig()->get("itemid");
    
    
    if($command->getName() === "Enchant"){
    return true;
    }
    return false;
    }
  2. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    PHP:
    strtolower($command->getName())
  3. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    and yes it should
  4. Deathcrow
    Offline

    Deathcrow Active Member

    Joined:
    Aug 20, 2015
    Posts:
    61
    Minecraft User:
    Deathcrow
    Thanks
  5. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    http://php.net/manual/en/function.strtolower.php
    Taha_The_Hacker likes this.
  6. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    PHP:
    strtolower($command->getName());
    //I know this works but don't know if it's a bad practice :P
    strtolower($command);
  7. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    why would you do
    PHP:
    strtolower($command):
    why not
    PHP:
    strtolower($cmd->getName());
    ??
  8. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    It still works, a Player instance can be passed as a Vector3. Why wouldn't it work?
  9. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    wait, what?
  10. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Don't worry, it's too much for ur little mind to handle ;)
    Legoboy0215 likes this.
  11. TryoneLegendZzz
    Offline

    TryoneLegendZzz Active Member

    Joined:
    May 31, 2015
    Posts:
    201
    Minecraft User:
    SavionLegendZzz
    PHP:
    if($sender instanceof Player){
    //code
    }
    ?
  12. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    #Roasted @TryoneLegendZzz you'll need some of this:
    [​IMG]
    CrazedMiner likes this.
  13. CookieSteve
    Offline

    CookieSteve Active Member

    Joined:
    Apr 22, 2014
    Posts:
    132
    Minecraft User:
    iStrqfeChris
    Nah, He needs a fire extinguisher that should work much better ;)
    CrazedMiner likes this.
  14. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Why don't you just switch() to the command Name?
  15. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    He means by a player object can also be a Vector3, Position... ETC.
    CrazedMiner and TryoneLegendZzz like this.
  16. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    When you switch($command) it doesn't automatically change the command to lowercase.
  17. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    You didn't look at the first post, didn't you? He meant this:
    PHP:
    //from:
    if($command->getName() === "name"){
        
    //code
    }
    //repeat that like 12 times
    //to:
    switch($command->getName()){
        
    //this way you don't need a bunch of if statements
    }
  18. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    there i dont know why you guys just dont post the right way to do it... hes asking such a simple question with a simple answer
    PHP:
    switch (strtolower($command->getName())){
           case 
    "command1":

           break;
           case 
    "command2":

           break;
           
    // and so on..

    }
    CrazedMiner and Deathcrow like this.
  19. Deathcrow
    Offline

    Deathcrow Active Member

    Joined:
    Aug 20, 2015
    Posts:
    61
    Minecraft User:
    Deathcrow
    Thanks!!!! :D
  20. BalAnce
    Offline

    BalAnce Active Member

    Joined:
    Mar 10, 2015
    Posts:
    125
    Minecraft User:
    BalAnce
    no problem :)

Share This Page

Advertisement