diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/SkillObject.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/SkillObject.kt new file mode 100644 index 0000000..6a676d3 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/SkillObject.kt @@ -0,0 +1,6 @@ +package com.willfp.ecoskills + +abstract class SkillObject( + val id: String +){ +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/Effect.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/Effect.kt index 748c9ea..01b9ab9 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/Effect.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/Effect.kt @@ -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() } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/Skill.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/Skill.kt index 4984c9f..b8ac3d8 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/Skill.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/Skill.kt @@ -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 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 { + return rewards.keys + } + + fun getLevelUpReward(skillObject: SkillObject): Int { + return rewards[skillObject] ?: 0 + } + + fun getRewardsMessages(player: Player): MutableList { + val messages = ArrayList() + for (string in this.config.getStrings("rewards-messages", false)) { + messages.add(StringUtils.format(string, player)) + } + return messages + } + open fun postUpdate() { // Override when needed } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillDisplayListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillDisplayListener.kt index 15f6860..12bc119 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillDisplayListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillDisplayListener.kt @@ -61,18 +61,19 @@ class SkillDisplayListener( if (this.plugin.configYml.getBool("skills.level-up.message.enabled")) { val messages = ArrayList() + 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) { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillLevellingListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillLevellingListener.kt index 054a268..5cac0df 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillLevellingListener.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/SkillLevellingListener.kt @@ -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)) + } + } + } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/stats/Stat.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/stats/Stat.kt index ca80474..4e34624 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/stats/Stat.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/stats/Stat.kt @@ -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) { diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 301358c..9a7b0bf 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -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: diff --git a/eco-core/core-plugin/src/main/resources/lang.yml b/eco-core/core-plugin/src/main/resources/lang.yml index b2ddd91..606f812 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -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"