mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Merge branch 'master' into configGui-part5
This commit is contained in:
commit
95c976bd56
11 changed files with 117 additions and 37 deletions
14
README.md
14
README.md
|
|
@ -1,7 +1,7 @@
|
||||||
# Custom Anvil
|
# Custom Anvil
|
||||||
|
|
||||||
**Custom Anvil** is a plugin that allows server administrators to customise every aspect of the anvil's mechanics.
|
**Custom Anvil** is a plugin that allows server administrators to customise every aspect of the anvil's mechanics.
|
||||||
It is expected to work on 1.18 to 1.20.4 minecraft servers running spigot or paper.
|
It is expected to work on 1.18 to 1.20.5 minecraft servers running spigot or paper.
|
||||||
|
|
||||||
**Custom Anvil** was previously named **Unsafe Enchants+**.
|
**Custom Anvil** was previously named **Unsafe Enchants+**.
|
||||||
It was renamed because it now affects every anvil aspect and not only unsafe enchants
|
It was renamed because it now affects every anvil aspect and not only unsafe enchants
|
||||||
|
|
@ -53,5 +53,13 @@ Default configuration can be found on following links:
|
||||||
- [unit_repair_item.yml](https://github.com/alexcrea/CustomAnvil/blob/master/src/main/resources/unit_repair_item.yml)
|
- [unit_repair_item.yml](https://github.com/alexcrea/CustomAnvil/blob/master/src/main/resources/unit_repair_item.yml)
|
||||||
- [custom_recipes.yml](https://github.com/alexcrea/CustomAnvil/blob/master/src/main/resources/custom_recipes.yml)
|
- [custom_recipes.yml](https://github.com/alexcrea/CustomAnvil/blob/master/src/main/resources/custom_recipes.yml)
|
||||||
---
|
---
|
||||||
### Know issue:
|
### Known issue:
|
||||||
There is non known issue, if you find one please report the issue.
|
- Custom recipe config GUI is not reloaded on reload config command. (this should not impact a lot of admin, Custom recipe config should be edited manually only in rare occasion)
|
||||||
|
|
||||||
|
### Planned:
|
||||||
|
- Finish the config gui
|
||||||
|
- Semi manual config update on pluign or minecraft update
|
||||||
|
- Check unknow registered enchantment & warn
|
||||||
|
- Warn admin on unsuported minecraft version
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ plugins {
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "xyz.alexcrea"
|
group = "xyz.alexcrea"
|
||||||
version = "1.4.1a"
|
version = "1.4.3a"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ public enum EnchantmentProperties {
|
||||||
SOUL_SPEED(EnchantmentRarity.VERY_RARE),
|
SOUL_SPEED(EnchantmentRarity.VERY_RARE),
|
||||||
SWIFT_SNEAK(EnchantmentRarity.VERY_RARE),
|
SWIFT_SNEAK(EnchantmentRarity.VERY_RARE),
|
||||||
SWEEPING(EnchantmentRarity.RARE),
|
SWEEPING(EnchantmentRarity.RARE),
|
||||||
|
SWEEPING_EDGE(EnchantmentRarity.RARE),
|
||||||
THORNS(EnchantmentRarity.VERY_RARE),
|
THORNS(EnchantmentRarity.VERY_RARE),
|
||||||
UNBREAKING(EnchantmentRarity.UNCOMMON),
|
UNBREAKING(EnchantmentRarity.UNCOMMON),
|
||||||
VANISHING_CURSE(EnchantmentRarity.VERY_RARE);
|
VANISHING_CURSE(EnchantmentRarity.VERY_RARE);
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ import io.delilaheve.util.ItemUtil.isEnchantedBook
|
||||||
import io.delilaheve.util.ItemUtil.repairFrom
|
import io.delilaheve.util.ItemUtil.repairFrom
|
||||||
import io.delilaheve.util.ItemUtil.setEnchantmentsUnsafe
|
import io.delilaheve.util.ItemUtil.setEnchantmentsUnsafe
|
||||||
import io.delilaheve.util.ItemUtil.unitRepair
|
import io.delilaheve.util.ItemUtil.unitRepair
|
||||||
|
import org.bukkit.ChatColor
|
||||||
import org.bukkit.GameMode
|
import org.bukkit.GameMode
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
|
|
@ -161,7 +162,9 @@ class AnvilEventListener : Listener {
|
||||||
private fun handleRename(resultItem: ItemStack, inventory: AnvilInventory): Int {
|
private fun handleRename(resultItem: ItemStack, inventory: AnvilInventory): Int {
|
||||||
// Rename item and add renaming cost
|
// Rename item and add renaming cost
|
||||||
resultItem.itemMeta?.let {
|
resultItem.itemMeta?.let {
|
||||||
if (!it.displayName.contentEquals(inventory.renameText)) {
|
val displayName = ChatColor.stripColor(it.displayName)
|
||||||
|
val inventoryName = ChatColor.stripColor(inventory.renameText)
|
||||||
|
if (!displayName.contentEquals(inventoryName)) {
|
||||||
it.setDisplayName(inventory.renameText)
|
it.setDisplayName(inventory.renameText)
|
||||||
resultItem.itemMeta = it
|
resultItem.itemMeta = it
|
||||||
return ConfigOptions.itemRenameCost
|
return ConfigOptions.itemRenameCost
|
||||||
|
|
|
||||||
|
|
@ -217,12 +217,32 @@ object ConfigOptions {
|
||||||
* Get the given [enchantment]'s limit
|
* Get the given [enchantment]'s limit
|
||||||
*/
|
*/
|
||||||
fun enchantLimit(enchantment: Enchantment): Int {
|
fun enchantLimit(enchantment: Enchantment): Int {
|
||||||
val path = "${ENCHANT_LIMIT_ROOT}.${enchantment.enchantmentName}"
|
return enchantLimit(enchantment.enchantmentName)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the given [enchantmentName]'s limit
|
||||||
|
*/
|
||||||
|
private fun enchantLimit(enchantmentName: String): Int {
|
||||||
|
val default = getDefaultLevel(enchantmentName)
|
||||||
|
|
||||||
|
val path = "${ENCHANT_LIMIT_ROOT}.$enchantmentName"
|
||||||
return CustomAnvil.instance
|
return CustomAnvil.instance
|
||||||
.config
|
.config
|
||||||
.getInt(path, defaultEnchantLimit)
|
.getInt(path, default)
|
||||||
.takeIf { it in ENCHANT_LIMIT_RANGE }
|
.takeIf { it in ENCHANT_LIMIT_RANGE }
|
||||||
?: defaultEnchantLimit
|
?: default
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get default value if enchantment do not exist on config
|
||||||
|
*/
|
||||||
|
private fun getDefaultLevel(enchantmentName: String, // compatibility with 1.20.5. TODO better update system
|
||||||
|
) : Int {
|
||||||
|
if(enchantmentName == "sweeping_edge"){
|
||||||
|
return enchantLimit("sweeping")
|
||||||
|
}
|
||||||
|
return defaultEnchantLimit
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -233,15 +253,39 @@ object ConfigOptions {
|
||||||
enchantment: Enchantment,
|
enchantment: Enchantment,
|
||||||
isFromBook: Boolean
|
isFromBook: Boolean
|
||||||
): Int {
|
): Int {
|
||||||
|
return enchantmentValue(enchantment.enchantmentName, isFromBook)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the appropriate [enchantmentName]'s value dependent on whether
|
||||||
|
* it's source [isFromBook]
|
||||||
|
*/
|
||||||
|
private fun enchantmentValue(
|
||||||
|
enchantmentName: String,
|
||||||
|
isFromBook: Boolean
|
||||||
|
): Int {
|
||||||
|
val default = getDefaultValue(enchantmentName, isFromBook)
|
||||||
|
|
||||||
val typeKey = if (isFromBook) KEY_BOOK else KEY_ITEM
|
val typeKey = if (isFromBook) KEY_BOOK else KEY_ITEM
|
||||||
val path = "${ENCHANT_VALUES_ROOT}.${enchantment.enchantmentName}.$typeKey"
|
val path = "${ENCHANT_VALUES_ROOT}.${enchantmentName}.$typeKey"
|
||||||
return CustomAnvil.instance
|
return CustomAnvil.instance
|
||||||
.config
|
.config
|
||||||
.getInt(path, DEFAULT_ENCHANT_VALUE)
|
.getInt(path, default)
|
||||||
.takeIf { it >= DEFAULT_ENCHANT_VALUE }
|
.takeIf { it >= DEFAULT_ENCHANT_VALUE }
|
||||||
?: DEFAULT_ENCHANT_VALUE
|
?: DEFAULT_ENCHANT_VALUE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get default value if enchantment do not exist on config
|
||||||
|
*/
|
||||||
|
private fun getDefaultValue(enchantmentName: String, // compatibility with 1.20.5. TODO better update system
|
||||||
|
isFromBook: Boolean) : Int {
|
||||||
|
if(enchantmentName == "sweeping_edge"){
|
||||||
|
return enchantmentValue("sweeping", isFromBook)
|
||||||
|
}
|
||||||
|
return DEFAULT_ENCHANT_VALUE
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an array of key of basic config options
|
* Get an array of key of basic config options
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,17 @@ object EnchantmentUtil {
|
||||||
) = mutableMapOf<Enchantment, Int>().apply {
|
) = mutableMapOf<Enchantment, Int>().apply {
|
||||||
putAll(this@combineWith)
|
putAll(this@combineWith)
|
||||||
other.forEach { (enchantment, level) ->
|
other.forEach { (enchantment, level) ->
|
||||||
|
// Get max level or 255 if player can bypass
|
||||||
|
val maxLevel = if (player.hasPermission(CustomAnvil.bypassLevelPermission))
|
||||||
|
{ 255 } else
|
||||||
|
{ ConfigOptions.enchantLimit(enchantment) }
|
||||||
|
|
||||||
|
val cappedLevel = min(level, maxLevel)
|
||||||
|
|
||||||
// Enchantment not yet in result list
|
// Enchantment not yet in result list
|
||||||
if (!containsKey(enchantment)) {
|
if (!containsKey(enchantment)) {
|
||||||
// Add the enchantment if it doesn't have conflicts, or if player is allowed to bypass enchantment restrictions
|
// Add the enchantment if it doesn't have conflicts, or if player is allowed to bypass enchantment restrictions
|
||||||
this[enchantment] = level
|
this[enchantment] = cappedLevel
|
||||||
val conflictType =
|
val conflictType =
|
||||||
ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys, mat, enchantment)
|
ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys, mat, enchantment)
|
||||||
if (!player.hasPermission(CustomAnvil.bypassFusePermission) &&
|
if (!player.hasPermission(CustomAnvil.bypassFusePermission) &&
|
||||||
|
|
@ -46,6 +53,8 @@ object EnchantmentUtil {
|
||||||
}
|
}
|
||||||
// Enchantment already in result list
|
// Enchantment already in result list
|
||||||
else {
|
else {
|
||||||
|
val oldLevel = this[enchantment]!! // should be true, see the comment above
|
||||||
|
|
||||||
// ... and they are conflicting
|
// ... and they are conflicting
|
||||||
val conflictType =
|
val conflictType =
|
||||||
ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys, mat, enchantment)
|
ConfigHolder.CONFLICT_HOLDER.conflictManager.isConflicting(this.keys, mat, enchantment)
|
||||||
|
|
@ -57,28 +66,18 @@ object EnchantmentUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ... and they're not the same level
|
// ... and they're not the same level
|
||||||
if (this[enchantment] != other[enchantment]) {
|
if (oldLevel != cappedLevel) {
|
||||||
val newLevel = max(this[enchantment] ?: 0, other[enchantment] ?: 0)
|
// apply the greater of the two or left one if right is above max
|
||||||
// apply the greater of the two if non-zero
|
this[enchantment] = max(oldLevel, cappedLevel)
|
||||||
|
|
||||||
if (newLevel > 0) {
|
|
||||||
this[enchantment] = newLevel
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// ... and they're the same level
|
// ... and they're the same level
|
||||||
else {
|
else {
|
||||||
// try to increase the enchantment level by 1
|
// try to increase the enchantment level by 1
|
||||||
var newLevel = this[enchantment]!! + 1
|
var newLevel = oldLevel + 1
|
||||||
// Get max level or 255 if player can bypass
|
newLevel = max(min(newLevel, maxLevel), oldLevel)
|
||||||
val maxLevel = if (player.hasPermission(CustomAnvil.bypassLevelPermission)) {
|
this[enchantment] = newLevel
|
||||||
255
|
|
||||||
} else {
|
|
||||||
ConfigOptions.enchantLimit(enchantment)
|
|
||||||
}
|
|
||||||
newLevel = min(newLevel, maxLevel)
|
|
||||||
if (newLevel > 0) {
|
|
||||||
this[enchantment] = newLevel
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,12 @@ class EnchantConflictManager {
|
||||||
|
|
||||||
// Default name for a joining group
|
// Default name for a joining group
|
||||||
private const val DEFAULT_GROUP_NAME = "joinedGroup"
|
private const val DEFAULT_GROUP_NAME = "joinedGroup"
|
||||||
|
|
||||||
|
// 1.20.5 compatibility TODO better update system
|
||||||
|
private val SWEEPING_EDGE_ENCHANT =
|
||||||
|
Enchantment.getByKey(NamespacedKey.minecraft("sweeping_edge")) ?:
|
||||||
|
Enchantment.SWEEPING_EDGE
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var conflictMap: HashMap<Enchantment, ArrayList<EnchantConflictGroup>>
|
private lateinit var conflictMap: HashMap<Enchantment, ArrayList<EnchantConflictGroup>>
|
||||||
|
|
@ -76,8 +82,7 @@ class EnchantConflictManager {
|
||||||
// Read and add enchantment to conflict
|
// Read and add enchantment to conflict
|
||||||
val enchantList = section.getStringList(ENCH_LIST_PATH)
|
val enchantList = section.getStringList(ENCH_LIST_PATH)
|
||||||
for (enchantName in enchantList) {
|
for (enchantName in enchantList) {
|
||||||
val enchantKey = NamespacedKey.minecraft(enchantName)
|
val enchant = getEnchantByName(enchantName);
|
||||||
val enchant = Enchantment.getByKey(enchantKey)
|
|
||||||
if (enchant == null) {
|
if (enchant == null) {
|
||||||
if (!futureUse) {
|
if (!futureUse) {
|
||||||
CustomAnvil.instance.logger.warning("Enchantment $enchantName do not exist but was asked for conflict $conflictName")
|
CustomAnvil.instance.logger.warning("Enchantment $enchantName do not exist but was asked for conflict $conflictName")
|
||||||
|
|
@ -95,6 +100,20 @@ class EnchantConflictManager {
|
||||||
return conflict
|
return conflict
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getEnchantByName(enchantName: String): Enchantment? {
|
||||||
|
|
||||||
|
// Temporary solution for 1.20.5
|
||||||
|
when(enchantName){
|
||||||
|
"sweeping", "sweeping_edge" -> {
|
||||||
|
return SWEEPING_EDGE_ENCHANT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val enchantKey = NamespacedKey.minecraft(enchantName)
|
||||||
|
return Enchantment.getByKey(enchantKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun createConflictObject(
|
private fun createConflictObject(
|
||||||
section: ConfigurationSection,
|
section: ConfigurationSection,
|
||||||
itemManager: ItemGroupManager,
|
itemManager: ItemGroupManager,
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,9 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||||
object MetricsUtil {
|
object MetricsUtil {
|
||||||
|
|
||||||
private const val baseConfigHash = -1592940914
|
private const val baseConfigHash = -1592940914
|
||||||
private const val enchantLimitsConfigHash = -1014133828
|
private const val enchantLimitsConfigHash = -275034280
|
||||||
private const val enchantValuesConfigHash = 1072574774
|
private const val enchantValuesConfigHash = -17048020
|
||||||
private const val enchantConflictConfigHash = 1406650190
|
private const val enchantConflictConfigHash = 546475833
|
||||||
private const val itemGroupsConfigHash = 1406650190
|
private const val itemGroupsConfigHash = 1406650190
|
||||||
private const val unitRepairItemConfigHash = 536871958
|
private const val unitRepairItemConfigHash = 536871958
|
||||||
private const val customAnvilCraftConfigHash = 0
|
private const val customAnvilCraftConfigHash = 0
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ enchant_limits:
|
||||||
fire_aspect: 2
|
fire_aspect: 2
|
||||||
looting: 3
|
looting: 3
|
||||||
sweeping: 3
|
sweeping: 3
|
||||||
|
sweeping_edge: 3
|
||||||
efficiency: 5
|
efficiency: 5
|
||||||
unbreaking: 3
|
unbreaking: 3
|
||||||
fortune: 3
|
fortune: 3
|
||||||
|
|
@ -208,6 +209,9 @@ enchant_values:
|
||||||
sweeping:
|
sweeping:
|
||||||
item: 4
|
item: 4
|
||||||
book: 2
|
book: 2
|
||||||
|
sweeping_edge:
|
||||||
|
item: 4
|
||||||
|
book: 2
|
||||||
thorns:
|
thorns:
|
||||||
item: 8
|
item: 8
|
||||||
book: 4
|
book: 4
|
||||||
|
|
@ -223,3 +227,5 @@ debug_log: false
|
||||||
|
|
||||||
# Whether to show verbose debug logging
|
# Whether to show verbose debug logging
|
||||||
debug_log_verbose: false
|
debug_log_verbose: false
|
||||||
|
|
||||||
|
configVersion: 1.4.3
|
||||||
|
|
|
||||||
|
|
@ -147,8 +147,8 @@ restriction_soul_speed:
|
||||||
enchantments: [ soul_speed ]
|
enchantments: [ soul_speed ]
|
||||||
notAffectedGroups: [ enchanted_book, boots ]
|
notAffectedGroups: [ enchanted_book, boots ]
|
||||||
|
|
||||||
restriction_sweeping:
|
restriction_sweeping_edge:
|
||||||
enchantments: [ sweeping ]
|
enchantments: [ sweeping, sweeping_edge ]
|
||||||
notAffectedGroups: [ enchanted_book, swords ]
|
notAffectedGroups: [ enchanted_book, swords ]
|
||||||
|
|
||||||
# Do not exist in 1.18, that mean useInFuture will be set to true
|
# Do not exist in 1.18, that mean useInFuture will be set to true
|
||||||
|
|
@ -156,7 +156,7 @@ restriction_sweeping:
|
||||||
restriction_swift_sneak:
|
restriction_swift_sneak:
|
||||||
useInFuture: true
|
useInFuture: true
|
||||||
enchantments: [ swift_sneak ]
|
enchantments: [ swift_sneak ]
|
||||||
notAffectedGroups: [ enchanted_book, boots ]
|
notAffectedGroups: [ enchanted_book, leggings ]
|
||||||
|
|
||||||
restriction_thorns:
|
restriction_thorns:
|
||||||
enchantments: [ thorns ]
|
enchantments: [ thorns ]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
main: io.delilaheve.CustomAnvil
|
main: io.delilaheve.CustomAnvil
|
||||||
name: CustomAnvil
|
name: CustomAnvil
|
||||||
prefix: "Custom Anvil"
|
prefix: "Custom Anvil"
|
||||||
version: 1.4.1a
|
version: 1.4.3a
|
||||||
description: Allow to customise anvil mechanics
|
description: Allow to customise anvil mechanics
|
||||||
api-version: 1.18
|
api-version: 1.18
|
||||||
load: POSTWORLD
|
load: POSTWORLD
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue