9
0
mirror of https://github.com/Auxilor/EcoSkills.git synced 2026-01-02 22:02:19 +00:00

Added level up rewards and rewards messages

This commit is contained in:
Auxilor
2021-08-20 16:54:41 +01:00
parent cb5f69db0e
commit dfc0779ba5
8 changed files with 120 additions and 16 deletions

View File

@@ -0,0 +1,6 @@
package com.willfp.ecoskills
abstract class SkillObject(
val id: String
){
}

View File

@@ -2,14 +2,18 @@ package com.willfp.ecoskills.effects
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.integrations.placeholder.PlaceholderEntry
import com.willfp.ecoskills.EcoSkillsPlugin
import com.willfp.ecoskills.SkillObject
import com.willfp.ecoskills.getEffectLevel
import com.willfp.ecoskills.getStatLevel
import org.bukkit.NamespacedKey
import org.bukkit.event.Listener
import java.util.*
abstract class Effect(
val id: String
): Listener {
id: String
): SkillObject(id), Listener {
protected val plugin: EcoPlugin = EcoSkillsPlugin.getInstance()
val key: NamespacedKey
@@ -30,5 +34,11 @@ abstract class Effect(
fun update() {
name = plugin.langYml.getString("effects.$id.name")
description = plugin.langYml.getString("effects.$id.description")
PlaceholderEntry(
id,
{ player -> player.getEffectLevel(this).toString() },
true
).register()
}
}

View File

@@ -3,19 +3,30 @@ package com.willfp.ecoskills.skills
import com.google.gson.annotations.Since
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.integrations.placeholder.PlaceholderEntry
import com.willfp.eco.util.StringUtils
import com.willfp.ecoskills.EcoSkillsPlugin
import com.willfp.ecoskills.SkillObject
import com.willfp.ecoskills.effects.Effects
import com.willfp.ecoskills.getSkillLevel
import com.willfp.ecoskills.getStatLevel
import com.willfp.ecoskills.stats.Stats
import org.bukkit.NamespacedKey
import org.bukkit.OfflinePlayer
import org.bukkit.entity.Player
import org.bukkit.event.Listener
import java.math.BigDecimal
import java.math.MathContext
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.math.pow
import kotlin.math.round
import kotlin.math.roundToInt
abstract class Skill(
val id: String
): Listener {
) : Listener {
protected val plugin: EcoPlugin = EcoSkillsPlugin.getInstance()
val key: NamespacedKey
@@ -23,22 +34,58 @@ abstract class Skill(
val uuid: UUID
val config: Config
lateinit var name: String
private val rewards: MutableMap<SkillObject, Int>
init {
key = plugin.namespacedKeyFactory.create(id)
xpKey = plugin.namespacedKeyFactory.create(id + "_progress")
uuid = UUID.nameUUIDFromBytes(id.toByteArray())
config = plugin.configYml.getSubsection("skills.$id")
rewards = HashMap()
Skills.registerNewSkill(this)
}
fun update() {
name = plugin.langYml.getString("skills.$id.name")
rewards.clear()
for (string in config.getStrings("level-up-rewards")) {
val split = string.split(":")
val asEffect = Effects.getByID(split[0].lowercase())
val asStat = Stats.getByID(split[0].lowercase())
if (asEffect != null) {
rewards[asEffect] = split[1].toInt()
}
if (asStat != null) {
rewards[asStat] = split[1].toInt()
}
}
PlaceholderEntry(
id,
{ player -> player.getSkillLevel(this).toString() },
true
).register()
postUpdate()
}
fun getLevelUpRewards(): Collection<SkillObject> {
return rewards.keys
}
fun getLevelUpReward(skillObject: SkillObject): Int {
return rewards[skillObject] ?: 0
}
fun getRewardsMessages(player: Player): MutableList<String> {
val messages = ArrayList<String>()
for (string in this.config.getStrings("rewards-messages", false)) {
messages.add(StringUtils.format(string, player))
}
return messages
}
open fun postUpdate() {
// Override when needed
}

View File

@@ -61,18 +61,19 @@ class SkillDisplayListener(
if (this.plugin.configYml.getBool("skills.level-up.message.enabled")) {
val messages = ArrayList<String>()
val levelName = if (this.plugin.configYml.getBool("skills.level-up.message.level-as-numeral")) NumberUtils.toNumeral(level) else level.toString()
for (string in this.plugin.configYml.getStrings("skills.level-up.message.message")) {
messages.add(
string.replace("%skill%", skill.name)
.replace("%level%", level.toString())
.replace("%level%", levelName)
)
}
val rewardIndex = messages.indexOf("%rewards%")
if (rewardIndex != -1) {
messages.removeAt(rewardIndex)
messages.addAll(rewardIndex, listOf())
messages.addAll(rewardIndex, skill.getRewardsMessages(player))
}
for (message in messages) {

View File

@@ -1,15 +1,11 @@
package com.willfp.ecoskills.skills
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.util.NumberUtils
import com.willfp.ecoskills.*
import com.willfp.ecoskills.api.PlayerSkillExpGainEvent
import com.willfp.ecoskills.api.PlayerSkillLevelUpEvent
import com.willfp.ecoskills.getSkillLevel
import com.willfp.ecoskills.getSkillProgress
import com.willfp.ecoskills.setSkillLevel
import com.willfp.ecoskills.setSkillProgress
import net.md_5.bungee.api.ChatMessageType
import net.md_5.bungee.api.chat.TextComponent
import com.willfp.ecoskills.effects.Effect
import com.willfp.ecoskills.stats.Stat
import org.bukkit.Bukkit
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
@@ -34,4 +30,19 @@ class SkillLevellingListener(
Bukkit.getPluginManager().callEvent(levelUpEvent)
}
}
@EventHandler(priority = EventPriority.HIGHEST)
fun onLevelUp(event: PlayerSkillLevelUpEvent) {
val player = event.player
val skill = event.skill
for (obj in skill.getLevelUpRewards()) {
if (obj is Effect) {
player.setEffectLevel(obj, player.getEffectLevel(obj) + skill.getLevelUpReward(obj))
}
if (obj is Stat) {
player.setStatLevel(obj, player.getStatLevel(obj) + skill.getLevelUpReward(obj))
}
}
}
}

View File

@@ -2,16 +2,20 @@ package com.willfp.ecoskills.stats
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.integrations.placeholder.PlaceholderEntry
import com.willfp.ecoskills.EcoSkillsPlugin
import com.willfp.ecoskills.SkillObject
import com.willfp.ecoskills.getStatLevel
import com.willfp.ecoskills.skills.Skills
import org.bukkit.NamespacedKey
import org.bukkit.entity.Player
import org.bukkit.event.Listener
import java.util.*
import java.util.function.Function
abstract class Stat(
val id: String
) : Listener {
id: String
) : SkillObject(id), Listener {
protected val plugin: EcoPlugin = EcoSkillsPlugin.getInstance()
val key: NamespacedKey
@@ -34,6 +38,12 @@ abstract class Stat(
icon = plugin.langYml.getString("stats.$id.icon")
name = plugin.langYml.getString("stats.$id.name")
color = plugin.langYml.getString("stats.$id.color")
PlaceholderEntry(
id,
{ player -> player.getStatLevel(this).toString() },
true
).register()
}
open fun updateStatLevel(player: Player) {

View File

@@ -68,12 +68,13 @@ skills:
# Ways to tell the player about levelling up
level-up:
message:
level-as-numeral: true
enabled: true
message:
- "&f"
- "&3You levelled up &9%skill%&3 to level &e%level%&3!"
- " &3You levelled up &9%skill%&3 to level &e%level%&3!"
- "&f"
- "&3&lREWARDS:"
- " &3&lREWARDS:"
- "%rewards%"
- "&f"
sound:
@@ -90,6 +91,15 @@ skills:
# The maximum obtainable level
max-level: 50
# The level/skill increases to give on levelup
level-up-rewards:
- "defense:2"
- "versatile_tools:1"
rewards-messages:
- " &f+2 &#e884b0❤ Defense"
- " &6Versatile Tools %ecoskills_versatile_tools%"
# The xp rewards for each block type
# Specify with type:xp
xp-rewards:

View File

@@ -58,28 +58,37 @@ stats:
effects:
bountiful_harvest:
name: "Bountiful Harvest"
color: "&6"
description: "Increases chance to get extra drops from farming"
versatile_tools:
name: "Versatile Tools"
color: "&6"
description: "Increases damage dealt by pickaxes"
eye_of_the_depths:
name: "Eye of the Depths"
color: "&6"
description: "Increases chance to get rare loot from fishing"
serrated_strikes:
name: "Serrated Strikes"
color: "&6"
description: "Increases chance to cause your opponent to bleed, damaging them repeatedly"
seamless_movement:
name: "Seamless Movement"
color: "&6"
description: "Increases chance to ignore fall damage"
potionmaster:
name: "Potionmaster"
color: "&6"
description: "Brewed Potions last longer"
shamanism:
name: "Shamanism"
color: "&6"
description: "Increases the speed at which you regain health"
craftsmanship:
name: "Craftsmanship"
color: "&6"
description: "Take less durability damage on axes"
second_chance:
name: "Second Chance"
color: "&6"
description: "Chance to instantly fix items on low durability"