diff --git a/src/main/kotlin/io/delilaheve/CustomAnvil.kt b/src/main/kotlin/io/delilaheve/CustomAnvil.kt index 5abf1719..321165e5 100644 --- a/src/main/kotlin/io/delilaheve/CustomAnvil.kt +++ b/src/main/kotlin/io/delilaheve/CustomAnvil.kt @@ -142,7 +142,7 @@ open class CustomAnvil : JavaPlugin() { // Add commands try { - CustomAnvilCommand(this) + prepareCommand() } catch (e: Exception) { logger.log(Level.SEVERE, "error trying to register commands", e) MetricsUtil.trackError(e) @@ -326,4 +326,14 @@ open class CustomAnvil : JavaPlugin() { return yamlConfig } + fun prepareCommand() { + var command = getCommand(commandReloadName) + command?.setExecutor(ReloadExecutor()) + + command = getCommand(commandConfigName) + command?.setExecutor(EditConfigExecutor()) + + CustomAnvilCommand(this) + } + } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt index e5e5bc7f..ff8f4476 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/anvil/AnvilMergeLogic.kt @@ -189,7 +189,9 @@ object AnvilMergeLogic { val firstEnchants = EnchantmentApi.getEnchantments(first) val secondEnchants = EnchantmentApi.getEnchantments(second) - val newEnchants = firstEnchants.combineWith(secondEnchants, first, player) + // newEnchants will be mutated by combineWith + val newEnchants = HashMap(firstEnchants) + newEnchants.combineWith(secondEnchants, first, player) var hasChanged = !isIdentical(firstEnchants, newEnchants) diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt index e76009ad..5df484ee 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CASubCommand.kt @@ -1,25 +1,50 @@ package xyz.alexcrea.cuanvil.command +import org.bukkit.ChatColor import org.bukkit.command.Command +import org.bukkit.command.CommandExecutor import org.bukkit.command.CommandSender -interface CASubCommand { +abstract class CASubCommand : CommandExecutor { - fun executeCommand( + private var alreadySaid = false; + override fun onCommand( + sender: CommandSender, + cmd: Command, + cmdstr: String, + args: Array + ): Boolean { + if (!alreadySaid) { + sender.sendMessage( + ChatColor.RED.toString() + + "Please not that this command will be replaced as a subcommand of `/customanvil` or `/ca`" + ) + alreadySaid = true + } + + return executeCommand(sender, cmd, cmdstr, args) + } + + abstract fun executeCommand( sender: CommandSender, cmd: Command, cmdstr: String, args: Array ): Boolean - fun allowed(sender: CommandSender): Boolean + open fun allowed(sender: CommandSender): Boolean { + return true + } - fun tabCompleter( + open fun tabCompleter( sender: CommandSender, args: Array, list: MutableList - ) + ) { + } - fun description(): String + open fun description(): String { + return "no description" + } } \ No newline at end of file diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DebugToggleExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DebugToggleExecutor.kt index 302ff782..c668e6e0 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DebugToggleExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DebugToggleExecutor.kt @@ -12,7 +12,7 @@ import org.bukkit.command.CommandSender import org.bukkit.entity.Player import xyz.alexcrea.cuanvil.command.DiagnosticExecutor.Companion.NO_DIAG_PERM -class DebugToggleExecutor : CASubCommand { +class DebugToggleExecutor : CASubCommand() { override fun description(): String { return "Used to toggle debug logs and retrieve it" diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt index efbf2902..b7bb1dd9 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/DiagnosticExecutor.kt @@ -30,7 +30,8 @@ import xyz.alexcrea.cuanvil.util.MetricsUtil import java.util.* import java.util.stream.Collectors -class DiagnosticExecutor : CASubCommand { + +class DiagnosticExecutor : CASubCommand() { companion object { const val NO_DIAG_PERM = "You do not have permission to diagnostic this server" @@ -326,10 +327,10 @@ class DiagnosticExecutor : CASubCommand { stb.append( "\nNamespaces: ${ - map.entries.stream() - .map { (key, value) -> "$key ($value)" } - .reduce { a, b -> "$a, $b" }.get() - }" + map.entries.stream() + .map { (key, value) -> "$key ($value)" } + .reduce { a, b -> "$a, $b" }.get() + }" ) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt index 53608818..8ff662f9 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/EditConfigExecutor.kt @@ -8,7 +8,7 @@ import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil import xyz.alexcrea.cuanvil.gui.config.MainConfigGui import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions -class EditConfigExecutor : CASubCommand { +class EditConfigExecutor : CASubCommand() { override fun executeCommand( sender: CommandSender, @@ -40,13 +40,6 @@ class EditConfigExecutor : CASubCommand { return sender.hasPermission(CustomAnvil.editConfigPermission) } - override fun tabCompleter( - sender: CommandSender, - args: Array, - list: MutableList - ) { - } - override fun description(): String { return "Gui to edit the plugin's config" } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt index c6c4d08c..1314d0ec 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt @@ -4,7 +4,7 @@ import com.google.common.collect.ImmutableMap import org.bukkit.command.Command import org.bukkit.command.CommandSender -class HelpExecutor : CASubCommand { +class HelpExecutor : CASubCommand() { lateinit var commands: ImmutableMap @@ -27,17 +27,6 @@ class HelpExecutor : CASubCommand { return true } - override fun allowed(sender: CommandSender): Boolean { - return true - } - - override fun tabCompleter( - sender: CommandSender, - args: Array, - list: MutableList - ) { - } - override fun description(): String { return "Help command" } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt index d3df341a..ab832c4f 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/ReloadExecutor.kt @@ -10,7 +10,7 @@ import xyz.alexcrea.cuanvil.dependency.DependencyManager import xyz.alexcrea.cuanvil.gui.config.global.* import xyz.alexcrea.cuanvil.update.UpdateHandler -class ReloadExecutor : CASubCommand { +class ReloadExecutor : CASubCommand() { override fun executeCommand( sender: CommandSender, @@ -40,13 +40,6 @@ class ReloadExecutor : CASubCommand { return sender.hasPermission(CustomAnvil.commandReloadPermission) } - override fun tabCompleter( - sender: CommandSender, - args: Array, - list: MutableList - ) { - } - override fun description(): String { return "Reload the configuration of this plugin" } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt index 2bfc97d0..7d750d06 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/listener/AnvilResultListener.kt @@ -115,7 +115,7 @@ class AnvilResultListener : Listener { if(!worked) { CustomAnvil.verboseLog("Merge extract failed. reset the displayed price") // Reset the price - AnvilXpUtil.setAnvilResult(view, player, result) + AnvilXpUtil.setAnvilResult(inventory, view, player, result) } return } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt index ae8a8035..55847180 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/util/anvil/AnvilXpUtil.kt @@ -32,7 +32,8 @@ object AnvilXpUtil { * Display the required cost (either as xp or as money) or reset anvil price depending on result */ fun setAnvilResult( - view: AnvilView, + inventory: AnvilInventory, + view: InventoryView, player: Player, result: AnvilResult) { if(result.item == null) { @@ -40,7 +41,7 @@ object AnvilXpUtil { return } - setAnvilInvCost(view, player, result.cost, result.ignoreXpRules) + setAnvilInvCost(inventory, view, player, result.cost, result.ignoreXpRules) } /** diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 199e0e51..9ee330f5 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -14,6 +14,18 @@ commands: description: Generic command for custom anvil aliases: - ca + anvilconfigreload: + description: Reload every config of this plugin + permission: ca.command.reload + aliases: + #- acreload # anvil config reload + #- careload # custom anvil reload + - carl # custom anvil reload + customanvilconfig: + description: open a menu for administrator to edit plugin's config in game + permission: ca.config.edit + aliases: + - configanvil permissions: ca.affected: