Use the delete function where a delete inteded.

This commit is contained in:
alexcrea 2024-07-23 03:09:34 +02:00
parent 5ed365b14d
commit 565bbb7e1c
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
8 changed files with 20 additions and 7 deletions

View file

@ -118,7 +118,7 @@ public class ConflictAPI {
ConfigHolder.CONFLICT_HOLDER.getConflictManager().removeConflict(conflict); ConfigHolder.CONFLICT_HOLDER.getConflictManager().removeConflict(conflict);
// Write as null and save to file // Write as null and save to file
ConfigHolder.CONFLICT_HOLDER.getConfig().set(conflict.getName(), null); ConfigHolder.CONFLICT_HOLDER.delete(conflict.getName());
prepareSaveTask(); prepareSaveTask();
// Remove from gui // Remove from gui

View file

@ -74,7 +74,7 @@ public class CustomAnvilRecipeApi {
ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager().cleanRemove(recipe); ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager().cleanRemove(recipe);
// Write as null and save to file // Write as null and save to file
ConfigHolder.CUSTOM_RECIPE_HOLDER.getConfig().set(recipe.getName(), null); ConfigHolder.CUSTOM_RECIPE_HOLDER.delete(recipe.getName());
prepareSaveTask(); prepareSaveTask();
// Remove from gui // Remove from gui

View file

@ -145,7 +145,7 @@ public class MaterialGroupApi {
ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().groupMap.remove(group.getName()); ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().groupMap.remove(group.getName());
// Write as null and save to file // Write as null and save to file
ConfigHolder.ITEM_GROUP_HOLDER.getConfig().set(group.getName(), null); ConfigHolder.ITEM_GROUP_HOLDER.delete(group.getName());
prepareSaveTask(); prepareSaveTask();
// Remove from gui // Remove from gui

View file

@ -251,6 +251,15 @@ public abstract class ConfigHolder {
return this.deletedListConfig.getBoolean(objectPath, false); return this.deletedListConfig.getBoolean(objectPath, false);
} }
/**
* Delete a certain object by its path. do not save the config.
* @param objectPath The object path to delete.
* @return True if successful.
*/
public boolean delete(String objectPath){
return delete(objectPath, false, false);
}
/** /**
* Delete a certain object by its path. * Delete a certain object by its path.
* @param objectPath The object path to delete. * @param objectPath The object path to delete.

View file

@ -120,7 +120,7 @@ public class CustomRecipeSubSettingGui extends MappedToListSubSettingGui {
cleanAndBeUnusable(); cleanAndBeUnusable();
// Update config file storage // Update config file storage
ConfigHolder.CUSTOM_RECIPE_HOLDER.getConfig().set(this.anvilRecipe.toString(), null); ConfigHolder.CUSTOM_RECIPE_HOLDER.delete(this.anvilRecipe.toString());
// Save // Save
boolean success = true; boolean success = true;

View file

@ -127,7 +127,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl
cleanAndBeUnusable(); cleanAndBeUnusable();
// Update config file storage // Update config file storage
ConfigHolder.CONFLICT_HOLDER.getConfig().set(this.enchantConflict.toString(), null); ConfigHolder.CONFLICT_HOLDER.delete(this.enchantConflict.toString());
// Save // Save
boolean success = true; boolean success = true;

View file

@ -129,7 +129,7 @@ public class GroupConfigSubSettingGui extends MappedToListSubSettingGui implemen
cleanAndBeUnusable(); cleanAndBeUnusable();
// Update config file storage // Update config file storage
ConfigHolder.CUSTOM_RECIPE_HOLDER.getConfig().set(this.group.getName(), null); ConfigHolder.CUSTOM_RECIPE_HOLDER.delete(this.group.getName());
// Save // Save
boolean success = true; boolean success = true;

View file

@ -316,7 +316,11 @@ public class DoubleSettingGui extends AbstractSettingGui {
@Override @Override
public boolean onSave() { public boolean onSave() {
if(isNull()){ if(isNull()){
this.holder.config.getConfig().set(this.holder.configPath, null); if(this.holder.config instanceof ConfigHolder.DeletableResource deletableResource){
deletableResource.delete(this.holder.configPath);
}else{
this.holder.config.getConfig().set(this.holder.configPath, null);
}
}else{ }else{
this.holder.config.getConfig().set(this.holder.configPath, now.doubleValue()); this.holder.config.getConfig().set(this.holder.configPath, now.doubleValue());
} }