diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/ProtectionType.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/ProtectionType.java index df48ca2eb..bb2fd0a17 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/ProtectionType.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/ProtectionType.java @@ -21,6 +21,11 @@ public enum ProtectionType { /** * This damage type represents damage caused by a {@link Bee} */ - BEES; + BEES, + + /** + * This damage type represents damage caused by flying into a wall with an elytra + */ + FLYING_INTO_WALL; } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/ElytraCap.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/ElytraCap.java index f81ab0e6f..025b7a027 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/ElytraCap.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/ElytraCap.java @@ -1,25 +1,51 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.armor; import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem; +import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType; +import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectiveArmor; +import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; +import org.bukkit.NamespacedKey; import org.bukkit.inventory.ItemStack; -import org.bukkit.potion.PotionEffect; + +import javax.annotation.Nonnull; /** * The {@link ElytraCap} negates damage taken when crashing into a wall using elytra. * * @author Seggan */ -public class ElytraCap extends SlimefunArmorPiece implements DamageableItem { +public class ElytraCap extends SlimefunArmorPiece implements DamageableItem, ProtectiveArmor { - public ElytraCap(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects) { - super(category, item, recipeType, recipe, effects); + private NamespacedKey key; + + public ElytraCap(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { + super(category, item, recipeType, recipe, null); + + key = new NamespacedKey(SlimefunPlugin.instance(), "elytra_armor"); } @Override public boolean isDamageable() { return true; } + + @Nonnull + @Override + public ProtectionType[] getProtectionTypes() { + return new ProtectionType[] {ProtectionType.FLYING_INTO_WALL}; + } + + @Override + public boolean isFullSetRequired() { + return false; + } + + @Nonnull + @Override + public NamespacedKey getArmorSetId() { + return key; + } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/ElytraCapListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/ElytraCapListener.java index 656ceaee3..3460ac580 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/ElytraCapListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/ElytraCapListener.java @@ -1,6 +1,8 @@ package io.github.thebusybiscuit.slimefun4.implementation.listeners; import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem; +import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType; +import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectiveArmor; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.items.armor.ElytraCap; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; @@ -12,9 +14,9 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.Damageable; import javax.annotation.Nonnull; +import java.util.Arrays; /** * The {@link Listener} for the {@link ElytraCap}. @@ -36,13 +38,15 @@ public class ElytraCapListener implements Listener { Player p = (Player) e.getEntity(); if (p.isGliding()) { ItemStack stack = p.getInventory().getHelmet(); - if (!Slimefun.hasUnlocked(p, stack, true)) return; SlimefunItem item = SlimefunItem.getByItem(stack); - if (item instanceof ElytraCap) { + if (!Slimefun.hasUnlocked(p, item, true)) return; + if (item instanceof ProtectiveArmor) { + if (!Arrays.asList(((ProtectiveArmor) item).getProtectionTypes()) + .contains(ProtectionType.FLYING_INTO_WALL)) return; e.setDamage(0); p.playSound(p.getLocation(), Sound.BLOCK_STONE_HIT, 20, 1); - if (p.getGameMode() != GameMode.CREATIVE) { - ((ElytraCap) item).damageItem(p, stack); + if (p.getGameMode() != GameMode.CREATIVE && item instanceof DamageableItem) { + ((DamageableItem) item).damageItem(p, stack); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java index 118f4e2fa..23f8e9fed 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/setup/SlimefunItemSetup.java @@ -1018,7 +1018,7 @@ public final class SlimefunItemSetup { .register(plugin); new ElytraCap(categories.technicalGadgets, SlimefunItems.ELYTRA_CAP, RecipeType.ARMOR_FORGE, - new ItemStack[]{new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), SlimefunItems.ELYTRA_SCALE, SlimefunItems.ELYTRA_SCALE, SlimefunItems.ELYTRA_SCALE, new ItemStack(Material.SLIME_BALL), new ItemStack(Material.LEATHER_HELMET), new ItemStack(Material.SLIME_BALL)}, null) + new ItemStack[]{new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), new ItemStack(Material.SLIME_BALL), SlimefunItems.ELYTRA_SCALE, SlimefunItems.ELYTRA_SCALE, SlimefunItems.ELYTRA_SCALE, new ItemStack(Material.SLIME_BALL), new ItemStack(Material.LEATHER_HELMET), new ItemStack(Material.SLIME_BALL)}) .register(plugin); new PickaxeOfContainment(categories.tools, SlimefunItems.PICKAXE_OF_CONTAINMENT, RecipeType.MAGIC_WORKBENCH,