From a4dc1428bc5bc52362c95ac3049079cbe12d977d Mon Sep 17 00:00:00 2001 From: Seggan Date: Mon, 5 Oct 2020 17:02:09 -0400 Subject: [PATCH] Changed protection check (untested) --- .../listeners/ElytraCrashListener.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/ElytraCrashListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/ElytraCrashListener.java index 8f43a7b28..f26d569b6 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/ElytraCrashListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/ElytraCrashListener.java @@ -1,5 +1,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.listeners; +import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile; import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem; import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType; import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectiveArmor; @@ -17,6 +18,7 @@ import org.bukkit.inventory.ItemStack; import javax.annotation.Nonnull; import java.util.Arrays; +import java.util.Optional; /** * The {@link Listener} for the {@link ElytraCap}. @@ -41,12 +43,19 @@ public class ElytraCrashListener implements Listener { SlimefunItem item = SlimefunItem.getByItem(stack); 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 && item instanceof DamageableItem) { - ((DamageableItem) item).damageItem(p, stack); + Optional optional = PlayerProfile.find(p); + if (!optional.isPresent()) { + PlayerProfile.request(p); + return; + } + PlayerProfile profile = optional.get(); + + if (profile.hasFullProtectionAgainst(ProtectionType.FLYING_INTO_WALL)) { + e.setDamage(0); + p.playSound(p.getLocation(), Sound.BLOCK_STONE_HIT, 20, 1); + if (p.getGameMode() != GameMode.CREATIVE && item instanceof DamageableItem) { + ((DamageableItem) item).damageItem(p, stack); + } } } }