diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/reforges/commands/CommandApply.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/reforges/commands/CommandApply.kt new file mode 100644 index 0000000..dd2ed9f --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/reforges/commands/CommandApply.kt @@ -0,0 +1,82 @@ +package com.willfp.reforges.commands + +import com.willfp.eco.core.EcoPlugin +import com.willfp.eco.core.command.impl.Subcommand +import com.willfp.reforges.reforges.Reforges +import com.willfp.reforges.reforges.util.ReforgeUtils +import org.bukkit.Bukkit +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import org.bukkit.util.StringUtil + +class CommandApply( + plugin: EcoPlugin +) : Subcommand(plugin, "apply", "reforges.command.apply", false) { + override fun onExecute(sender: CommandSender, args: MutableList) { + if (args.isEmpty()) { + sender.sendMessage(plugin.langYml.getMessage("needs-reforge")) + return + } + + val reforge = Reforges.getByKey(args[0].lowercase()) + + if (reforge == null) { + sender.sendMessage(plugin.langYml.getMessage("invalid-reforge")) + return + } + + if (sender is Player) { + val item = sender.inventory.itemInMainHand + ReforgeUtils.setReforge(item, reforge) + sender.sendMessage( + plugin.langYml.getMessage("applied-reforge") + .replace("%reforge%", reforge.name) + ) + } else { + if (args.size < 2) { + sender.sendMessage(plugin.langYml.getMessage("needs-player")) + return + } + + val player = Bukkit.getPlayer(args[1]) + + if (player == null) { + sender.sendMessage(plugin.langYml.getMessage("invalid-player")) + return + } + + ReforgeUtils.setReforge(player.inventory.itemInMainHand, reforge) + sender.sendMessage( + plugin.langYml.getMessage("applied-reforge") + .replace("%reforge%", reforge.name) + ) + } + } + + override fun tabComplete(sender: CommandSender, args: List): List { + val completions = mutableListOf() + if (args.isEmpty()) { + // Currently, this case is not ever reached + return Reforges.values().map { it.id } + } + if (args.size == 1) { + StringUtil.copyPartialMatches( + args[0], + Reforges.values().map { it.id }, + completions + ) + completions.sort() + return completions + } + if (args.size == 2) { + StringUtil.copyPartialMatches( + args[1], + Bukkit.getOnlinePlayers().map { it.name }, + completions + ) + completions.sort() + return completions + } + return emptyList() + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/reforges/commands/CommandReforges.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/reforges/commands/CommandReforges.kt index 077cd8e..1c67d8d 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/reforges/commands/CommandReforges.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/reforges/commands/CommandReforges.kt @@ -15,5 +15,6 @@ class CommandReforges(plugin: EcoPlugin) : PluginCommand(plugin, "reforges", "re addSubcommand(CommandReload(plugin)) .addSubcommand(CommandGive(plugin)) .addSubcommand(CommandOpen(plugin)) + .addSubcommand(CommandApply(plugin)) } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/lang.yml b/eco-core/core-plugin/src/main/resources/lang.yml index 2cd0969..80bc9d8 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -15,6 +15,8 @@ messages: on-cooldown: "&cThis reforge is on cooldown! &fTime left: &a%seconds% seconds" cannot-afford: "&cYou can't afford to do this! &fCost: &a$$%cost%" cannot-afford-type: "&cYou can't afford to do this! &fCost: &a%cost% %type%" + invalid-reforge: "&cInvalid reforge!" + needs-reforge: "&cYou must specify a reforge" menu: title: "Reforge Item" diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index 5d3d139..4baf234 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -38,6 +38,7 @@ permissions: reforges.command.reforges: true reforges.command.reforge: true reforges.command.give: true + reforges.command.apply: true reforges.command.open: true reforges.command.reload: @@ -55,3 +56,6 @@ permissions: reforges.command.open: description: Allows the user of /reforges open. default: op + reforges.command.apply: + description: Allows the user of /reforges apply. + default: op