Solved Generating a File

Discussion in 'Plugin Development' started by KeybordPiano459, Dec 28, 2012.

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

    KeybordPiano459

    When I generate a file using this code, it just makes a blank file. How do I actually add the defaults to this custom config?

    Code:java
    1. @EventHandler
    2. public void onJoin(PlayerJoinEvent event) {
    3. final Player player = event.getPlayer();
    4. File playerConfig = new File(plugin.getDataFolder() + "playerdata" + File.separator + player.getName() + ".yml");
    5. if (!player.hasPlayedBefore() || !playerConfig.exists()) {
    6. reloadPlayerConfig(player.getName());
    7. getPlayerConfig(player.getName()).addDefault("muted", false);
    8. savePlayerConfig(player.getName());
    9. reloadPlayerConfig(player.getName());
    10. }
    11. }

    The PlayerConfig class is here (the methods are taken from "extends PlayerConfig").
     
  2. Offline

    ImDeJay

    playerConfig.set(PATH, STRING);
     
    KeybordPiano459 likes this.
  3. Offline

    KeybordPiano459

    Geez, sometimes I feel so stupid...
     
  4. Offline

    ImDeJay

    happens to the best of us.
     
    KeybordPiano459 likes this.
  5. Offline

    fireblast709

    KeybordPiano459 you can also:
    1. create a default config in the jar
    2. get the InputStream with getResource("path in jar")
    3. load that InputStream with YamlConfiguration.loadConfiguration(InputStream)
    4. set the default with .setDefaults(YamlConfiguration you just loaded)
    5. set .options().copydefaults(true)
    6. and save it
     
  6. Offline

    KeybordPiano459

    It works, so I'm fine as far as this goes :p
     
  7. Offline

    fireblast709

    KeybordPiano459 just was too lazy to open the link :p (in which I noticed you already had that ;D)
     
  8. Offline

    KeybordPiano459

Thread Status:
Not open for further replies.

Share This Page