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 c21c8e4..fffc8be 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 @@ -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) { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/stats/stats/StatAttackSpeed.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/stats/stats/StatAttackSpeed.kt new file mode 100644 index 0000000..04faca3 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/stats/stats/StatAttackSpeed.kt @@ -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) + } + } +} diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index e7c5c6b..eaa41a2 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -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 diff --git a/eco-extensions/attackspeed/build.gradle b/eco-extensions/attackspeed/build.gradle deleted file mode 100644 index d7fde28..0000000 --- a/eco-extensions/attackspeed/build.gradle +++ /dev/null @@ -1,7 +0,0 @@ -group 'com.willfp' -version '1.0.0' -description = 'Attack Speed Extension' - -shadowJar { - archiveFileName = project.getDescription() + " v" + project.version + ".jar" -} \ No newline at end of file diff --git a/eco-extensions/attackspeed/src/main/java/com/willfp/ecoskills/attackspeed/AttackSpeedConfig.java b/eco-extensions/attackspeed/src/main/java/com/willfp/ecoskills/attackspeed/AttackSpeedConfig.java deleted file mode 100644 index e72d35e..0000000 --- a/eco-extensions/attackspeed/src/main/java/com/willfp/ecoskills/attackspeed/AttackSpeedConfig.java +++ /dev/null @@ -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); - } -} diff --git a/eco-extensions/attackspeed/src/main/java/com/willfp/ecoskills/attackspeed/AttackSpeedMain.java b/eco-extensions/attackspeed/src/main/java/com/willfp/ecoskills/attackspeed/AttackSpeedMain.java deleted file mode 100644 index 59cd619..0000000 --- a/eco-extensions/attackspeed/src/main/java/com/willfp/ecoskills/attackspeed/AttackSpeedMain.java +++ /dev/null @@ -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; - } -} diff --git a/eco-extensions/attackspeed/src/main/java/com/willfp/ecoskills/attackspeed/StatAttackSpeed.java b/eco-extensions/attackspeed/src/main/java/com/willfp/ecoskills/attackspeed/StatAttackSpeed.java deleted file mode 100644 index 8a7661b..0000000 --- a/eco-extensions/attackspeed/src/main/java/com/willfp/ecoskills/attackspeed/StatAttackSpeed.java +++ /dev/null @@ -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); - }); - } -} diff --git a/eco-extensions/attackspeed/src/main/resources/attackspeed.yml b/eco-extensions/attackspeed/src/main/resources/attackspeed.yml deleted file mode 100644 index 869e10f..0000000 --- a/eco-extensions/attackspeed/src/main/resources/attackspeed.yml +++ /dev/null @@ -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 \ No newline at end of file diff --git a/eco-extensions/attackspeed/src/main/resources/extension.yml b/eco-extensions/attackspeed/src/main/resources/extension.yml deleted file mode 100644 index a343cb0..0000000 --- a/eco-extensions/attackspeed/src/main/resources/extension.yml +++ /dev/null @@ -1,4 +0,0 @@ -name: Attack Speed -main: com.willfp.ecoskills.attackspeed.AttackSpeedMain -version: ${projectVersion} -author: Auxilor \ No newline at end of file diff --git a/eco-extensions/build.gradle b/eco-extensions/build.gradle deleted file mode 100644 index e1cfea7..0000000 --- a/eco-extensions/build.gradle +++ /dev/null @@ -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 -} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 1b53d73..aafa1fc 100644 --- a/settings.gradle +++ b/settings.gradle @@ -3,7 +3,3 @@ rootProject.name = 'EcoSkills' // Core include ':eco-core' include ':eco-core:core-plugin' - -// Extensions -include ':eco-extensions' -include ':eco-extensions:attackspeed' \ No newline at end of file