mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
Fix Custom Recipe not being registered.
Fix conflict from api not working. Add remove api for custom recipe, material group and conflict.
This commit is contained in:
parent
a40d2c6530
commit
6f1e53f68e
8 changed files with 93 additions and 10 deletions
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue