Last active
January 12, 2022 11:18
-
-
Save dlsf/508c3ff5e1dc87df6388858e0a6cea5c to your computer and use it in GitHub Desktop.
Config Class
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 java.io.File; | |
import java.io.IOException; | |
import org.bukkit.configuration.InvalidConfigurationException; | |
import org.bukkit.configuration.file.YamlConfiguration; | |
import org.bukkit.plugin.java.JavaPlugin; | |
public class Config extends YamlConfiguration { | |
private final String name; | |
private final JavaPlugin javaPlugin; | |
private File file; | |
public Config(String name, JavaPlugin javaPlugin) { | |
this.name = name; | |
this.javaPlugin = javaPlugin; | |
reload(); | |
} | |
private void reload() { | |
file = new File(javaPlugin.getDataFolder(), name); | |
try { | |
if (!file.exists()) | |
if (!file.createNewFile()) | |
throw new RuntimeException("Could not create ${NAME} " + name); | |
load(file); | |
} catch (IOException | InvalidConfigurationException e) { | |
//Do nothing | |
} | |
} | |
public void save() { | |
try { | |
save(file); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
public void setDefault(String path, Object value) { | |
if (!isSet(path)) { | |
set(path, value); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment