Solved How do I use the Config.yml writes?

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

  1. ToddyWars

    ToddyWars Spider Jockey

    Messages:
    30
    GitHub:
    ToddyWars
    Code:
    //Main.php
    <?php
    
    namespace toddyn;
    
    use pocketmine\command\CommandSender;
    use pocketmine\command\Command;
    use pocketmine\plugin\PluginBase;
    use pocketmine\event\Listener;
    use pocketmine\item\Item;
    use pocketmine\utils\Config;
    use pocketmine\plugin\PluginManager;
    
    class Main extends PluginBase implements Listener {
    public $cfg;
       public function onEnable(){
       $this->getlogger()->info("Plugin on");
       
       $this->getServer()->getPluginManager()->registerEvents($this, $this);
    
       }
       
       public function onDisable(){$this->getlogger()->info("plugin off");
       }
             public function onCommand(CommandSender $sender, Command $command, $label, array $args){
         
            switch($command->getName()){
                case "ku":
    if (!isset($args[0])){
    $sender->sendMessage("§7Error, test /ku msg.");
    return; 
    }
    if(strtolower($args[0]) == "msg"){
    $sender->sendMessage($this->getConfig()->get("messages")["msg"]);
    return true;
    }
        }
       
       }
      }
    
    
      }
     
    Last edited: Feb 5, 2019
  2. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    160
    GitHub:
    diamondgamermcpe
    Instead of what you did, try:
    PHP:
    $this->getConfig()->get(“messages”)[“msg”];
     
  3. KielKing

    KielKing Zombie

    Messages:
    217
    GitHub:
    kielking
    do you have a resource folder? if so, do
    PHP:
    //onEnable(){
    $this->saveDefaultConfig();
     
  4. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    160
    GitHub:
    diamondgamermcpe
    OOF, I was viewing this from my phone.
     
  5. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    463
    GitHub:
    InspectorGadget
    Your " " font is so different xD
     
    xXNiceAssassinlo YT likes this.
  6. DiamondGamer30

    DiamondGamer30 Baby Zombie

    Messages:
    160
    GitHub:
    diamondgamermcpe
    Was on my phone before :p
     
    InspectorGadget likes this.

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.