From efc3994551dda4108756730ff6d4482d308b2489 Mon Sep 17 00:00:00 2001 From: _OfTeN_ Date: Tue, 2 Nov 2021 16:59:42 +0300 Subject: [PATCH 1/2] Added "allow-flying" option to Exploration skill to allow/prevent flying players to get XP for that skill --- .../com/willfp/ecoskills/skills/skills/SkillExploration.kt | 4 ++++ .../core-plugin/src/main/resources/skills/exploration.yml | 4 +++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/skills/SkillExploration.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/skills/SkillExploration.kt index 8cd68de..010b6f7 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/skills/SkillExploration.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/skills/SkillExploration.kt @@ -22,6 +22,10 @@ class SkillExploration : Skill( return } + if (!this.config.getBool("allow-flying") && player.isFlying) { + return; + } + val from = event.from val to = event.to ?: return diff --git a/eco-core/core-plugin/src/main/resources/skills/exploration.yml b/eco-core/core-plugin/src/main/resources/skills/exploration.yml index 2396330..5e166c2 100644 --- a/eco-core/core-plugin/src/main/resources/skills/exploration.yml +++ b/eco-core/core-plugin/src/main/resources/skills/exploration.yml @@ -79,4 +79,6 @@ multiply-xp-by-speed: true # The amount of experience to give for each point of fall damage taken fall-damage-xp-per-hp: 16 # If experience should be given when the player dies of fall damage -give-xp-on-fatal-fall: false \ No newline at end of file +give-xp-on-fatal-fall: false +# If experience should be given when the player is flying (/fly) +allow-flying: true \ No newline at end of file From e88cb89fbbf8106e5b5013917eb1ee67755460ab Mon Sep 17 00:00:00 2001 From: _OfTeN_ Date: Tue, 2 Nov 2021 21:51:33 +0300 Subject: [PATCH 2/2] Added /ecoskills recount command --- .../ecoskills/commands/CommandEcoskills.kt | 1 + .../ecoskills/commands/CommandRecount.kt | 126 ++++++++++++++++++ .../core-plugin/src/main/resources/lang.yml | 3 + 3 files changed, 130 insertions(+) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandRecount.kt 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 f87b98b..18ccb50 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 @@ -24,5 +24,6 @@ class CommandEcoskills(plugin: EcoPlugin) : addSubcommand(CommandReload(plugin)) .addSubcommand(CommandReset(plugin)) .addSubcommand(CommandGive(plugin)) + .addSubcommand(CommandRecount(plugin)) } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandRecount.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandRecount.kt new file mode 100644 index 0000000..85ae8e3 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandRecount.kt @@ -0,0 +1,126 @@ +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.util.PlayerUtils +import com.willfp.eco.util.StringUtils +import com.willfp.ecoskills.data.LeaderboardHandler +import com.willfp.ecoskills.effects.Effect +import com.willfp.ecoskills.effects.Effects +import com.willfp.ecoskills.getSkillLevel +import com.willfp.ecoskills.setEffectLevel +import com.willfp.ecoskills.skills.Skills +import org.bukkit.Bukkit +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import org.bukkit.util.StringUtil + +class CommandRecount(plugin: EcoPlugin): Subcommand( + plugin, + "recount", + "ecoskills.command.recount", + false +) { + + override fun getHandler(): CommandHandler { + return CommandHandler { sender: CommandSender, args: List -> + + if (args.isEmpty()) { + sender.sendMessage(plugin.langYml.getMessage("requires-player")) + return@CommandHandler + } + + val player = Bukkit.getPlayer(args[0]) + + if (player == null) { + sender.sendMessage(plugin.langYml.getMessage("invalid-player")) + return@CommandHandler + } + + if (args.size < 2) { + sender.sendMessage(plugin.langYml.getMessage("requires-effect")) + return@CommandHandler + } + + val effect = Effects.getByID(args[1].lowercase()) + + if (effect == null) { + if (args[1].lowercase().contentEquals("all")) { + var total = 0; + for (ceffect in Effects.values()) { + total+=recount(player, ceffect) + } + sender.sendMessage( + plugin.langYml.getMessage("recounted-player") + .replace("%player%", player.name) + .replace("%effect%", "&6ALL") + .replace("%level%", total.toString()) + ) + } else { + sender.sendMessage(plugin.langYml.getMessage("invalid-effect")) + return@CommandHandler + } + } else { + sender.sendMessage( + plugin.langYml.getMessage("recounted-player") + .replace("%player%", player.name) + .replace("%effect%", effect.id) + .replace("%level%", recount(player, effect).toString()) + ) + } + + } + } + + override fun getTabCompleter(): TabCompleteHandler { + return TabCompleteHandler { _, args -> + val completions = mutableListOf() + + if (args.size == 1) { + StringUtil.copyPartialMatches( + args[0], + Bukkit.getOnlinePlayers().map { player -> player.name }.toMutableList(), + completions + ) + return@TabCompleteHandler completions + } + + if (args.size == 2) { + completions.add("all") + StringUtil.copyPartialMatches( + args[1], + Effects.values().map { effect -> effect.id }.toMutableList(), + completions + ) + return@TabCompleteHandler completions + } + + return@TabCompleteHandler emptyList() + } + } + + private fun recount(player: Player, effect: Effect): Int { + var total = 0 + for (skill in Skills.values()) { + + var ofSkill = 0 + val range = 1..player.getSkillLevel(skill) + + for (reward in skill.getLevelUpRewards()) { + if (reward.obj is Effect && reward.obj == effect) { + for (i in range) { + val obj = reward.obj + val toGive = skill.getLevelUpReward(obj, i) + ofSkill+=toGive + } + } + } + total+=ofSkill + } + player.setEffectLevel(effect, total) + return total + } + +} \ 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 81e3aff..40cba91 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -6,7 +6,10 @@ messages: reloaded: "Reloaded!" requires-player: "&cYou must specify a player!" invalid-player: "&cInvalid player!" + requires-effect: "&cYou must specify an effect!" + invalid-effect: "&cInvalid effect!" reset-player: "&fReset player!" + recounted-player: "&fRecounted effect &6%effect% &ffor player &a%player%&f to level &6%level%&f!" requires-skill: "&cYou must specify a skill!" invalid-skill: "&cInvalid skill!" requires-amount: "&cYou must specify the amount!"