Solved Search for player in config.yml

Discussion in 'Development' started by ToddyWars, Feb 7, 2019.

  1. ToddyWars

    ToddyWars Silverfish

    Messages:
    21
    GitHub:
    ToddyWars
    I want to check if the player has the same name as this in config.yml, how do I?
    PHP:
    $player $event->getPlayer();
    $cfgPlayer$this->config["Names"]->getAll();
    if(
    $player == $cfgPlayer){
    $player->sendMessage("you're on the list");
    }else{
    $player->sendMessage("you are not on the list");
    }
     
  2. wolfdale

    wolfdale Baby Zombie

    Messages:
    197
    PHP:
    $names $config->get("Names");
    if(isset(
    $names[$player->getName()]))
    $player->sendMessage("you are on the list");
    else
    $player->sendMessage("you are not on the list");
     
    ToddyWars and InspectorGadget like this.
  3. ToddyWars

    ToddyWars Silverfish

    Messages:
    21
    GitHub:
    ToddyWars
    PHP:
    //I use, should I change?

    //config
       
    if(!is_dir($this->getDataFolder()))
                    @
    mkdir($this->getDataFolder());
                
    $this->saveDefaultConfig();
                
    $this->config = (new Config($this->getDataFolder()."config.yml"Config::YAML))->getAll();
     
  4. wolfdale

    wolfdale Baby Zombie

    Messages:
    197
    The error is not in the code you posted, please post full code and error if you dont know where is it, alternatively use an IDE to help you
     
  5. tungstenvm

    tungstenvm Silverfish

    Messages:
    17
  6. ToddyWars

    ToddyWars Silverfish

    Messages:
    21
    GitHub:
    ToddyWars
    Oops ... it works, thx.

    I only know for 2 commands, how can I for more? /ku msg1 msg2 or /ku msg1 / /ku msg2?
    Using:
    PHP:
    switch($command->getName()){
                case 
    "ku":
    if (!isset(
    $args[0])){
    $sender->sendMessage("§7Plugin em beta, tente: §a/ku msg");
    return; 
     }
    if(
    strtolower($args[0]) == "msg"){

    $page1 $this->config["Grupos"];
    $sender->sendMessage($page1["Admin"]);

    return 
    true;
    }

        }
     
  7. wolfdale

    wolfdale Baby Zombie

    Messages:
    197
    For
    /ku msg1
    /ku msg2
    you can use
    PHP:
    switch($args[0]??null){
    case 
    "msg1":
        break;
    case 
    "msg2":
        break;
    default:
    //not set or none of the above
        
    break;
    }
    //for /ku msg1 msg2
    if(($args[0]??null) === "msg1" && ($args[1]??null) === "msg2"){

    }
     
  8. ToddyWars

    ToddyWars Silverfish

    Messages:
    21
    GitHub:
    ToddyWars
    Thx,If it is not abuse, how do I get what the player typed in the command? Example: :alert (PlayerMsg)
     
  9. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    626
    implode(" ", $args);
     
    ToddyWars likes this.
  10. wolfdale

    wolfdale Baby Zombie

    Messages:
    197
    I do not unserstand what you are trying to do, but basically
    $args is an array of words after the command
    /ku test test2
    $args will contain [test,test2]
    in this case, $args[0] will be test
    $args[1] will be test2
     
    ToddyWars likes this.
  11. ToddyWars

    ToddyWars Silverfish

    Messages:
    21
    GitHub:
    ToddyWars
    I want: "/ ku set blabla blabla" (and more) but only works "/ ku set blabla" the rest of the message does not work.
    PHP:
    public function onCommand(CommandSender $senderCommand $command$label, array $args){
       
            switch(
    $command->getName()){
                case 
    "ku":{
               
                if(isset(
    $args[0]) == "set"){
                }
     if(isset(
    $args[1])){
     
     
    $player $args[1];
    $sender->sendMessage("§7Work, you say:§6 $player");

    return 
    true;
    }else 
    $sender->sendMessage("Don't work. Try /ku set <msg>");
    }

    }
    }
     
  12. wolfdale

    wolfdale Baby Zombie

    Messages:
    197
    If you want to join all args after the first argument
    Do a array_shift($args) to remove the first argument
    and implode(" ",$args) to join the rest of the args
     
  13. ToddyWars

    ToddyWars Silverfish

    Messages:
    21
    GitHub:
    ToddyWars
    What is necessary, is to send a normal text message, for example, I type the text of the command only takes the first word.
     
  14. KielKing

    KielKing Baby Zombie

    Messages:
    112
    GitHub:
    kielking
    PHP:
    public function onCommand(CommandSender $senderCommand $commandstring $label, array $args): bool{
        switch(
    $command->getName()){
            case 
    "ku":
                if(isset(
    $args[0])){
                    if(
    $args[0] == "set"){
                        if(isset(
    $args[1])){
                            unset(
    $args[0], $args[1]);
                            
    $sender->sendMessage(implode(" "$args));
                        }else{
                            
    $sender->sendMessage("Message not set");
                        }
                    }else{
                        
    $sender->sendMessage("Usage: /ku set <msg>");
                    }
                }else{
                    
    $sender->sendMessage("argument one not set");
                }
                break;
        }
        return 
    true;
    }
     
    ToddyWars likes this.
  15. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    626
    PHP:
        public function onCommand(CommandSender $senderCommand $command$label, array $args){
            switch(
    $command->getName()){
                case 
    "ku":
                if(
    $args[0] == "set"){
                    
    array_shift($args);
                    
    $player implode(" "$args);
                    
    $sender->sendMessage("It worked, you said: §6".$player);
                    return 
    true;
                }else{
                    
    $sender->sendMessage("Usage: /ku set <message>");
                }
                break;
            }
        }
     
    ToddyWars likes this.
  16. ToddyWars

    ToddyWars Silverfish

    Messages:
    21
    GitHub:
    ToddyWars
    Thx all, solved.
    PHP:
    $cfg $this->getConfig();
    $cfg->get("Groups");
    $cfg->set("Savage""joined in the server!");
    $cfg->save();
    Change value in savage don't work, why?
     
  17. KielKing

    KielKing Baby Zombie

    Messages:
    112
    GitHub:
    kielking
    can you show your onEnable function?
     
  18. ToddyWars

    ToddyWars Silverfish

    Messages:
    21
    GitHub:
    ToddyWars
    PHP:
    if(!is_dir($this->getDataFolder()))
                    @
    mkdir($this->getDataFolder());
                
    $this->saveDefaultConfig();
                
    $this->config = (new Config($this->getDataFolder()."config.yml"Config::YAML))->getAll();
    //Config::YAML, array("Groups" => array("Savage" => "any msg"));
    Everything works, but the code should be edited, but he is adding another "Savage: msg"
     
    Last edited: Feb 9, 2019
  19. KielKing

    KielKing Baby Zombie

    Messages:
    112
    GitHub:
    kielking
    use this:
    PHP:
    $this->config = new Config($this->getDataFolder() . "config.yml"Config::YAML, [
        
    "Groups" => [
        ],
        
    "Savage" => "any msg"
    ]);
    then to fetch it:
    PHP:
    $this->config->set("Savage""joined in the server!");
    $this->config->save();
     
  20. ToddyWars

    ToddyWars Silverfish

    Messages:
    21
    GitHub:
    ToddyWars
    But "Savage: any msg" have to stay within "Groups" there is not only "Savage" there, if I take things from within "Groups" outside, would have to change a lot in other lines
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.