Added /ecopets reset

This commit is contained in:
Auxilor
2022-06-18 12:10:32 +01:00
parent 8b585af4e2
commit 34026be77b
4 changed files with 87 additions and 1 deletions

View File

@@ -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<String>) {

View File

@@ -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<String>) {
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<String>): List<String> {
if (args.size == 1) {
return Bukkit.getOnlinePlayers().map { it.name }
}
if (args.size == 2) {
return Pets.values().map { it.id }
}
return emptyList()
}
}

View File

@@ -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!"

View File

@@ -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