mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
The API now test if the object were deleted before adding.
This commit is contained in:
parent
565bbb7e1c
commit
e39bee5952
4 changed files with 50 additions and 3 deletions
|
|
@ -30,13 +30,28 @@ public class ConflictAPI {
|
||||||
* @return True if successful.
|
* @return True if successful.
|
||||||
*/
|
*/
|
||||||
public static boolean addConflict(@NotNull ConflictBuilder builder){
|
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();
|
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(config.contains(builder.getName())) return false;
|
||||||
|
|
||||||
if(!writeConflict(builder, false)) return false;
|
if(!writeConflict(builder, false)) return false;
|
||||||
|
|
||||||
EnchantConflictGroup conflict = builder.build();
|
|
||||||
|
|
||||||
|
EnchantConflictGroup conflict = builder.build();
|
||||||
// Register conflict
|
// Register conflict
|
||||||
ConfigHolder.CONFLICT_HOLDER.getConflictManager().addConflict(conflict);
|
ConfigHolder.CONFLICT_HOLDER.getConflictManager().addConflict(conflict);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,10 +29,24 @@ public class CustomAnvilRecipeApi {
|
||||||
* @return True if successful.
|
* @return True if successful.
|
||||||
*/
|
*/
|
||||||
public static boolean addRecipe(@NotNull AnvilRecipeBuilder builder){
|
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();
|
FileConfiguration config = ConfigHolder.CUSTOM_RECIPE_HOLDER.getConfig();
|
||||||
String name = builder.getName();
|
String name = builder.getName();
|
||||||
|
|
||||||
|
if(!overrideDeleted && ConfigHolder.CUSTOM_RECIPE_HOLDER.isDeleted(builder.getName())) return false;
|
||||||
if(config.contains(builder.getName())) return false;
|
if(config.contains(builder.getName())) return false;
|
||||||
|
|
||||||
if(builder.getName().contains(".")) {
|
if(builder.getName().contains(".")) {
|
||||||
CustomAnvil.instance.getLogger().warning("Custom anvil recipe " + name + " contain \".\" in its name but should not. this recipe is ignored.");
|
CustomAnvil.instance.getLogger().warning("Custom anvil recipe " + name + " contain \".\" in its name but should not. this recipe is ignored.");
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -27,16 +27,34 @@ public class MaterialGroupApi {
|
||||||
private static int saveChangeTask = -1;
|
private static int saveChangeTask = -1;
|
||||||
private static int reloadChangeTask = -1;
|
private static int reloadChangeTask = -1;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write and add a group.
|
* Write and add a group.
|
||||||
* Will not write the group if it already exists.
|
* 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.
|
* @return true if successful.
|
||||||
*/
|
*/
|
||||||
public static boolean addMaterialGroup(@NotNull AbstractMaterialGroup group){
|
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();
|
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;
|
if(itemGroupManager.get(group.getName()) != null) return false;
|
||||||
|
|
||||||
|
// Add group
|
||||||
itemGroupManager.getGroupMap().put(group.getName(), group);
|
itemGroupManager.getGroupMap().put(group.getName(), group);
|
||||||
|
|
||||||
if(!writeMaterialGroup(group, false)) return false;
|
if(!writeMaterialGroup(group, false)) return false;
|
||||||
|
|
|
||||||
|
|
@ -245,7 +245,7 @@ public abstract class ConfigHolder {
|
||||||
* @param objectPath The object path to delete.
|
* @param objectPath The object path to delete.
|
||||||
* @return True if successful.
|
* @return True if successful.
|
||||||
*/
|
*/
|
||||||
private boolean wasDeleted(String objectPath){
|
public boolean isDeleted(String objectPath){
|
||||||
if(this.deletedListConfig == null) return false;
|
if(this.deletedListConfig == null) return false;
|
||||||
|
|
||||||
return this.deletedListConfig.getBoolean(objectPath, false);
|
return this.deletedListConfig.getBoolean(objectPath, false);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue