mirror of
https://github.com/Auxilor/EcoSkills.git
synced 2026-01-02 05:46:57 +00:00
Merge pull request #19
Added "allow-flying" option to Exploration skill to allow/prevent flying players to get XP for that skill and /ecoskills recount command
This commit is contained in:
@@ -24,5 +24,6 @@ class CommandEcoskills(plugin: EcoPlugin) :
|
||||
addSubcommand(CommandReload(plugin))
|
||||
.addSubcommand(CommandReset(plugin))
|
||||
.addSubcommand(CommandGive(plugin))
|
||||
.addSubcommand(CommandRecount(plugin))
|
||||
}
|
||||
}
|
||||
@@ -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<String> ->
|
||||
|
||||
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<String>()
|
||||
|
||||
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<String>()
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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!"
|
||||
|
||||
@@ -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
|
||||
give-xp-on-fatal-fall: false
|
||||
# If experience should be given when the player is flying (/fly)
|
||||
allow-flying: true
|
||||
Reference in New Issue
Block a user