9
0
mirror of https://github.com/Auxilor/EcoSkills.git synced 2026-01-02 22:02:19 +00:00

Merged attack speed stat into base plugin

This commit is contained in:
Auxilor
2022-04-02 17:25:27 +01:00
parent b096fdd2f5
commit 9c5d66bda0
11 changed files with 53 additions and 152 deletions

View File

@@ -2,6 +2,7 @@ package com.willfp.ecoskills.stats;
import com.google.common.collect.ImmutableSet;
import com.willfp.eco.core.config.updating.ConfigUpdater;
import com.willfp.ecoskills.stats.stats.StatAttackSpeed;
import com.willfp.ecoskills.stats.stats.StatCritChance;
import com.willfp.ecoskills.stats.stats.StatCritDamage;
import com.willfp.ecoskills.stats.stats.StatDefense;
@@ -33,6 +34,7 @@ public class Stats {
public static final Stat WISDOM = new StatWisdom();
public static final Stat FEROCITY = new StatFerocity();
public static final Stat HEALTH = new StatHealth();
public static final Stat ATTACK_SPEED = new StatAttackSpeed();
@ApiStatus.Internal
public static void registerNewStat(@NotNull final Stat skill) {

View File

@@ -0,0 +1,44 @@
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.player.PlayerChangedWorldEvent
class StatAttackSpeed : Stat(
"attack_speed"
) {
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_ATTACK_SPEED) ?: return
instance.removeModifier(modifier)
if (this.config.getStrings("disabled-in-worlds").contains(player.world.name)) {
return
}
plugin.scheduler.run {
instance.removeModifier(modifier)
instance.addModifier(modifier)
}
}
@EventHandler(priority = EventPriority.LOW)
fun handle(event: PlayerChangedWorldEvent) {
val player = event.player
plugin.scheduler.run {
updateStatLevel(player)
}
}
}

View File

@@ -277,6 +277,13 @@ stats:
disabled-in-worlds: [ ]
# The extra hp per level
health-per-level: 1
attack_speed:
name: "&#fcba03⚔ Attack Speed"
# Disabled worlds
disabled-in-worlds: [ ]
# The percent more speed to give for the speed attribute (internal in the game)
# for each level
percent-faster-per-level: 1
damage-indicators:
# Requires HolographicDisplays/GHolo/CMI to be installed

View File

@@ -1,7 +0,0 @@
group 'com.willfp'
version '1.0.0'
description = 'Attack Speed Extension'
shadowJar {
archiveFileName = project.getDescription() + " v" + project.version + ".jar"
}

View File

@@ -1,12 +0,0 @@
package com.willfp.ecoskills.attackspeed;
import com.willfp.eco.core.PluginLike;
import com.willfp.eco.core.config.BaseConfig;
import com.willfp.eco.core.config.ConfigType;
import org.jetbrains.annotations.NotNull;
public class AttackSpeedConfig extends BaseConfig {
public AttackSpeedConfig(@NotNull final PluginLike plugin) {
super("attackspeed", plugin, true, ConfigType.YAML);
}
}

View File

@@ -1,56 +0,0 @@
package com.willfp.ecoskills.attackspeed;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.config.interfaces.Config;
import com.willfp.eco.core.extensions.Extension;
import org.jetbrains.annotations.NotNull;
public class AttackSpeedMain extends Extension {
/**
* The instance.
*/
private static AttackSpeedMain instance;
/**
* attackspeed.yml.
*/
private final Config config = new AttackSpeedConfig(this);
/**
* Create a new extension for a plugin.
*
* @param plugin The plugin.
*/
public AttackSpeedMain(@NotNull final EcoPlugin plugin) {
super(plugin);
instance = this;
}
@Override
protected void onEnable() {
new StatAttackSpeed();
}
@Override
protected void onDisable() {
}
/**
* Get attackspeed.yml.
*
* @return The config.
*/
public Config getConfig() {
return config;
}
/**
* Get instance.
*
* @return The instance.
*/
public static AttackSpeedMain getInstance() {
return instance;
}
}

View File

@@ -1,50 +0,0 @@
package com.willfp.ecoskills.attackspeed;
import com.willfp.eco.core.config.interfaces.Config;
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.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 AttackSpeedMain.getInstance().getConfig();
}
@Override
public void updateStatLevel(@NotNull final Player player) {
AttributeModifier modifier = new AttributeModifier(
this.getUuid(),
this.getName(),
(
this.config.getDouble("percent-faster-per-level")
* EcoSkillsAPI.getInstance().getStatLevel(player, this)
) / 100.0,
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);
});
}
}

View File

@@ -1,4 +0,0 @@
name: '&#fcba03⚔ Attack Speed'
# The percent more speed to give for the attack speed attribute (internal in the game)
# for each level
percent-faster-per-level: 1

View File

@@ -1,4 +0,0 @@
name: Attack Speed
main: com.willfp.ecoskills.attackspeed.AttackSpeedMain
version: ${projectVersion}
author: Auxilor

View File

@@ -1,15 +0,0 @@
group 'com.willfp'
description = 'Extension Parent'
subprojects {
dependencies {
compileOnly project(":eco-core:core-plugin")
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
}
tasks.withType(Jar) {
destinationDirectory = file("$rootDir/bin/")
}
tasks.jar.enabled = false
}

View File

@@ -3,7 +3,3 @@ rootProject.name = 'EcoSkills'
// Core
include ':eco-core'
include ':eco-core:core-plugin'
// Extensions
include ':eco-extensions'
include ':eco-extensions:attackspeed'