The API now test if the object were deleted before adding.

This commit is contained in:
alexcrea 2024-07-23 03:22:31 +02:00
parent 565bbb7e1c
commit e39bee5952
No known key found for this signature in database
GPG key ID: 43FD265DB0DBF91F
4 changed files with 50 additions and 3 deletions

View file

@ -30,13 +30,28 @@ public class ConflictAPI {
* @return True if successful.
*/
public static boolean addConflict(@NotNull ConflictBuilder builder){
return addConflict(builder, false);
}
/**
* Write and add a conflict.
* Will not write the conflict if it already exists.
*
* @param builder The conflict builder to be based on
* @param overrideDeleted If we should write even if the conflict was previously deleted.
* @return True if successful.
*/
public static boolean addConflict(@NotNull ConflictBuilder builder, boolean overrideDeleted){
FileConfiguration config = ConfigHolder.CONFLICT_HOLDER.getConfig();
// Test if conflict can be added
if(!overrideDeleted && ConfigHolder.CONFLICT_HOLDER.isDeleted(builder.getName())) return false;
if(config.contains(builder.getName())) return false;
if(!writeConflict(builder, false)) return false;
EnchantConflictGroup conflict = builder.build();
EnchantConflictGroup conflict = builder.build();
// Register conflict
ConfigHolder.CONFLICT_HOLDER.getConflictManager().addConflict(conflict);

View file

@ -29,10 +29,24 @@ public class CustomAnvilRecipeApi {
* @return True if successful.
*/
public static boolean addRecipe(@NotNull AnvilRecipeBuilder builder){
return addRecipe(builder, false);
}
/**
* Write and add a custom anvil recipe.
* Will not write the recipe if it already exists.
*
* @param builder The recipe builder to be based on
* @param overrideDeleted If we should write even if the recipe was previously deleted.
* @return True if successful.
*/
public static boolean addRecipe(@NotNull AnvilRecipeBuilder builder, boolean overrideDeleted){
FileConfiguration config = ConfigHolder.CUSTOM_RECIPE_HOLDER.getConfig();
String name = builder.getName();
if(!overrideDeleted && ConfigHolder.CUSTOM_RECIPE_HOLDER.isDeleted(builder.getName())) return false;
if(config.contains(builder.getName())) return false;
if(builder.getName().contains(".")) {
CustomAnvil.instance.getLogger().warning("Custom anvil recipe " + name + " contain \".\" in its name but should not. this recipe is ignored.");
return false;

View file

@ -27,16 +27,34 @@ public class MaterialGroupApi {
private static int saveChangeTask = -1;
private static int reloadChangeTask = -1;
/**
* Write and add a group.
* Will not write the group if it already exists.
*
* @param group the group to add
* @param group The group to add
* @return true if successful.
*/
public static boolean addMaterialGroup(@NotNull AbstractMaterialGroup group){
return addMaterialGroup(group, false);
}
/**
* Write and add a group.
* Will not write the group if it already exists.
*
* @param group The group to add
* @param overrideDeleted If we should write even if the group was previously deleted.
* @return true if successful.
*/
public static boolean addMaterialGroup(@NotNull AbstractMaterialGroup group, boolean overrideDeleted){
ItemGroupManager itemGroupManager = ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager();
// Test if it exists/existed
if(!overrideDeleted && ConfigHolder.ITEM_GROUP_HOLDER.isDeleted(group.getName())) return false;
if(itemGroupManager.get(group.getName()) != null) return false;
// Add group
itemGroupManager.getGroupMap().put(group.getName(), group);
if(!writeMaterialGroup(group, false)) return false;

View file

@ -245,7 +245,7 @@ public abstract class ConfigHolder {
* @param objectPath The object path to delete.
* @return True if successful.
*/
private boolean wasDeleted(String objectPath){
public boolean isDeleted(String objectPath){
if(this.deletedListConfig == null) return false;
return this.deletedListConfig.getBoolean(objectPath, false);