Solved Config not being saved

Discussion in 'Spigot Plugin Development' started by Banbeucmas, May 22, 2016.

  1. Ok i am having a bit of proplem here in my player.yml config
    I am trying to store the UUID data for 2 players upon accomplishing a refer to each other, here is the code
    Code (Text):
        //Execute the method upon a player firing command
        /*
        * @param Player r The player execute the command
        * @param Player t The player that r is targeting to
        *
         */
        public static void giveRewards(Player r, Player t){
            playerData tData = new playerData(t);
            playerData rData = new playerData(r);
            String prefix = new generalData().getPrefix();
            if(tData.hadReferred(r) || rData.hadReferred(t)){
                r.sendMessage(prefix + ChatColor.RED + " You have referred/or being referred by this guy before!");
                return;
            }

            if(rData.getReferredTime() >= new generalData().getReferredLimit()){
                r.sendMessage(prefix + ChatColor.RED + " You cannot refer more than " + new generalData().getReferredLimit() + " times");
                return;
            }

            for(String cmd : new generalData().getDefaultCommands()){
                String newCmd = cmd.replaceAll("%referral%", r.getName())
                        .replaceAll("%receiver%", t.getName());
                Bukkit.dispatchCommand(Bukkit.getConsoleSender(), newCmd);
            }

            //Add to the list, where i got the proplem, only player r got his data stored
            rData.addNewReferrals(t);
            tData.addNewReferrals(r);
            rData.addReferredTime(1);

            r.sendMessage(prefix + " " + ChatColor.GOLD + "You have referred " + ChatColor.YELLOW + t.getName());
            t.sendMessage(prefix + " " + ChatColor.YELLOW + r.getName() + ChatColor.GOLD + " had just referred " + ChatColor.GOLD + " you");

            r.sendMessage(prefix + " " + ChatColor.GOLD + "Your current referral point: " + ChatColor.WHITE + rData.getCurrentPoints());
            t.sendMessage(prefix + " " + ChatColor.GOLD + "Your current referral point: " + ChatColor.WHITE + tData.getCurrentPoints());

            Map<Integer, rewardData> rewardPoint = rewardData.getPointReward();
            if(rewardPoint.keySet().contains(tData.getCurrentPoints())){
                t.sendMessage(prefix + " " + ChatColor.GOLD + "Congratulation, you just reached " + ChatColor.YELLOW + rewardPoint.get(tData.getCurrentPoints()).getTierName() + ChatColor.GOLD +  "Milestone");
            }
            if(rewardPoint.keySet().contains(rData.getCurrentPoints())){
                r.sendMessage(prefix + " " + ChatColor.GOLD + "Congratulation, you just reached " + ChatColor.YELLOW + rewardPoint.get(rData.getCurrentPoints()).getTierName() + ChatColor.GOLD +  "Milestone");
            }
        }
     

    Code (Text):
        private void addNewReferrals(Player t){
            List<String> ref = getReferrals();
            ref.add(t.getUniqueId().toString());
            config.set(uuid + ".Referrals", ref);
            data.saveConfig();
    //Breakpoint, for some reason, getStringList still being printed whie it didnt being saved
            System.out.println("Added " + t.getUniqueId().toString() + " for player " + p.getPlayer());
            System.out.println(config.getStringList(uuid + ".Referrals"));
        }

    Code (Text):
        private List<String> getReferrals(){
            if(!config.isSet(uuid + ".Referrals")){
                config.set(uuid + ".Referrals", new ArrayList<>());
                data.saveConfig();
            }
            return config.getStringList(uuid + ".Referrals");
        }
     
     
  2. Is data defined? Also if you're doing this where config was defined you could also try:

    Code (Text):
    File f = new File("plugins/"+pluginname, "config.yml");
    config.save(f);
    you could compact it of course but this is more "seethroughable"
     
  3. Ah thanks but i found out a way to fix the issue myself
    the proplem is tData and rData are 2 diferrent instance so it dont save the save type of file