1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Get $value ?

Discussion in 'Development' started by GOdly, Jan 8, 2017.

  1. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    When i use
    Code:
    /cmd ex args
    how can i get the "args" in config file
    Code:
    - Example:
       - args
       - args1
      - args2
    with the PHP code
     
  2. eDroid

    eDroid Witch

    Messages:
    59
    GitHub:
    edroiid
    please elaborate.. you want to get the args from the file or to the file?
     
    applqpak likes this.
  3. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    get the args :)
     
  4. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    or both ?
     
  5. eDroid

    eDroid Witch

    Messages:
    59
    GitHub:
    edroiid
    PHP:
    public function onCommand(CommandSender $senderCommand $command$label, array $args){
      
    $conf = new Config($this->getDataFolder(), Config::YAML);
      
    $cmd $command->getName();
      if(
    $cmd[0] == "cmd"){
        if(
    $cmd[1] == "ex"){
          
    array_shift($cmd);
          
    array_shift($cmd);
          
    $i 0;
          foreach(
    $cmd as $arg){
            
    $conf->set($i$arg);
            
    $i++;
          }
          
    $conf->save();
        }
    }
    }
    basic idea..
     
    applqpak likes this.
  6. xZeroMCPE

    xZeroMCPE Witch

    Messages:
    67
    GitHub:
    xZeroMCPE
    You can always use this for configs

    Code:
    $conf->getNested("blah.blah");
    Or this for arguments

    Code:
    
    $test = $args[0];
    
    // that above, gets the first argument. Replace 0 with 1, etc for each other(S)
     
    applqpak likes this.
  7. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    the args is not saved in config file, you shall save it before trying to get it
     
    applqpak likes this.
  8. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    How can I get "args" (args have been saved) in
    Code:
    -Example:
         - args
         - args1
         - args2
    When i use /cmd args ($args[0] is args) and it will check in the Example
     
  9. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    I have the same question... xD
     
  10. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    may i ask why you wish to do that firstly?
     
    applqpak likes this.
  11. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Try this:
    PHP:
    $argsArray $cfgObject->get("Example"); //Get the array under 'Example'
    var_dump($argsArray); //Outputs sth like:
    array(3) {
      [
    0]=>
      
    string(4"args"
      
    [1]=>
      
    string(5"args1"
      
    [2]=>
      
    string(5"args2"
    }
     
    applqpak likes this.
  12. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    I wanna to do a GiftCode plugin and I stuck at get exist code in .yml file
     
  13. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    Or you guys check for me about my code
    PHP:
    $this->code = new Config($this->getDataFolder() . "code.yml"Config::YAML, array(
            
    "Code" => "TESTINGC",
    ));
    if((
    $this->code->getAll("Code"))){
                                
    $sender->sendMessage("Yes");
                                return 
    true;
                            } else {
                                
    $sender->sendMessage("No");
                                return 
    true;
                            }
    when i use /cmd TESTINGC it show "Yes" but when i use /cmd blahblah it also "Yes"
    although it doesn't in array
     
  14. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    any help about that error ?
     
  15. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    To do's
    1) Please add this
    PHP:
    $this->code = new Config($this->getDataFolder() . "code.yml"Config::YAML, array(
            
    "Code" => "TESTINGC",
    ));
    on enable()
    2) You dont need to add return everywhere,
    PHP:
    if(($this->code->getAll("Code"))) {
        
    $sender->sendMessage("Yes");
    } else {
             
    $sender->sendMessage("No");
    }
    You can use this code when youre calling a command..
    or if u wanna do on start use
    PHP:
    $this->getLogger()->warning("yes");
     
  16. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    Is this can be work ?
     
  17. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Try it out :).
    Your issues:
    - You didnt know when to call that getAll() method!
    - How would the server know who is the "$sender" without u calling it?
    - You didnt add the config method onEnable();
     
    applqpak likes this.
  18. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    actruelly i add the config method onEnable() :p
    But how when to call that getAll() method and the code have to be what ?
    It's so confused with me to check this
     
  19. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Example:
    PHP:
    public function onCommand(CommandSender $senderCommand $cmd$label, array $args) {
      if(
    $cmd->getName() === "list") {
         if(
    $this->code->get("Code") === true) {
              
    $sender->sendMessage("woah");
        } 
         else {
           
    $sender->sendMessage("Nooooo");
         }
    }
     
    applqpak likes this.
  20. GOdly

    GOdly Witch

    Messages:
    50
    GitHub:
    CentOsDogE
    thanks
     
  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.