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 f0fad9a..70789a3 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 @@ -9,6 +9,7 @@ class CommandEcopets(plugin: EcoPlugin) : PluginCommand(plugin, "ecopets", "ecop this.addSubcommand(CommandReload(plugin)) .addSubcommand(CommandGive(plugin)) .addSubcommand(CommandGiveEgg(plugin)) + .addSubcommand(CommandGiveXP(plugin)) } override fun onExecute(sender: CommandSender, args: List) { 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 new file mode 100644 index 0000000..dc6a7d2 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/commands/CommandGiveXP.kt @@ -0,0 +1,72 @@ +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.ecopets.pets.Pets +import com.willfp.ecopets.pets.givePetExperience +import com.willfp.ecopets.pets.hasPet +import org.bukkit.Bukkit +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import org.bukkit.util.StringUtil + +class CommandGiveXP(plugin: EcoPlugin) : Subcommand(plugin, "givexp", "ecopets.command.givexp", false) { + + override fun onExecute(sender: CommandSender, args: List) { + if (args.isEmpty()) { + sender.sendMessage(plugin.langYml.getMessage("needs-pet")) + return + } + if (args.size == 1) { + sender.sendMessage(plugin.langYml.getMessage("needs-amount")) + return + } + var player = sender + if (args.size == 3){ + player = Bukkit.getPlayer(args[2])!! + } + if (!(player is Player)) { + sender.sendMessage(plugin.langYml.getMessage("invalid-player")) + return + } + val pet = Pets.getByID(args[0]) + + if (pet == null) { + sender.sendMessage(plugin.langYml.getMessage("invalid-pet")) + return + } + if (!player.hasPet(pet)) { + sender.sendMessage(plugin.langYml.getMessage("doenst-have-pet")) + return + } + player.givePetExperience( + pet, + args[1].toDouble() + ) + sender.sendMessage( + plugin.langYml.getMessage("give-xp", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS) + .replace("%player%", player.savedDisplayName) + .replace("%xp%", args[1]) + .replace("%pet%", pet.name) + ) + } + + override fun tabComplete(sender: CommandSender, args: List): List { + if (args.size == 1) { + return Pets.values().map { it.id } + } + if (args.size == 2) { + return listOf("10", "100", "1000", "10000") + } + + if (args.size == 3) { + return Bukkit.getOnlinePlayers().map { it.name } + } + + + + 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 a1be3ab..54ce6b2 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -9,10 +9,13 @@ 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!" + give-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" 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" 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!"