mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 16:35:57 +02:00
Compare commits
9 commits
896b1db0b8
...
26bba65a9d
| Author | SHA1 | Date | |
|---|---|---|---|
| 26bba65a9d | |||
| 2bf913293b | |||
| dbdce37c74 | |||
| f8622e9867 | |||
| 9acf9a62d2 | |||
| 4e8acef7c3 | |||
| 297f41c347 | |||
| 010b54e9ed | |||
| 0ab7abd6b4 |
11 changed files with 45 additions and 71 deletions
|
|
@ -142,7 +142,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
|
|
||||||
// Add commands
|
// Add commands
|
||||||
try {
|
try {
|
||||||
prepareCommand()
|
CustomAnvilCommand(this)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.log(Level.SEVERE, "error trying to register commands", e)
|
logger.log(Level.SEVERE, "error trying to register commands", e)
|
||||||
MetricsUtil.trackError(e)
|
MetricsUtil.trackError(e)
|
||||||
|
|
@ -326,14 +326,4 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
return yamlConfig
|
return yamlConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
fun prepareCommand() {
|
|
||||||
var command = getCommand(commandReloadName)
|
|
||||||
command?.setExecutor(ReloadExecutor())
|
|
||||||
|
|
||||||
command = getCommand(commandConfigName)
|
|
||||||
command?.setExecutor(EditConfigExecutor())
|
|
||||||
|
|
||||||
CustomAnvilCommand(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -189,9 +189,7 @@ object AnvilMergeLogic {
|
||||||
val firstEnchants = EnchantmentApi.getEnchantments(first)
|
val firstEnchants = EnchantmentApi.getEnchantments(first)
|
||||||
val secondEnchants = EnchantmentApi.getEnchantments(second)
|
val secondEnchants = EnchantmentApi.getEnchantments(second)
|
||||||
|
|
||||||
// newEnchants will be mutated by combineWith
|
val newEnchants = firstEnchants.combineWith(secondEnchants, first, player)
|
||||||
val newEnchants = HashMap(firstEnchants)
|
|
||||||
newEnchants.combineWith(secondEnchants, first, player)
|
|
||||||
|
|
||||||
var hasChanged = !isIdentical(firstEnchants, newEnchants)
|
var hasChanged = !isIdentical(firstEnchants, newEnchants)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,50 +1,25 @@
|
||||||
package xyz.alexcrea.cuanvil.command
|
package xyz.alexcrea.cuanvil.command
|
||||||
|
|
||||||
import org.bukkit.ChatColor
|
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
import org.bukkit.command.CommandExecutor
|
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
|
|
||||||
abstract class CASubCommand : CommandExecutor {
|
interface CASubCommand {
|
||||||
|
|
||||||
private var alreadySaid = false;
|
fun executeCommand(
|
||||||
override fun onCommand(
|
|
||||||
sender: CommandSender,
|
|
||||||
cmd: Command,
|
|
||||||
cmdstr: String,
|
|
||||||
args: Array<out String>
|
|
||||||
): 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,
|
sender: CommandSender,
|
||||||
cmd: Command,
|
cmd: Command,
|
||||||
cmdstr: String,
|
cmdstr: String,
|
||||||
args: Array<out String>
|
args: Array<out String>
|
||||||
): Boolean
|
): Boolean
|
||||||
|
|
||||||
open fun allowed(sender: CommandSender): Boolean {
|
fun allowed(sender: CommandSender): Boolean
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
open fun tabCompleter(
|
fun tabCompleter(
|
||||||
sender: CommandSender,
|
sender: CommandSender,
|
||||||
args: Array<out String>,
|
args: Array<out String>,
|
||||||
list: MutableList<String>
|
list: MutableList<String>
|
||||||
) {
|
)
|
||||||
}
|
|
||||||
|
|
||||||
open fun description(): String {
|
fun description(): String
|
||||||
return "no description"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -12,7 +12,7 @@ import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
import xyz.alexcrea.cuanvil.command.DiagnosticExecutor.Companion.NO_DIAG_PERM
|
import xyz.alexcrea.cuanvil.command.DiagnosticExecutor.Companion.NO_DIAG_PERM
|
||||||
|
|
||||||
class DebugToggleExecutor : CASubCommand() {
|
class DebugToggleExecutor : CASubCommand {
|
||||||
|
|
||||||
override fun description(): String {
|
override fun description(): String {
|
||||||
return "Used to toggle debug logs and retrieve it"
|
return "Used to toggle debug logs and retrieve it"
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,7 @@ import xyz.alexcrea.cuanvil.util.MetricsUtil
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.stream.Collectors
|
import java.util.stream.Collectors
|
||||||
|
|
||||||
|
class DiagnosticExecutor : CASubCommand {
|
||||||
class DiagnosticExecutor : CASubCommand() {
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val NO_DIAG_PERM = "You do not have permission to diagnostic this server"
|
const val NO_DIAG_PERM = "You do not have permission to diagnostic this server"
|
||||||
|
|
@ -327,10 +326,10 @@ class DiagnosticExecutor : CASubCommand() {
|
||||||
|
|
||||||
stb.append(
|
stb.append(
|
||||||
"\nNamespaces: ${
|
"\nNamespaces: ${
|
||||||
map.entries.stream()
|
map.entries.stream()
|
||||||
.map { (key, value) -> "$key ($value)" }
|
.map { (key, value) -> "$key ($value)" }
|
||||||
.reduce { a, b -> "$a, $b" }.get()
|
.reduce { a, b -> "$a, $b" }.get()
|
||||||
}"
|
}"
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil
|
||||||
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
|
import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions
|
||||||
|
|
||||||
class EditConfigExecutor : CASubCommand() {
|
class EditConfigExecutor : CASubCommand {
|
||||||
|
|
||||||
override fun executeCommand(
|
override fun executeCommand(
|
||||||
sender: CommandSender,
|
sender: CommandSender,
|
||||||
|
|
@ -40,6 +40,13 @@ class EditConfigExecutor : CASubCommand() {
|
||||||
return sender.hasPermission(CustomAnvil.editConfigPermission)
|
return sender.hasPermission(CustomAnvil.editConfigPermission)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun tabCompleter(
|
||||||
|
sender: CommandSender,
|
||||||
|
args: Array<out String>,
|
||||||
|
list: MutableList<String>
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
override fun description(): String {
|
override fun description(): String {
|
||||||
return "Gui to edit the plugin's config"
|
return "Gui to edit the plugin's config"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import com.google.common.collect.ImmutableMap
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
|
|
||||||
class HelpExecutor : CASubCommand() {
|
class HelpExecutor : CASubCommand {
|
||||||
|
|
||||||
lateinit var commands: ImmutableMap<String, CASubCommand>
|
lateinit var commands: ImmutableMap<String, CASubCommand>
|
||||||
|
|
||||||
|
|
@ -27,6 +27,17 @@ class HelpExecutor : CASubCommand() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun allowed(sender: CommandSender): Boolean {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun tabCompleter(
|
||||||
|
sender: CommandSender,
|
||||||
|
args: Array<out String>,
|
||||||
|
list: MutableList<String>
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
override fun description(): String {
|
override fun description(): String {
|
||||||
return "Help command"
|
return "Help command"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||||
import xyz.alexcrea.cuanvil.gui.config.global.*
|
import xyz.alexcrea.cuanvil.gui.config.global.*
|
||||||
import xyz.alexcrea.cuanvil.update.UpdateHandler
|
import xyz.alexcrea.cuanvil.update.UpdateHandler
|
||||||
|
|
||||||
class ReloadExecutor : CASubCommand() {
|
class ReloadExecutor : CASubCommand {
|
||||||
|
|
||||||
override fun executeCommand(
|
override fun executeCommand(
|
||||||
sender: CommandSender,
|
sender: CommandSender,
|
||||||
|
|
@ -40,6 +40,13 @@ class ReloadExecutor : CASubCommand() {
|
||||||
return sender.hasPermission(CustomAnvil.commandReloadPermission)
|
return sender.hasPermission(CustomAnvil.commandReloadPermission)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun tabCompleter(
|
||||||
|
sender: CommandSender,
|
||||||
|
args: Array<out String>,
|
||||||
|
list: MutableList<String>
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
override fun description(): String {
|
override fun description(): String {
|
||||||
return "Reload the configuration of this plugin"
|
return "Reload the configuration of this plugin"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ class AnvilResultListener : Listener {
|
||||||
if(!worked) {
|
if(!worked) {
|
||||||
CustomAnvil.verboseLog("Merge extract failed. reset the displayed price")
|
CustomAnvil.verboseLog("Merge extract failed. reset the displayed price")
|
||||||
// Reset the price
|
// Reset the price
|
||||||
AnvilXpUtil.setAnvilResult(inventory, view, player, result)
|
AnvilXpUtil.setAnvilResult(view, player, result)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,7 @@ object AnvilXpUtil {
|
||||||
* Display the required cost (either as xp or as money) or reset anvil price depending on result
|
* Display the required cost (either as xp or as money) or reset anvil price depending on result
|
||||||
*/
|
*/
|
||||||
fun setAnvilResult(
|
fun setAnvilResult(
|
||||||
inventory: AnvilInventory,
|
view: AnvilView,
|
||||||
view: InventoryView,
|
|
||||||
player: Player,
|
player: Player,
|
||||||
result: AnvilResult) {
|
result: AnvilResult) {
|
||||||
if(result.item == null) {
|
if(result.item == null) {
|
||||||
|
|
@ -41,7 +40,7 @@ object AnvilXpUtil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
setAnvilInvCost(inventory, view, player, result.cost, result.ignoreXpRules)
|
setAnvilInvCost(view, player, result.cost, result.ignoreXpRules)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,6 @@ commands:
|
||||||
description: Generic command for custom anvil
|
description: Generic command for custom anvil
|
||||||
aliases:
|
aliases:
|
||||||
- ca
|
- 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:
|
permissions:
|
||||||
ca.affected:
|
ca.affected:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue