mirror of
https://github.com/Auxilor/EcoSkills.git
synced 2026-01-02 22:02:19 +00:00
Readded /ecoskills give and /ecoskills reset
This commit is contained in:
@@ -4,11 +4,14 @@ package com.willfp.ecoskills.api
|
||||
|
||||
import com.willfp.ecoskills.api.modifiers.StatModifier
|
||||
import com.willfp.ecoskills.effects.Effect
|
||||
import com.willfp.ecoskills.effects.Effects
|
||||
import com.willfp.ecoskills.effects.effects
|
||||
import com.willfp.ecoskills.skills.Skill
|
||||
import com.willfp.ecoskills.skills.SkillLevel
|
||||
import com.willfp.ecoskills.skills.Skills
|
||||
import com.willfp.ecoskills.skills.skills
|
||||
import com.willfp.ecoskills.stats.Stat
|
||||
import com.willfp.ecoskills.stats.Stats
|
||||
import com.willfp.ecoskills.stats.statModifiers
|
||||
import com.willfp.ecoskills.stats.stats
|
||||
import org.bukkit.OfflinePlayer
|
||||
@@ -21,6 +24,18 @@ Skills
|
||||
|
||||
*/
|
||||
|
||||
fun OfflinePlayer.resetSkills() {
|
||||
for (skill in Skills.values()) {
|
||||
this.skills.reset(skill)
|
||||
}
|
||||
for (stat in Stats.values()) {
|
||||
this.stats.reset(stat)
|
||||
}
|
||||
for (effect in Effects.values()) {
|
||||
this.effects.reset(effect)
|
||||
}
|
||||
}
|
||||
|
||||
fun OfflinePlayer.getSkillXP(skill: Skill): Double =
|
||||
this.skills[skill].xp
|
||||
|
||||
|
||||
@@ -12,6 +12,8 @@ class CommandEcoSkills(plugin: EcoPlugin) : PluginCommand(
|
||||
) {
|
||||
init {
|
||||
this.addSubcommand(CommandReload(plugin))
|
||||
.addSubcommand(CommandGive(plugin))
|
||||
.addSubcommand(CommandReset(plugin))
|
||||
}
|
||||
|
||||
override fun onExecute(sender: CommandSender, args: List<String>) {
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
package com.willfp.ecoskills.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.formatEco
|
||||
import com.willfp.ecoskills.api.giveSkillXP
|
||||
import com.willfp.ecoskills.skills.Skills
|
||||
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 onExecute(sender: CommandSender, args: List<String>) {
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("requires-player"))
|
||||
return
|
||||
}
|
||||
|
||||
if (args.size == 1) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("requires-skill"))
|
||||
return
|
||||
}
|
||||
|
||||
if (args.size == 2) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("requires-amount"))
|
||||
return
|
||||
}
|
||||
|
||||
val player = Bukkit.getPlayer(args[0])
|
||||
|
||||
if (player == null) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("invalid-player"))
|
||||
return
|
||||
}
|
||||
|
||||
val obj = Skills.getByID(args[1].lowercase())
|
||||
|
||||
if (obj == null) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("invalid-skill"))
|
||||
return
|
||||
}
|
||||
|
||||
val amount = args[2].toIntOrNull()
|
||||
|
||||
if (amount == null) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("invalid-amount"))
|
||||
return
|
||||
}
|
||||
|
||||
player.giveSkillXP(obj, amount.toDouble())
|
||||
|
||||
sender.sendMessage(
|
||||
this.plugin.langYml.getMessage("gave-skill-xp", StringUtils.FormatOption.WITHOUT_PLACEHOLDERS)
|
||||
.replace("%player%", player.name)
|
||||
.replace("%amount%", amount.toString())
|
||||
.replace("%skill%", obj.name)
|
||||
.formatEco()
|
||||
)
|
||||
}
|
||||
|
||||
override fun tabComplete(sender: CommandSender, args: List<String>): List<String> {
|
||||
val completions = mutableListOf<String>()
|
||||
|
||||
if (args.size == 1) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[0],
|
||||
Bukkit.getOnlinePlayers().map { player -> player.name }.toCollection(ArrayList()),
|
||||
completions
|
||||
)
|
||||
return completions
|
||||
}
|
||||
|
||||
if (args.size == 2) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[1],
|
||||
Skills.values().map { it.id },
|
||||
completions
|
||||
)
|
||||
return completions
|
||||
}
|
||||
|
||||
if (args.size == 3) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[2],
|
||||
listOf(1, 2, 5, 10, 100).map { it.toString() },
|
||||
completions
|
||||
)
|
||||
return completions
|
||||
}
|
||||
|
||||
return emptyList()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
@file:Suppress("DEPRECATION")
|
||||
|
||||
package com.willfp.ecoskills.commands
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.command.impl.Subcommand
|
||||
import com.willfp.ecoskills.api.resetSkills
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.command.CommandSender
|
||||
import org.bukkit.util.StringUtil
|
||||
|
||||
class CommandReset(plugin: EcoPlugin) :
|
||||
Subcommand(
|
||||
plugin,
|
||||
"reset",
|
||||
"ecoskills.command.reset",
|
||||
false
|
||||
) {
|
||||
|
||||
override fun onExecute(sender: CommandSender, args: List<String>) {
|
||||
if (args.isEmpty()) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("requires-player"))
|
||||
return
|
||||
}
|
||||
|
||||
if (args[0].equals("all", ignoreCase = true)) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("resetting-all-players"))
|
||||
Bukkit.getOfflinePlayers().forEach { it.resetSkills() }
|
||||
sender.sendMessage(plugin.langYml.getMessage("reset-all-players"))
|
||||
} else {
|
||||
val player = Bukkit.getOfflinePlayer(args[0])
|
||||
if (!player.hasPlayedBefore()) {
|
||||
sender.sendMessage(plugin.langYml.getMessage("invalid-player"))
|
||||
return
|
||||
}
|
||||
|
||||
sender.sendMessage(plugin.langYml.getMessage("reset-player"))
|
||||
player.resetSkills()
|
||||
}
|
||||
}
|
||||
|
||||
override fun tabComplete(sender: CommandSender, args: List<String>): List<String> {
|
||||
val completions = mutableListOf<String>()
|
||||
|
||||
if (args.size == 1) {
|
||||
StringUtil.copyPartialMatches(
|
||||
args[0],
|
||||
Bukkit.getOnlinePlayers().map { player -> player.name },
|
||||
completions
|
||||
)
|
||||
return completions
|
||||
}
|
||||
|
||||
return emptyList()
|
||||
}
|
||||
}
|
||||
@@ -30,11 +30,13 @@ abstract class Levellable(
|
||||
val config: Config,
|
||||
protected val plugin: EcoSkillsPlugin
|
||||
) : KRegistrable {
|
||||
open val startLevel = 1
|
||||
|
||||
private val key by lazy {
|
||||
PersistentDataKey(
|
||||
plugin.createNamespacedKey(id),
|
||||
PersistentDataKeyType.INT,
|
||||
1
|
||||
startLevel
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -77,4 +77,11 @@ class SkillLevelMap(
|
||||
giveXP(skill, xp)
|
||||
}
|
||||
}
|
||||
|
||||
fun reset(skill: Skill) {
|
||||
this[skill] = SkillLevel(
|
||||
skill.startLevel,
|
||||
0.0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,4 +15,8 @@ class LevelMap<T : Levellable>(
|
||||
|
||||
levellable.setSavedLevel(player, level)
|
||||
}
|
||||
}
|
||||
|
||||
fun reset(levellable: T) {
|
||||
levellable.setSavedLevel(player, levellable.startLevel)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user