Solved Configs for each uuid/player

Discussion in 'Plugin Development' started by XxZHALO13Xx, Jan 13, 2015.

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

    XxZHALO13Xx

    Again with configs XD this is the way im doing configs..

    Code:
    public class MessagesConfig {
    
        public Core plugin;
    
        public File messagesConfig = new File(plugin.getDataFolder()+"/Data/messages.yml");
        public FileConfiguration pdata = YamlConfiguration.loadConfiguration(messagesConfig);
    
        public void saveMessagesConfig(){
            try{
                pdata.save(messagesConfig);
            } catch(IOException e){
                e.printStackTrace();
            }
        }
    
        public void loadMessagesConfig(){
            if(messagesConfig.exists()){
                try{
                    pdata.load(messagesConfig);
                } catch (IOException | InvalidConfigurationException e){
                    e.printStackTrace();
                }
            }else{
                try{
                    pdata.save(messagesConfig);
                } catch (IOException e){
                    e.printStackTrace();
                }
            }
        }
    }
    
    how do i make so when a player joins it creates them a config file that has things like
    kills:
    wins:
    deaths:
    Not sure how i would do this. i want the name to be there name - uuid

    EDIT: For some reason these configs dont generate
     
  2. Offline

    Krizeh

    Code:
    pdata.setInt(p.getName() + ".Stats.Kills", 0);
    Example of using this:


    Code:
    if (pdata.getInt(p.getName() + ".Stats.Kills") >= 5) {
    bukkit.broadcastMessage(ChatColor.GOLD + p.getName() + " has 5 kills ohmygurd");
    }
     
  3. Offline

    XxZHALO13Xx

    @Krizeh main issue is the configs dont generate...

    Code:
     public void onEnable() {
    
    if (messagesConfig != null) {
                    messagesConfig.loadMessagesConfig();
                }
    }
    
     
  4. Offline

    Krizeh

    Sorry, I read that and assumed you didn't know how to set.

    Try this:
    Code:
         File messagesConfig = new File(plugin.getDataFolder() + File.separator
                      + "Data"+ File.separator + "messages.yml");
     
    Last edited: Jan 13, 2015
  5. Offline

    XxZHALO13Xx

    @Krizeh XD we all have those days

    @Krizeh how would i create it? im the worst at configs lol i have to visually see it to understand

    EDIT: I've tried all java docs and pages but i still dont understand
     
    Last edited by a moderator: Jan 14, 2015
  6. Offline

    Krizeh

    In your onEnable put this
    Code:
            File file = new File(getDataFolder(), "Data");
            if (!file.exists()) {
                file.mkdir();
            }
            }
     
  7. Offline

    XxZHALO13Xx

    @Krizeh ok.. and then the config files inside of the data folder?

    EDIT: mkdir means make directory right? just wondering
     
  8. Offline

    Krizeh

    Once the directory is created you can create the config there
     
  9. Offline

    XxZHALO13Xx

    @Krizeh gotcha.. data folder still not being created... i have an idea tho..

    Nevermind what i said lol i wasnt creating the main folder so i made method to do that and i got the data folder thank u so much!
     
  10. Offline

    Krizeh

    Lol, I should've asked that first. Mark thread as solved please.
     
Thread Status:
Not open for further replies.

Share This Page