9
0
mirror of https://github.com/Auxilor/EcoSkills.git synced 2026-01-02 22:02:19 +00:00
This commit is contained in:
Auxilor
2021-08-20 16:25:39 +01:00
parent c0f6a6fa83
commit cb5f69db0e
11 changed files with 171 additions and 40 deletions

View File

@@ -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;
}

View File

@@ -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();
}
}
}

View File

@@ -22,5 +22,6 @@ class CommandEcoskills(plugin: EcoPlugin) :
init {
addSubcommand(CommandReload(plugin))
.addSubcommand(CommandReset(plugin))
}
}

View File

@@ -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<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
}
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<String> = ArrayList()
if (args.size == 1) {
StringUtil.copyPartialMatches(
args[0],
Bukkit.getOnlinePlayers().map { player -> player.name }.toCollection(ArrayList()),
completions
)
return@TabCompleteHandler completions
}
return@TabCompleteHandler ArrayList<String>(0)
}
}
}

View File

@@ -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
}
}

View File

@@ -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(

View File

@@ -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)

View File

@@ -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<Material, Double>
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
}

View File

@@ -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:

View File

@@ -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"

View File

@@ -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