From f152845c732881a7e1bba93f4a155d4315e80012 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 30 Aug 2020 10:58:44 +0100 Subject: [PATCH] Added Graceful --- .../ecoenchants/enchantments/EcoEnchants.java | 1 + .../ecoenchants/normal/Graceful.java | 43 +++++++++++++++++++ .../resources/enchants/normal/graceful.yml | 23 ++++++++++ Plugin/src/main/resources/plugin.yml | 4 ++ 4 files changed, 71 insertions(+) create mode 100644 Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Graceful.java create mode 100644 Plugin/src/main/resources/enchants/normal/graceful.yml diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java index d912a90c..ab47f6c6 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java @@ -221,6 +221,7 @@ public class EcoEnchants { public static final EcoEnchant QUADRILATERALISM = new Quadrilateralism(); public static final EcoEnchant LESION = new Lesion(); public static final EcoEnchant CONCLUDE = new Conclude(); + public static final EcoEnchant GRACEFUL = new Graceful(); /** * Get all registered {@link EcoEnchant}s diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Graceful.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Graceful.java new file mode 100644 index 00000000..8b401991 --- /dev/null +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Graceful.java @@ -0,0 +1,43 @@ +package com.willfp.ecoenchants.enchantments.ecoenchants.normal; + +import com.willfp.ecoenchants.enchantments.EcoEnchant; +import com.willfp.ecoenchants.enchantments.EcoEnchantBuilder; +import com.willfp.ecoenchants.enchantments.EcoEnchants; +import com.willfp.ecoenchants.enchantments.util.checks.EnchantChecks; +import com.willfp.ecoenchants.nms.Target; +import com.willfp.ecoenchants.util.Rand; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class Graceful extends EcoEnchant { + public Graceful() { + super( + new EcoEnchantBuilder("graceful", EnchantmentType.NORMAL, Target.Applicable.BOOTS, 4.0) + ); + } + + // START OF LISTENERS + + @EventHandler + public void onFall(PlayerMoveEvent event) { + Player player = event.getPlayer(); + + if (player.isOnGround()) + return; + + if(player.getLocation().clone().add(0, -1, 0).getBlock().getType().equals(Material.AIR)) + return; + + if(!EnchantChecks.boots(player, this)) return; + int level = EnchantChecks.getBootsLevel(player, this); + + if (Rand.randFloat(0, 1) > level * 0.01 * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level")) + return; + + player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 20, 1, false, false, false)); + } +} diff --git a/Plugin/src/main/resources/enchants/normal/graceful.yml b/Plugin/src/main/resources/enchants/normal/graceful.yml new file mode 100644 index 00000000..8d5187ef --- /dev/null +++ b/Plugin/src/main/resources/enchants/normal/graceful.yml @@ -0,0 +1,23 @@ +# +# Graceful EcoEnchant +# + +config-version: 4.0 # Don't edit this. + +name: "Graceful" + +description: Chance of getting slow falling just above hitting the ground. + +obtaining: + table: true + villager: true + loot: true + rarity: legendary + +general-config: + grindstoneable: true + conflicts: [] + maximum-level: 4 + +config: + chance-per-level: 5 #chance of slow falling per level \ No newline at end of file diff --git a/Plugin/src/main/resources/plugin.yml b/Plugin/src/main/resources/plugin.yml index 2c134e23..200ed22c 100644 --- a/Plugin/src/main/resources/plugin.yml +++ b/Plugin/src/main/resources/plugin.yml @@ -240,6 +240,7 @@ permissions: ecoenchants.fromtable.quadrilateralism: true ecoenchants.fromtable.lesion: true ecoenchants.fromtable.conclude: true + ecoenchants.fromtable.graceful: true ecoenchants.updateannounce: description: Informs admins of a new update @@ -832,4 +833,7 @@ permissions: default: true ecoenchants.fromtable.conclude: description: Allows getting conclude from an enchanting table + default: true + ecoenchants.fromtable.graceful: + description: Allows getting graceful from an enchanting table default: true \ No newline at end of file