Cant save custom config

Discussion in 'Plugin Development' started by CrazyGuy3000, Mar 24, 2014.

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

    CrazyGuy3000

    I cant save a different gangs.yml

    Code:java
    1. public void reloadGangConfig() {
    2. if (gangConfigFile == null) {
    3. gangConfigFile = new File(getDataFolder(), "gangs.yml");
    4. }
    5. gangFile = YamlConfiguration.loadConfiguration(gangConfigFile);
    6.  
    7. InputStream defConfigStream = this.getResource("gangs.yml");
    8. if (defConfigStream != null) {
    9. YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
    10. gangFile.setDefaults(defConfig);
    11. }
    12. }
    13.  
    14. public FileConfiguration getGangConfig() {
    15. if (gangConfigFile == null) {
    16. reloadGangConfig();
    17. }
    18. return getGangConfig();
    19. }
    20.  
    21. public void saveGangConfig() {
    22. if (gangFile == null || gangConfigFile == null) {
    23. return;
    24. }
    25. try {
    26. getGangConfig().save(gangConfigFile);
    27.  
    28. getLogger().info("Saved Configuration");
    29. } catch (IOException ex) {
    30. getLogger().log(Level.SEVERE, "Could not save config to " + gangConfigFile, ex);
    31. }
    32. }
    33.  


    onEnable()
    Code:java
    1. saveGangConfig();


    Defining
    Code:java
    1. private FileConfiguration gangFile = null;
    2.  
    3. private File gangConfigFile = null;




    Le' Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    Gopaintman

    I'm a bit confused on what your problem is. Do you mind clarifying?
     
  3. Offline

    Prothean_IGS

    You forgot a line of code in the saveGangConfig method. Here's what it should be:
    Code:java
    1. public void saveGangConfig() {
    2. if (gangFile == null || gangConfigFile == null) {
    3. reloadGangConfig(); // You forgot this line
    4. return;
    5. }
    6. try {
    7. getGangConfig().save(gangConfigFile);
    8.  
    9. getLogger().info("Saved Configuration");
    10. } catch (IOException ex) {
    11. getLogger().log(Level.SEVERE, "Could not save config to " + gangConfigFile, ex);
    12. }
    13. }
     
  4. Offline

    CrazyGuy3000

    Still not generating the file :/
    (in onEnable im using this.saveGangConfig(); )

    le' Bump!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  5. CrazyGuy3000
    The problem is that you're not creating it. You should have something like this:

    Code:java
    1. public void saveDefaultGangConfig() {
    2. if (gangConfigFile == null) {
    3. gangConfigFile = new File(getDataFolder(), "gangconfig.yml"); //main class instance + getDataFolder()
    4. }
    5. if (!gangConfigFile.exists()) {
    6. plugin.saveResource("gangonfig.yml", false); //replace plugin with main class instance
    7. }
    8. }
     
  6. Offline

    DigitalCookie

    Watch this tutorial, it helped me and its from pogostick29
     
    PogoStick29 likes this.
  7. Offline

    CrazyGuy3000

    @DigitalCookie Thanks, for that. I am aware of Pogostick's work i just find it easier sometimes to goto here in order for support.

    The Gaming Grunts I got most of my code from the Configuration API.
     
  8. CrazyGuy3000
    That explains everything better than most tutorials tutorials do.
     
  9. Offline

    CrazyGuy3000

    And actually teaches you rather than just telling you how to code. IMO
     
  10. Offline

    PogoStick29

    How about mine? If the answer is no, I could make a better video.

    I think what you meant to say is "Actually teaches you rather than just giving you the code." I believe I do a good job of explaining things, but I'm open for criticism.
     
  11. PogoStick29
    I never said you didn't do a good job. Keep in mind I said "most", not "every".
     
  12. Offline

    JBoss925


    Wow pogostick29dev, never thought I'd see you on here. I've seen a few vids from a long time ago. Wow, I'm gonna go check out some of your recent work.
     
  13. Offline

    PogoStick29

    Fair enough. If there's anything I can do better, let me know.

    I come on here occasionally when I have free time and want to either help people or leave smart-ass, grammatically correct comments. I'll do the former if this issue is still unresolved.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  14. Offline

    JBoss925

    A fellow grammar nazi, I see.
     
  15. Offline

    PogoStick29

    I smile whenever someone uses "you" instead of "u" on the internet.
     
  16. Offline

    JBoss925

    Amen.
     
  17. Offline

    CrazyGuy3000

    PogoStick29
    Im not trying to say all your code is wrong, you dont teach people anything. What im trying to imply is if I cant work it out on my own I will look for a way to do it and learn. Most people just go straight to your channel and spam the comments asking for you to do tutorials on this that and the other. Also wow, I never thought id see you on my thread ._.
     
  18. Offline

    PogoStick29

    Whenever I come here, I check my notifications to see where I've been tagged. Feel free to email me any questions at [email protected] (or ask them here of course). You could also join the "spammers" and ask for a specific video. I don't see it as spam, I see it as my community telling me what they're interested in.
     
Thread Status:
Not open for further replies.

Share This Page