9
0
mirror of https://github.com/Auxilor/EcoSkills.git synced 2026-01-06 15:51:52 +00:00

Continued backend

This commit is contained in:
Auxilor
2021-08-20 15:04:45 +01:00
parent 5d6eb185dd
commit 2510032a65
15 changed files with 310 additions and 36 deletions

View File

@@ -5,13 +5,8 @@
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
<!-- Effects don't need javadoc. -->
<suppress files="[\\/]effects[\\/]effects[\\/]" checks="MissingJavadocMethod"/>
<suppress files="[\\/]effects[\\/]effects[\\/]" checks="JavadocVariable"/>
<suppress files="[\\/]conditions[\\/]conditions[\\/]" checks="MissingJavadocMethod"/>
<suppress files="[\\/]conditions[\\/]conditions[\\/]" checks="JavadocVariable"/>
<!-- Fields don't need javadoc -->
<suppress files="Effects.java" checks="JavadocVariable"/>
<suppress files="Conditions.java" checks="JavadocVariable"/>
<suppress files="Skills.java" checks="JavadocVariable"/>
<suppress files="Stats.java" checks="JavadocVariable"/>
</suppressions>

View File

@@ -0,0 +1,86 @@
package com.willfp.ecoskills.api;
import com.willfp.ecoskills.skills.Skill;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.jetbrains.annotations.NotNull;
public class PlayerSkillExpGainEvent extends PlayerEvent {
/**
* Bukkit parity.
*/
private static final HandlerList HANDLERS = new HandlerList();
/**
* The skill.
*/
private final Skill skill;
/**
* The amount.
*/
private double amount;
/**
* Create a new PlayerSkillExpGainEvent.
*
* @param who The player.
* @param skill The skill.
* @param amount The amount of skill exp gained.
*/
public PlayerSkillExpGainEvent(@NotNull final Player who,
@NotNull final Skill skill,
final double amount) {
super(who);
this.skill = skill;
this.amount = amount;
}
/**
* Get the skill for the event.
*
* @return The skill.
*/
public Skill getSkill() {
return this.skill;
}
/**
* Get the amount of experience.
*
* @return The experience.
*/
public double getAmount() {
return amount;
}
/**
* Set the amount of experience.
*
* @param amount The amount.
*/
public void setAmount(final double amount) {
this.amount = amount;
}
/**
* Bukkit parity.
*
* @return The handler list.
*/
@NotNull
@Override
public HandlerList getHandlers() {
return HANDLERS;
}
/**
* Bukkit parity.
*
* @return The handler list.
*/
public static HandlerList getHandlerList() {
return HANDLERS;
}
}

View File

@@ -2,7 +2,6 @@ package com.willfp.ecoskills.effects;
import com.google.common.collect.ImmutableSet;
import com.willfp.eco.core.config.updating.ConfigUpdater;
import com.willfp.ecoskills.EcoSkillsPlugin;
import com.willfp.ecoskills.effects.effects.EffectBountifulHarvest;
import com.willfp.ecoskills.effects.effects.EffectCraftsmanship;
import com.willfp.ecoskills.effects.effects.EffectEyeOfTheDepths;
@@ -27,11 +26,6 @@ public class Effects {
*/
private static final Map<String, Effect> REGISTRY = new HashMap<>();
/**
* Instance of EcoSkills.
*/
private static final EcoSkillsPlugin PLUGIN = EcoSkillsPlugin.getInstance();
public static final Effect BOUNTIFUL_HARVEST = new EffectBountifulHarvest();
public static final Effect CRAFTSMANSHIP = new EffectCraftsmanship();
public static final Effect EYE_OF_THE_DEPTHS = new EffectEyeOfTheDepths();

View File

@@ -18,11 +18,6 @@ public class Skills {
*/
private static final Map<String, Skill> REGISTRY = new HashMap<>();
/**
* Instance of EcoSkills.
*/
private static final EcoSkillsPlugin PLUGIN = EcoSkillsPlugin.getInstance();
public static final Skill MINING = new Skill(PLUGIN, "mining");
public static final Skill COMBAT = new Skill(PLUGIN, "combat");
public static final Skill ENCHANTING = new Skill(PLUGIN, "enchanting");

View File

@@ -2,7 +2,12 @@ package com.willfp.ecoskills.stats;
import com.google.common.collect.ImmutableSet;
import com.willfp.eco.core.config.updating.ConfigUpdater;
import com.willfp.ecoskills.EcoSkillsPlugin;
import com.willfp.ecoskills.stats.stats.StatCritChance;
import com.willfp.ecoskills.stats.stats.StatCritDamage;
import com.willfp.ecoskills.stats.stats.StatDefense;
import com.willfp.ecoskills.stats.stats.StatSpeed;
import com.willfp.ecoskills.stats.stats.StatStrength;
import com.willfp.ecoskills.stats.stats.StatWisdom;
import org.bukkit.NamespacedKey;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
@@ -18,17 +23,12 @@ public class Stats {
*/
private static final Map<String, Stat> REGISTRY = new HashMap<>();
/**
* Instance of EcoSkills.
*/
private static final EcoSkillsPlugin PLUGIN = EcoSkillsPlugin.getInstance();
public static final Stat DEFENCE = new Stat(PLUGIN, "defence");
public static final Stat STRENGTH = new Stat(PLUGIN, "strength");
public static final Stat CRIT_CHANCE = new Stat(PLUGIN, "crit_chance");
public static final Stat CRIT_DAMAGE = new Stat(PLUGIN, "crit_damage");
public static final Stat SPEED = new Stat(PLUGIN, "speed");
public static final Stat WISDOM = new Stat(PLUGIN, "wisdom");
public static final Stat DEFENSE = new StatDefense();
public static final Stat STRENGTH = new StatStrength();
public static final Stat CRIT_CHANCE = new StatCritChance();
public static final Stat CRIT_DAMAGE = new StatCritDamage();
public static final Stat SPEED = new StatSpeed();
public static final Stat WISDOM = new StatWisdom();
@ApiStatus.Internal
public static void registerNewStat(@NotNull final Stat skill) {

View File

@@ -1,18 +1,27 @@
package com.willfp.ecoskills
import com.willfp.ecoskills.effects.Effect
import com.willfp.ecoskills.skills.Skill
import com.willfp.ecoskills.stats.Stat
import org.bukkit.entity.Player
import org.bukkit.persistence.PersistentDataType
fun Player.getSkillLevel(skill: Stat): Int {
fun Player.getSkillLevel(skill: Skill): Int {
return this.persistentDataContainer.getOrDefault(skill.key, PersistentDataType.INTEGER, 1)
}
fun Player.setSkillLevel(skill: Stat, level: Int) {
fun Player.setSkillLevel(skill: Skill, level: Int) {
this.persistentDataContainer.set(skill.key, PersistentDataType.INTEGER, level)
}
fun Player.getSkillExperience(skill: Skill): Double {
return this.persistentDataContainer.getOrDefault(skill.xpKey, PersistentDataType.DOUBLE, 0.0)
}
fun Player.setSkillExperience(skill: Skill, level: Double) {
this.persistentDataContainer.set(skill.xpKey, PersistentDataType.DOUBLE, level)
}
fun Player.getEffectLevel(effect: Effect): Int {
return this.persistentDataContainer.getOrDefault(effect.key, PersistentDataType.INTEGER, 1)
}

View File

@@ -0,0 +1,16 @@
package com.willfp.ecoskills.skills
import com.willfp.eco.core.EcoPlugin
import com.willfp.ecoskills.api.PlayerSkillExpGainEvent
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
class ProgressDisplayListener(
private val plugin: EcoPlugin
) : Listener {
@EventHandler(priority = EventPriority.MONITOR)
fun onProgress(event: PlayerSkillExpGainEvent) {
}
}

View File

@@ -1,23 +1,28 @@
package com.willfp.ecoskills.skills
import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.ecoskills.EcoSkillsPlugin
import org.bukkit.NamespacedKey
import java.util.*
class Skill(
abstract class Skill(
val id: String
) {
protected val plugin: EcoPlugin = EcoSkillsPlugin.getInstance()
val key: NamespacedKey
val xpKey: NamespacedKey
val uuid: UUID
val config: Config
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")
Skills.registerNewSkill(this)
}

View File

@@ -0,0 +1,43 @@
package com.willfp.ecoskills.stats.stats
import com.willfp.eco.util.NumberUtils
import com.willfp.ecoskills.getStatLevel
import com.willfp.ecoskills.stats.Stat
import com.willfp.ecoskills.stats.Stats
import org.bukkit.entity.Player
import org.bukkit.entity.Projectile
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.entity.EntityDamageByEntityEvent
class StatCritChance : Stat(
"crit_chance"
) {
@EventHandler(priority = EventPriority.LOW)
fun handle(event: EntityDamageByEntityEvent) {
var player = event.damager
if (player is Projectile) {
if (player.shooter !is Player) {
return
} else {
player = player.shooter as Player
}
}
if (player !is Player) {
return
}
if (NumberUtils.randFloat(0.0, 100.0) >= (this.config.getDouble("chance-per-level") * player.getStatLevel(this))) {
return
}
var multiplier = Stats.CRIT_DAMAGE.config.getDouble("percent-more-damage-per-level") * player.getStatLevel(Stats.CRIT_DAMAGE)
multiplier += Stats.CRIT_DAMAGE.config.getDouble("base-percent-more")
multiplier /= 100
multiplier += 1
event.damage = (event.damage) * multiplier
}
}

View File

@@ -0,0 +1,15 @@
package com.willfp.ecoskills.stats.stats
import com.willfp.eco.util.NumberUtils
import com.willfp.ecoskills.getStatLevel
import com.willfp.ecoskills.stats.Stat
import org.bukkit.entity.Player
import org.bukkit.entity.Projectile
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.entity.EntityDamageByEntityEvent
class StatCritDamage : Stat(
"crit_damage"
) {
}

View File

@@ -7,7 +7,7 @@ import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.entity.EntityDamageEvent
class StatDefense() : Stat(
class StatDefense : Stat(
"defense"
) {
@EventHandler(priority = EventPriority.LOW)

View File

@@ -0,0 +1,28 @@
package com.willfp.ecoskills.stats.stats
import com.willfp.ecoskills.getStatLevel
import com.willfp.ecoskills.stats.Stat
import org.bukkit.attribute.Attribute
import org.bukkit.attribute.AttributeModifier
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.entity.EntityDamageEvent
class StatSpeed : Stat(
"speed"
) {
override fun updateStatLevel(player: Player) {
val modifier = AttributeModifier(
this.uuid,
this.name,
(this.config.getDouble("percent-faster-per-level") * player.getStatLevel(this)) / 100,
AttributeModifier.Operation.MULTIPLY_SCALAR_1
)
val instance = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED) ?: return
instance.removeModifier(modifier)
plugin.scheduler.runLater({
instance.addModifier(modifier)
}, 1)
}
}

View File

@@ -8,8 +8,8 @@ import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.entity.EntityDamageByEntityEvent
class StatStrength() : Stat(
"defense"
class StatStrength : Stat(
"strength"
) {
@EventHandler(priority = EventPriority.LOW)
fun handle(event: EntityDamageByEntityEvent) {

View File

@@ -0,0 +1,25 @@
package com.willfp.ecoskills.stats.stats
import com.willfp.eco.core.events.NaturalExpGainEvent
import com.willfp.ecoskills.getStatLevel
import com.willfp.ecoskills.stats.Stat
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.entity.EntityDamageEvent
import kotlin.math.ceil
class StatWisdom : Stat(
"wisdom"
) {
@EventHandler(priority = EventPriority.LOW)
fun handle(event: NaturalExpGainEvent) {
val player = event.expChangeEvent.player
var multiplier = this.config.getDouble("percent-more-xp-gain") * player.getStatLevel(this)
multiplier /= 100
multiplier += 1
event.expChangeEvent.amount = ceil((event.expChangeEvent.amount * multiplier)).toInt()
}
}

View File

@@ -3,6 +3,69 @@
# by Auxilor
#
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
# Ways to tell the player about skill progress
progress:
action-bar:
# If the action bar should be used
enabled: true
format:
mining:
gui-item: stone_pickaxe
# The maximum obtainable level
max-level: 50
name: "Mining"
combat:
gui-item: stone_sword
# The maximum obtainable level
max-level: 50
name: "Combat"
enchanting:
gui-item: enchanting_table
# The maximum obtainable level
max-level: 50
name: "Enchanting"
farming:
gui-item: golden_hoe
# The maximum obtainable level
max-level: 50
name: "Farming"
woodcutting:
gui-item: jungle_sapling
# The maximum obtainable level
max-level: 50
name: "Woodcutting"
fishing:
gui-item: fishing_rod
# The maximum obtainable level
max-level: 50
name: "Fishing"
alchemy:
gui-item: brewing_stand
# The maximum obtainable level
max-level: 50
name: "Alchemy"
armory:
gui-item: iron_chestplate
# The maximum obtainable level
max-level: 50
name: "Armory"
exploration:
gui-item: leather_boots
# The maximum obtainable level
max-level: 50
name: "Exploration"
stats:
defense:
# 100% halves the incoming damage