diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandEcoskills.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandEcoskills.kt index 9097d75..f87b98b 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandEcoskills.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandEcoskills.kt @@ -23,5 +23,6 @@ class CommandEcoskills(plugin: EcoPlugin) : init { addSubcommand(CommandReload(plugin)) .addSubcommand(CommandReset(plugin)) + .addSubcommand(CommandGive(plugin)) } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandGive.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandGive.kt new file mode 100644 index 0000000..5310566 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandGive.kt @@ -0,0 +1,147 @@ +package com.willfp.ecoskills.commands + +import com.willfp.eco.core.EcoPlugin +import com.willfp.eco.core.command.CommandHandler +import com.willfp.eco.core.command.TabCompleteHandler +import com.willfp.eco.core.command.impl.Subcommand +import com.willfp.eco.core.config.updating.ConfigUpdater +import com.willfp.ecoskills.* +import com.willfp.ecoskills.effects.Effects +import com.willfp.ecoskills.skills.Skill +import com.willfp.ecoskills.skills.Skills +import com.willfp.ecoskills.stats.Stat +import com.willfp.ecoskills.stats.Stats +import org.bukkit.Bukkit +import org.bukkit.command.CommandSender +import org.bukkit.util.StringUtil + + +class CommandGive(plugin: EcoPlugin) : + Subcommand( + plugin, + "give", + "ecoskills.command.give", + false + ) { + override fun getHandler(): CommandHandler { + return CommandHandler { sender: CommandSender, args: List -> + if (args.isEmpty()) { + sender.sendMessage(plugin.langYml.getMessage("requires-player")) + return@CommandHandler + } + + if (args.size == 1) { + sender.sendMessage(plugin.langYml.getMessage("requires-skill-stat")) + return@CommandHandler + } + + if (args.size == 2) { + sender.sendMessage(plugin.langYml.getMessage("requires-amount")) + return@CommandHandler + } + + val player = Bukkit.getPlayer(args[0]) + if (player == null) { + sender.sendMessage(plugin.langYml.getMessage("invalid-player")) + return@CommandHandler + } + + val obj = Skills.getByID(args[1].lowercase()) ?: Stats.getByID(args[1].lowercase()) + + if (obj == null) { + sender.sendMessage(plugin.langYml.getMessage("invalid-skill-stat")) + return@CommandHandler + } + + val amount = args[2].toIntOrNull() + + if (amount == null) { + sender.sendMessage(plugin.langYml.getMessage("invalid-amount")) + return@CommandHandler + } + + if (obj is Skill) { + player.giveSkillExperience(obj, amount.toDouble()) + player.sendMessage( + this.plugin.langYml.getMessage("gave-skill-xp") + .replace("%player%", player.name) + .replace("%amount%", amount.toString()) + .replace("%skill%", obj.name) + ) + return@CommandHandler + } + + if (obj is Stat) { + player.setStatLevel(obj, player.getStatLevel(obj) + amount) + player.sendMessage( + this.plugin.langYml.getMessage("gave-stat") + .replace("%player%", player.name) + .replace("%amount%", amount.toString()) + .replace("%stat%", obj.name) + ) + return@CommandHandler + } + } + } + + override fun getTabCompleter(): TabCompleteHandler { + return TabCompleteHandler { _, args -> + val completions: MutableList = ArrayList() + + if (args.size == 1) { + StringUtil.copyPartialMatches( + args[0], + Bukkit.getOnlinePlayers().map { player -> player.name }.toCollection(ArrayList()), + completions + ) + return@TabCompleteHandler completions + } + + if (args.size == 2) { + StringUtil.copyPartialMatches( + args[1], + skills union stats, + completions + ) + return@TabCompleteHandler completions + } + + if (args.size == 3) { + StringUtil.copyPartialMatches( + args[2], + amount, + completions + ) + return@TabCompleteHandler completions + } + + return@TabCompleteHandler ArrayList(0) + } + } + + companion object { + val skills = ArrayList() + val stats = ArrayList() + val amount = listOf( + "1", + "2", + "3", + "4", + "5", + "10" + ) + + @JvmStatic + @ConfigUpdater + fun update(plugin: EcoPlugin) { + skills.clear() + skills.addAll( + Skills.values().map { skill -> skill.id.lowercase() }.toList() + ) + stats.clear() + stats.addAll( + Stats.values().map { stat -> stat.id.lowercase() }.toList() + ) + } + } +} \ 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 ce9450f..b2c6e65 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -7,6 +7,12 @@ messages: requires-player: "&cYou must specify a player!" invalid-player: "&cInvalid player!" reset-player: "&fReset player!" + requires-skill-stat: "&cYou must specify a skill or stat!" + invalid-skill-stat: "&cInvalid a skill or stat!" + requires-amount: "&cYou must specify the amount!" + invalid-amount: "&cInvalid amount!" + gave-skill-xp: "Gave %player% %amount% %skill% experience!" + gave-stat: "Gave %player% %amount% %stat% levels!" top-line-format: "%rank%. %player% - %level%" top: diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index 58a04a1..d7e1190 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -38,6 +38,7 @@ permissions: ecoskills.command.ecoskills: true ecoskills.command.reset: true ecoskills.command.skills: true + ecoskills.command.give: true ecoskills.command.reload: description: Allows reloading the config @@ -51,6 +52,9 @@ permissions: ecoskills.command.reset: description: Allows the use of /ecoskills reset. default: op + ecoskills.command.give: + description: Allows the use of /ecoskills give. + default: op ecoskills.xpmultiplier.50percent: description: Gives the player 50% more skill experience diff --git a/eco-core/core-plugin/src/main/resources/skills/mining.yml b/eco-core/core-plugin/src/main/resources/skills/mining.yml index 29fd216..019174b 100644 --- a/eco-core/core-plugin/src/main/resources/skills/mining.yml +++ b/eco-core/core-plugin/src/main/resources/skills/mining.yml @@ -50,30 +50,32 @@ rewards: # The xp rewards for each block type # Specify with type:xp xp-rewards: + - "netherrack:0.5" - "stone:1" - "diorite:1" - "andesite:1" - "granite:1" - - "tuff:1" - - "deepslate:1" - "cobblestone:1" - - "netherrack:0.5" + - "tuff:1.5" + - "blackstone:1.5" + - "deepslate:1.5" - "sand:3" - "gravel:4" - "nether_quartz_ore:5" - "end_stone:3" - "coal_ore:5" - - "deepslate_coal_ore:5" + - "deepslate_coal_ore:7.5" - "iron_ore:5" - - "deepslate_iron_ore:5" + - "deepslate_iron_ore:7.5" - "gold_ore:6" - - "deepslate_gold_ore:6" + - "deepslate_gold_ore:9" + - "gilded_blackstone:10" - "lapis_lazuli_ore:7" - - "deepslate_lapis_lazuli_ore:7" + - "deepslate_lapis_lazuli_ore:10.5" - "redstone_ore:7" - - "deepslate_redstone_ore:7" + - "deepslate_redstone_ore:10.5" - "emerald_ore:9" - - "deepslate_emerald_ore:9" + - "deepslate_emerald_ore:13.5" - "diamond_ore:10" - - "deepslate_diamond_ore:10" - - "ancient_debris:20" \ No newline at end of file + - "deepslate_diamond_ore:15" + - "ancient_debris:22" \ No newline at end of file