1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Changed protection check (untested)

This commit is contained in:
Seggan 2020-10-05 17:02:09 -04:00
parent 4b3e31a8c7
commit a4dc1428bc

View File

@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.implementation.listeners; 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.DamageableItem;
import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType; import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType;
import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectiveArmor; import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectiveArmor;
@ -17,6 +18,7 @@ import org.bukkit.inventory.ItemStack;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Arrays; import java.util.Arrays;
import java.util.Optional;
/** /**
* The {@link Listener} for the {@link ElytraCap}. * The {@link Listener} for the {@link ElytraCap}.
@ -41,12 +43,19 @@ public class ElytraCrashListener implements Listener {
SlimefunItem item = SlimefunItem.getByItem(stack); SlimefunItem item = SlimefunItem.getByItem(stack);
if (!Slimefun.hasUnlocked(p, item, true)) return; if (!Slimefun.hasUnlocked(p, item, true)) return;
if (item instanceof ProtectiveArmor) { if (item instanceof ProtectiveArmor) {
if (!Arrays.asList(((ProtectiveArmor) item).getProtectionTypes()) Optional<PlayerProfile> optional = PlayerProfile.find(p);
.contains(ProtectionType.FLYING_INTO_WALL)) return; if (!optional.isPresent()) {
e.setDamage(0); PlayerProfile.request(p);
p.playSound(p.getLocation(), Sound.BLOCK_STONE_HIT, 20, 1); return;
if (p.getGameMode() != GameMode.CREATIVE && item instanceof DamageableItem) { }
((DamageableItem) item).damageItem(p, stack); 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);
}
} }
} }
} }