diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandEcopets.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandEcopets.kt index 70789a3..04ca5db 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandEcopets.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandEcopets.kt @@ -10,6 +10,7 @@ class CommandEcopets(plugin: EcoPlugin) : PluginCommand(plugin, "ecopets", "ecop .addSubcommand(CommandGive(plugin)) .addSubcommand(CommandGiveEgg(plugin)) .addSubcommand(CommandGiveXP(plugin)) + .addSubcommand(CommandReset(plugin)) } override fun onExecute(sender: CommandSender, args: List) { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandReset.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandReset.kt new file mode 100644 index 0000000..260522b --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandReset.kt @@ -0,0 +1,76 @@ +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.eco.util.savedDisplayName +import com.willfp.eco.util.toNiceString +import com.willfp.ecopets.pets.Pets +import com.willfp.ecopets.pets.activePet +import com.willfp.ecopets.pets.givePetExperience +import com.willfp.ecopets.pets.hasPet +import com.willfp.ecopets.pets.setPetLevel +import com.willfp.ecopets.pets.setPetXP +import org.bukkit.Bukkit +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import org.bukkit.util.StringUtil + +class CommandReset(plugin: EcoPlugin) : Subcommand(plugin, "reset", "ecopets.command.reset", false) { + override fun onExecute(sender: CommandSender, args: List) { + if (args.isEmpty()) { + sender.sendMessage(plugin.langYml.getMessage("needs-player")) + return + } + + if (args.size == 1) { + sender.sendMessage(plugin.langYml.getMessage("needs-pet")) + return + } + + val playerName = args[0] + + val player = Bukkit.getPlayer(playerName) + + if (player == null) { + sender.sendMessage(plugin.langYml.getMessage("invalid-player")) + return + } + + val pet = Pets.getByID(args[1]) + + if (pet == null) { + sender.sendMessage(plugin.langYml.getMessage("invalid-pet")) + return + } + + if (!player.hasPet(pet)) { + sender.sendMessage(plugin.langYml.getMessage("doesnt-have-pet")) + return + } + + if (player.activePet == pet) { + player.activePet = null + } + player.setPetXP(pet, 0.0) + player.setPetLevel(pet, 0) + + sender.sendMessage( + plugin.langYml.getMessage("reset-xp", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS) + .replace("%player%", player.savedDisplayName) + .replace("%pet%", pet.name) + ) + } + + override fun tabComplete(sender: CommandSender, args: List): List { + if (args.size == 1) { + return Bukkit.getOnlinePlayers().map { it.name } + } + + if (args.size == 2) { + return Pets.values().map { it.id } + } + + return emptyList() + } +} \ 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 63f650b..25d8370 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -9,7 +9,8 @@ messages: on-cooldown: "&cThis effect is on cooldown! &fTime left: &a%seconds% seconds" cannot-transmit: "&cYou can't transmit here!" needs-player: "&cYou must specify a player!" - gave-xp: "&fYou have given &a%xp% &fXP to %player%'s %pet%&f!" + gave-xp: "&fYou have given &a%xp% &fXP to %player%&f's %pet%&f!" + reset-xp: "&fYou have reset %player%&f's %pet%&f XP!" needs-pet: "&cYou must specify a pet!" need-amount: "&cYou must specify a amount!" invalid-player: "&cInvalid player!" diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index 26468df..492b05c 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -48,6 +48,8 @@ permissions: ecopets.command.pets: true ecopets.command.give: true ecopets.command.giveegg: true + ecopets.command.givexp: true + ecopets.command.reset: true ecopets.command.reload: description: Allows reloading the config @@ -64,6 +66,12 @@ permissions: ecopets.command.giveegg: description: Allows the use of /ecopets giveegg. default: op + ecopets.command.givexp: + description: Allows the use of /ecopets givexp. + default: op + ecopets.command.reset: + description: Allows the use of /ecopets reset. + default: op ecopets.xpmultiplier.50percent: description: Gives the player 50% more skill experience