9
0
mirror of https://github.com/Auxilor/EcoMenus.git synced 2025-12-28 03:19:23 +00:00

Added /ecomenus open and /ecomenus forceopen

This commit is contained in:
Auxilor
2023-06-03 19:26:54 +01:00
parent cafc3ed343
commit aa70210cab
8 changed files with 134 additions and 8 deletions

View File

@@ -12,6 +12,8 @@ class CommandEcoMenus(plugin: EcoPlugin) : PluginCommand(
) {
init {
this.addSubcommand(CommandReload(plugin))
.addSubcommand(CommandOpen(plugin))
.addSubcommand(CommandForceOpen(plugin))
}
override fun onExecute(sender: CommandSender, args: List<String>) {

View File

@@ -0,0 +1,50 @@
package com.willfp.ecomenus.commands
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.command.impl.Subcommand
import com.willfp.eco.util.StringUtils
import com.willfp.eco.util.savedDisplayName
import com.willfp.ecomenus.menus.EcoMenus
import org.bukkit.command.CommandSender
import org.bukkit.util.StringUtil
class CommandForceOpen(plugin: EcoPlugin) : Subcommand(
plugin,
"forceopen",
"ecomenus.command.forceopen",
false
) {
override fun onExecute(sender: CommandSender, args: List<String>) {
val menu = notifyNull(EcoMenus[args.getOrNull(0)], "invalid-menu")
val player = notifyPlayerRequired(args.getOrNull(1), "invalid-player")
menu.forceOpen(player)
sender.sendMessage(
plugin.langYml.getMessage("opened", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS)
.replace("%player%", player.savedDisplayName)
.replace("%menu%", menu.id)
)
}
override fun tabComplete(sender: CommandSender, args: List<String>): List<String> {
val completions = mutableListOf<String>()
if (args.size == 1) {
StringUtil.copyPartialMatches(
args[0],
EcoMenus.values().map { it.id },
completions
)
}
if (args.size == 2) {
StringUtil.copyPartialMatches(
args[1],
plugin.server.onlinePlayers.map { it.name },
completions
)
}
return completions
}
}

View File

@@ -0,0 +1,50 @@
package com.willfp.ecomenus.commands
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.command.impl.Subcommand
import com.willfp.eco.util.StringUtils
import com.willfp.eco.util.savedDisplayName
import com.willfp.ecomenus.menus.EcoMenus
import org.bukkit.command.CommandSender
import org.bukkit.util.StringUtil
class CommandOpen(plugin: EcoPlugin) : Subcommand(
plugin,
"open",
"ecomenus.command.open",
false
) {
override fun onExecute(sender: CommandSender, args: List<String>) {
val menu = notifyNull(EcoMenus[args.getOrNull(0)], "invalid-menu")
val player = notifyPlayerRequired(args.getOrNull(1), "invalid-player")
menu.open(player)
sender.sendMessage(
plugin.langYml.getMessage("opened", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS)
.replace("%player%", player.savedDisplayName)
.replace("%menu%", menu.id)
)
}
override fun tabComplete(sender: CommandSender, args: List<String>): List<String> {
val completions = mutableListOf<String>()
if (args.size == 1) {
StringUtil.copyPartialMatches(
args[0],
EcoMenus.values().map { it.id },
completions
)
}
if (args.size == 2) {
StringUtil.copyPartialMatches(
args[1],
plugin.server.onlinePlayers.map { it.name },
completions
)
}
return completions
}
}

View File

@@ -40,6 +40,10 @@ class EcoMenu(
return
}
forceOpen(player, parent)
}
fun forceOpen(player: Player, parent: Menu? = null) {
menu.open(player, parent)
}
}

View File

@@ -20,7 +20,7 @@ object EcoMenus : ConfigCategory("menu", "menus") {
return registry.values()
}
operator fun get(id: String): EcoMenu? {
return registry.get(id)
operator fun get(id: String?): EcoMenu? {
return registry.get(id ?: return null)
}
}

View File

@@ -4,3 +4,7 @@ messages:
not-player: "&cThis command must be run by a player"
invalid-command: "&cUnknown subcommand!"
reloaded: "Reloaded!"
invalid-player: "&cInvalid player!"
invalid-menu: "&cInvalid menu!"
opened: "Opened &a%menu%&r for &a%player%&r!"

View File

@@ -28,10 +28,18 @@ permissions:
children:
ecomenus.command.reload: true
ecomenus.command.ecomenus: true
ecomenus.command.open: true
ecomenus.command.forceopen: true
ecomenus.command.reload:
description: Allows reloading the config
default: op
ecomenus.command.ecomenus:
description: Allows the use of /ecomenus.
default: true
ecomenus.command.reload:
description: Allows reloading the config
default: op
ecomenus.command.open:
description: Allows the use of /ecomenus open.
default: op
ecomenus.command.forceopen:
description: Allows the use of /ecomenus forceopen.
default: op

View File

@@ -27,10 +27,18 @@ permissions:
children:
ecomenus.command.reload: true
ecomenus.command.ecomenus: true
ecomenus.command.open: true
ecomenus.command.forceopen: true
ecomenus.command.reload:
description: Allows reloading the config
default: op
ecomenus.command.ecomenus:
description: Allows the use of /ecomenus.
default: true
ecomenus.command.reload:
description: Allows reloading the config
default: op
ecomenus.command.open:
description: Allows the use of /ecomenus open.
default: op
ecomenus.command.forceopen:
description: Allows the use of /ecomenus forceopen.
default: op