Skip to content

Instantly share code, notes, and snippets.

@KoalaOnCaffeine
Last active March 24, 2019 15:55
Show Gist options
  • Save KoalaOnCaffeine/3c732e38a6cf70957f43dd5557b9dccf to your computer and use it in GitHub Desktop.
Save KoalaOnCaffeine/3c732e38a6cf70957f43dd5557b9dccf to your computer and use it in GitHub Desktop.
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