mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 16:16:17 +02:00
Compare commits
3 commits
v1.x.x
...
v1.7.1-tes
| Author | SHA1 | Date | |
|---|---|---|---|
| 4e46206541 | |||
| 0d034c890e | |||
| 1db6385082 |
3 changed files with 51 additions and 20 deletions
|
|
@ -16,7 +16,7 @@ plugins {
|
|||
}
|
||||
|
||||
group = "xyz.alexcrea"
|
||||
version = "1.7.0"
|
||||
version = "1.7.1"
|
||||
|
||||
repositories {
|
||||
// EcoEnchants
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import io.delilaheve.CustomAnvil
|
|||
import io.delilaheve.util.ConfigOptions
|
||||
import io.delilaheve.util.ItemUtil.canMergeWith
|
||||
import io.delilaheve.util.ItemUtil.unitRepair
|
||||
import org.bukkit.ChatColor
|
||||
import org.bukkit.GameMode
|
||||
import org.bukkit.Material
|
||||
import org.bukkit.entity.Player
|
||||
|
|
@ -23,6 +24,7 @@ import xyz.alexcrea.cuanvil.recipe.AnvilCustomRecipe
|
|||
import xyz.alexcrea.cuanvil.util.AnvilXpUtil
|
||||
import xyz.alexcrea.cuanvil.util.CustomRecipeUtil
|
||||
import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair
|
||||
import java.util.logging.Level
|
||||
import kotlin.math.min
|
||||
|
||||
class AnvilResultListener: Listener {
|
||||
|
|
@ -45,8 +47,22 @@ class AnvilResultListener: Listener {
|
|||
if (event.rawSlot != ANVIL_OUTPUT_SLOT) {
|
||||
return
|
||||
}
|
||||
|
||||
// Test if the event should bypass custom anvil.
|
||||
if(DependencyManager.tryClickAnvilResultBypass(event, inventory)) return
|
||||
var shouldBypass: Boolean
|
||||
try {
|
||||
shouldBypass = DependencyManager.tryClickAnvilResultBypass(event, inventory)
|
||||
} catch (e: Exception){
|
||||
shouldBypass = true
|
||||
CustomAnvil.instance.logger.log(Level.SEVERE, "Error while trying to handle custom anvil supported plugin: ", e)
|
||||
|
||||
// Just in case to avoid illegal items
|
||||
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
||||
|
||||
// Finally, warn the player, maybe a lot of time but better warn than do nothing
|
||||
player.sendMessage(ChatColor.RED.toString() + "Error while handling the anvil.")
|
||||
}
|
||||
if(shouldBypass) return
|
||||
|
||||
val output = inventory.getItem(ANVIL_OUTPUT_SLOT) ?: return
|
||||
val leftItem = inventory.getItem(ANVIL_INPUT_LEFT) ?: return
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import xyz.alexcrea.cuanvil.util.AnvilColorUtil
|
|||
import xyz.alexcrea.cuanvil.util.AnvilXpUtil
|
||||
import xyz.alexcrea.cuanvil.util.CustomRecipeUtil
|
||||
import xyz.alexcrea.cuanvil.util.UnitRepairUtil.getRepair
|
||||
import java.util.logging.Level
|
||||
|
||||
/**
|
||||
* Listener for anvil events
|
||||
|
|
@ -45,7 +46,20 @@ class PrepareAnvilListener : Listener {
|
|||
val player: HumanEntity = event.viewers.first()
|
||||
|
||||
// Test if the event should bypass custom anvil.
|
||||
if(DependencyManager.tryEventPreAnvilBypass(event, player)) return
|
||||
var shouldBypass: Boolean
|
||||
try {
|
||||
shouldBypass = DependencyManager.tryEventPreAnvilBypass(event, player)
|
||||
} catch (e: Exception){
|
||||
shouldBypass = true
|
||||
CustomAnvil.instance.logger.log(Level.SEVERE, "Error while trying to handle custom anvil supported plugin: ", e)
|
||||
|
||||
// Just in case to avoid illegal items
|
||||
event.inventory.setItem(ANVIL_OUTPUT_SLOT, null)
|
||||
|
||||
// Finally, warn the player, maybe a lot of time but better warn than do nothing
|
||||
player.sendMessage(ChatColor.RED.toString() + "Error while handling the anvil.")
|
||||
}
|
||||
if(shouldBypass) return
|
||||
|
||||
val inventory = event.inventory
|
||||
val first = inventory.getItem(ANVIL_INPUT_LEFT) ?: return
|
||||
|
|
@ -116,26 +130,27 @@ class PrepareAnvilListener : Listener {
|
|||
}
|
||||
|
||||
private fun handleRename(resultItem: ItemStack, inventory: AnvilInventory, player: HumanEntity): Int {
|
||||
// Can be null
|
||||
var inventoryName = ChatColor.stripColor(inventory.renameText)
|
||||
|
||||
var sumCost = 0
|
||||
var useColor = false
|
||||
if(ConfigOptions.renameColorPossible && inventoryName != null){
|
||||
val resultString = StringBuilder(inventoryName)
|
||||
|
||||
useColor = AnvilColorUtil.handleRenamingColor(resultString, player)
|
||||
|
||||
if(useColor) {
|
||||
inventoryName = resultString.toString()
|
||||
|
||||
sumCost+= ConfigOptions.useOfColorCost
|
||||
}
|
||||
}
|
||||
|
||||
// Rename item and add renaming cost
|
||||
resultItem.itemMeta?.let {
|
||||
|
||||
val displayName = ChatColor.stripColor(it.displayName)
|
||||
var inventoryName = ChatColor.stripColor(inventory.renameText)
|
||||
|
||||
var sumCost = 0
|
||||
|
||||
var useColor = false
|
||||
if(ConfigOptions.renameColorPossible){
|
||||
val resultString = StringBuilder(inventoryName)
|
||||
|
||||
useColor = AnvilColorUtil.handleRenamingColor(resultString, player)
|
||||
|
||||
if(useColor) {
|
||||
inventoryName = resultString.toString()
|
||||
|
||||
sumCost+= ConfigOptions.useOfColorCost
|
||||
}
|
||||
}
|
||||
|
||||
if ((!useColor && (!displayName.contentEquals(inventoryName))) || (useColor && !(it.displayName).contentEquals(inventoryName))) {
|
||||
it.setDisplayName(inventoryName)
|
||||
resultItem.itemMeta = it
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue