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

Did more requested changes.

This commit is contained in:
LinoxGH 2020-06-28 05:29:51 +03:00
parent a935951c22
commit 3e271ac786
5 changed files with 39 additions and 44 deletions

View File

@ -455,7 +455,6 @@ public final class PlayerProfile {
public boolean isProtected(ProtectionType type) {
int armorCount = 0;
boolean first = true;
NamespacedKey setId = null;
for (HashedArmorpiece armor : armor) {
@ -465,16 +464,15 @@ public final class PlayerProfile {
if (armorPiece.get() instanceof CustomProtection) {
CustomProtection protectedArmor = (CustomProtection) armorPiece.get();
if (first) {
if (protectedArmor.isFullSetRequired()) setId = armorPiece.get().getSetId();
first = false;
if (setId == null && protectedArmor.isFullSetRequired()) {
setId = protectedArmor.getSetId();
}
for (ProtectionType protectionType : protectedArmor.getProtectionTypes()) {
if (protectionType == type) {
if (setId == null) {
return true;
} else if (setId.equals(armorPiece.get().getSetId())) {
} else if (setId.equals(protectedArmor.getSetId())) {
armorCount++;
}
}

View File

@ -1,5 +1,6 @@
package io.github.thebusybiscuit.slimefun4.core.attributes;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
@ -7,12 +8,12 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.armor.HazmatArmor
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece;
/**
* Implement this interface for any {@link SlimefunArmorPiece} to prevent
* the {@link Player} wearing that {@link SlimefunArmorPiece}
* Implement this interface to a {@link SlimefunArmorPiece} to protect
* the {@link Player} who wears that {@link SlimefunArmorPiece} from
* {@link ProtectionType} damage.
*
* <b>Important</b>: This will not cancel any {@link EntityDamageEvent}.
* It will simply prevent Slimefun from ever applying {@link ProtectionType}
* to this {@link SlimefunArmorPiece}'s wearer.
* <b>Important:</b> You need to specify which {@link ProtectionType} damages
* to protect the {@link Player} from.
*
* @author Linox
*
@ -24,18 +25,25 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArm
public interface CustomProtection extends ItemAttribute {
/**
* This returns the {@link ProtectionType}s this {@link ItemAttribute}
* prevents the assigned {@link SlimefunArmorPiece} to be damaged by.
* This returns which {@link ProtectionType} damages this {@link ItemAttribute}
* will protect the {@link Player} from.
*
* @return The {@link ProtectionType}s
* @return The {@link ProtectionType}s.
*/
ProtectionType[] getProtectionTypes();
/**
* This returns the {@link ProtectionType}s this {@link ItemAttribute}
* prevents the assigned {@link SlimefunArmorPiece} to be damaged by.
* This returns whether the full set is required for {@link Player}'s protection on
* assigned {@link ProtectionType} damages.
*
* @return The {@link ProtectionType}s
* @return Whether or not he full set is required.
*/
boolean isFullSetRequired();
/**
* This returns the armor set {@link NamespacedKey} of this {@link SlimefunArmorPiece}.
*
* @return The set {@link NamespacedKey}, <code>null</code> if none is found.
*/
NamespacedKey getSetId();
}

View File

@ -5,7 +5,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
@ -14,6 +13,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import io.github.thebusybiscuit.slimefun4.core.attributes.MachineTier;
import io.github.thebusybiscuit.slimefun4.core.attributes.MachineType;
@ -299,36 +299,35 @@ public final class SlimefunItems {
REINFORCED_ALLOY_BOOTS.addUnsafeEnchantments(reinforced);
if (SlimefunPlugin.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_15)) {
ItemMeta scubaHelmetMeta = SCUBA_HELMET.getItemMeta();
List<String> scubaHelmetMetaLore = scubaHelmetMeta.getLore();
scubaHelmetMetaLore.addAll(Arrays.asList("",
ChatColor.translateAlternateColorCodes('&', "&7Equip the full set for:"),
ChatColor.translateAlternateColorCodes('&', "&7+Bee Protection")));
ChatColors.color( "&7Equip the full set for:"),
ChatColors.color( "&7+Bee Protection")));
scubaHelmetMeta.setLore(scubaHelmetMetaLore);
SCUBA_HELMET.setItemMeta(scubaHelmetMeta);
ItemMeta hazmatChestplateItemMeta = HAZMAT_CHESTPLATE.getItemMeta();
List<String> hazmatChestplateItemMetaLore = hazmatChestplateItemMeta.getLore();
hazmatChestplateItemMetaLore.addAll(Arrays.asList("",
ChatColor.translateAlternateColorCodes('&', "&7Equip the full set for:"),
ChatColor.translateAlternateColorCodes('&', "&7+Bee Protection")));
ChatColors.color( "&7Equip the full set for:"),
ChatColors.color( "&7+Bee Protection")));
hazmatChestplateItemMeta.setLore(hazmatChestplateItemMetaLore);
HAZMAT_CHESTPLATE.setItemMeta(hazmatChestplateItemMeta);
ItemMeta hazmatLeggingsItemMeta = HAZMAT_LEGGINGS.getItemMeta();
List<String> hazmatLeggingsItemMetaLore = hazmatLeggingsItemMeta.getLore();
hazmatLeggingsItemMetaLore.addAll(Arrays.asList("",
ChatColor.translateAlternateColorCodes('&', "&7Equip the full set for:"),
ChatColor.translateAlternateColorCodes('&', "&7+Bee Protection")));
ChatColors.color( "&7Equip the full set for:"),
ChatColors.color( "&7+Bee Protection")));
hazmatLeggingsItemMeta.setLore(hazmatLeggingsItemMetaLore);
HAZMAT_LEGGINGS.setItemMeta(hazmatLeggingsItemMeta);
ItemMeta rubberBootsItemMeta = RUBBER_BOOTS.getItemMeta();
List<String> rubberBootsItemMetaLore = rubberBootsItemMeta.getLore();
rubberBootsItemMetaLore.addAll(Arrays.asList("",
ChatColor.translateAlternateColorCodes('&', "&7Equip the full set for:"),
ChatColor.translateAlternateColorCodes('&', "&7+Bee Protection")));
ChatColors.color( "&7Equip the full set for:"),
ChatColors.color( "&7+Bee Protection")));
rubberBootsItemMeta.setLore(rubberBootsItemMetaLore);
RUBBER_BOOTS.setItemMeta(rubberBootsItemMeta);
}

View File

@ -23,12 +23,14 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
*/
public class HazmatArmorPiece extends SlimefunArmorPiece implements CustomProtection {
private final NamespacedKey setId;
private final ProtectionType[] types;
public HazmatArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects) {
super(category, item, recipeType, recipe, effects, new NamespacedKey(SlimefunPlugin.instance, "hazmat_suit"));
super(category, item, recipeType, recipe, effects);
types = new ProtectionType[] {ProtectionType.BEES, ProtectionType.RADIATION};
setId = new NamespacedKey(SlimefunPlugin.instance, "hazmat_suit");
}
@Override
@ -40,4 +42,9 @@ public class HazmatArmorPiece extends SlimefunArmorPiece implements CustomProtec
public boolean isFullSetRequired() {
return true;
}
@Override
public NamespacedKey getSetId() {
return setId;
}
}

View File

@ -1,11 +1,9 @@
package io.github.thebusybiscuit.slimefun4.implementation.items.armor;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@ -13,7 +11,6 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class SlimefunArmorPiece extends SlimefunItem {
private NamespacedKey id = null;
private final PotionEffect[] effects;
public SlimefunArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects) {
@ -22,11 +19,6 @@ public class SlimefunArmorPiece extends SlimefunItem {
this.effects = effects == null ? new PotionEffect[0] : effects;
}
public SlimefunArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects, NamespacedKey setId) {
this(category, item, recipeType, recipe, effects);
this.id = setId;
}
/**
* An Array of {@link PotionEffect PotionEffects} which get applied to a {@link Player} wearing
* this {@link SlimefunArmorPiece}.
@ -36,13 +28,4 @@ public class SlimefunArmorPiece extends SlimefunItem {
public PotionEffect[] getPotionEffects() {
return effects;
}
/**
* This returns the armor set {@link NamespacedKey} of this {@link SlimefunArmorPiece}.
*
* @return The set {@link NamespacedKey}, <code>null</code> if none is found.
*/
public NamespacedKey getSetId() {
return id;
}
}