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

Added crash protection type

This commit is contained in:
Seggan 2020-10-04 21:59:10 -04:00
parent 8bbef4c911
commit d6df2ea00c
4 changed files with 46 additions and 11 deletions

View File

@ -21,6 +21,11 @@ public enum ProtectionType {
/** /**
* This damage type represents damage caused by a {@link Bee} * 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;
} }

View File

@ -1,25 +1,51 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.armor; package io.github.thebusybiscuit.slimefun4.implementation.items.armor;
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.ProtectiveArmor;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack; import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack; 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. * The {@link ElytraCap} negates damage taken when crashing into a wall using elytra.
* *
* @author Seggan * @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) { private NamespacedKey key;
super(category, item, recipeType, recipe, effects);
public ElytraCap(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe, null);
key = new NamespacedKey(SlimefunPlugin.instance(), "elytra_armor");
} }
@Override @Override
public boolean isDamageable() { public boolean isDamageable() {
return true; 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;
}
} }

View File

@ -1,6 +1,8 @@
package io.github.thebusybiscuit.slimefun4.implementation.listeners; package io.github.thebusybiscuit.slimefun4.implementation.listeners;
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.ProtectiveArmor;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.ElytraCap; import io.github.thebusybiscuit.slimefun4.implementation.items.armor.ElytraCap;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; 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.Listener;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.Damageable;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.Arrays;
/** /**
* The {@link Listener} for the {@link ElytraCap}. * The {@link Listener} for the {@link ElytraCap}.
@ -36,13 +38,15 @@ public class ElytraCapListener implements Listener {
Player p = (Player) e.getEntity(); Player p = (Player) e.getEntity();
if (p.isGliding()) { if (p.isGliding()) {
ItemStack stack = p.getInventory().getHelmet(); ItemStack stack = p.getInventory().getHelmet();
if (!Slimefun.hasUnlocked(p, stack, true)) return;
SlimefunItem item = SlimefunItem.getByItem(stack); 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); e.setDamage(0);
p.playSound(p.getLocation(), Sound.BLOCK_STONE_HIT, 20, 1); p.playSound(p.getLocation(), Sound.BLOCK_STONE_HIT, 20, 1);
if (p.getGameMode() != GameMode.CREATIVE) { if (p.getGameMode() != GameMode.CREATIVE && item instanceof DamageableItem) {
((ElytraCap) item).damageItem(p, stack); ((DamageableItem) item).damageItem(p, stack);
} }
} }
} }

View File

@ -1018,7 +1018,7 @@ public final class SlimefunItemSetup {
.register(plugin); .register(plugin);
new ElytraCap(categories.technicalGadgets, SlimefunItems.ELYTRA_CAP, RecipeType.ARMOR_FORGE, 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); .register(plugin);
new PickaxeOfContainment(categories.tools, SlimefunItems.PICKAXE_OF_CONTAINMENT, RecipeType.MAGIC_WORKBENCH, new PickaxeOfContainment(categories.tools, SlimefunItems.PICKAXE_OF_CONTAINMENT, RecipeType.MAGIC_WORKBENCH,