From d351c0b0c1fcc97a4f9d6b7b89e127ad7d45357e Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 30 Aug 2020 11:14:11 +0100 Subject: [PATCH] Added Block Breather --- .../ecoenchants/enchantments/EcoEnchants.java | 1 + .../ecoenchants/normal/BlockBreather.java | 43 +++++++++++++++++++ .../enchants/normal/blockbreather.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/BlockBreather.java create mode 100644 Plugin/src/main/resources/enchants/normal/blockbreather.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 ab47f6c6..08678724 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/EcoEnchants.java @@ -222,6 +222,7 @@ public class EcoEnchants { public static final EcoEnchant LESION = new Lesion(); public static final EcoEnchant CONCLUDE = new Conclude(); public static final EcoEnchant GRACEFUL = new Graceful(); + public static final EcoEnchant BLOCK_BREATHER = new BlockBreather(); /** * Get all registered {@link EcoEnchant}s diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/BlockBreather.java b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/BlockBreather.java new file mode 100644 index 00000000..1b04f2fd --- /dev/null +++ b/Plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/BlockBreather.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.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent; + +public class BlockBreather extends EcoEnchant { + public BlockBreather() { + super( + new EcoEnchantBuilder("block_breather", EnchantmentType.NORMAL, Target.Applicable.HELMET, 4.0) + ); + } + + // START OF LISTENERS + + @EventHandler + public void onHurt(EntityDamageEvent event) { + if (!(event.getEntity() instanceof Player)) + return; + + if(!event.getCause().equals(EntityDamageEvent.DamageCause.SUFFOCATION)) + return; + + Player player = (Player) event.getEntity(); + + if(!EnchantChecks.helmet(player, this)) return; + int level = EnchantChecks.getHelmetLevel(player, this); + + double chance = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "chance-per-level"); + + if (Rand.randFloat(0, 1) > level * 0.01 * chance) + return; + + event.setCancelled(true); + } + +} diff --git a/Plugin/src/main/resources/enchants/normal/blockbreather.yml b/Plugin/src/main/resources/enchants/normal/blockbreather.yml new file mode 100644 index 00000000..e23f0093 --- /dev/null +++ b/Plugin/src/main/resources/enchants/normal/blockbreather.yml @@ -0,0 +1,23 @@ +# +# Block Breather EcoEnchant +# + +config-version: 4.0 # Don't edit this. + +name: "Block Breather" + +description: Chance to ignore suffocation damage. + +obtaining: + table: true + villager: true + loot: true + rarity: rare + +general-config: + grindstoneable: true + conflicts: [] + maximum-level: 3 + +config: + chance-per-level: 15 \ No newline at end of file diff --git a/Plugin/src/main/resources/plugin.yml b/Plugin/src/main/resources/plugin.yml index 200ed22c..714d389d 100644 --- a/Plugin/src/main/resources/plugin.yml +++ b/Plugin/src/main/resources/plugin.yml @@ -241,6 +241,7 @@ permissions: ecoenchants.fromtable.lesion: true ecoenchants.fromtable.conclude: true ecoenchants.fromtable.graceful: true + ecoenchants.fromtable.blockbreather: true ecoenchants.updateannounce: description: Informs admins of a new update @@ -836,4 +837,7 @@ permissions: default: true ecoenchants.fromtable.graceful: description: Allows getting graceful from an enchanting table + default: true + ecoenchants.fromtable.blockbreather: + description: Allows getting block breather from an enchanting table default: true \ No newline at end of file