diff --git a/build.gradle.kts b/build.gradle.kts index fc654d2..ab22355 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,7 @@ plugins { kotlin("jvm") version "1.9.24" java + id("org.jetbrains.dokka").version("1.9.20") id("com.github.johnrengelman.shadow").version("7.1.2") } diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/ConflictAPI.java b/src/main/java/xyz/alexcrea/cuanvil/api/ConflictAPI.java index bab98b8..4bdb6d2 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/ConflictAPI.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/ConflictAPI.java @@ -41,7 +41,7 @@ public class ConflictAPI { EnchantConflictGroup conflict = builder.build(); // Register conflict - ConfigHolder.CONFLICT_HOLDER.getConflictManager().getConflictList().add(conflict); + ConfigHolder.CONFLICT_HOLDER.getConflictManager().addConflict(conflict); // Add conflict to gui EnchantConflictGui.INSTANCE.updateValueForGeneric(conflict, true); @@ -110,6 +110,25 @@ public class ConflictAPI { return result; } + /** + * Remove a conflict. + * + * @param conflict The conflict to remove + * @return True if successful. + */ + public static boolean removeConflict(@NotNull EnchantConflictGroup conflict){ + // Remove from registry + ConfigHolder.CONFLICT_HOLDER.getConflictManager().removeConflict(conflict); + + // Write as null and save to file + ConfigHolder.CONFLICT_HOLDER.getConfig().set(conflict.getName(), null); + prepareSaveTask(); + + // Remove from gui + EnchantConflictGui.INSTANCE.removeGeneric(conflict); + + return true; + } /** * Prepare a task to save conflict configuration. diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/CustomAnvilRecipeApi.java b/src/main/java/xyz/alexcrea/cuanvil/api/CustomAnvilRecipeApi.java index 01682e6..69bfad2 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/CustomAnvilRecipeApi.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/CustomAnvilRecipeApi.java @@ -11,6 +11,9 @@ import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe; import java.util.Collections; import java.util.List; +/** + * Custom Anvil api for custom anvil recipes. + */ @SuppressWarnings("unused") public class CustomAnvilRecipeApi { @@ -47,16 +50,39 @@ public class CustomAnvilRecipeApi { return false; } + // Add to registry + ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager().cleanAddNew(recipe); + // Save to file recipe.saveToFile(false, false); prepareSaveTask(); - // Update gui + // Add from gui CustomRecipeConfigGui.INSTANCE.updateValueForGeneric(recipe, true); return true; } + /** + * Remove a custom anvil recipe. + * + * @param recipe The recipe to remove + * @return True if successful. + */ + public static boolean removeRecipe(@NotNull AnvilCustomRecipe recipe){ + // Remove from registry + ConfigHolder.CUSTOM_RECIPE_HOLDER.getRecipeManager().cleanRemove(recipe); + + // Write as null and save to file + ConfigHolder.CUSTOM_RECIPE_HOLDER.getConfig().set(recipe.getName(), null); + prepareSaveTask(); + + // Remove from gui + CustomRecipeConfigGui.INSTANCE.removeGeneric(recipe); + + return true; + } + /** * Prepare a task to save custom recipe configuration. */ diff --git a/src/main/java/xyz/alexcrea/cuanvil/api/MaterialGroupApi.java b/src/main/java/xyz/alexcrea/cuanvil/api/MaterialGroupApi.java index 76030a8..769b0bf 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/api/MaterialGroupApi.java +++ b/src/main/java/xyz/alexcrea/cuanvil/api/MaterialGroupApi.java @@ -121,6 +121,30 @@ public class MaterialGroupApi { } + /** + * Remove a material group. + * Caution ! It will not be removed from depending conflict or other material group at runtime. + * For that reason, it is not recommended to use this function. + * + * @param group The recipe to remove + * @return True if successful. + */ + public static boolean removeGroup(@NotNull AbstractMaterialGroup group){ + // Remove from registry + ConfigHolder.ITEM_GROUP_HOLDER.getItemGroupsManager().groupMap.remove(group.getName()); + + // Write as null and save to file + ConfigHolder.ITEM_GROUP_HOLDER.getConfig().set(group.getName(), null); + prepareSaveTask(); + + // Remove from gui + if(group instanceof IncludeGroup includeGroup){ + GroupConfigGui.INSTANCE.removeGeneric(includeGroup); + } + + return true; + } + /** * Prepare a task to reload every conflict. */ diff --git a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/EnchantConflictSubSettingGui.java b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/EnchantConflictSubSettingGui.java index 8c17f39..56c4420 100644 --- a/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/EnchantConflictSubSettingGui.java +++ b/src/main/java/xyz/alexcrea/cuanvil/gui/config/list/elements/EnchantConflictSubSettingGui.java @@ -118,10 +118,7 @@ public class EnchantConflictSubSettingGui extends MappedToListSubSettingGui impl EnchantConflictManager manager = ConfigHolder.CONFLICT_HOLDER.getConflictManager(); // Remove from enchantment - for (CAEnchantment enchantment : this.enchantConflict.getEnchants()) { - enchantment.removeConflict(this.enchantConflict); - } - manager.conflictList.remove(this.enchantConflict); + manager.removeConflict(this.enchantConflict); // Remove from parent this.parent.removeGeneric(this.enchantConflict); diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt index be8d085..c58c6bf 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictGroup.kt @@ -5,7 +5,7 @@ import org.bukkit.Material import xyz.alexcrea.cuanvil.enchant.CAEnchantment class EnchantConflictGroup( - private val name: String, + val name: String, private val cantConflict: AbstractMaterialGroup, var minBeforeBlock: Int ) { diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt index 2ff60a7..dbe2374 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/group/EnchantConflictManager.kt @@ -52,12 +52,21 @@ class EnchantConflictManager { val section = config.getConfigurationSection(key)!! val conflict = createConflict(section, itemManager, key) - addConflictToEnchantments(conflict) - conflictList.add(conflict) + addConflict(conflict) } } + fun addConflict(conflict: EnchantConflictGroup){ + addConflictToEnchantments(conflict) + conflictList.add(conflict) + } + + fun removeConflict(conflict: EnchantConflictGroup){ + removeConflictFromEnchantments(conflict) + conflictList.remove(conflict) + } + // Add the conflict to enchantments private fun addConflictToEnchantments(conflict: EnchantConflictGroup) { conflict.getEnchants().forEach { enchant -> @@ -65,6 +74,13 @@ class EnchantConflictManager { } } + // Remove the conflict from enchantments + private fun removeConflictFromEnchantments(conflict: EnchantConflictGroup) { + conflict.getEnchants().forEach { enchant -> + enchant.removeConflict(conflict) + } + } + // create and read a conflict from a yaml section private fun createConflict( section: ConfigurationSection, diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/recipe/AnvilCustomRecipe.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/recipe/AnvilCustomRecipe.kt index 801a077..114dbe3 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/recipe/AnvilCustomRecipe.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/recipe/AnvilCustomRecipe.kt @@ -7,7 +7,7 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant class AnvilCustomRecipe( - private val name: String, + val name: String, var exactCount: Boolean, //var exactLeft: Boolean, //var exactRight: Boolean,