Config wont set

Discussion in 'Development' started by xXNiceAssassinlo YT, Jun 20, 2018.

  1. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
    Variable:
    PHP:
    $cfg $player->getCfg($player);
    How i used it:
    PHP:
    $cfg->set("coins"$cfg->get("coins") + 10);
    $cfg->save();
    Config Code:
    PHP:
        public function getCfgPath($player): string{
            return 
    Core::get()->getDataFolder() . "players" DIRECTORY_SEPARATOR strtolower($player->getName()) . ".yml";
        }

        public function 
    getCfg($player): Config{
            return new 
    Config($this->getCfgPath($player), Config::YAML);
        }

        public function 
    regCfg($player): void{
            new 
    Config($this->getCfgPath($player), Config::YAML, [
                
    "rank" => "Recruit",
                
    "title" => "none",
                
    "coins" => 0,
                
    "vote" => 0,
                
    "rare" => 0,
                
    "omega" => 0,
                
    "legendary" => 0,
                
    "swim" => false
            
    ]);
        }
     
    byyEmirhanWSD likes this.
  2. Levi

    Levi Zombie Pigman

    Messages:
    763
    GitHub:
    captainleviftw
    What's the problem? :facepalm:
     
  3. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
    Coins won’t set didnt u read title
     
  4. Levi

    Levi Zombie Pigman

    Messages:
    763
    GitHub:
    captainleviftw
    The title does not state that coins won't set :facepalm:
     
  5. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
    It’s clickbait xd

    Since the guy says Which Entity, when I gave u Import

    I am off topic use conversations.
     
  6. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
  7. yuko fuyutsuki

    yuko fuyutsuki Witch

    Messages:
    70
    GitHub:
    fuyutsuki
    Did any errors occur when using that code?
     
  8. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
    No it just won’t set it when I use
    PHP:
     switch(mt_rand(16)){
     
  9. yuko fuyutsuki

    yuko fuyutsuki Witch

    Messages:
    70
    GitHub:
    fuyutsuki
    Is the "players" folder correctly created in the plugin_data folder? Or is there an empty .yml file installed?
     
  10. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
    Everything works I used same code for a command call AddCoinCommand it works but it just won’t work for InteractEvent
     
  11. yuko fuyutsuki

    yuko fuyutsuki Witch

    Messages:
    70
    GitHub:
    fuyutsuki
    Ah, do you mean that this code works with commands and does not work with InteractEvent?
     
  12. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
    Yes
     
  13. yuko fuyutsuki

    yuko fuyutsuki Witch

    Messages:
    70
    GitHub:
    fuyutsuki
    It seems that InteractEvent processing is probably wrong. Would you please show me the code?
     
  14. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
    PHP:
        public function onInteract(PlayerInteractEvent $e): void{
            
    $player $e->getPlayer();
            
    $block $e->getBlock();
            
    $x $block->getX();
            
    $y $block->getY();
            
    $z $block->getZ();

            if(
    $player instanceof ExonPlayer){
                
    $cfg Configuration::get()->getCfg($player);

                if(
    $block->getId() == Block::CHEST){
                    if(
    $x == 274 && $y == 135 && $z == 70){
                        
    $e->setCancelled();
                        if(!
    $cfg->get("vote") >= 1){
                            
    $player->sendMessage(C::RED "You don't have vote key.");
                            return;
                        }

                        if(
    $this->checkArray($player)){
                            
    $player->sendMessage(C::RED "Please wait until your crate done opening!");
                            return;
                        }

                        
    $this->Crates($player"Vote");
                        
    $cfg->set("vote"$cfg->get("vote") - 1);
                        
    $cfg->save();
                    }
                }
            }
        }
    PHP:
        public function Crates(ExonPlayer $playerstring $crate): void{
            
    $inv $player->getInventory();
            
    $cfg Configuration::get()->getCfg($player);

            if(
    $crate == "Vote"){
                switch(
    mt_rand(16)){
                    case 
    1:
                    
    $item Item::get(27601);
                    
    $item->addEnchantment($this->Enchant(93));
                    
    $inv->addItem($item);
                    
    $player->sendMessage(C::GREEN "You have received a Diamond Sword with Sharpness 3");
                    break;
                    case 
    2:
                    
    $item Item::get(46605);
                    
    $inv->addItem($item);
                    
    $player->sendMessage(C::GREEN "You have received 5 Enchanted Golden Apple");
                    break;
                    case 
    3:
                    
    $item Item::get(322010);
                    
    $inv->addItem($item);
                    
    $player->sendMessage(C::GREEN "You have received 10 Golden Apple");
                    break;
                    
    $item Item::get(46010);
                    
    $inv->addItem($item);
                    
    $player->sendMessage(C::GREEN "You have received 10 TNT");
                    case 
    4:
                    
    $item Item::get(27601);
                    
    $item->addEnchantment($this->Enchant(131));
                    
    $inv->addItem($item);
                    
    $player->sendMessage(C::GREEN "You have received a Diamond Sword with Fire Aspect");
                    break;
                    case 
    5:
                    
    $item Item::get(5705);
                    
    $inv->addItem($item);
                    
    $player->sendMessage(C::GREEN "You have received 5 Diamond Block");
                    break;
                    case 
    6:
                    
    $cfg $player->getCfg($player);
                    
    $cfg->set("coins"$cfg->get("coins") + 10);
                    
    $cfg->save();
                    
    $player->sendMessage(C::GREEN "You have received 10 coins");
                    break;
                }
            }
        }
     
  15. yuko fuyutsuki

    yuko fuyutsuki Witch

    Messages:
    70
    GitHub:
    fuyutsuki
    Please check with var_dump(), echo() etc during processing to see if processing is proceeding
     
  16. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
    Check which
     
  17. corytortoise

    corytortoise Skeleton

    Messages:
    842
    GitHub:
    corytortoise
    We don't know everything about your problem. How are you checking the coin value? Can you properly retrieve the coin value if you set it manually in the config file? Does every other value in the config set and get correctly?
     
  18. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    686
    GitHub:
    xXNiceYT
    Yes, it only do it when at interact when I tried on a command set coins works but only in interact won’t work
     
  19. Mespeczek

    Mespeczek Silverfish

    Messages:
    16
    GitHub:
    Igomisz123
    I had this same problem on My Plugin

    ^^^ some of my code

    '$this->arena' is my config

    and in Config "current" does not change
     

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.