Last active
March 24, 2019 15:55
-
-
Save KoalaOnCaffeine/3c732e38a6cf70957f43dd5557b9dccf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.bukkit.configuration.file.FileConfiguration; | |
import org.bukkit.configuration.file.YamlConfiguration; | |
import java.io.File; | |
import java.nio.file.Path; | |
public class FileHandler { | |
private FileConfiguration config = new YamlConfiguration(); | |
private File file; | |
public FileHandler(File file) { | |
this.file = file; | |
} | |
public FileConfiguration create() { | |
try { | |
file.createNewFile(); | |
config.load(file); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
return null; | |
} | |
return config; | |
} | |
public final FileConfiguration save() { | |
try { | |
config.save(file); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return config; | |
} | |
private final FileConfiguration load(File file) { | |
try { | |
config.load(file); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
return null; | |
} | |
return config; | |
} | |
public final FileConfiguration reload() { | |
try { | |
config.load(file); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
return config; | |
} | |
public FileConfiguration get(Path path) { | |
File file = path.toFile(); | |
if (!file.exists()) { | |
return null; | |
} | |
return load(file); | |
} | |
public final FileConfiguration getConfig() { | |
return config; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment