How to access custom per-player configs?

Discussion in 'Plugin Development' started by Graffetus, Nov 13, 2017.

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

    Graffetus

    Hi. I am having some trouble accessing my per-player configs, but my code isn't working. Here is what I have:
    Code:
            File pyaml = Core.plugin.getDataFolder().getAbsolutePath() + File.separator + "players" + p.getUniqueId().toString() + ".yml";
            String prefix =  pyaml.getString(affixes.prefix);
            prefix = ChatColor.translateAlternateColorCodes('&', prefix);
    Please help!
     
  2. Offline

    Zombie_Striker

    @Graffetus
    That's not how any of that works:
    1. File types have no access to the content of the files. You're thinking of FileConfiguration
    2. Do not use static when making plugins; If you have to use it, it is a sign you did not think about how your plugin is should be structured.
    3. That should not even compile. A string cannot be a turned into a file. There is no getString method for Files.
     
  3. Offline

    Graffetus

    @Zombie_Striker How should I got about accessing the file then?
     
  4. Offline

    Zombie_Striker

    @Graffetus
    File file = new File(getDataFolder()......);
    FileConfiguration yml = YamlConfiguration.loadFile(file);
     
  5. Offline

    timtower Administrator Administrator Moderator

    @Graffetus Make getters instead.
    getPlayerConfig(UUID player)
     
  6. Offline

    Graffetus

    How would that work? Sorry I am new to this
     
  7. Offline

    timtower Administrator Administrator Moderator

    @Graffetus Instead of using the same code 30 times you call a single method 30 so you only need to modify 1 thing
     
  8. Offline

    Graffetus

    Alright, will try, but I have used the code that @Zombie_Killer showed me temporarily, which seems to work. I do have another problem, which is that this line:
    Code:
    File file = new File(Core.plugin.getDataFolder().getAbsolutePath() + File.separator + "players" + p.getUniqueId().toString());
    doesn't seem to be able to find the yml file. I am assuming the problem is between "players" and p.getUniqueId().toString(). If you could help me out I would appreciate it :)
     
  9. Offline

    timtower Administrator Administrator Moderator

    @Graffetus This is exactly why you should have a getter for it.
    Then you always get the same results.
    I don't know the difference between this one and the other one.
     
  10. Offline

    Graffetus

    Could you please show me an example of a getter? I don't understand what you meant earlier.
     
  11. Offline

    timtower Administrator Administrator Moderator

    Getters and setters are basic java. Which you should know when working with Bukkit in my opinion.
    I won't spoonfeed those.
     
  12. Offline

    Graffetus

    I am not asking to be spoonfed, I am asking to see an example because I don't understand why or how I would use a getter in this situation. Looking / playing with something IS a great way to learn about it.
     
  13. Offline

    timtower Administrator Administrator Moderator

Thread Status:
Not open for further replies.

Share This Page