This commit is contained in:
alexcrea 2025-09-16 15:39:57 +02:00 committed by alexcrea
parent 4023eda3e3
commit a0654489bb
Signed by: alexcrea
GPG key ID: E346CD16413450E3
5 changed files with 94 additions and 4 deletions

View file

@ -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)
}

View file

@ -22,9 +22,11 @@ class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
init {
commands = ImmutableMap.of<String, CASubCommand>(
"gui", editConfigCommand,
"reload", ReloadExecutor()
"reload", ReloadExecutor(),
"diagnostic", Diagnostic(),
)
println(plugin.getCommand(genericCommandName))
val self = plugin.getCommand(genericCommandName)!!
self.setExecutor(this)
self.tabCompleter = this

View file

@ -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<out String>
): 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");
}
}

View file

@ -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:

View file

@ -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