#Problem with my File Manager class ( custom yml )

1 messages · Page 1 of 1 (latest)

novel knot
#

Hi, I have this File Manager class from CodedRed's video on youtube, But this just works in Main class and I don't know how to use it in another classes, can some body help? thanks.

#

Main Class

public final class Main extends JavaPlugin {

    public FileManager data;
    public static Plugin plugin;

    @Override
    public void onEnable() {
        plugin = this;
        this.data = new FileManager(this);
        data.saveDefaultFile();
    }

    @Override
    public void onDisable() {
        plugin = null;
    }

    public static Plugin getInstance() {
        return plugin;
    }

}

FileManager Class

public class FileManager {

    private Main plugin;
    private File file = null;
    private FileConfiguration fileConfiguration = null;

    public FileManager(Main plugin) {
        this.plugin = plugin;
    }

    public void reloadFile() {
        if (this.file == null) {
            this.file = new File(this.plugin.getDataFolder(), "data.yml");
        }
        this.fileConfiguration = YamlConfiguration.loadConfiguration(this.file);
        InputStream inputStream = this.plugin.getResource("data.yml");
        if (inputStream != null) {
            YamlConfiguration yamlConfiguration = YamlConfiguration.loadConfiguration(new InputStreamReader(inputStream));
        }
    }

    public FileConfiguration getFile() {
        if (this.fileConfiguration == null) {
            reloadFile();
        }
        return this.fileConfiguration;
    }

    public void saveFile() {
        if ((this.file == null) || (this.fileConfiguration == null)) {
            return;
        }
        try {
            this.getFile().save(file);
        } catch (IOException e) {
            this.plugin.getServer().getConsoleSender().sendMessage(Utils.colorize("&cCannot save &edata.yml &c!"));
        }
    }

    public void saveDefaultFile() {
        if (this.file == null) {
            this.file = new File(this.plugin.getDataFolder(), "data.yml");
        }
        if (!this.file.exists()) {
            this.plugin.saveResource("data.yml", false);
        }
    }

}
craggy frigate
#

you should concider learning how objects/java works...

its very simple and should be basic knowledge to know that you just need an getter for that