Solved Ints not reloading in yml files.

Discussion in 'Plugin Development' started by SneakyBruh, Oct 1, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    SneakyBruh

    Everytime i change a int like coins or rank in my yml file it doesn't update until i /reload. Eg if i set someones coins to 10k they cant rankup as it thinks they don't have enough coins but when i reload the server it will let them rankup.

    My File Code:
    Code:
    File yml= newFile("plugins/FortisMC/players.yml");
    FileConfiguration cfg = YamlConfiguration.loadConfiguration(yml);
    
    
    Yes i save the yml after i set the the ints and yes i have tried cfg.load(yml) before the command and nothing works?
     
  2. Offline

    timtower Moderator Moderator

  3. Offline

    SneakyBruh

    When they first join
    Code:
    
       if(!(cfg.contains(p.getUniqueId().toString()))){
        cfg.set(p.getUniqueId() + "." + "kills", 0);
        cfg.set(p.getUniqueId() + "." + "coins", 0);
        cfg.set(p.getUniqueId() + "." + "rank", 1);
        cfg.save(yml);
        }
    
    /setcoins:
    Code:
           int amount;
            try{
            amount = Integer.parseInt(args[1]);
            }catch(NumberFormatExceptione){
    sender.sendMessage(ChatColor.translateAlternateColorCodes('&',"&7&l[&8&lFortisMC&7&l] &7Invalid number!"));
    return true;
            }
    
            if(amount < 0){
    sender.sendMessage(ChatColor.translateAlternateColorCodes('&',"&7&l[&8&lFortisMC&7&l] &7Please only use positive numbers!"));
    return true;
            }
            Player target = Bukkit.getPlayer(args[0]);
            if(target != null){
            UUID targetName = target.getUniqueId();
    
        try {
        cfg.load(yml);
        }catch(IOException|InvalidConfigurationExceptione1){
        // TODO Auto-generated catch block
        e1.printStackTrace();
        }
            cfg.set(targetName + "." + "coins", amount);
            try {
    cfg.save(yml);
    
    }catch(IOExceptione){
    
    
    e.printStackTrace();
    
    }
    
    
    
            p.sendMessage(ChatColor.translateAlternateColorCodes('&',"&7&l[&8&lFortisMC&7&l] &7You set "+target.getName()+"s coins to "+amount));
    
            target.sendMessage(ChatColor.translateAlternateColorCodes('&',"&7&l[&8&lFortisMC&7&l] &7Your coins have been set to "+amount+" by "+p.getName()));
    
     
  4. Offline

    timtower Moderator Moderator

    @SneakyBruh Does the value in the config change as well?
     
  5. Offline

    SneakyBruh

    Yes they update
     
  6. Offline

    SneakyBruh

  7. Offline

    Minesuchtiiii

    Had the same problem, I had to replace cfg with (this.plugin).getConfig() and it worked
     
  8. Offline

    SneakyBruh

    Interesting... i reloaded the server twice and it worked?
     
  9. Offline

    Minesuchtiiii

    Did you change something in the Code?
     
  10. Offline

    SneakyBruh

    No.. thats the weird thing
     
  11. Offline

    TGamingStudio

    @SneakyBruh
    Do you have getconfig?? just
    Code:
    getConfig().getInt("name of int");
     
  12. Offline

    SneakyBruh

    Yes :)
     
Thread Status:
Not open for further replies.

Share This Page