From 8b585af4e212c399cb07e70ab3e1068b382efbee Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 18 Jun 2022 12:06:51 +0100 Subject: [PATCH] Fixed /ecopets givexp --- .../com/willfp/ecopets/commands/CommandGiveXP.kt | 12 ++++++++++-- .../src/main/kotlin/com/willfp/ecopets/pets/Pet.kt | 9 ++++++++- eco-core/core-plugin/src/main/resources/config.yml | 2 +- eco-core/core-plugin/src/main/resources/lang.yml | 7 +++++-- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandGiveXP.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandGiveXP.kt index 872e7af..340eccd 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandGiveXP.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandGiveXP.kt @@ -4,6 +4,7 @@ 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.givePetExperience import com.willfp.ecopets.pets.hasPet @@ -50,15 +51,22 @@ class CommandGiveXP(plugin: EcoPlugin) : Subcommand(plugin, "givexp", "ecopets.c return } + val amount = args[2].toDoubleOrNull() + + if (amount == null) { + sender.sendMessage(plugin.langYml.getMessage("invalid-amount")) + return + } + player.givePetExperience( pet, - args[1].toDouble() + amount ) sender.sendMessage( plugin.langYml.getMessage("gave-xp", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS) .replace("%player%", player.savedDisplayName) - .replace("%xp%", args[1]) + .replace("%xp%", amount.toNiceString()) .replace("%pet%", pet.name) ) } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt index d2c3c80..92dea62 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/Pet.kt @@ -311,7 +311,14 @@ class Pet( .map { it.replace("%percentage_progress%", (player.getPetProgress(this) * 100).toNiceString()) .replace("%current_xp%", player.getPetXP(this).toNiceString()) - .replace("%required_xp%", this.getExpForLevel(player.getPetLevel(this) + 1).toNiceString()) + .replace("%required_xp%", this.getExpForLevel(player.getPetLevel(this) + 1).let { req -> + if (req == Int.MAX_VALUE) { + plugin.langYml.getFormattedString("infinity") + } else { + req.toNiceString() + } + } + ) .replace("%description%", this.description) .replace("%pet%", this.name) .replace("%level%", (forceLevel ?: player.getPetLevel(this)).toString()) diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index f81230d..1d0daaa 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -216,7 +216,7 @@ level-up: enabled: true message: - "&f" - - " &#d977c2You levelled up your %pet%&#d977c2 petW to &eLevel %level%&#d977c2!" + - " &#d977c2You levelled up your %pet%&#d977c2 pet to &eLevel %level%&#d977c2!" - "&f" - " &#d977c2&lREWARDS:" - " %level_up_messages%" diff --git a/eco-core/core-plugin/src/main/resources/lang.yml b/eco-core/core-plugin/src/main/resources/lang.yml index 8115451..63f650b 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -11,14 +11,17 @@ messages: needs-player: "&cYou must specify a player!" gave-xp: "&fYou have given &a%xp% &fXP to %player%'s %pet%&f!" needs-pet: "&cYou must specify a pet!" - need-amount: "&cYou must specify a amount" + need-amount: "&cYou must specify a amount!" invalid-player: "&cInvalid player!" invalid-pet: "&cInvalid pet!" already-has-pet: "&cPlayer already has this pet!" - doesnt-have-pet: "&cPlayer doesn't have this pet" + doesnt-have-pet: "&cPlayer doesn't have this pet!" gave-pet: "&fSuccessfully gave %player%&f the %pet%&f pet!" 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!" menu: title: "Pets" + +infinity: "∞"