mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Create global and sub setting recipe config gui.
This commit is contained in:
parent
0004f2426f
commit
e440d05bb9
13 changed files with 613 additions and 180 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
7
src/main/kotlin/xyz/alexcrea/cuanvil/interfaces/Named.kt
Normal file
7
src/main/kotlin/xyz/alexcrea/cuanvil/interfaces/Named.kt
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
package xyz.alexcrea.cuanvil.interfaces
|
||||
|
||||
interface Named {
|
||||
|
||||
fun getName(): String
|
||||
|
||||
}
|
||||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue