mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-08-28 08:25:56 +02:00
finished adding command text to trans file
This commit is contained in:
parent
e6ebdcdfc0
commit
3c3ee00a50
15 changed files with 334 additions and 153 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package io.delilaheve
|
package io.delilaheve
|
||||||
|
|
||||||
import io.delilaheve.util.ConfigOptions
|
import io.delilaheve.util.ConfigOptions
|
||||||
|
import net.kyori.adventure.text.Component
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.configuration.file.YamlConfiguration
|
import org.bukkit.configuration.file.YamlConfiguration
|
||||||
import org.bukkit.plugin.java.JavaPlugin
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
|
|
@ -76,7 +77,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
var latestVer: String? = null
|
var latestVer: String? = null
|
||||||
|
|
||||||
// Debug
|
// Debug
|
||||||
val debugStorageQueue = ArrayDeque<String>()
|
val debugStorageQueue = ArrayDeque<Component>()
|
||||||
|
|
||||||
private fun addToLogQueue(message: String) {
|
private fun addToLogQueue(message: String) {
|
||||||
if(debugStorageQueue.size >= 200) {
|
if(debugStorageQueue.size >= 200) {
|
||||||
|
|
@ -84,7 +85,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
debugStorageQueue.removeFirst()
|
debugStorageQueue.removeFirst()
|
||||||
}
|
}
|
||||||
|
|
||||||
debugStorageQueue.addLast(message)
|
debugStorageQueue.addLast(Component.text(message))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package xyz.alexcrea.cuanvil.command
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
||||||
|
import xyz.alexcrea.cuanvil.lang.MessageLike
|
||||||
|
|
||||||
interface CASubCommand {
|
interface CASubCommand {
|
||||||
|
|
||||||
|
|
@ -21,7 +22,7 @@ interface CASubCommand {
|
||||||
list: MutableList<String>
|
list: MutableList<String>
|
||||||
)
|
)
|
||||||
|
|
||||||
fun description(): String
|
fun description(): MessageLike
|
||||||
|
|
||||||
fun allEnchantmentsByName(): Collection<String> {
|
fun allEnchantmentsByName(): Collection<String> {
|
||||||
val names = mutableSetOf<String>()
|
val names = mutableSetOf<String>()
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import org.bukkit.command.Command
|
||||||
import org.bukkit.command.CommandExecutor
|
import org.bukkit.command.CommandExecutor
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.command.TabCompleter
|
import org.bukkit.command.TabCompleter
|
||||||
|
import xyz.alexcrea.cuanvil.lang.MsgCommand
|
||||||
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
||||||
|
|
||||||
class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
||||||
|
|
@ -57,15 +58,15 @@ class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (subcmd == null || !subcmd.allowed(sender)) {
|
if (subcmd == null || !subcmd.allowed(sender)) {
|
||||||
sender.sendMessage("Invalid subcommand. run `$cmdstr help` to see available commands")
|
MsgCommand.ROOT_UNKNOWN_SUBCOMMAND.send(sender, cmdstr)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return subcmd.executeCommand(sender, cmd, subcmdStr, newargs)
|
return subcmd.executeCommand(sender, cmd, subcmdStr, newargs)
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
MetricsUtil.trackError(e)
|
CustomAnvil.logError("Error running /$cmdstr ${args.joinToString(" ")}", e)
|
||||||
sender.sendMessage("§cError running this command")
|
MsgCommand.ROOT_ERROR_SUBCOMMAND.send(sender)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,17 @@ import net.md_5.bungee.api.chat.ClickEvent
|
||||||
import net.md_5.bungee.api.chat.HoverEvent
|
import net.md_5.bungee.api.chat.HoverEvent
|
||||||
import net.md_5.bungee.api.chat.TextComponent
|
import net.md_5.bungee.api.chat.TextComponent
|
||||||
import net.md_5.bungee.api.chat.hover.content.Text
|
import net.md_5.bungee.api.chat.hover.content.Text
|
||||||
import org.bukkit.ChatColor
|
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
import org.bukkit.command.CommandSender
|
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.lang.MessageLike
|
||||||
|
import xyz.alexcrea.cuanvil.lang.MsgCommand
|
||||||
|
import xyz.alexcrea.cuanvil.util.MiniMessageUtil
|
||||||
|
|
||||||
class DebugToggleExecutor : CASubCommand {
|
class DebugToggleExecutor : CASubCommand {
|
||||||
|
|
||||||
override fun description(): String {
|
override fun description(): MessageLike {
|
||||||
return "Used to toggle debug logs and retrieve it"
|
return MsgCommand.DEBUG_DESCRIPTION
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun allowed(sender: CommandSender): Boolean {
|
override fun allowed(sender: CommandSender): Boolean {
|
||||||
|
|
@ -26,18 +27,18 @@ class DebugToggleExecutor : CASubCommand {
|
||||||
sender: CommandSender,
|
sender: CommandSender,
|
||||||
cmd: Command,
|
cmd: Command,
|
||||||
cmdstr: String,
|
cmdstr: String,
|
||||||
args: Array<out String>
|
args: Array<out String>,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (!allowed(sender)) {
|
if(!allowed(sender)) {
|
||||||
sender.sendMessage(NO_DIAG_PERM)
|
MsgCommand.SHARED_NO_DIAG_PERM.send(sender)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.isEmpty()) {
|
if(args.isEmpty()) {
|
||||||
sender.sendMessage("Need to specify a subcommand: \"toggle\" or \"get\"")
|
MsgCommand.SHARED_MISSING_SUBCOMMAND.send(sender)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
when (args[0].lowercase()) {
|
when(args[0].lowercase()) {
|
||||||
"toggle" -> executeToggle(sender, args)
|
"toggle" -> executeToggle(sender, args)
|
||||||
"get" -> executeGet(sender)
|
"get" -> executeGet(sender)
|
||||||
"get-and-clear" -> {
|
"get-and-clear" -> {
|
||||||
|
|
@ -47,52 +48,57 @@ class DebugToggleExecutor : CASubCommand {
|
||||||
|
|
||||||
"clear" -> {
|
"clear" -> {
|
||||||
CustomAnvil.debugStorageQueue.clear()
|
CustomAnvil.debugStorageQueue.clear()
|
||||||
sender.sendMessage("Log Cleared")
|
MsgCommand.DEBUG_LOG_CLEARED.send(sender)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> return false
|
else -> {
|
||||||
|
MsgCommand.SHARED_UNKNOWN_SUB_COMMAND.send(sender)
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun executeToggle(sender: CommandSender, args: Array<out String>) {
|
private fun executeToggle(sender: CommandSender, args: Array<out String>) {
|
||||||
if (args.size < 2) {
|
if(args.size < 2) {
|
||||||
sender.sendMessage("Need to specify which type of debug to toggle: \"default\" or \"verbose\"")
|
MsgCommand.DEBUG_WARNING_UNSPECIFIED_TYPE.send(sender)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
when (args[1].lowercase()) {
|
when(args[1].lowercase()) {
|
||||||
"default" -> {
|
"default" -> {
|
||||||
ConfigOptions.OVERRIDE_DEBUG_LOG = !ConfigOptions.debugLog
|
ConfigOptions.OVERRIDE_DEBUG_LOG = !ConfigOptions.debugLog
|
||||||
sender.sendMessage("Debug toggle to: ${ConfigOptions.debugLog}")
|
MsgCommand.DEBUG_TOGGLED.send(sender, ConfigOptions.debugLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
"verbose" -> {
|
"verbose" -> {
|
||||||
ConfigOptions.OVERRIDE_VERBOSE_DEBUG_LOG = !ConfigOptions.verboseDebugLog
|
ConfigOptions.OVERRIDE_VERBOSE_DEBUG_LOG = !ConfigOptions.verboseDebugLog
|
||||||
sender.sendMessage("Debug toggle to: ${ConfigOptions.verboseDebugLog}")
|
MsgCommand.DEBUG_TOGGLED.send(sender, ConfigOptions.debugLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> sender.sendMessage("Invalid debug type: ${args[1]}")
|
else -> MsgCommand.DEBUG_WARNING_INVALID_TYPE.send(sender, ConfigOptions.debugLog)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun executeGet(sender: CommandSender) {
|
private fun executeGet(sender: CommandSender) {
|
||||||
val stb = StringBuilder("Debug Log data:")
|
if(CustomAnvil.debugStorageQueue.isEmpty()) {
|
||||||
if (CustomAnvil.debugStorageQueue.isEmpty()) {
|
MsgCommand.DEBUG_WARNING_NO_LOG.send(sender, "/ca debug toggle")
|
||||||
sender.sendMessage("No log to show ? make sure you tried with debug log toggled (/ca debug toggle)")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
stb.append("\nFound ${CustomAnvil.debugStorageQueue.size} lines\n")
|
val stb = StringBuilder(MsgCommand.DEBUG_DATA_HEADER.unformatted()).append(' ')
|
||||||
for (log in CustomAnvil.debugStorageQueue) {
|
stb.append(MsgCommand.DEBUG_DATA_LINE_COUNT.unformatted(CustomAnvil.debugStorageQueue.size))
|
||||||
stb.append('\n').append(log)
|
for(log in CustomAnvil.debugStorageQueue) {
|
||||||
|
stb.append('\n').append(MiniMessageUtil.plain_text_mm.serialize(log))
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sender is Player) {
|
if(sender is Player) {
|
||||||
val message = TextComponent(ChatColor.GREEN.toString() + "Click to copy log data")
|
val message = TextComponent(MsgCommand.DEBUG_COPY.legacy())
|
||||||
|
|
||||||
message.clickEvent = ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, stb.toString())
|
message.clickEvent = ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, stb.toString())
|
||||||
message.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text("§7Click to copy"))
|
message.hoverEvent = HoverEvent(
|
||||||
|
HoverEvent.Action.SHOW_TEXT,
|
||||||
|
Text(MsgCommand.SHARED_HOVER_COPY.legacy())
|
||||||
|
)
|
||||||
|
|
||||||
sender.spigot().sendMessage(message);
|
sender.spigot().sendMessage(message);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -101,12 +107,12 @@ class DebugToggleExecutor : CASubCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun tabCompleter(sender: CommandSender, args: Array<out String>, list: MutableList<String>) {
|
override fun tabCompleter(sender: CommandSender, args: Array<out String>, list: MutableList<String>) {
|
||||||
if (!allowed(sender)) return
|
if(!allowed(sender)) return
|
||||||
|
|
||||||
list.addAll(
|
list.addAll(
|
||||||
when (args.size) {
|
when(args.size) {
|
||||||
1 -> listOf("toggle", "get", "get-and-clear", "clear")
|
1 -> listOf("toggle", "get", "get-and-clear", "clear")
|
||||||
2 -> when (args[0].lowercase()) {
|
2 -> when(args[0].lowercase()) {
|
||||||
"toggle" -> listOf("default", "verbose")
|
"toggle" -> listOf("default", "verbose")
|
||||||
else -> listOf()
|
else -> listOf()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import net.md_5.bungee.api.chat.HoverEvent
|
||||||
import net.md_5.bungee.api.chat.TextComponent
|
import net.md_5.bungee.api.chat.TextComponent
|
||||||
import net.md_5.bungee.api.chat.hover.content.Text
|
import net.md_5.bungee.api.chat.hover.content.Text
|
||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.ChatColor
|
|
||||||
import org.bukkit.Material
|
import org.bukkit.Material
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
|
|
@ -25,15 +24,17 @@ import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||||
import xyz.alexcrea.cuanvil.dependency.packet.NoPacketManager
|
import xyz.alexcrea.cuanvil.dependency.packet.NoPacketManager
|
||||||
import xyz.alexcrea.cuanvil.dependency.packet.ProtocoLibWrapper
|
import xyz.alexcrea.cuanvil.dependency.packet.ProtocoLibWrapper
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantmentRegistry
|
||||||
|
import xyz.alexcrea.cuanvil.lang.MessageLike
|
||||||
|
import xyz.alexcrea.cuanvil.lang.MsgCommand
|
||||||
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener
|
import xyz.alexcrea.cuanvil.listener.PrepareAnvilListener
|
||||||
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.stream.Collectors
|
import java.util.stream.Collectors
|
||||||
|
|
||||||
|
@Suppress("UnstableApiUsage")
|
||||||
class DiagnosticExecutor : CASubCommand {
|
class DiagnosticExecutor : CASubCommand {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val NO_DIAG_PERM = "You do not have permission to diagnostic this server"
|
|
||||||
|
|
||||||
fun fetchNMSType(): String {
|
fun fetchNMSType(): String {
|
||||||
val packetManager = DependencyManager.packetManager
|
val packetManager = DependencyManager.packetManager
|
||||||
|
|
@ -101,7 +102,7 @@ class DiagnosticExecutor : CASubCommand {
|
||||||
args: Array<out String>
|
args: Array<out String>
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (!allowed(sender)) {
|
if (!allowed(sender)) {
|
||||||
sender.sendMessage(NO_DIAG_PERM)
|
MsgCommand.SHARED_NO_DIAG_PERM.send(sender)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,11 +123,11 @@ class DiagnosticExecutor : CASubCommand {
|
||||||
|
|
||||||
if (sender is HumanEntity) {
|
if (sender is HumanEntity) {
|
||||||
if (hasError)
|
if (hasError)
|
||||||
sender.sendMessage(ChatColor.RED.toString() + "There was an error running the diagnostic")
|
MsgCommand.DIAGNOSTIC_ERROR_GENERIC.send(sender)
|
||||||
val message = TextComponent(ChatColor.GREEN.toString() + "Click to copy diagnostic data")
|
val message = TextComponent(MsgCommand.DIAGNOSTIC_COPY.legacy())
|
||||||
|
|
||||||
message.clickEvent = ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, stb.toString())
|
message.clickEvent = ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, stb.toString())
|
||||||
message.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text("§7Click to copy"))
|
message.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text(MsgCommand.SHARED_HOVER_COPY.legacy()))
|
||||||
|
|
||||||
sender.spigot().sendMessage(message)
|
sender.spigot().sendMessage(message)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -213,8 +214,8 @@ class DiagnosticExecutor : CASubCommand {
|
||||||
return this.name + " v" + this.description.version
|
return this.name + " v" + this.description.version
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun description(): String {
|
override fun description(): MessageLike {
|
||||||
return "Basic diagnostic of this plugin"
|
return MsgCommand.DIAGNOSTIC_DESCRIPTION
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun pluginListDiag(sender: CommandSender, stb: StringBuilder) {
|
private fun pluginListDiag(sender: CommandSender, stb: StringBuilder) {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ import xyz.alexcrea.cuanvil.gui.config.MainConfigGui
|
||||||
import xyz.alexcrea.cuanvil.gui.config.global.EnchantConfigGui
|
import xyz.alexcrea.cuanvil.gui.config.global.EnchantConfigGui
|
||||||
import xyz.alexcrea.cuanvil.gui.config.global.ItemConfigGui
|
import xyz.alexcrea.cuanvil.gui.config.global.ItemConfigGui
|
||||||
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions
|
import xyz.alexcrea.cuanvil.gui.util.GuiGlobalActions
|
||||||
|
import xyz.alexcrea.cuanvil.lang.MessageLike
|
||||||
|
import xyz.alexcrea.cuanvil.lang.MsgCommand
|
||||||
import xyz.alexcrea.cuanvil.util.MaterialUtil.customType
|
import xyz.alexcrea.cuanvil.util.MaterialUtil.customType
|
||||||
import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir
|
import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir
|
||||||
|
|
||||||
|
|
@ -20,42 +22,38 @@ class EditConfigExecutor : CASubCommand {
|
||||||
return sender.hasPermission(CustomAnvil.editConfigPermission)
|
return sender.hasPermission(CustomAnvil.editConfigPermission)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun description(): String {
|
override fun description(): MessageLike {
|
||||||
return "Gui to edit the plugin's config"
|
return MsgCommand.CONFIG_DESCRIPTION
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun executeCommand(
|
override fun executeCommand(
|
||||||
sender: CommandSender,
|
sender: CommandSender,
|
||||||
cmd: Command,
|
cmd: Command,
|
||||||
cmdstr: String,
|
cmdstr: String,
|
||||||
args: Array<out String>
|
args: Array<out String>,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (sender !is HumanEntity) return false
|
if(sender !is HumanEntity) return false
|
||||||
|
|
||||||
if (!allowed(sender)) {
|
if(!allowed(sender)) {
|
||||||
sender.sendMessage(GuiGlobalActions.NO_EDIT_PERM)
|
sender.sendMessage(GuiGlobalActions.NO_EDIT_PERM)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (PlatformUtil.isFolia) {
|
if(PlatformUtil.isFolia) {
|
||||||
sender.sendMessage("§cIt look like you are using Folia. Sadly Custom Anvil do not support Config gui for Folia.")
|
MsgCommand.CONFIG_FOLIA_ISSUE.send(sender)
|
||||||
sender.sendMessage("§eIt is may come in a future version.")
|
|
||||||
sender.sendMessage("")
|
|
||||||
sender.sendMessage("§eCurrently you need to edit manually the config or copy from another server (spigot or better)")
|
|
||||||
sender.sendMessage("§eThen /ca reload after config file is edited")
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("gui".equals(cmdstr, ignoreCase = true)) {
|
if("gui".equals(cmdstr, ignoreCase = true)) {
|
||||||
sender.sendMessage("§c/ca gui has been moved to /ca config")
|
MsgCommand.CONFIG_LEGACY_NAME_WARNING.send(sender)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (args.isEmpty())
|
if(args.isEmpty())
|
||||||
processOpen(sender)
|
processOpen(sender)
|
||||||
else when (args[0].lowercase()) {
|
else when(args[0].lowercase()) {
|
||||||
"open" -> processOpen(sender)
|
"open" -> processOpen(sender)
|
||||||
"enchant" -> processEnchant(sender, args)
|
"enchant" -> processEnchant(sender, args)
|
||||||
"item" -> processItem(sender)
|
"item" -> processItem(sender)
|
||||||
else -> sender.sendMessage("Unknown subcommand \"${args[0]}\"")
|
else -> MsgCommand.SHARED_UNKNOWN_SUB_COMMAND.send(sender)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
|
|
@ -63,31 +61,30 @@ class EditConfigExecutor : CASubCommand {
|
||||||
|
|
||||||
private fun processEnchant(sender: HumanEntity, args: Array<out String>) {
|
private fun processEnchant(sender: HumanEntity, args: Array<out String>) {
|
||||||
val enchantToFilter: Set<CAEnchantment>
|
val enchantToFilter: Set<CAEnchantment>
|
||||||
if (args.size <= 1) {
|
if(args.size <= 1) {
|
||||||
val item = sender.inventory.itemInMainHand
|
val item = sender.inventory.itemInMainHand
|
||||||
|
|
||||||
enchantToFilter = EnchantmentApi.getEnchantments(item).keys
|
enchantToFilter = EnchantmentApi.getEnchantments(item).keys
|
||||||
if (enchantToFilter.isEmpty()) {
|
if(enchantToFilter.isEmpty()) {
|
||||||
sender.sendMessage("No enchantment found in the item you are holding")
|
MsgCommand.CONFIG_ENCHANTMENT_NO_IN_HAND.send(sender)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
enchantToFilter = HashSet(EnchantmentApi.getByName(args[1].lowercase()))
|
enchantToFilter = HashSet(EnchantmentApi.getByName(args[1].lowercase()))
|
||||||
|
|
||||||
if (enchantToFilter.isEmpty()) {
|
if(enchantToFilter.isEmpty()) {
|
||||||
sender.sendMessage("No enchantment found with the name \"${args[1]}\"")
|
MsgCommand.CONFIG_ENCHANTMENT_NO_NAME.send(sender, args[1])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EnchantConfigGui(enchantToFilter).show(sender)
|
EnchantConfigGui(enchantToFilter).show(sender)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun processItem(sender: HumanEntity) {
|
private fun processItem(sender: HumanEntity) {
|
||||||
val item = sender.inventory.itemInMainHand
|
val item = sender.inventory.itemInMainHand
|
||||||
if (item.isAir) {
|
if(item.isAir) {
|
||||||
sender.sendMessage("Cannot configure the item in hand")
|
MsgCommand.CONFIG_CANNOT_CONFIGURE_WARNING.send(sender)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,10 +101,10 @@ class EditConfigExecutor : CASubCommand {
|
||||||
|
|
||||||
override fun tabCompleter(sender: CommandSender, args: Array<out String>, list: MutableList<String>) {
|
override fun tabCompleter(sender: CommandSender, args: Array<out String>, list: MutableList<String>) {
|
||||||
list.addAll(
|
list.addAll(
|
||||||
when (args.size) {
|
when(args.size) {
|
||||||
1 -> listOf("item", "enchant", "open")
|
1 -> listOf("item", "enchant", "open")
|
||||||
2 -> {
|
2 -> {
|
||||||
when (args[0].lowercase()) {
|
when(args[0].lowercase()) {
|
||||||
"enchant" -> allEnchantmentsByName()
|
"enchant" -> allEnchantmentsByName()
|
||||||
else -> listOf()
|
else -> listOf()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,8 @@ import org.bukkit.command.CommandSender
|
||||||
import org.bukkit.entity.HumanEntity
|
import org.bukkit.entity.HumanEntity
|
||||||
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
import xyz.alexcrea.cuanvil.api.EnchantmentApi
|
||||||
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
import xyz.alexcrea.cuanvil.enchant.CAEnchantment
|
||||||
|
import xyz.alexcrea.cuanvil.lang.MessageLike
|
||||||
|
import xyz.alexcrea.cuanvil.lang.MsgCommand
|
||||||
import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir
|
import xyz.alexcrea.cuanvil.util.MaterialUtil.isAir
|
||||||
|
|
||||||
class EnchantExecutor : CASubCommand {
|
class EnchantExecutor : CASubCommand {
|
||||||
|
|
@ -19,74 +21,74 @@ class EnchantExecutor : CASubCommand {
|
||||||
return sender.hasPermission(CustomAnvil.giveEnchantmentPermission)
|
return sender.hasPermission(CustomAnvil.giveEnchantmentPermission)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun description(): String {
|
override fun description(): MessageLike {
|
||||||
return "Allows to set enchantment to holden item"
|
return MsgCommand.ENCHANT_DESCRIPTION
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun executeCommand(
|
override fun executeCommand(
|
||||||
sender: CommandSender,
|
sender: CommandSender,
|
||||||
cmd: Command,
|
cmd: Command,
|
||||||
cmdstr: String,
|
cmdstr: String,
|
||||||
args: Array<out String>
|
args: Array<out String>,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (sender !is HumanEntity) return true
|
if(sender !is HumanEntity) return true
|
||||||
|
|
||||||
if (!allowed(sender)) {
|
if(!allowed(sender)) {
|
||||||
sender.sendMessage("No permission to execute this command")
|
MsgCommand.SHARED_NO_PERMISSION.send(sender)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
when (args.size) {
|
when(args.size) {
|
||||||
0 -> {
|
0 -> {
|
||||||
sender.sendMessage("Missing enchantment parameter")
|
MsgCommand.ENCHANT_MISSING_PARAMETER_WARNING.send(sender)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val enchant = firstEnchantment(args[0])
|
val enchant = firstEnchantment(args[0])
|
||||||
if (enchant == null) {
|
if(enchant == null) {
|
||||||
sender.sendMessage("Enchantment not found: ${args[0]}")
|
MsgCommand.ENCHANT_NOT_FOUND_WARNING.send(sender, args[0])
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
val level = if (args.size > 1)
|
val level = if(args.size > 1)
|
||||||
args[1].toIntOrNull()?.coerceIn(0, ConfigOptions.ENCHANT_LIMIT)
|
args[1].toIntOrNull()?.coerceIn(0, ConfigOptions.ENCHANT_LIMIT)
|
||||||
else 1
|
else 1
|
||||||
|
|
||||||
if (level == null) {
|
if(level == null) {
|
||||||
sender.sendMessage("Invalid number: ${args[1]}")
|
MsgCommand.ENCHANT_MALFORMED_NUMBER_WARNING.send(sender, args[1])
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
val inHand = sender.inventory.itemInMainHand
|
val inHand = sender.inventory.itemInMainHand
|
||||||
if (inHand.isAir) {
|
if(inHand.isAir) {
|
||||||
sender.sendMessage("Cannot enchant this item")
|
MsgCommand.ENCHANT_CANNOT_ENCHANT_WARNING.send(sender)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level == 0) {
|
if(level == 0) {
|
||||||
enchant.removeFrom(inHand)
|
enchant.removeFrom(inHand)
|
||||||
|
|
||||||
if (inHand.isEnchantedBook() && EnchantmentApi.getEnchantments(inHand).isEmpty())
|
if(inHand.isEnchantedBook() && EnchantmentApi.getEnchantments(inHand).isEmpty())
|
||||||
inHand.type = Material.BOOK
|
inHand.type = Material.BOOK
|
||||||
|
|
||||||
sender.sendMessage("${enchant.prettyName} removed")
|
MsgCommand.ENCHANT_REMOVE.send(sender, enchant.prettyName)
|
||||||
} else {
|
} else {
|
||||||
if (Material.BOOK == inHand.type)
|
if(Material.BOOK == inHand.type)
|
||||||
inHand.type = Material.ENCHANTED_BOOK
|
inHand.type = Material.ENCHANTED_BOOK
|
||||||
|
|
||||||
enchant.addEnchantmentUnsafe(inHand, level)
|
enchant.addEnchantmentUnsafe(inHand, level)
|
||||||
sender.sendMessage("${enchant.prettyName} set to level $level")
|
MsgCommand.ENCHANT_SET.send(sender, enchant.prettyName, level)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun tabCompleter(sender: CommandSender, args: Array<out String>, list: MutableList<String>) {
|
override fun tabCompleter(sender: CommandSender, args: Array<out String>, list: MutableList<String>) {
|
||||||
if (sender !is HumanEntity) return
|
if(sender !is HumanEntity) return
|
||||||
|
|
||||||
list.addAll(
|
list.addAll(
|
||||||
when (args.size) {
|
when(args.size) {
|
||||||
1 -> allEnchantmentsByName()
|
1 -> allEnchantmentsByName()
|
||||||
2 -> findEnchantmentLevels(sender, args[0])
|
2 -> findEnchantmentLevels(sender, args[0])
|
||||||
|
|
||||||
|
|
@ -97,19 +99,19 @@ class EnchantExecutor : CASubCommand {
|
||||||
|
|
||||||
private fun findEnchantmentLevels(
|
private fun findEnchantmentLevels(
|
||||||
sender: HumanEntity,
|
sender: HumanEntity,
|
||||||
name: String
|
name: String,
|
||||||
): Collection<String> {
|
): Collection<String> {
|
||||||
val enchant = firstEnchantment(name) ?: return listOf()
|
val enchant = firstEnchantment(name) ?: return listOf()
|
||||||
|
|
||||||
val limit = ConfigOptions.enchantLimit(enchant)
|
val limit = ConfigOptions.enchantLimit(enchant)
|
||||||
val result = mutableListOf<String>()
|
val result = mutableListOf<String>()
|
||||||
|
|
||||||
for (i in 1 until limit + 1) {
|
for(i in 1 until limit + 1) {
|
||||||
result.add(i.toString())
|
result.add(i.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
val inHand = sender.inventory.itemInMainHand
|
val inHand = sender.inventory.itemInMainHand
|
||||||
if (enchant.isEnchantmentPresent(inHand))
|
if(enchant.isEnchantmentPresent(inHand))
|
||||||
result.add("0")
|
result.add("0")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
@ -117,7 +119,7 @@ class EnchantExecutor : CASubCommand {
|
||||||
|
|
||||||
private fun firstEnchantment(name: String): CAEnchantment? {
|
private fun firstEnchantment(name: String): CAEnchantment? {
|
||||||
val enchants = EnchantmentApi.getByName(name.lowercase())
|
val enchants = EnchantmentApi.getByName(name.lowercase())
|
||||||
if (!enchants.isEmpty())
|
if(!enchants.isEmpty())
|
||||||
return enchants.iterator().next()
|
return enchants.iterator().next()
|
||||||
|
|
||||||
return EnchantmentApi.getByKey(NamespacedKey.fromString(name))
|
return EnchantmentApi.getByKey(NamespacedKey.fromString(name))
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,38 @@
|
||||||
package xyz.alexcrea.cuanvil.command
|
package xyz.alexcrea.cuanvil.command
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap
|
import com.google.common.collect.ImmutableMap
|
||||||
|
import net.kyori.adventure.text.Component
|
||||||
|
import net.kyori.adventure.text.TextComponent
|
||||||
import org.bukkit.command.Command
|
import org.bukkit.command.Command
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
|
import xyz.alexcrea.cuanvil.lang.MessageLike
|
||||||
|
import xyz.alexcrea.cuanvil.lang.MsgCommand
|
||||||
|
import xyz.alexcrea.cuanvil.util.ComponentUtil.send
|
||||||
|
|
||||||
class HelpExecutor : CASubCommand {
|
class HelpExecutor : CASubCommand {
|
||||||
|
|
||||||
|
override fun description(): MessageLike {
|
||||||
|
return MsgCommand.HELP_DESCRIPTION
|
||||||
|
}
|
||||||
|
|
||||||
lateinit var commands: ImmutableMap<String, CASubCommand>
|
lateinit var commands: ImmutableMap<String, CASubCommand>
|
||||||
|
|
||||||
override fun executeCommand(
|
override fun executeCommand(
|
||||||
sender: CommandSender,
|
sender: CommandSender,
|
||||||
cmd: Command,
|
cmd: Command,
|
||||||
cmdstr: String,
|
cmdstr: String,
|
||||||
args: Array<out String>
|
args: Array<out String>,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
|
var text = MsgCommand.HELP_HEADER.formatted()
|
||||||
|
for((key, cmd) in commands) {
|
||||||
|
if(!cmd.allowed(sender)) continue
|
||||||
|
|
||||||
val stb = StringBuilder("List of available commands:")
|
text = text.appendNewline()
|
||||||
for ((key, cmd) in commands) {
|
.append(Component.text("- $key: "))
|
||||||
if (!cmd.allowed(sender)) continue
|
.append(cmd.description().formatted())
|
||||||
|
|
||||||
stb.append("\n- $key: ").append(cmd.description())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sender.sendMessage(stb.toString())
|
text.send(sender)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -34,12 +43,8 @@ class HelpExecutor : CASubCommand {
|
||||||
override fun tabCompleter(
|
override fun tabCompleter(
|
||||||
sender: CommandSender,
|
sender: CommandSender,
|
||||||
args: Array<out String>,
|
args: Array<out String>,
|
||||||
list: MutableList<String>
|
list: MutableList<String>,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun description(): String {
|
|
||||||
return "Help command"
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -9,29 +9,35 @@ import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||||
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
import xyz.alexcrea.cuanvil.dependency.DependencyManager
|
||||||
import xyz.alexcrea.cuanvil.gui.config.global.*
|
import xyz.alexcrea.cuanvil.gui.config.global.*
|
||||||
import xyz.alexcrea.cuanvil.lang.Lang
|
import xyz.alexcrea.cuanvil.lang.Lang
|
||||||
|
import xyz.alexcrea.cuanvil.lang.MessageLike
|
||||||
|
import xyz.alexcrea.cuanvil.lang.MsgCommand
|
||||||
import xyz.alexcrea.cuanvil.update.UpdateHandler
|
import xyz.alexcrea.cuanvil.update.UpdateHandler
|
||||||
|
|
||||||
class ReloadExecutor : CASubCommand {
|
class ReloadExecutor : CASubCommand {
|
||||||
|
|
||||||
|
override fun description(): MessageLike {
|
||||||
|
return MsgCommand.RELOAD_DESCRIPTION
|
||||||
|
}
|
||||||
|
|
||||||
override fun executeCommand(
|
override fun executeCommand(
|
||||||
sender: CommandSender,
|
sender: CommandSender,
|
||||||
cmd: Command,
|
cmd: Command,
|
||||||
cmdstr: String,
|
cmdstr: String,
|
||||||
args: Array<out String>
|
args: Array<out String>,
|
||||||
): Boolean {
|
): Boolean {
|
||||||
if (!allowed(sender)) {
|
if(!allowed(sender)) {
|
||||||
sender.sendMessage("§cYou do not have permission to reload the config")
|
MsgCommand.SHARED_NO_PERMISSION.send(sender)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
sender.sendMessage("§eReloading config...")
|
MsgCommand.RELOAD_START.send(sender)
|
||||||
val hardfail = args.isNotEmpty() && ("hard".equals(args[0], true))
|
val hardfail = args.isNotEmpty() && ("hard".equals(args[0], true))
|
||||||
val commandSuccess = commandBody(hardfail)
|
val commandSuccess = commandBody(hardfail)
|
||||||
if (commandSuccess) {
|
if(commandSuccess) {
|
||||||
sender.sendMessage("§aConfig reloaded !")
|
MsgCommand.RELOAD_SUCCESS.send(sender)
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage("§cConfig was not able to be reloaded...")
|
MsgCommand.RELOAD_FAIL.send(sender)
|
||||||
if (hardfail) {
|
if(hardfail) {
|
||||||
sender.sendMessage("§4Hard fail, plugin disabled")
|
MsgCommand.RELOAD_HARD_FAIL.send(sender)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return commandSuccess
|
return commandSuccess
|
||||||
|
|
@ -44,20 +50,16 @@ class ReloadExecutor : CASubCommand {
|
||||||
override fun tabCompleter(
|
override fun tabCompleter(
|
||||||
sender: CommandSender,
|
sender: CommandSender,
|
||||||
args: Array<out String>,
|
args: Array<out String>,
|
||||||
list: MutableList<String>
|
list: MutableList<String>,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun description(): String {
|
|
||||||
return "Reload the configuration of this plugin"
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute the command, return true if success or false otherwise
|
* Execute the command, return true if success or false otherwise
|
||||||
*/
|
*/
|
||||||
private fun commandBody(hardfail: Boolean): Boolean {
|
private fun commandBody(hardfail: Boolean): Boolean {
|
||||||
try {
|
try {
|
||||||
if (!ConfigHolder.reloadAllFromDisk(hardfail)) return false
|
if(!ConfigHolder.reloadAllFromDisk(hardfail)) return false
|
||||||
|
|
||||||
// reload language config
|
// reload language config
|
||||||
Lang.reload()
|
Lang.reload()
|
||||||
|
|
@ -83,7 +85,7 @@ class ReloadExecutor : CASubCommand {
|
||||||
Bukkit.getServer().pluginManager.callEvent(configReadyEvent)
|
Bukkit.getServer().pluginManager.callEvent(configReadyEvent)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
} catch (e: Exception) {
|
} catch(e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ package xyz.alexcrea.cuanvil.lang
|
||||||
import io.delilaheve.CustomAnvil
|
import io.delilaheve.CustomAnvil
|
||||||
import net.kyori.adventure.text.Component
|
import net.kyori.adventure.text.Component
|
||||||
import org.bukkit.command.CommandSender
|
import org.bukkit.command.CommandSender
|
||||||
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.sendPaperMessage
|
import xyz.alexcrea.cuanvil.util.ComponentUtil.send
|
||||||
import xyz.alexcrea.cuanvil.util.MiniMessageUtil
|
import xyz.alexcrea.cuanvil.util.MiniMessageUtil
|
||||||
import java.util.logging.Level
|
import java.util.logging.Level
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
@ -13,18 +13,28 @@ interface MessageLike {
|
||||||
fun log(vararg params: Any)
|
fun log(vararg params: Any)
|
||||||
|
|
||||||
fun send(destination: CommandSender, vararg params: Any)
|
fun send(destination: CommandSender, vararg params: Any)
|
||||||
|
|
||||||
|
fun unformatted(vararg params: Any): String
|
||||||
|
|
||||||
|
fun formatted(vararg params: Any): Component
|
||||||
|
|
||||||
|
fun legacy(vararg params: Any): String {
|
||||||
|
val formated = formatted(*params)
|
||||||
|
return MiniMessageUtil.legacy_mm.serialize(formated)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class MessageType {
|
enum class MessageType {
|
||||||
DEFAULT,
|
DEFAULT, WARNING, ERROR, COMMAND, UI,
|
||||||
WARNING,
|
|
||||||
ERROR,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open class Message(val key: String, vararg val params: String) : MessageLike {
|
open class Message(val key: String, vararg val params: String) : MessageLike {
|
||||||
|
|
||||||
protected fun replaceParameters(stb: StringBuilder, vararg values: Any) {
|
protected fun replaceParameters(stb: StringBuilder, vararg values: Any) {
|
||||||
// replace all placeholder thingy %key -> value
|
// replace all placeholder thingy %key -> value
|
||||||
|
if(params.size != values.size) {
|
||||||
|
CustomAnvil.log("Wrong number of argument for parameter for key $key (${params.size}/${values.size})")
|
||||||
|
}
|
||||||
|
|
||||||
for(i in 0 until min(params.size, values.size)) {
|
for(i in 0 until min(params.size, values.size)) {
|
||||||
val key = params[i]
|
val key = params[i]
|
||||||
|
|
@ -33,7 +43,7 @@ open class Message(val key: String, vararg val params: String) : MessageLike {
|
||||||
var current = 0
|
var current = 0
|
||||||
while(true) {
|
while(true) {
|
||||||
current = stb.indexOf('%', current) + 1
|
current = stb.indexOf('%', current) + 1
|
||||||
if(current < 0 || current + key.length > stb.length) break // may be able to be removed if bound checked in startsWith ?
|
if(current <= 0 || current + key.length > stb.length) break // may be able to be removed if bound checked in startsWith ?
|
||||||
if(!stb.startsWith(key, current, false)) continue
|
if(!stb.startsWith(key, current, false)) continue
|
||||||
|
|
||||||
stb.replace(current - 1, current + key.length, replacement)
|
stb.replace(current - 1, current + key.length, replacement)
|
||||||
|
|
@ -42,16 +52,16 @@ open class Message(val key: String, vararg val params: String) : MessageLike {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun unformatted(vararg params: Any): String {
|
override fun unformatted(vararg params: Any): String {
|
||||||
val translated = Lang.getTranslated(key)
|
val translated = Lang.getTranslated(key)
|
||||||
if(params.isEmpty()) return translated
|
if(params.isEmpty() && this.params.isEmpty()) return translated
|
||||||
|
|
||||||
val stb = StringBuilder(translated)
|
val stb = StringBuilder(translated)
|
||||||
replaceParameters(stb, *params)
|
replaceParameters(stb, *params)
|
||||||
return stb.toString()
|
return stb.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun formatted(vararg params: Any): Component {
|
override fun formatted(vararg params: Any): Component {
|
||||||
val unformatted = unformatted(*params)
|
val unformatted = unformatted(*params)
|
||||||
|
|
||||||
return MiniMessageUtil.mm.deserialize(unformatted)
|
return MiniMessageUtil.mm.deserialize(unformatted)
|
||||||
|
|
@ -64,9 +74,7 @@ open class Message(val key: String, vararg val params: String) : MessageLike {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun send(destination: CommandSender, vararg params: Any) {
|
override fun send(destination: CommandSender, vararg params: Any) {
|
||||||
val message = formatted(*params)
|
formatted(*params).send(destination)
|
||||||
if(!destination.sendPaperMessage(message))
|
|
||||||
destination.sendMessage(MiniMessageUtil.legacy_mm.serialize(message))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,6 +103,10 @@ class ErrorMessage(key: String, vararg params: String) : Message("error.$key", *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class CommandMessage(key: String, vararg params: String) : Message("command.$key", *params)
|
||||||
|
class UIMessage(key: String, vararg params: String) : Message("ui.$key", *params)
|
||||||
|
|
||||||
class MultiLineMessage(type: MessageType, baseKey: String, count: Int, vararg params: String) : MessageLike {
|
class MultiLineMessage(type: MessageType, baseKey: String, count: Int, vararg params: String) : MessageLike {
|
||||||
|
|
||||||
private val messages = ArrayList<MessageLike>()
|
private val messages = ArrayList<MessageLike>()
|
||||||
|
|
@ -111,6 +123,8 @@ class MultiLineMessage(type: MessageType, baseKey: String, count: Int, vararg pa
|
||||||
MessageType.DEFAULT -> Message(key, *params)
|
MessageType.DEFAULT -> Message(key, *params)
|
||||||
MessageType.WARNING -> WarningMessage(key, *params)
|
MessageType.WARNING -> WarningMessage(key, *params)
|
||||||
MessageType.ERROR -> ErrorMessage(key, *params)
|
MessageType.ERROR -> ErrorMessage(key, *params)
|
||||||
|
MessageType.COMMAND -> CommandMessage(key, *params)
|
||||||
|
MessageType.UI -> UIMessage(key, *params)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,4 +139,25 @@ class MultiLineMessage(type: MessageType, baseKey: String, count: Int, vararg pa
|
||||||
message.send(destination, *params)
|
message.send(destination, *params)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun unformatted(vararg params: Any): String {
|
||||||
|
val stb = StringBuilder()
|
||||||
|
stb.append(messages[0].unformatted(*params))
|
||||||
|
|
||||||
|
for(i in 1 until messages.size) {
|
||||||
|
stb.append('\n').append(messages[i].unformatted(*params))
|
||||||
|
}
|
||||||
|
|
||||||
|
return stb.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun formatted(vararg params: Any): Component {
|
||||||
|
val component = messages[0].formatted(*params)
|
||||||
|
|
||||||
|
for(i in 1 until messages.size) {
|
||||||
|
component.appendNewline().append(messages[i].formatted(*params))
|
||||||
|
}
|
||||||
|
|
||||||
|
return component
|
||||||
|
}
|
||||||
}
|
}
|
||||||
74
src/main/kotlin/xyz/alexcrea/cuanvil/lang/MsgCommand.kt
Normal file
74
src/main/kotlin/xyz/alexcrea/cuanvil/lang/MsgCommand.kt
Normal file
|
|
@ -0,0 +1,74 @@
|
||||||
|
package xyz.alexcrea.cuanvil.lang
|
||||||
|
|
||||||
|
import xyz.alexcrea.cuanvil.lang.CommandMessage as Message
|
||||||
|
|
||||||
|
object MsgCommand {
|
||||||
|
|
||||||
|
fun multiLine(basekey: String, count: Int): MultiLineMessage {
|
||||||
|
return MultiLineMessage(
|
||||||
|
MessageType.COMMAND, basekey, count
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Root
|
||||||
|
val ROOT_UNKNOWN_SUBCOMMAND = Message("root.warning.unknown-sub", "command")
|
||||||
|
val ROOT_ERROR_SUBCOMMAND = Message("root.error.generic")
|
||||||
|
|
||||||
|
// Shared
|
||||||
|
val SHARED_NO_DIAG_PERM = Message("shared.no-diag-permission")
|
||||||
|
val SHARED_HOVER_COPY = Message("shared.hover-copy")
|
||||||
|
val SHARED_MISSING_SUBCOMMAND = Message("shared.warning.missing-subcmd", "example1", "example2")
|
||||||
|
val SHARED_UNKNOWN_SUB_COMMAND = Message("shared.unknown-subcmd", "command")
|
||||||
|
val SHARED_NO_PERMISSION = Message("shared.no-permission")
|
||||||
|
|
||||||
|
// Debug
|
||||||
|
val DEBUG_DESCRIPTION = Message("debug.description")
|
||||||
|
val DEBUG_LOG_CLEARED = Message("debug.log-cleared")
|
||||||
|
val DEBUG_TOGGLED = Message("debug.toggled", "type")
|
||||||
|
val DEBUG_COPY = Message("debug.copy")
|
||||||
|
|
||||||
|
val DEBUG_DATA_HEADER = Message("debug.data.header")
|
||||||
|
val DEBUG_DATA_LINE_COUNT = Message("debug.data.line-count", "count")
|
||||||
|
|
||||||
|
val DEBUG_WARNING_UNSPECIFIED_TYPE = Message("debug.warning.unspecified-type")
|
||||||
|
val DEBUG_WARNING_INVALID_TYPE = Message("debug.warning.invalid-type", "type")
|
||||||
|
val DEBUG_WARNING_NO_LOG = Message("debug.warning.no-log", "command")
|
||||||
|
|
||||||
|
// Diagnostic
|
||||||
|
val DIAGNOSTIC_DESCRIPTION = Message("diagnostic.description")
|
||||||
|
val DIAGNOSTIC_ERROR_GENERIC = Message("diagnostic.had-error")
|
||||||
|
val DIAGNOSTIC_COPY = Message("diagnostic.copy")
|
||||||
|
|
||||||
|
// Config
|
||||||
|
val CONFIG_DESCRIPTION = Message("config.description")
|
||||||
|
val CONFIG_LEGACY_NAME_WARNING = Message("config.warning.legacy-name")
|
||||||
|
val CONFIG_FOLIA_ISSUE = multiLine("config.folia-issue", 5)
|
||||||
|
|
||||||
|
val CONFIG_ENCHANTMENT_NO_IN_HAND = Message("config.enchantment.no_hand")
|
||||||
|
val CONFIG_ENCHANTMENT_NO_NAME = Message("config.enchantment.no_name", "name")
|
||||||
|
|
||||||
|
val CONFIG_CANNOT_CONFIGURE_WARNING = Message("config.warning.cannot_configure")
|
||||||
|
|
||||||
|
// Enchant
|
||||||
|
val ENCHANT_DESCRIPTION = Message("enchant.description")
|
||||||
|
val ENCHANT_REMOVE = Message("enchant.remove.", "name")
|
||||||
|
val ENCHANT_SET = Message("enchant.set.", "name", "level")
|
||||||
|
|
||||||
|
val ENCHANT_MISSING_PARAMETER_WARNING = Message("enchant.warning.missing_parameter")
|
||||||
|
val ENCHANT_NOT_FOUND_WARNING = Message("enchant.warning.not_found", "path")
|
||||||
|
val ENCHANT_MALFORMED_NUMBER_WARNING = Message("enchant.warning.malformed_number", "num")
|
||||||
|
val ENCHANT_CANNOT_ENCHANT_WARNING = Message("enchant.warning.cannot_enchant")
|
||||||
|
|
||||||
|
// Help
|
||||||
|
val HELP_DESCRIPTION = Message("help.description")
|
||||||
|
val HELP_HEADER = Message("help.header")
|
||||||
|
|
||||||
|
// Reload
|
||||||
|
val RELOAD_DESCRIPTION = Message("reload.description")
|
||||||
|
val RELOAD_START = Message("reload.start")
|
||||||
|
val RELOAD_SUCCESS = Message("reload.success")
|
||||||
|
val RELOAD_FAIL = Message("reload.fail")
|
||||||
|
val RELOAD_HARD_FAIL = Message("reload.hard-fail")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
6
src/main/kotlin/xyz/alexcrea/cuanvil/lang/MsgUI.kt
Normal file
6
src/main/kotlin/xyz/alexcrea/cuanvil/lang/MsgUI.kt
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
package xyz.alexcrea.cuanvil.lang
|
||||||
|
|
||||||
|
object MsgUI {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,17 +1,26 @@
|
||||||
package xyz.alexcrea.cuanvil.lang
|
package xyz.alexcrea.cuanvil.lang
|
||||||
|
|
||||||
|
import xyz.alexcrea.cuanvil.lang.WarningMessage as Message
|
||||||
|
|
||||||
object MsgWarning {
|
object MsgWarning {
|
||||||
|
|
||||||
|
fun multiLine(basekey: String, count: Int): MultiLineMessage {
|
||||||
|
return MultiLineMessage(
|
||||||
|
MessageType.WARNING,
|
||||||
|
basekey,
|
||||||
|
count
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ---------------
|
* -----------------
|
||||||
* Load and reload
|
* Load and reload
|
||||||
* ---------------
|
* -----------------
|
||||||
*/
|
*/
|
||||||
val LOAD_UPDATE_AVAILABLE = WarningMessage("load.update.available", "version")
|
val LOAD_UPDATE_AVAILABLE = Message("load.update.available", "version")
|
||||||
|
|
||||||
val LOAD_LEGACY_OLD_NAME = MultiLineMessage(MessageType.WARNING, "load.legacy.old-name", 2)
|
|
||||||
val LOAD_LEGACY_SPIGOT = MultiLineMessage(MessageType.WARNING, "load.legacy.spigot", 2)
|
|
||||||
val LOAD_LEGACY_SPIGOT_OLD = MultiLineMessage(MessageType.WARNING, "load.legacy.spigot", 2)
|
|
||||||
|
|
||||||
|
val LOAD_LEGACY_OLD_NAME = multiLine("load.legacy.old-name", 2)
|
||||||
|
val LOAD_LEGACY_SPIGOT = multiLine("load.legacy.spigot", 2)
|
||||||
|
val LOAD_LEGACY_SPIGOT_OLD = multiLine("load.legacy.spigot", 2)
|
||||||
|
|
||||||
}
|
}
|
||||||
14
src/main/kotlin/xyz/alexcrea/cuanvil/util/ComponentUtil.kt
Normal file
14
src/main/kotlin/xyz/alexcrea/cuanvil/util/ComponentUtil.kt
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
package xyz.alexcrea.cuanvil.util
|
||||||
|
|
||||||
|
import net.kyori.adventure.text.Component
|
||||||
|
import org.bukkit.command.CommandSender
|
||||||
|
import xyz.alexcrea.cuanvil.dependency.util.PlatformUtil.sendPaperMessage
|
||||||
|
|
||||||
|
object ComponentUtil {
|
||||||
|
|
||||||
|
fun Component.send(destination: CommandSender) {
|
||||||
|
if(!destination.sendPaperMessage(this))
|
||||||
|
destination.sendMessage(MiniMessageUtil.legacy_mm.serialize(this))
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -32,8 +32,9 @@ error:
|
||||||
command:
|
command:
|
||||||
shared:
|
shared:
|
||||||
no-diag-permission: "<red>You do not have permission to diagnostic this server"
|
no-diag-permission: "<red>You do not have permission to diagnostic this server"
|
||||||
# I try to avoid using & for color but this is for a bungee text component
|
hover-copy: "<gray>Click to copy"
|
||||||
hover-copy: "§7Click to copy"
|
unknown-subcmd: "Unknown subcommand %command"
|
||||||
|
no-permission: "No permission to execute this command"
|
||||||
warning:
|
warning:
|
||||||
missing-subcmd: "Need to specify a subcommand. for example %example1 or %example2"
|
missing-subcmd: "Need to specify a subcommand. for example %example1 or %example2"
|
||||||
root:
|
root:
|
||||||
|
|
@ -45,21 +46,47 @@ command:
|
||||||
description: "Used to toggle debug logs and retrieve them"
|
description: "Used to toggle debug logs and retrieve them"
|
||||||
log-cleared: "Log Cleared"
|
log-cleared: "Log Cleared"
|
||||||
toggled: "Debug toggled to %type"
|
toggled: "Debug toggled to %type"
|
||||||
# I try to avoid using & for color but this is for a bungee text component
|
copy: "<green>Click to copy log data"
|
||||||
copy: "§aClick to copy log data"
|
|
||||||
data:
|
data:
|
||||||
header: "Debug Log data:"
|
header: "Debug Log data:"
|
||||||
line-count: "Found %count lines"
|
line-count: "Found %count lines"
|
||||||
warning:
|
warning:
|
||||||
unspecified-type: "Need to specify which type of debug to toggle: \"default\" or \"verbose\""
|
unspecified-type: "Need to specify which type of debug to toggle: \"default\" or \"verbose\""
|
||||||
|
invalid-type: "Invalid debug type \"%type\""
|
||||||
no-log: "No log to show ? make sure you tried with debug log toggled (%command)"
|
no-log: "No log to show ? make sure you tried with debug log toggled (%command)"
|
||||||
diagnostic:
|
diagnostic:
|
||||||
description: "Basic diagnostic of this plugin"
|
description: "Basic diagnostic of this plugin"
|
||||||
had-error: "<red>There was an error running the diagnostic"
|
had-error: "<red>There was an error running the diagnostic"
|
||||||
# I try to avoid using & for color but this is for a bungee text component
|
copy: "<green>Click to copy diagnostic data"
|
||||||
copy: "§aClick to copy diagnostic data"
|
|
||||||
config:
|
config:
|
||||||
description: "Used to edit the configuration of the plugin"
|
description: "Used to edit the configuration of the plugin"
|
||||||
|
folia-issue:
|
||||||
|
1: "<red>It look like you are using Folia. Sadly Custom Anvil do not support Config gui for Folia."
|
||||||
|
2: "<yellow>It is may come in a future version."
|
||||||
|
3: ""
|
||||||
|
4: "<yellow>Currently you need to edit manually the config or copy from another server (spigot or better)"
|
||||||
|
5: "<yellow>Then /ca reload after config file is edited"
|
||||||
|
enchantment:
|
||||||
|
no_hand: "No enchantment found in the item you are holding"
|
||||||
|
no_name: "No enchantment found with the name %name"
|
||||||
warning:
|
warning:
|
||||||
legacy-name: "<red>/ca gui has been moved to /ca config"
|
legacy-name: "<red>/ca gui has been moved to /ca config"
|
||||||
|
cannot_configure: "Cannot configure the item in hand"
|
||||||
|
enchant:
|
||||||
|
description: "Allows to set enchantment to holden item"
|
||||||
|
warning:
|
||||||
|
missing_parameter: "Missing enchantment parameter"
|
||||||
|
not_found: "Enchantment not found: %path"
|
||||||
|
malformed_number: "Invalid number: %num"
|
||||||
|
cannot_enchant: "Cannot enchant this item"
|
||||||
|
removed: "%name removed"
|
||||||
|
set: "%name set to level %level"
|
||||||
|
help:
|
||||||
|
description: "Help command"
|
||||||
|
header: "List of available commands:"
|
||||||
|
reload:
|
||||||
|
description: "Reload the configuration of this plugin"
|
||||||
|
start: "<yellow>Reloading config..."
|
||||||
|
success: "<green>Config reloaded !"
|
||||||
|
fail: "<red>Config was not able to be reloaded..."
|
||||||
|
hard-fail: "<red>Hard fail, plugin disabled"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue