diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandActivate.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandActivate.kt new file mode 100644 index 0000000..6ceaa22 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandActivate.kt @@ -0,0 +1,53 @@ +package com.willfp.boosters.commands + +import com.willfp.boosters.activateBooster +import com.willfp.boosters.boosters.Boosters +import com.willfp.boosters.incrementBoosters +import com.willfp.eco.core.EcoPlugin +import com.willfp.eco.core.command.impl.Subcommand +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import org.bukkit.util.StringUtil + +class CommandActivate(plugin: EcoPlugin) : + Subcommand( + plugin, + "activate", + "boosters.command.activate", + true + ) { + + override fun onExecute(sender: CommandSender, args: List) { + val player = sender as? Player ?: return + + if (args.isEmpty()) { + sender.sendMessage(plugin.langYml.getMessage("requires-booster")) + return + } + + val booster = Boosters.getByID(args[0].lowercase()) + + if (booster == null) { + sender.sendMessage(plugin.langYml.getMessage("invalid-booster")) + return + } + + player.incrementBoosters(booster, 1) + player.activateBooster(booster) + } + + override fun tabComplete(sender: CommandSender, args: List): List { + val completions = mutableListOf() + + if (args.size == 1) { + StringUtil.copyPartialMatches( + args[0], + Boosters.values().map { it.id }, + completions + ) + return completions + } + + return emptyList() + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandBoosters.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandBoosters.kt index 183855e..ec48372 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandBoosters.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/boosters/commands/CommandBoosters.kt @@ -18,6 +18,7 @@ class CommandBoosters(plugin: EcoPlugin) : this.addSubcommand(CommandGive(plugin)) .addSubcommand(CommandReload(plugin)) .addSubcommand(CommandCancel(plugin)) + .addSubcommand(CommandActivate(plugin)) } override fun onExecute(sender: CommandSender, args: List) {