From f58d1018a6342118ef5d8ca2c92b4dbef2838c7f Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 5 Sep 2022 15:26:46 +0100 Subject: [PATCH] Added rapid --- .../willfp/ecoenchants/EcoEnchantsPlugin.kt | 2 + .../enchants/impl/EnchantmentRapid.kt | 45 +++++++++++++++++++ .../src/main/resources/enchants/rapid.yml | 18 ++++++++ 3 files changed, 65 insertions(+) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/impl/EnchantmentRapid.kt create mode 100644 eco-core/core-plugin/src/main/resources/enchants/rapid.yml diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/EcoEnchantsPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/EcoEnchantsPlugin.kt index 45854137..5732b6db 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/EcoEnchantsPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/EcoEnchantsPlugin.kt @@ -13,6 +13,7 @@ import com.willfp.ecoenchants.display.EnchantDisplay import com.willfp.ecoenchants.enchants.EcoEnchants import com.willfp.ecoenchants.enchants.LoreConversion import com.willfp.ecoenchants.enchants.impl.EnchantmentPermanenceCurse +import com.willfp.ecoenchants.enchants.impl.EnchantmentRapid import com.willfp.ecoenchants.enchants.impl.EnchantmentRepairing import com.willfp.ecoenchants.enchants.impl.EnchantmentTelekinesis import com.willfp.ecoenchants.enchants.registerVanillaEnchants @@ -50,6 +51,7 @@ class EcoEnchantsPlugin : LibReforgePlugin() { EnchantmentTelekinesis(this) EnchantmentPermanenceCurse(this) EnchantmentRepairing(this) + EnchantmentRapid(this) registerVanillaEnchants(this) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/impl/EnchantmentRapid.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/impl/EnchantmentRapid.kt new file mode 100644 index 00000000..99048df2 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/impl/EnchantmentRapid.kt @@ -0,0 +1,45 @@ +package com.willfp.ecoenchants.enchants.impl + +import com.willfp.ecoenchants.EcoEnchantsPlugin +import com.willfp.ecoenchants.enchants.EcoEnchant +import com.willfp.ecoenchants.target.EnchantLookup.getEnchantLevel +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.Listener +import org.bukkit.event.entity.EntityShootBowEvent + +class EnchantmentRapid( + plugin: EcoEnchantsPlugin +) : EcoEnchant( + "rapid", + plugin, + force = false +) { + init { + this.registerListener(RapidHandler(this)) + } + + private class RapidHandler( + private val enchant: EcoEnchant + ) : Listener { + @EventHandler( + priority = EventPriority.HIGH, + ignoreCancelled = true + ) + fun handle(event: EntityShootBowEvent) { + val player = event.entity as? Player ?: return + + val level = player.getEnchantLevel(enchant) + + val multiplier = 1 - enchant.config.getDouble("percent-faster-per-level") * level / 100 + + if (event.force < multiplier) { + return + } + + val force = 1 / event.force + event.projectile.velocity = event.projectile.velocity.multiply(force) + } + } +} diff --git a/eco-core/core-plugin/src/main/resources/enchants/rapid.yml b/eco-core/core-plugin/src/main/resources/enchants/rapid.yml new file mode 100644 index 00000000..0b6e7a83 --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/rapid.yml @@ -0,0 +1,18 @@ +display-name: "Rapid" +description: "Lets you shoot full speed arrows with the bow at &a%placeholder%%&8 tension" +placeholder: "1 - (15 * %level%)" +type: normal + +targets: + - bow +conflicts: [ ] +rarity: epic +max-level: 6 + +tradeable: true +discoverable: true +enchantable: true + +conditions: [ ] + +percent-faster-per-level: 15