diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/EcoSkillsPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/EcoSkillsPlugin.java index cf41f40..08725f3 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/EcoSkillsPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/EcoSkillsPlugin.java @@ -26,7 +26,7 @@ public class EcoSkillsPlugin extends EcoPlugin { * Internal constructor called by bukkit on plugin load. */ public EcoSkillsPlugin() { - super(94630, 12205, "&#ff00ae"); + super(0, 12205, "&#ff00ae"); instance = this; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/stats/Stats.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/stats/Stats.java index 0e7a3d2..a0ecc77 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/stats/Stats.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/stats/Stats.java @@ -51,8 +51,8 @@ public class Stats { @ConfigUpdater public static void update() { - for (Stat skill : Stats.values()) { - skill.update(); + for (Stat stat : Stats.values()) { + stat.update(); } } } 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 25a2767..9097d75 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 @@ -22,5 +22,6 @@ class CommandEcoskills(plugin: EcoPlugin) : init { addSubcommand(CommandReload(plugin)) + .addSubcommand(CommandReset(plugin)) } } \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandReset.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandReset.kt new file mode 100644 index 0000000..5901fdb --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/commands/CommandReset.kt @@ -0,0 +1,71 @@ +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.ecoskills.effects.Effects +import com.willfp.ecoskills.setEffectLevel +import com.willfp.ecoskills.setSkillLevel +import com.willfp.ecoskills.setSkillProgress +import com.willfp.ecoskills.setStatLevel +import com.willfp.ecoskills.skills.Skills +import com.willfp.ecoskills.stats.Stats +import org.bukkit.Bukkit +import org.bukkit.command.CommandSender +import org.bukkit.entity.Player +import org.bukkit.util.StringUtil +import java.util.stream.Collectors + + +class CommandReset(plugin: EcoPlugin) : + Subcommand( + plugin, + "reset", + "ecoskills.command.reset", + 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 + } + + sender.sendMessage(plugin.langYml.getMessage("reset-player")) + for (stat in Stats.values()) { + player.setStatLevel(stat, 0) + } + for (effect in Effects.values()) { + player.setEffectLevel(effect, 0) + } + for (skill in Skills.values()) { + player.setSkillLevel(skill, 0) + player.setSkillProgress(skill, 0.0) + } + } + } + + override fun getTabCompleter(): TabCompleteHandler { + return TabCompleteHandler { _, args -> + val completions: MutableList = ArrayList() + + if (args.size == 1) { + StringUtil.copyPartialMatches( + args[0], + Bukkit.getOnlinePlayers().map { player -> player.name }.toCollection(ArrayList()), + completions + ) + return@TabCompleteHandler completions + } + + return@TabCompleteHandler ArrayList(0) + } + } +} \ 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 b5aa61f..4984c9f 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 @@ -25,29 +25,25 @@ abstract class Skill( lateinit var name: String init { - update() key = plugin.namespacedKeyFactory.create(id) xpKey = plugin.namespacedKeyFactory.create(id + "_progress") uuid = UUID.nameUUIDFromBytes(id.toByteArray()) - config = plugin.configYml.getSubsection("stats.$id") + config = plugin.configYml.getSubsection("skills.$id") Skills.registerNewSkill(this) } fun update() { name = plugin.langYml.getString("skills.$id.name") + + postUpdate() + } + + open fun postUpdate() { + // Override when needed } fun getExpForLevel(level: Int): Int { - val level1xp = this.plugin.configYml.getInt("skills.level-1-xp") - val multiplier = this.plugin.configYml.getDouble("skills.xp-multiplier-per-level") - val sigFig = this.plugin.configYml.getInt("skills.sig-fig") - val roundTo = this.plugin.configYml.getInt("skills.round-to") - - var xp = level1xp * (level.toDouble().pow(multiplier)) - val bigDecimal = BigDecimal(xp) - bigDecimal.round(MathContext(sigFig)) - xp = bigDecimal.toDouble() - return ((xp / roundTo).roundToInt() * roundTo) + return this.plugin.configYml.getInts("skills.level-xp-requirements")[level - 1] ?: Integer.MAX_VALUE } } \ No newline at end of file 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 e102a7a..15f6860 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 @@ -26,11 +26,11 @@ class SkillDisplayListener( var string = this.plugin.configYml.getString("skills.progress.action-bar.format") string = string.replace("%skill%", skill.name) string = string.replace("%current_xp%", NumberUtils.format(player.getSkillProgress(skill))) + val nextLevel = skill.getExpForLevel(player.getSkillLevel(skill) + 1).toDouble() + val nextLevelMessage = if (nextLevel >= 2_000_000_000) "∞" else NumberUtils.format(nextLevel) string = string.replace( "%required_xp%", - NumberUtils.format( - skill.getExpForLevel(player.getSkillLevel(skill) + 1).toDouble() - ) + nextLevelMessage ) string = string.replace("%gained_xp%", NumberUtils.format(amount)) player.spigot().sendMessage( 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 678d11d..054a268 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 @@ -25,7 +25,9 @@ class SkillLevellingListener( val amount = event.amount val level = player.getSkillLevel(skill) - if (player.getSkillProgress(skill) + amount >= skill.getExpForLevel(level + 1)) { + player.setSkillProgress(skill, player.getSkillProgress(skill) + amount) + + if (player.getSkillProgress(skill) >= skill.getExpForLevel(level + 1)) { player.setSkillProgress(skill, 0.0) player.setSkillLevel(skill, level + 1) val levelUpEvent = PlayerSkillLevelUpEvent(player, skill, level + 1) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/skills/SkillMining.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/skills/SkillMining.kt index 1ff9593..8889dd0 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/skills/SkillMining.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/skills/SkillMining.kt @@ -1,31 +1,41 @@ package com.willfp.ecoskills.skills.skills import com.willfp.ecoskills.api.PlayerSkillExpGainEvent -import com.willfp.ecoskills.getSkillProgress import com.willfp.ecoskills.skills.Skill import org.bukkit.Bukkit +import org.bukkit.Material +import org.bukkit.enchantments.Enchantment import org.bukkit.event.EventHandler import org.bukkit.event.EventPriority import org.bukkit.event.block.BlockBreakEvent +import java.util.* class SkillMining : Skill( "mining" ) { + private val rewards: MutableMap + + init { + rewards = EnumMap(org.bukkit.Material::class.java) + } + + override fun postUpdate() { + rewards.clear() + for (string in this.config.getStrings("xp-rewards", false)) { + val split = string.split(":") + val material = Material.getMaterial(split[0].uppercase()) ?: continue + rewards[material] = split[1].toDouble() + } + } + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) fun handleLevelling(event: BlockBreakEvent) { val type = event.block.type val player = event.player - var xp = player.getSkillProgress(this) - var toGive = 0.0 - for (string in this.config.getStrings("xp-rewards", false)) { - if (string.startsWith(type.name.lowercase())) { - toGive = string.split(":")[1].toDouble() - break; - } - } + val toGive = rewards[type] ?: return - if (toGive == 0.0) { + if (player.inventory.itemInMainHand.getEnchantmentLevel(Enchantment.SILK_TOUCH) != 0) { return } diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 7491b7c..301358c 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -4,16 +4,58 @@ # skills: - # The experience needed to get to level 1 of the skill - level-1-xp: 50 - # The percent more experience needed to get to the next level relative to the previous level - # In short, the experience required for one level follows this formula: - # level-1-xp * (multiplier ^ level) - xp-multiplier-per-level: 1.26 - # Since the formula will give unpleasant ratios, then truncate it to an amount of significant figures. - sig-fig: 2 - # Always round to the nearest also - round-to: 10 + # Add more levels depending on the highest max level for all skills + level-xp-requirements: + - 50 + - 125 + - 200 + - 300 + - 500 + - 750 + - 1000 + - 1500 + - 2000 + - 3500 + - 5000 + - 7500 + - 10000 + - 15000 + - 20000 + - 30000 + - 50000 + - 75000 + - 100000 + - 200000 + - 300000 + - 400000 + - 500000 + - 600000 + - 700000 + - 800000 + - 900000 + - 1000000 + - 1100000 + - 1200000 + - 1300000 + - 1400000 + - 1500000 + - 1600000 + - 1700000 + - 1800000 + - 1900000 + - 2000000 + - 2100000 + - 2200000 + - 2300000 + - 2400000 + - 2500000 + - 2600000 + - 2750000 + - 2900000 + - 3100000 + - 3400000 + - 3700000 + - 4000000 # Ways to tell the player about skill progress progress: diff --git a/eco-core/core-plugin/src/main/resources/lang.yml b/eco-core/core-plugin/src/main/resources/lang.yml index 52defa7..b2ddd91 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -4,6 +4,9 @@ messages: not-player: "&cThis command must be run by a player" invalid-command: "&cUnknown subcommand!" reloaded: "Reloaded! (Restart if you're removed weapons!)" + requires-player: "&cYou must specify a player!" + invalid-player: "&cInvalid player!" + reset-player: "&fReset player!" skills: color: "&9" diff --git a/eco-core/core-plugin/src/main/resources/plugin.yml b/eco-core/core-plugin/src/main/resources/plugin.yml index 18b18cc..3b7e256 100644 --- a/eco-core/core-plugin/src/main/resources/plugin.yml +++ b/eco-core/core-plugin/src/main/resources/plugin.yml @@ -7,6 +7,8 @@ website: willfp.com load: STARTUP depend: - eco +libraries: + - org.jetbrains.kotlin:kotlin-stdlib:1.5.21 commands: ecoskills: @@ -25,10 +27,14 @@ permissions: children: ecoskills.command.reload: true ecoskills.command.ecoskills: true + ecoskills.command.reset: true ecoskills.command.reload: description: Allows reloading the config default: op ecoskills.command.ecoskills: - description: Allows the user of /ecoskills. + description: Allows the use of /ecoskills. default: true + ecoskills.command.reset: + description: Allows the use of /ecoskills reset. + default: op