Solved help, my cfg file don't save

Discussion in 'Plugin Help' started by Duvewo, Jan 11, 2019.

  1. Duvewo

    Duvewo Spider

    Messages:
    6
    GitHub:
    loneliplay
    Why command /setgroup don't change config values? Command registered at plugin.yml. help me please!

    Code:
    <?php
    
    namespace duvewo;
    
    use pocketmine\plugin\PluginBase as PB;
    use pocketmine\event\Listener as L;
    use pocketmine\event\player\PlayerJoinEvent as PJE;
    use pocketmine\event\player\PlayerQuitEvent as PQE;
    use pocketmine\event\player\PlayerChatEvent as PCE;
    use pocketmine\command\Command;
    use pocketmine\command\CommandSender;
    use pocketmine\utils\Config;
    
    class main extends PB implements L {
        
        private $cfg;
        
        public function onEnable(){
            if(!is_dir($this->getDataFolder())){
            @mkdir($this->getDataFolder());
            }
            $this->cfg = new Config($this->getDataFolder()."config.yml",Config::YAML);
            $this->getLogger()->info("аъ");
            $this->getServer()->getPluginManager()->registerEvents($this,$this);
        }
        
        public function onJoin(PJE $e){
            $p = $e->getPlayer();
            $name = $p->getName();
            if($this->cfg->get($name) == null){
                $this->cfg->set($name, "user");
                $this->cfg->save();
            }
            
        }
        
        public function onChat(PCE $e){
            $p = $e->getPlayer();
            $name = $p->getName();
            $msg = $e->getMessage();
            $group = $this->cfg->get($name);
            foreach($this->getServer()->getOnlinePlayers() as $pon){
            if($group == "user"){
            $e->setCancelled();
            $pon->sendMessage($name. ": " .$msg);
            }
            if($group == "vip"){
            $e->setCancelled();
            $pon->sendMessage("VIP >> " .$name. ": " .$msg);
            }
            if($group == "premium"){
            $e->setCancelled();
            $pon->sendMessage("Premium >> " .$name. ": " .$msg);
            }
            }
        }
        
        public function onCmd(CommandSender $s, Command $c, $label, array $args):bool{
            if($c->getName() == "setgroup"){
                if(count($args) !== 2){
                return true;
                }
                if($s->isOp(true) || $s instanceof ConsoleCommandSender){
                        $this->cfg->set($args[0],$args[1]);
                        $this->cfg->save();
                    }
                }
                return true;
            }
        
        public function onQuit(PQE $e){
            $p = $e->getPlayer();
            $name = $p->getPlayer();
            $this->cfg->save();
        }
        
        public function onDisable(){
            $this->cfg->save();
        }
    }
     
  2. Muqsit

    Muqsit Wither Skeleton Verified

    Messages:
    1,441
    GitHub:
    muqsit
    onCmd? It's supposed to be onCommand. You should probably add a method to debug your code as well. For example, sendMessage to CommandSender when the command successfully runs so you know your code actually executed that far (than assuming your code executed). That will help your future cases.
     
    Duvewo likes this.
  3. Duvewo

    Duvewo Spider

    Messages:
    6
    GitHub:
    loneliplay
    thank you!!! Problem solved
     

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.