From 7efbe8220f7138837c5d735f3aba926441892c61 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 8 Apr 2021 00:18:46 +0100 Subject: [PATCH] Added Rebounding --- .../ecoenchants/enchantments/EcoEnchants.java | 2 + .../ecoenchants/normal/Rebounding.java | 63 +++++++++++++++++++ .../resources/enchants/normal/rebounding.yml | 27 ++++++++ 3 files changed, 92 insertions(+) create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Rebounding.java create mode 100644 eco-core/core-plugin/src/main/resources/enchants/normal/rebounding.yml diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java index 60fa5ea5..1f3ca5e2 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java @@ -161,6 +161,7 @@ import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Radiance; import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Rage; import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Rapid; import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Reaper; +import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Rebounding; import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Reel; import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Reinforcement; import com.willfp.ecoenchants.enchantments.ecoenchants.normal.Rejuvenation; @@ -489,6 +490,7 @@ public class EcoEnchants { public static final EcoEnchant SWEEP_ARTIFACT = new SweepArtifact(); public static final EcoEnchant REAPER = new Reaper(); public static final EcoEnchant WOOD_SWITCHER = new WoodSwitcher(); + public static final EcoEnchant REBOUNDING = new Rebounding(); /** * Get all registered {@link EcoEnchant}s. diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Rebounding.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Rebounding.java new file mode 100644 index 00000000..4e23c9cc --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Rebounding.java @@ -0,0 +1,63 @@ +package com.willfp.ecoenchants.enchantments.ecoenchants.normal; + +import com.willfp.eco.util.VectorUtils; +import com.willfp.ecoenchants.enchantments.EcoEnchant; +import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; +import com.willfp.ecoenchants.enchantments.util.EnchantChecks; +import org.bukkit.entity.LivingEntity; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; + +public class Rebounding extends EcoEnchant { + public Rebounding() { + super( + "rebounding", EnchantmentType.NORMAL + ); + } + + @EventHandler + public void onDamage(@NotNull final EntityDamageByEntityEvent event) { + if (!(event.getEntity() instanceof LivingEntity)) { + return; + } + + if (!(event.getDamager() instanceof LivingEntity)) { + return; + } + + if (event.isCancelled()) { + return; + } + + LivingEntity victim = (LivingEntity) event.getEntity(); + LivingEntity attacker = (LivingEntity) event.getDamager(); + + int level = EnchantChecks.getArmorPoints(attacker, this); + + if (level == 0) { + return; + } + + if (this.getDisabledWorlds().contains(attacker.getWorld())) { + return; + } + + Vector vector = attacker.getLocation().toVector().clone().subtract(victim.getLocation().toVector()).normalize() + .multiply((-level * (this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "velocity-multiplier") - 1)) + 1); + + if (!VectorUtils.isFinite(vector)) { + return; + } + + vector.setY(0.2); + + if (!VectorUtils.isFinite(vector)) { + return; + } + + attacker.setVelocity(vector); + } +} diff --git a/eco-core/core-plugin/src/main/resources/enchants/normal/rebounding.yml b/eco-core/core-plugin/src/main/resources/enchants/normal/rebounding.yml new file mode 100644 index 00000000..37eaeb98 --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/normal/rebounding.yml @@ -0,0 +1,27 @@ +# +# Rebounding EcoEnchant +# + +name: "Rebounding" +description: Deal knockback to entities that attack you. +enabled: true + +obtaining: + table: true + villager: true + loot: true + rarity: epic + +general-config: + targets: + - helmet + - chestplate + - leggings + - boots + grindstoneable: true + disabled-in-worlds: [ ] + conflicts: [ ] + maximum-level: 2 + +config: + velocity-multiplier: 1.2