Create global and sub setting recipe config gui.

This commit is contained in:
alexcrea 2024-04-06 15:21:40 +02:00
parent 0004f2426f
commit e440d05bb9
13 changed files with 613 additions and 180 deletions

View file

@ -3,12 +3,13 @@ package xyz.alexcrea.cuanvil.group
import io.delilaheve.CustomAnvil
import org.bukkit.Material
import org.bukkit.enchantments.Enchantment
import xyz.alexcrea.cuanvil.interfaces.Named
class EnchantConflictGroup(
val name: String,
private val name: String,
private val cantConflict: AbstractMaterialGroup,
val minBeforeBlock: Int
) {
): Named {
private val enchantments = HashSet<Enchantment>()
@ -62,4 +63,8 @@ class EnchantConflictGroup(
return Material.ENCHANTED_BOOK
}
override fun getName(): String {
return name
}
}

View file

@ -139,9 +139,9 @@ class EnchantConflictManager {
var result = ConflictType.NO_CONFLICT
for (conflict in conflictList) {
CustomAnvil.verboseLog("Is against ${conflict.name}")
CustomAnvil.verboseLog("Is against ${conflict.getName()}")
val conflicting = conflict.allowed(base, mat)
CustomAnvil.verboseLog("Was against ${conflict.name} and conflicting: $conflicting ")
CustomAnvil.verboseLog("Was against ${conflict.getName()} and conflicting: $conflicting ")
if (!conflicting) {
if (conflict.getEnchants().size <= 1) {
result = ConflictType.SMALL_CONFLICT

View file

@ -0,0 +1,7 @@
package xyz.alexcrea.cuanvil.interfaces
interface Named {
fun getName(): String
}

View file

@ -4,9 +4,10 @@ import org.bukkit.configuration.ConfigurationSection
import org.bukkit.inventory.ItemStack
import xyz.alexcrea.cuanvil.config.ConfigHolder
import xyz.alexcrea.cuanvil.gui.util.GuiSharedConstant
import xyz.alexcrea.cuanvil.interfaces.Named
class AnvilCustomRecipe(
val name: String,
private val name: String,
var exactCount: Boolean,
//var exactLeft: Boolean,
//var exactRight: Boolean,
@ -16,7 +17,7 @@ class AnvilCustomRecipe(
var leftItem: ItemStack?,
var rightItem: ItemStack?,
var resultItem: ItemStack?,
) {
): Named {
// Static config name
companion object {
@ -37,9 +38,9 @@ class AnvilCustomRecipe(
val DEFAULT_XP_COST_CONFIG = 1
val DEFAULT_LEFT_ITEM_CONFIG = null
val DEFAULT_RIGHT_ITEM_CONFIG = null
val DEFAULT_RESULT_ITEM_CONFIG = null
val DEFAULT_LEFT_ITEM_CONFIG: ItemStack? = null
val DEFAULT_RIGHT_ITEM_CONFIG: ItemStack? = null
val DEFAULT_RESULT_ITEM_CONFIG: ItemStack? = null;
val XP_COST_CONFIG_RANGE = 0..255
@ -115,5 +116,9 @@ class AnvilCustomRecipe(
return true
}
override fun getName(): String {
return name
}
}

View file

@ -4,34 +4,37 @@ import io.delilaheve.CustomAnvil
import org.bukkit.Material
import org.bukkit.configuration.file.FileConfiguration
import org.bukkit.inventory.ItemStack
import java.util.LinkedHashMap
class CustomAnvilRecipeManager {
lateinit var recipeMap: LinkedHashMap<String, AnvilCustomRecipe>
lateinit var recipeList: ArrayList<AnvilCustomRecipe>
lateinit var recipeByMat: LinkedHashMap<Material, ArrayList<AnvilCustomRecipe>>
fun prepareRecipes(config: FileConfiguration) {
recipeMap = LinkedHashMap()
recipeList = ArrayList()
recipeByMat = LinkedHashMap()
// read all configs
val keys = config.getKeys(false)
for (key in keys) {
if (recipeMap.containsKey(key))
continue
val recipe = AnvilCustomRecipe.getFromConfig(key)
if(recipe == null){
CustomAnvil.log("Can't load recipe $key")
continue
}
recipeMap[key] = recipe
val leftItem = recipe.leftItem
if(leftItem != null){
addToMap(recipe, leftItem)
}
cleanAddNew(recipe)
}
}
fun cleanAddNew(recipe: AnvilCustomRecipe){
recipeList.add(recipe)
val leftItem = recipe.leftItem
if(leftItem != null){
addToMatMap(recipe, leftItem)
}
}
@ -46,13 +49,13 @@ class CustomAnvilRecipeManager {
test!!.remove(recipe)
}
if(leftItem != null){
addToMap(recipe, leftItem)
addToMatMap(recipe, leftItem)
}
recipe.leftItem = leftItem
}
fun addToMap(recipe: AnvilCustomRecipe, leftItem: ItemStack){
private fun addToMatMap(recipe: AnvilCustomRecipe, leftItem: ItemStack){
var recipeList = recipeByMat[leftItem.type]
if(recipeList == null){
recipeList = ArrayList()
@ -62,4 +65,11 @@ class CustomAnvilRecipeManager {
}
fun cleanRemove(recipe: AnvilCustomRecipe) {
recipeList.remove(recipe)
cleanSetLeftItem(recipe, null)
}
}