mirror of
https://github.com/alexcrea/CustomAnvil.git
synced 2026-06-23 08:14:00 +02:00
Help Command
This commit is contained in:
parent
bc7ed5af85
commit
0440835013
7 changed files with 58 additions and 5 deletions
|
|
@ -6,7 +6,7 @@ import org.bukkit.configuration.file.YamlConfiguration
|
||||||
import org.bukkit.plugin.java.JavaPlugin
|
import org.bukkit.plugin.java.JavaPlugin
|
||||||
import xyz.alexcrea.cuanvil.api.event.CAConfigReadyEvent
|
import xyz.alexcrea.cuanvil.api.event.CAConfigReadyEvent
|
||||||
import xyz.alexcrea.cuanvil.api.event.CAEnchantRegistryReadyEvent
|
import xyz.alexcrea.cuanvil.api.event.CAEnchantRegistryReadyEvent
|
||||||
import xyz.alexcrea.cuanvil.command.CustomAnvilCmd
|
import xyz.alexcrea.cuanvil.command.CustomAnvilCommand
|
||||||
import xyz.alexcrea.cuanvil.command.EditConfigExecutor
|
import xyz.alexcrea.cuanvil.command.EditConfigExecutor
|
||||||
import xyz.alexcrea.cuanvil.command.ReloadExecutor
|
import xyz.alexcrea.cuanvil.command.ReloadExecutor
|
||||||
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
import xyz.alexcrea.cuanvil.config.ConfigHolder
|
||||||
|
|
@ -309,7 +309,7 @@ open class CustomAnvil : JavaPlugin() {
|
||||||
command = getCommand(commandConfigName)
|
command = getCommand(commandConfigName)
|
||||||
command?.setExecutor(EditConfigExecutor())
|
command?.setExecutor(EditConfigExecutor())
|
||||||
|
|
||||||
CustomAnvilCmd(this)
|
CustomAnvilCommand(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,4 +39,8 @@ abstract class CASubCommand: CommandExecutor {
|
||||||
list: MutableList<String>) {
|
list: MutableList<String>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun description(): String {
|
||||||
|
return "no description"
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -9,7 +9,7 @@ import org.bukkit.command.TabCompleter
|
||||||
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
import xyz.alexcrea.cuanvil.util.MetricsUtil
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
|
|
||||||
class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
class CustomAnvilCommand(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
// Name of the generic command
|
// Name of the generic command
|
||||||
companion object {
|
companion object {
|
||||||
|
|
@ -17,16 +17,20 @@ class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
||||||
}
|
}
|
||||||
|
|
||||||
private val editConfigCommand = EditConfigExecutor()
|
private val editConfigCommand = EditConfigExecutor()
|
||||||
|
private val helpCommand = HelpExecutor()
|
||||||
private val commands = ImmutableMap.of(
|
private val commands = ImmutableMap.of(
|
||||||
"gui", editConfigCommand,
|
"gui", editConfigCommand,
|
||||||
"reload", ReloadExecutor(),
|
"reload", ReloadExecutor(),
|
||||||
"diagnostic", DiagnosticExecutor(),
|
"diagnostic", DiagnosticExecutor(),
|
||||||
|
"help", helpCommand,
|
||||||
)
|
)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
val self = plugin.getCommand(genericCommandName)!!
|
val self = plugin.getCommand(genericCommandName)!!
|
||||||
self.setExecutor(this)
|
self.setExecutor(this)
|
||||||
self.tabCompleter = this
|
self.tabCompleter = this
|
||||||
|
|
||||||
|
helpCommand.commands = commands
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCommand(
|
override fun onCommand(
|
||||||
|
|
@ -68,8 +72,9 @@ class CustomAnvilCmd(plugin: CustomAnvil) : CommandExecutor, TabCompleter {
|
||||||
): MutableList<String> {
|
): MutableList<String> {
|
||||||
val result = ArrayList<String>()
|
val result = ArrayList<String>()
|
||||||
if(args.size < 2) {
|
if(args.size < 2) {
|
||||||
for (cmd in commands) {
|
for ((key, cmd) in commands) {
|
||||||
result.add(cmd.key)
|
if(!cmd.allowed(sender)) continue
|
||||||
|
result.add(key)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val subcmd = commands[args[0].lowercase()]
|
val subcmd = commands[args[0].lowercase()]
|
||||||
|
|
@ -204,6 +204,10 @@ class DiagnosticExecutor: CASubCommand() {
|
||||||
return this.name + " v" + this.description.version
|
return this.name + " v" + this.description.version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun description(): String {
|
||||||
|
return "Basic diagnostic of this plugin"
|
||||||
|
}
|
||||||
|
|
||||||
private fun pluginListDiag(sender: CommandSender, stb: StringBuilder) {
|
private fun pluginListDiag(sender: CommandSender, stb: StringBuilder) {
|
||||||
val enabledPlugins: MutableList<Plugin?> = ArrayList<Plugin?>()
|
val enabledPlugins: MutableList<Plugin?> = ArrayList<Plugin?>()
|
||||||
val disabledPlugins: MutableList<Plugin?> = ArrayList<Plugin?>()
|
val disabledPlugins: MutableList<Plugin?> = ArrayList<Plugin?>()
|
||||||
|
|
|
||||||
|
|
@ -38,4 +38,8 @@ class EditConfigExecutor: CASubCommand() {
|
||||||
return sender.hasPermission(CustomAnvil.editConfigPermission)
|
return sender.hasPermission(CustomAnvil.editConfigPermission)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun description(): String {
|
||||||
|
return "Gui to edit the plugin's config"
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
32
src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt
Normal file
32
src/main/kotlin/xyz/alexcrea/cuanvil/command/HelpExecutor.kt
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
package xyz.alexcrea.cuanvil.command
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap
|
||||||
|
import org.bukkit.command.Command
|
||||||
|
import org.bukkit.command.CommandSender
|
||||||
|
|
||||||
|
class HelpExecutor: CASubCommand() {
|
||||||
|
|
||||||
|
lateinit var commands: ImmutableMap<String, CASubCommand>
|
||||||
|
|
||||||
|
override fun executeCommand(sender: CommandSender,
|
||||||
|
cmd: Command,
|
||||||
|
cmdstr: String,
|
||||||
|
args: Array<out String>): Boolean {
|
||||||
|
|
||||||
|
val stb = StringBuilder("List of available commands:")
|
||||||
|
for ((key, cmd) in commands) {
|
||||||
|
if(!cmd.allowed(sender)) continue
|
||||||
|
|
||||||
|
stb.append("\n- $key: ").append(cmd.description())
|
||||||
|
}
|
||||||
|
|
||||||
|
sender.sendMessage(stb.toString())
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun description(): String {
|
||||||
|
return "Help command"
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -39,6 +39,10 @@ class ReloadExecutor : CASubCommand() {
|
||||||
return sender.hasPermission(CustomAnvil.commandReloadPermission)
|
return sender.hasPermission(CustomAnvil.commandReloadPermission)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue