https://github.com/happyuky7/filemanagerbukkit1
FileManagerBukkit1
https://github.com/happyuky7/filemanagerbukkit1
Last synced: about 2 months ago
JSON representation
FileManagerBukkit1
- Host: GitHub
- URL: https://github.com/happyuky7/filemanagerbukkit1
- Owner: Happyuky7
- License: mit
- Created: 2022-06-19T08:07:00.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-12-07T07:02:05.000Z (6 months ago)
- Last Synced: 2025-03-26T19:11:12.306Z (2 months ago)
- Language: Java
- Homepage:
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# FileManagerBukkit1
FileManagerBukkit1[My website](https://happy7.xyz), My website
[Discord](https://discord.gg/3EebYUyeUX), Support My Server Discord
## Using:
```javapackage com.github.happyuky7.filemanagerbukkit1;
import com.github.happyuky7.filemanagerbukkit1.FileManager;
import org.bukkit.plugin.java.JavaPlugin;public class YourPluginMain extends JavaPlugin {
/*Created
private FileManager yourconfignameorvalue;
*/
private FileManager config;
private FileManager playerdata;
@Override
public void onEnable() {
// Plugin startup logicregisterConfigs();
}
@Override
public void onDisable() {
// Plugin shutdown logic
}public void registerConfigs() {
/*Register your config
this.yourconfignameorvalue = new FileManager(this, "yourconfignameorvalue");
*/
this.config = new FileManager(this, "config");
this.playerdata = new FileManager(this, "data/playerdata");
}/*Created Method to call in another class
public FileManager getYpurConfigNameORValue() {
return this.yourconfignameorvalue;
}
*/
public FileManager getConfig() {
return this.config;
}public FileManager getPlayerData() {
return this.playerdata;
}
}```
```java
package com.github.happyuky7.filemanagerbukkit1;import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationOptions;
import org.bukkit.configuration.MemoryConfigurationOptions;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.java.JavaPlugin;public class FileManager extends YamlConfiguration {
/*
Code by: Happyuky7
Github: https://github.com/Happyuky7
License: MIT
Link: https://github.com/Happyuky7/FileManagerBukkit1
*//*
FileManager Link: https://github.com/Happyuky7/FileManagerBukkit1
*/private final String fileName;
private final JavaPlugin plugin;
private final File folder;
public FileManager(JavaPlugin plugin, String fileName, File folder) {
this(plugin, fileName, ".yml", folder);
}public FileManager(JavaPlugin plugin, String filename, String fileextension, File folder) {
this.folder = folder;
this.plugin = plugin;
this.fileName = filename + (filename.endsWith(fileextension) ? "" : fileextension);
createFile();
}public FileManager(JavaPlugin plugin, String fileName) {
this(plugin, fileName, ".yml");
}public FileManager(JavaPlugin plugin, String fileName, String fileExtension) {
this(plugin, fileName, fileExtension, plugin.getDataFolder());
}public JavaPlugin getPlugin() {
return this.plugin;
}public T get(Class clazz, String path) {
Object obj = get(path);
return clazz.cast(obj);
}private void createFile() {
try {
File file = new File(this.folder, this.fileName);
if (!file.exists()) {
if (this.plugin.getResource(this.fileName) != null) {
this.plugin.saveResource(this.fileName, false);
} else {
save(file);
}
load(file);
} else {
load(file);
save(file);
}
} catch (Exception ex) {
this.plugin.getLogger().log(Level.SEVERE, "error occurred creating the " + this.fileName + " file");
this.plugin.getLogger().log(Level.SEVERE, "");
this.plugin.getLogger().log(Level.SEVERE, "Error:" + ex.getMessage());
}
}public void save() {
File folder = this.plugin.getDataFolder();
try {
save(new File(folder, this.fileName));
} catch (Exception ex) {
this.plugin.getLogger().log(Level.SEVERE, "error occurred while saving the " + this.fileName + " file");
this.plugin.getLogger().log(Level.SEVERE, "");
this.plugin.getLogger().log(Level.SEVERE, "Error:" + ex.getMessage());
}
}public void reload() {
File folder = this.plugin.getDataFolder();
File file = new File(folder, this.fileName);
try {
load(file);
} catch (IOException|org.bukkit.configuration.InvalidConfigurationException e) {
this.plugin.getLogger().log(Level.SEVERE, "error occurred while reloading the " + this.fileName + " file");
this.plugin.getLogger().log(Level.SEVERE, "");
this.plugin.getLogger().log(Level.SEVERE, "Error:" + e.getMessage());
}
}// You can remove this if you are using versions higher than 1.16,
// soon I will implement a new improved FileManager stay tuned to the
// Github repository: https://github.com/Happyuky7/FileManagerBukkit1
// START | Use only for legacy colors i.e. below Minecraft version 1.16.X
/*public String getColouredString(String path) {
String getted;
try {
getted = getString(path);
} catch (NullPointerException e) {
getted = path;
}
return ChatColor.translateAlternateColorCodes('&', getted);
}public List getColouredStringList(String path) {
List f = new ArrayList<>();
for (String l : getStringList(path))
f.add(l.replace('&', '&'));
return f;
}*/
// END | Use only for legacy colors i.e. below Minecraft version 1.16.X}
```
---
## Join us
* Feel free to open a PR! We accept contributions.
* [Discord](https://discord.gg/3EebYUyeUX)## Special Thanks To


[IntelliJ IDEA](https://www.jetbrains.com/idea/), Code editor for Java and other programming languages and programs.
[Azul Java](https://www.azul.com/) The world’s largest commercial provider of OpenJDK