diff --git a/src/main/kotlin/io/delilaheve/CustomAnvil.kt b/src/main/kotlin/io/delilaheve/CustomAnvil.kt index 7e1d959..e870bf0 100644 --- a/src/main/kotlin/io/delilaheve/CustomAnvil.kt +++ b/src/main/kotlin/io/delilaheve/CustomAnvil.kt @@ -49,9 +49,13 @@ open class CustomAnvil : JavaPlugin() { // Permission string required to reload the config const val commandReloadPermission = "ca.command.reload" + // Permission string required to get diagnostic data + const val diagnosticPermission = "ca.command.diagnostic" + // Permission string required to edit the plugin's config const val editConfigPermission = "ca.config.edit" + // Command Name to reload the config const val commandReloadName = "anvilconfigreload" @@ -292,6 +296,8 @@ open class CustomAnvil : JavaPlugin() { command = getCommand(commandConfigName) command?.setExecutor(EditConfigExecutor()) + println(getCommand("customanvil")) + println(getCommand("customanvila")) CustomAnvilCmd(this) } diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCmd.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCmd.kt index 5333b94..5de1c04 100644 --- a/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCmd.kt +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/CustomAnvilCmd.kt @@ -22,9 +22,11 @@ class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter { init { commands = ImmutableMap.of( "gui", editConfigCommand, - "reload", ReloadExecutor() + "reload", ReloadExecutor(), + "diagnostic", Diagnostic(), ) + println(plugin.getCommand(genericCommandName)) val self = plugin.getCommand(genericCommandName)!! self.setExecutor(this) self.tabCompleter = this diff --git a/src/main/kotlin/xyz/alexcrea/cuanvil/command/Diagnostic.kt b/src/main/kotlin/xyz/alexcrea/cuanvil/command/Diagnostic.kt new file mode 100644 index 0000000..9752894 --- /dev/null +++ b/src/main/kotlin/xyz/alexcrea/cuanvil/command/Diagnostic.kt @@ -0,0 +1,77 @@ +package xyz.alexcrea.cuanvil.command + +import io.delilaheve.CustomAnvil +import net.md_5.bungee.api.chat.ClickEvent +import net.md_5.bungee.api.chat.HoverEvent +import net.md_5.bungee.api.chat.TextComponent +import net.md_5.bungee.api.chat.hover.content.Text +import org.bukkit.Bukkit +import org.bukkit.ChatColor +import org.bukkit.command.Command +import org.bukkit.command.CommandSender +import org.bukkit.entity.HumanEntity + +class Diagnostic: CASubCommand() { + + companion object{ + private const val NO_DIAG_PERM = "You do not have permission to diagnostic this server" + } + + override fun executeCommand( + sender: CommandSender, + cmd: Command, + cmdstr: String, + args: Array + ): Boolean { + if (!allowed(sender)) { + sender.sendMessage(NO_DIAG_PERM) + return false + } + + val stb = StringBuilder("```\n") + try { + diagnostic(stb) + } catch(e: Exception){ + // TODO append error message to diag + TODO("error not handled yet $e") + } + + stb.append("\n```") + + if (sender is HumanEntity) { + val message = TextComponent(ChatColor.GREEN.toString() + "Click to copy diagnostic data") + + message.clickEvent = ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, stb.toString()) + message.hoverEvent = HoverEvent(HoverEvent.Action.SHOW_TEXT, Text("ยง7Click to copy")) + + sender.spigot().sendMessage(message); + } else { + sender.sendMessage(stb.toString()); + } + + return true + } + + override fun allowed(sender: CommandSender): Boolean { + return sender.hasPermission(CustomAnvil.diagnosticPermission) + } + + fun diagnostic(stb: StringBuilder){ + stb.append("Server Info\n"); + stb.append("Plugin Version: ").append(CustomAnvil.instance.description.version).append("\n"); + stb.append("Server Version: ").append(Bukkit.getVersion()).append(" (").append(Bukkit.getName()).append(')').append("\n"); + stb.append("Plugin Enabled: ").append(if(CustomAnvil.instance.isEnabled) "Yes" else "No").append("\n"); + //stb.append("NMS type: ").append(NMSMapper.hasNMS() ? "Yes" : "No").append("\n"); + stb.append("Java Version: ").append(System.getProperty("java.version")).append("\n"); + stb.append("OS: ").append(System.getProperty("os.name")).append(" ") + .append(System.getProperty("os.version")) + .append(System.getProperty("os.arch")) + .append("\n\n"); + stb.append("Architecture: ").append(System.getProperty("os.arch")).append("\n\n"); + + + + } + + +} \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index f90f975..03ed5aa 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -38,7 +38,7 @@ permissions: ca.command.reload: default: op description: Allow administrator to reload the plugin's configs - ca.command.debug: + ca.command.diagnostic: default: op description: Get debug information about the plugin and server ca.config.edit: diff --git a/src/test/resources/plugin.yml b/src/test/resources/plugin.yml index c116cce..37fb95a 100644 --- a/src/test/resources/plugin.yml +++ b/src/test/resources/plugin.yml @@ -11,6 +11,8 @@ libraries: - org.jetbrains.kotlin:kotlin-stdlib:2.0.21 commands: + customanvil: + description: Generic command for custom anvil anvilconfigreload: description: Reload every config of this plugin permission: ca.command.reload @@ -37,6 +39,9 @@ permissions: ca.command.reload: default: op description: Allow administrator to reload the plugin's configs + ca.command.diagnostic: + default: op + description: Get debug information about the plugin and server ca.config.edit: default: op description: Allow administrator to edit the plugin's config in game @@ -55,8 +60,7 @@ permissions: default: op description: Allow player to edit lore via paper if enabled (toggleable) - -# soft depend on old name (UnsafeEnchantsPlus), so I can disable it if it is on the same server (old name for this plugin) +# soft depend on old name of this plugin (UnsafeEnchantsPlus), so I can disable it if it is on the same server # Also depend to other plugin for compatibility softdepend: - UnsafeEnchantsPlus @@ -66,3 +70,4 @@ softdepend: - EcoEnchants - eco - ExcellentEnchants + - HavenBags