Saving/Loading fiel in onDisable/onEnable doesn't work

Discussion in 'Plugin Development' started by DerFreakey, Aug 9, 2015.

Thread Status:
Not open for further replies.
  1. Hey Guys,
    I have another problem. Actually I am trying to save some files in the onDisable, so they are being loaded in the onEnable. The problem is, that they aren't saving in the onDisable method. I don't know why... The void is being executed but the first for() isn't. Is it possible that my ArrayList has already been removed?

    How can I save a file in the onDisable? Because it just doesn't do anything.
     
  2. Offline

    mine-care

    @DerFreakey Hello,
    We can know what is wrong without your code but the posibilities are endless so instead of us writing a massive list of what can be the problem, can you show us your onEnable and onDisable code as well as any external class members used dusing their execution?
    Thanks.
     
  3. Hey, thanks for your help, but I fixed my problem. I just rewrote the class, it now directly saves the tickets.

    ~Fixed
     
  4. Please mark the thread as solved.
     
  5. Offline

    ChintziSecilMC

    @DerFreakey im not sure if this is the best way and if not someone please correct is but try this:

    Code:
        public File playerData = new File(getDataFolder() + "/playerdata.yml");
        public FileConfiguration pdata = YamlConfiguration.loadConfiguration(playerData);
    
        @Override
        public void onEnable() {
            loadFiles();
            saveFiles();
        }
        @Override
        public void onDisable() {
            saveFiles();
        }
    Load files and save files code:

    Code:
        public void saveFiles() {
            try {
                pdata.save(playerData);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    
        public void loadFiles() {
            if (playerData.exists()) {
                try {
                    pdata.load(playerData);
                } catch (IOException | InvalidConfigurationException e) {
                    e.printStackTrace();
                }
            } else {
                try {
                    pdata.save(playerData);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
     
  6. Thanks, thats what I tried. The point is, that it doesn't execute my voids in onEnable/onDisable!
     
  7. Offline

    ChintziSecilMC

  8. It just doesn't execute for exampe the saveFiles(); and the loadFiles();
     
Thread Status:
Not open for further replies.

Share This Page