
walkmc.extensions.Files.kt Maven / Gradle / Ivy
@file:Suppress("NOTHING_TO_INLINE")
package walkmc.extensions
import org.bukkit.plugin.*
import java.io.*
/**
* Creates this file if not exists.
*/
fun File.create(): File = apply {
if (!exists()) {
if (parentFile != null)
parentFile.mkdirs()
createNewFile()
}
}
/**
* Creates a folder from this file if not exists.
*/
fun File.createFolder(): File = apply {
if (!exists())
mkdirs()
}
/**
* Gets a file from the specified path. This not creates the file.
*/
inline fun file(path: String) = File(path)
/**
* Gets a file from the specified path. This not creates the file.
*/
inline fun file(parent: String, name: String) = File(parent, name)
/**
* Gets a file from the specified path. This not creates the file.
*/
inline fun file(parent: File, name: String) = File(parent, name)
/**
* Gets a file from the specified path and creates them.
*/
inline fun newFile(path: String) = File(path).create()
/**
* Gets a file from the specified path and creates them.
*/
inline fun newFile(parent: String, name: String) = File(parent, name).create()
/**
* Gets a file from the specified path and creates them.
*/
inline fun newFile(parent: File, name: String) = File(parent, name).create()
/**
* Gets a folder from the specified path and creates them.
*/
inline fun newFolder(path: String) = File(path).createFolder()
/**
* Gets a folder from the specified path and creates them.
*/
inline fun newFolder(parent: String, name: String) = File(parent, name).createFolder()
/**
* Gets a folder from the specified path and creates them.
*/
inline fun newFolder(parent: File, name: String) = File(parent, name).createFolder()
/**
* Gets a file from the data folder of this plugin.
* This not creates the file.
*/
inline fun Plugin.file(name: String) = File(dataFolder, name)
/**
* Gets a file from the data folder of this plugin and creates them.
*/
inline fun Plugin.newFile(name: String) = File(dataFolder, name).create()
/**
* Gets a folder from the data folder of this plugin and creates them.
*/
inline fun Plugin.newFolder(name: String) = File(dataFolder, name).createFolder()
/**
* Gets a json file from the data folder of this plugin.
*/
inline fun Plugin.json(name: String) = File(dataFolder, "$name.json")
/**
* Gets a json file from the data folder of this plugin and creates them.
*/
inline fun Plugin.newJson(name: String) = File(dataFolder, "$name.json").create()
/**
* Gets a yaml file from the data folder of this plugin.
*/
inline fun Plugin.yaml(name: String) = File(dataFolder, "$name.yaml")
/**
* Gets a yaml file from the data folder of this plugin and creates them.
*/
inline fun Plugin.newYaml(name: String) = File(dataFolder, "$name.yaml").create()
/**
* Gets a nbt file from the data folder of this plugin.
*/
inline fun Plugin.nbt(name: String) = File(dataFolder, "$name.dat")
/**
* Gets a nbt file from the data folder of this plugin and creates them.
*/
inline fun Plugin.newNbt(name: String) = File(dataFolder, "$name.dat").create()
/**
* Gets a protobuf file from the data folder of this plugin.
*/
inline fun Plugin.proto(name: String) = File(dataFolder, "$name.proto")
/**
* Gets a protobuf file from the data folder of this plugin and creates them.
*/
inline fun Plugin.newProto(name: String) = File(dataFolder, "$name.proto").create()
/**
* Gets a dat file from the data folder of this plugin.
*/
inline fun Plugin.dat(name: String) = File(dataFolder, "$name.dat")
/**
* Gets a dat file from the data folder of this plugin and creates them.
*/
inline fun Plugin.newDat(name: String) = File(dataFolder, "$name.dat").create()
© 2015 - 2025 Weber Informatics LLC | Privacy Policy