mirror of
https://github.com/Auxilor/EcoSkills.git
synced 2026-01-02 13:56:38 +00:00
Fixed attack speed and improved APIO
This commit is contained in:
@@ -13,22 +13,31 @@ import java.util.*
|
||||
|
||||
abstract class Effect(
|
||||
id: String
|
||||
): SkillObject(id), Listener {
|
||||
) : SkillObject(id), Listener {
|
||||
protected val plugin: EcoSkillsPlugin = EcoSkillsPlugin.getInstance()
|
||||
|
||||
val key: NamespacedKey
|
||||
open val config: Config
|
||||
val uuid: UUID
|
||||
lateinit var config: Config
|
||||
|
||||
init {
|
||||
update()
|
||||
uuid = UUID.nameUUIDFromBytes(id.toByteArray())
|
||||
key = plugin.namespacedKeyFactory.create(id)
|
||||
config = plugin.effectsYml.getSubsection(id)
|
||||
|
||||
finishLoading()
|
||||
}
|
||||
|
||||
private fun finishLoading() {
|
||||
config = loadConfig()
|
||||
|
||||
Effects.registerNewEffect(this)
|
||||
}
|
||||
|
||||
open fun loadConfig(): Config {
|
||||
return plugin.effectsYml.getSubsection(id)
|
||||
}
|
||||
|
||||
abstract fun formatDescription(string: String, level: Int): String
|
||||
|
||||
fun getDescription(level: Int): String {
|
||||
|
||||
@@ -22,7 +22,7 @@ abstract class Skill(
|
||||
|
||||
val key: NamespacedKey = plugin.namespacedKeyFactory.create(id)
|
||||
val xpKey: NamespacedKey = plugin.namespacedKeyFactory.create(id + "_progress")
|
||||
open val config: Config
|
||||
lateinit var config: Config
|
||||
lateinit var name: String
|
||||
lateinit var description: String
|
||||
lateinit var gui: SkillGUI
|
||||
@@ -35,11 +35,19 @@ abstract class Skill(
|
||||
private val messagesCache = mutableMapOf<Int, List<String>>()
|
||||
|
||||
init {
|
||||
config = SkillConfig(this.id, this.javaClass, plugin)
|
||||
finishLoading()
|
||||
}
|
||||
|
||||
private fun finishLoading() {
|
||||
config = loadConfig()
|
||||
|
||||
Skills.registerNewSkill(this)
|
||||
}
|
||||
|
||||
open fun loadConfig(): Config {
|
||||
return SkillConfig(this.id, this.javaClass, plugin)
|
||||
}
|
||||
|
||||
fun update() {
|
||||
name = config.getString("name")
|
||||
description = config.getString("description")
|
||||
|
||||
@@ -19,18 +19,27 @@ abstract class Stat(
|
||||
|
||||
val key: NamespacedKey
|
||||
val uuid: UUID
|
||||
open val config: Config
|
||||
lateinit var config: Config
|
||||
lateinit var name: String
|
||||
|
||||
init {
|
||||
update()
|
||||
key = plugin.namespacedKeyFactory.create(id)
|
||||
uuid = UUID.nameUUIDFromBytes(id.toByteArray())
|
||||
config = plugin.configYml.getSubsection("stats.$id")
|
||||
|
||||
finishLoading()
|
||||
}
|
||||
|
||||
private fun finishLoading() {
|
||||
config = loadConfig()
|
||||
|
||||
Stats.registerNewStat(this)
|
||||
}
|
||||
|
||||
open fun loadConfig(): Config {
|
||||
return plugin.configYml.getSubsection("stats.$id")
|
||||
}
|
||||
|
||||
fun update() {
|
||||
name = plugin.langYml.getString("stats.$id.name")
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.willfp.ecoskills.attackspeed;
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin;
|
||||
import com.willfp.eco.core.extensions.Extension;
|
||||
import com.willfp.ecoskills.stats.Stat;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AttackSpeedMain extends Extension {
|
||||
/**
|
||||
* Attack Speed.
|
||||
*/
|
||||
public static final Stat ATTACK_SPEED = new StatAttackSpeed();
|
||||
|
||||
/**
|
||||
* Create a new extension for a plugin.
|
||||
*
|
||||
* @param plugin The plugin.
|
||||
*/
|
||||
public AttackSpeedMain(@NotNull final EcoPlugin plugin) {
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEnable() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDisable() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.willfp.ecoskills.attackspeed;
|
||||
|
||||
import com.willfp.eco.core.config.interfaces.Config;
|
||||
import com.willfp.eco.core.config.yaml.YamlTransientConfig;
|
||||
import com.willfp.ecoskills.api.EcoSkillsAPI;
|
||||
import com.willfp.ecoskills.stats.Stat;
|
||||
import org.bukkit.attribute.Attribute;
|
||||
import org.bukkit.attribute.AttributeInstance;
|
||||
import org.bukkit.attribute.AttributeModifier;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class StatAttackSpeed extends Stat {
|
||||
/**
|
||||
* Create attack speed stat.
|
||||
*/
|
||||
public StatAttackSpeed() {
|
||||
super("attack_speed");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Config loadConfig() {
|
||||
return new YamlTransientConfig(new YamlConfiguration());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStatLevel(@NotNull final Player player) {
|
||||
AttributeModifier modifier = new AttributeModifier(
|
||||
this.getUuid(),
|
||||
this.getName(),
|
||||
EcoSkillsAPI.getInstance().getStatLevel(player, this) / 100D,
|
||||
AttributeModifier.Operation.MULTIPLY_SCALAR_1
|
||||
);
|
||||
|
||||
AttributeInstance instance = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED);
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
instance.removeModifier(modifier);
|
||||
|
||||
this.getPlugin().getScheduler().run(() -> {
|
||||
instance.removeModifier(modifier);
|
||||
instance.addModifier(modifier);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package com.willfp.ecoskills.attackspeed
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.config.yaml.YamlExtendableConfig
|
||||
|
||||
class AttackSpeedConfig(plugin: EcoPlugin) : YamlExtendableConfig(
|
||||
"attackspeed",
|
||||
true,
|
||||
plugin,
|
||||
AttackSpeedConfig::class.java,
|
||||
"stats/"
|
||||
) {
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package com.willfp.ecoskills.attackspeed
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.extensions.Extension
|
||||
|
||||
class AttackSpeedMain(plugin: EcoPlugin) : Extension(plugin) {
|
||||
val attackSpeed = StatAttackSpeed()
|
||||
|
||||
override fun onEnable() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
override fun onDisable() {
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.willfp.ecoskills.attackspeed
|
||||
|
||||
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
|
||||
|
||||
class StatAttackSpeed : Stat(
|
||||
"attack_speed"
|
||||
) {
|
||||
override val config = AttackSpeedConfig(plugin)
|
||||
|
||||
override fun updateStatLevel(player: Player) {
|
||||
val modifier = AttributeModifier(
|
||||
this.uuid,
|
||||
this.name,
|
||||
(this.config.getDouble("percent-faster-per-level") * player.getStatLevel(this)) / 100.0,
|
||||
AttributeModifier.Operation.MULTIPLY_SCALAR_1
|
||||
)
|
||||
val instance = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED) ?: return
|
||||
instance.removeModifier(modifier)
|
||||
|
||||
plugin.scheduler.run {
|
||||
instance.removeModifier(modifier)
|
||||
instance.addModifier(modifier)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
percent-faster-per-level: 1
|
||||
Reference in New Issue
Block a user