@@ -82,6 +82,15 @@ public YamlConfig(Plugin plugin, File file, boolean copyDefaults) {
8282 this .COPY_DEFAULTS = copyDefaults ;
8383 }
8484
85+ /**
86+ * Verifies if the config file exists.
87+ *
88+ * @return True if the config exists.
89+ */
90+ public boolean exists () {
91+ return CONFIG_FILE .exists ();
92+ }
93+
8594 /**
8695 * @see #set(java.lang.String, java.lang.Object)
8796 */
@@ -389,21 +398,6 @@ public <K, V> Map<K, V> getMap(String path) {
389398 return keyMap ;
390399 }
391400
392- /**
393- * Saves the configuration to the predefined file.
394- *
395- * @see #YamlConfig(Plugin, String, boolean)
396- */
397- @ Override
398- public void save () {
399- try {
400- super .save (CONFIG_FILE );
401- } catch (Exception ex ) {
402- InternalExceptionHandler .handle (PLUGIN , "Could not save configuration file: " + CONFIG_FILE .getName ());
403- InternalExceptionHandler .handle (PLUGIN , ex );
404- }
405- }
406-
407401 /**
408402 * Loads the configuration from the predefined file.
409403 *
@@ -415,7 +409,7 @@ public void save() {
415409 public void load () {
416410 try {
417411 if (COPY_DEFAULTS ) {
418- if (!CONFIG_FILE . exists ()) {
412+ if (!exists ()) {
419413 CONFIG_FILE .getParentFile ().mkdirs ();
420414 try {
421415 FileUtils .copy (PLUGIN .getResource (CONFIG_FILE .getName ()), CONFIG_FILE );
@@ -436,6 +430,39 @@ public void load() {
436430 }
437431 }
438432
433+ /**
434+ * Saves the configuration to the predefined file.
435+ *
436+ * @see #YamlConfig(Plugin, String, boolean)
437+ */
438+ @ Override
439+ public void save () {
440+ try {
441+ super .save (CONFIG_FILE );
442+ } catch (Exception ex ) {
443+ InternalExceptionHandler .handle (PLUGIN , "Could not save configuration file: " + CONFIG_FILE .getName ());
444+ InternalExceptionHandler .handle (PLUGIN , ex );
445+ }
446+ }
447+
448+ /**
449+ * Deletes all the values in the config.
450+ */
451+ public void clear () {
452+ for (String key : super .getKeys (false )) {
453+ super .set (key , null );
454+ }
455+ }
456+
457+ /**
458+ * Deletes the config if it exists.
459+ */
460+ public void delete () {
461+ if (exists ()) {
462+ CONFIG_FILE .delete ();
463+ }
464+ }
465+
439466 /**
440467 * Returns the raw YamlConfiguration this config is based on.
441468 *
0 commit comments