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

Configs

Discussion in 'Development' started by esh123cookie, Aug 12, 2020.

  1. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    104
    GitHub:
    esh123cookie
    How do I create a config using arrays for example,

    - Item
    - id
    - custom name
    - Item
    - id
    - custom name
     
  2. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    i saw your github, you know how to create Config and use it correct? now you want to know how to save stuff array in config? for doing that:
    PHP:
    $this->getConfig()->set("Items"/*your own array here?*/);
    please tell me what do you want to save in to cfg? i'll make full code for you, just tell me what should save like array in Config.
     
  3. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    for example, this mybe help you?

    PHP:
    //IDK function
    $configToturial $this->getConfig();
    $yourArray = ["Apple" => 2/*you can get apples form player inv onJoin Event*/"Beef" => 10];
    $configToturial->set("Items"$yourArray);
    //sorry im not in my ide, mybe this code have a little wrong? :P
    any more questions or problems?
     
  4. GodWeedZao

    GodWeedZao Zombie Pigman

    Messages:
    401
    GitHub:
    godweedzao
    also, you should read about Array's in php.net to know about array codings ;)
     
  5. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    104
    GitHub:
    esh123cookie
    not exactly what i meant, I'm trying to make a gui which allows the user to config for each slot.
     
  6. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    104
    GitHub:
    esh123cookie
    PHP:
        public function openDouble(Player $sender) {
                  foreach (
    $this->getAllAdd() as $config) {
                  
    $item $this->getItem($config["item"]);
              
    $slot $this->getSlot($config["slot"]);
              
    $name $this->getName($config["name"]);
              
    $name $this->getLore($config["lore"]);
                  
    $warpmenu InvMenu::create(InvMenu::TYPE_DOUBLE_CHEST);
               
    $double = new Config($this->getDataFolder() . "/doublegui.yml"Config::YAML);   
              
    $warpmenu->readonly();
                
    $warpmenu->setName($double->get("title"));
                
    $warpmenu->setListener([$this"handleDoubleMenu"]);
                
    $inventory $warpmenu->getInventory();
                
    $inventory->setItem($slot$item->setCustomName($name)->setLore([$lore)]));
                  
    $warpmenu->send($sender);
              }
        }
    this is what i have right now for the gui
     
  7. Primus

    Primus Zombie Pigman

    Messages:
    749
    PHP:
    # YAML
    yaml_emit_file("file.yml"$array);
    # JSON
    file_put_contents("file.json"json_encode($array));
     
  8. esh123cookie

    esh123cookie Baby Zombie

    Messages:
    104
    GitHub:
    esh123cookie
    could you show an example of some code with it
     
  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.