diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandActivate.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandActivate.kt new file mode 100644 index 0000000..963112a --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandActivate.kt @@ -0,0 +1,65 @@ +package com.willfp.ecopets.commands + +import com.willfp.eco.core.EcoPlugin +import com.willfp.eco.core.command.impl.Subcommand +import com.willfp.eco.util.StringUtils +import com.willfp.ecopets.pets.Pets +import com.willfp.ecopets.pets.activePet +import com.willfp.ecopets.pets.hasPet +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import org.bukkit.util.StringUtil + +class CommandActivate(plugin: EcoPlugin) : Subcommand(plugin, "activate", "ecopets.command.activate", true) { + override fun onExecute(player: CommandSender, args: List) { + player as Player + + if (args.isEmpty()) { + player.sendMessage(plugin.langYml.getMessage("needs-pet")) + return + } + + val id = args[0] + + val pet = Pets.getByID(id) + + if (pet == null || !player.hasPet(pet)) { + player.sendMessage(plugin.langYml.getMessage("invalid-pet")) + return + } + + if (player.activePet == pet) { + player.sendMessage(plugin.langYml.getMessage("pet-already-active")) + return + } + + player.sendMessage( + plugin.langYml.getMessage("activated-pet", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS) + .replace("%pet%", pet.name) + ) + player.activePet = pet + } + + override fun tabComplete(sender: CommandSender, args: List): List { + if (sender !is Player) { + return emptyList() + } + + val completions = mutableListOf() + if (args.isEmpty()) { + // Currently, this case is not ever reached + return Pets.values().filter { sender.hasPet(it) }.map { it.id } + } + + if (args.size == 1) { + StringUtil.copyPartialMatches( + args[1], + Pets.values().filter { sender.hasPet(it) }.map { it.id }, + completions + ) + return completions + } + + return emptyList() + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandDeactivate.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandDeactivate.kt new file mode 100644 index 0000000..43efbe8 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandDeactivate.kt @@ -0,0 +1,26 @@ +package com.willfp.ecopets.commands + +import com.willfp.eco.core.EcoPlugin +import com.willfp.eco.core.command.impl.Subcommand +import com.willfp.eco.util.StringUtils +import com.willfp.ecopets.pets.activePet +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player + +class CommandDeactivate(plugin: EcoPlugin) : Subcommand(plugin, "deactivate", "ecopets.command.deactivate", true) { + override fun onExecute(player: CommandSender, args: List) { + player as Player + + if (player.activePet == null) { + player.sendMessage(plugin.langYml.getMessage("no-pet-active")) + return + } + + player.sendMessage( + plugin.langYml.getMessage("deactivated-pet", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS) + .replace("%pet%", player.activePet?.name ?: "") + ) + + player.activePet = null + } +} diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandPets.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandPets.kt index ea28833..c52c611 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandPets.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandPets.kt @@ -7,6 +7,11 @@ import org.bukkit.command.CommandSender import org.bukkit.entity.Player class CommandPets(plugin: EcoPlugin) : PluginCommand(plugin, "pets", "ecopets.command.pets", true) { + init { + this.addSubcommand(CommandActivate(plugin)) + .addSubcommand(CommandDeactivate(plugin)) + } + override fun onExecute(player: CommandSender, args: List) { player as Player PetsGUI.open(player) diff --git a/eco-core/core-plugin/src/main/resources/lang.yml b/eco-core/core-plugin/src/main/resources/lang.yml index 25d8370..f25af15 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -21,6 +21,10 @@ messages: gave-pet-egg: "&fSuccessfully gave %player%&f the %pet%&f pet egg!" cannot-spawn-pet: "&cYou already have this pet unlocked!" invalid-amount: "&cInvalid amount!" + pet-already-active: "&cYou already have this pet active!" + no-pet-active: "&cYou don't have a pet active!" + activated-pet: "&fYou have activated the %pet%&f pet!" + deactivated-pet: "&fYou have deactivated the %pet%&f pet!" menu: title: "Pets" diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index 1bc7807..8d6000d 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -52,6 +52,8 @@ permissions: ecopets.command.giveegg: true ecopets.command.givexp: true ecopets.command.reset: true + ecopets.command.activate: true + ecopets.command.deactivate: true ecopets.command.reload: description: Allows reloading the config @@ -74,6 +76,12 @@ permissions: ecopets.command.reset: description: Allows the use of /ecopets reset. default: op + ecopets.command.activate: + description: Allows the use of /pets activate. + default: true + ecopets.command.deactivate: + description: Allows the use of /pets deactivate. + default: true ecopets.xpmultiplier.50percent: description: Gives the player 50% more skill experience