diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/CustomProtection.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/CustomProtection.java
new file mode 100644
index 000000000..c142ca7fc
--- /dev/null
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/CustomProtection.java
@@ -0,0 +1,48 @@
+package io.github.thebusybiscuit.slimefun4.core.attributes;
+
+import org.bukkit.entity.Player;
+import org.bukkit.event.entity.EntityDamageEvent;
+
+import io.github.thebusybiscuit.slimefun4.implementation.items.armor.HazmatArmorPiece;
+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}
+ *
+ * Important: This will not cancel any {@link EntityDamageEvent}.
+ * It will simply prevent Slimefun from ever applying {@link ProtectionType}
+ * to this {@link SlimefunArmorPiece}'s wearer.
+ *
+ * @author Linox
+ *
+ * @see SlimefunArmorPiece
+ * @see HazmatArmorPiece
+ * @see ItemAttribute
+ *
+ */
+public interface CustomProtection extends ItemAttribute {
+
+ /**
+ * This returns the {@link ProtectionType}s this {@link ItemAttribute}
+ * prevents the assigned {@link SlimefunArmorPiece} to be damaged by.
+ *
+ * @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.
+ *
+ * @return The {@link ProtectionType}s
+ */
+ boolean requireFullSet();
+
+ enum ProtectionType {
+
+ RADIATION,
+
+ BEES;
+ }
+}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java
new file mode 100644
index 000000000..0216d1036
--- /dev/null
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/HazmatArmorPiece.java
@@ -0,0 +1,30 @@
+package io.github.thebusybiscuit.slimefun4.implementation.items.armor;
+
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.potion.PotionEffect;
+
+import io.github.thebusybiscuit.slimefun4.core.attributes.CustomProtection;
+import me.mrCookieSlime.Slimefun.Lists.RecipeType;
+import me.mrCookieSlime.Slimefun.Objects.Category;
+import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
+
+public class HazmatArmorPiece extends SlimefunArmorPiece implements CustomProtection {
+
+ private final ProtectionType[] types;
+
+ public HazmatArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects, String setID) {
+ super(category, item, recipeType, recipe, effects, setID);
+
+ types = new ProtectionType[] {ProtectionType.BEES, ProtectionType.RADIATION};
+ }
+
+ @Override
+ public ProtectionType[] getProtectionTypes() {
+ return types;
+ }
+
+ @Override
+ public boolean requireFullSet() {
+ return true;
+ }
+}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java
index 925934c64..40c8540ad 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/armor/SlimefunArmorPiece.java
@@ -11,6 +11,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class SlimefunArmorPiece extends SlimefunItem {
+ private String setID = null;
private final PotionEffect[] effects;
public SlimefunArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects) {
@@ -19,6 +20,12 @@ 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, String setID) {
+ this(category, item, recipeType, recipe, effects);
+
+ this.setID = setID;
+ }
+
/**
* An Array of {@link PotionEffect PotionEffects} which get applied to a {@link Player} wearing
* this {@link SlimefunArmorPiece}.
@@ -29,4 +36,12 @@ public class SlimefunArmorPiece extends SlimefunItem {
return effects;
}
+ /**
+ * This returns the armor set ID of this {@link SlimefunArmorPiece}.
+ *
+ * @return The set ID, null
if no set ID is found.
+ */
+ public String getSetID() {
+ return setID;
+ }
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java
index a23335ece..57b54b787 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeListener.java
@@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.listeners;
import java.util.Optional;
+import io.github.thebusybiscuit.slimefun4.core.attributes.CustomProtection;
import org.bukkit.entity.Bee;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@@ -12,6 +13,7 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.inventory.ItemUtils;
import io.github.thebusybiscuit.slimefun4.api.items.HashedArmorpiece;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
+import io.github.thebusybiscuit.slimefun4.implementation.items.armor.HazmatArmorPiece;
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
@@ -30,39 +32,55 @@ public class BeeListener implements Listener {
@EventHandler
public void onDamage(EntityDamageByEntityEvent e) {
- if (e.getDamager() instanceof Bee) {
- if (e.getEntity() instanceof Player) {
- Player p = (Player) e.getEntity();
- PlayerProfile.get(p, profile -> {
+ if (e.getDamager() instanceof Bee && e.getEntity() instanceof Player) {
- HashedArmorpiece[] armors = profile.getArmor();
- if (hasFullHazmat(armors)) {
- for (ItemStack armor : p.getInventory().getArmorContents()) {
- ItemUtils.damageItem(armor, 1, false);
- }
- e.setDamage(0D);
- }
- });
+ Player p = (Player) e.getEntity();
+ Optional optional = PlayerProfile.find(p);
+ if (!optional.isPresent()) {
+ PlayerProfile.request(p);
+ return;
+ }
+ PlayerProfile profile = optional.get();
+
+ HashedArmorpiece[] armors = profile.getArmor();
+ if (shouldProtect(armors)) {
+ for (ItemStack armor : p.getInventory().getArmorContents()) {
+ ItemUtils.damageItem(armor, 1, false);
+ }
+ e.setDamage(0D);
}
}
}
- private boolean hasFullHazmat(HashedArmorpiece[] armors) {
- int hazmatCount = 0;
+ private boolean shouldProtect(HashedArmorpiece[] armors) {
+ int armorCount = 0;
+ boolean first = true;
- // Check for a Hazmat Suit
+ String setID = null;
for (HashedArmorpiece armor : armors) {
Optional armorPiece = armor.getItem();
if (!armorPiece.isPresent()) return false;
- if (armorPiece.get().getID().equals("SCUBA_HELMET") ||
- armorPiece.get().getID().equals("HAZMAT_CHESTPLATE") ||
- armorPiece.get().getID().equals("HAZMAT_LEGGINGS") ||
- armorPiece.get().getID().equals("RUBBER_BOOTS")) {
- hazmatCount++;
+ if (armorPiece.get() instanceof CustomProtection) {
+ CustomProtection protectedArmor = (CustomProtection) armorPiece.get();
+
+ if (first) {
+ if (protectedArmor.requireFullSet()) setID = armorPiece.get().getSetID();
+ first = false;
+ }
+
+ for (CustomProtection.ProtectionType protectionType : protectedArmor.getProtectionTypes()) {
+ if (protectionType == CustomProtection.ProtectionType.BEES) {
+ if (setID == null) {
+ return true;
+ }
+ armorCount++;
+ }
+ }
+
}
}
- return hazmatCount == 4;
+ return armorCount == 4;
}
}
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 1395f213f..f0b0d6e71 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
@@ -3,6 +3,7 @@ package io.github.thebusybiscuit.slimefun4.implementation.setup;
import java.util.ArrayList;
import java.util.List;
+import io.github.thebusybiscuit.slimefun4.implementation.items.armor.HazmatArmorPiece;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.inventory.ItemStack;
@@ -903,22 +904,22 @@ public final class SlimefunItemSetup {
SlimefunItems.GILDED_IRON_HELMET, SlimefunItems.GILDED_IRON_CHESTPLATE, SlimefunItems.GILDED_IRON_LEGGINGS, SlimefunItems.GILDED_IRON_BOOTS
}, "GILDED_IRON", false, plugin);
- new SlimefunArmorPiece(categories.armor, SlimefunItems.SCUBA_HELMET, RecipeType.ARMOR_FORGE,
+ new HazmatArmorPiece(categories.armor, SlimefunItems.SCUBA_HELMET, RecipeType.ARMOR_FORGE,
new ItemStack[] {new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.GLASS_PANE), new ItemStack(Material.BLACK_WOOL), null, null, null},
- new PotionEffect[] {new PotionEffect(PotionEffectType.WATER_BREATHING, 300, 1)})
+ new PotionEffect[] {new PotionEffect(PotionEffectType.WATER_BREATHING, 300, 1)}, "HAZMAT_SUIT")
.register(plugin);
- new SlimefunArmorPiece(categories.armor, SlimefunItems.HAZMAT_CHESTPLATE, RecipeType.ARMOR_FORGE,
+ new HazmatArmorPiece(categories.armor, SlimefunItems.HAZMAT_CHESTPLATE, RecipeType.ARMOR_FORGE,
new ItemStack[] {new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL)},
- new PotionEffect[] {new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 300, 1)})
+ new PotionEffect[] {new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 300, 1)}, "HAZMAT_SUIT")
.register(plugin);
- new SlimefunArmorPiece(categories.armor, SlimefunItems.HAZMAT_LEGGINGS, RecipeType.ARMOR_FORGE,
- new ItemStack[] {new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL)}, null)
+ new HazmatArmorPiece(categories.armor, SlimefunItems.HAZMAT_LEGGINGS, RecipeType.ARMOR_FORGE,
+ new ItemStack[] {new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL), new ItemStack(Material.ORANGE_WOOL), null, new ItemStack(Material.ORANGE_WOOL)}, null, "HAZMAT_SUIT")
.register(plugin);
- new SlimefunArmorPiece(categories.armor, SlimefunItems.RUBBER_BOOTS, RecipeType.ARMOR_FORGE,
- new ItemStack[] {null, null, null, new ItemStack(Material.BLACK_WOOL), null, new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), null, new ItemStack(Material.BLACK_WOOL)}, null)
+ new HazmatArmorPiece(categories.armor, SlimefunItems.RUBBER_BOOTS, RecipeType.ARMOR_FORGE,
+ new ItemStack[] {null, null, null, new ItemStack(Material.BLACK_WOOL), null, new ItemStack(Material.BLACK_WOOL), new ItemStack(Material.BLACK_WOOL), null, new ItemStack(Material.BLACK_WOOL)}, null, "HAZMAT_SUIT")
.register(plugin);
new SlimefunItem(categories.misc, SlimefunItems.CRUSHED_ORE, RecipeType.ORE_CRUSHER,
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java
index 8203ee9d3..69dd15444 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/tasks/ArmorTask.java
@@ -15,6 +15,7 @@ import org.bukkit.potion.PotionEffectType;
import io.github.thebusybiscuit.slimefun4.api.items.HashedArmorpiece;
import io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile;
+import io.github.thebusybiscuit.slimefun4.core.attributes.CustomProtection;
import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece;
@@ -64,7 +65,7 @@ public class ArmorTask implements Runnable {
checkForSolarHelmet(p);
}
- checkForRadiation(profile);
+ checkForRadiation(p, profile);
});
}
}
@@ -120,35 +121,19 @@ public class ArmorTask implements Runnable {
return (world.getTime() < 12300 || world.getTime() > 23850) && p.getEyeLocation().getBlock().getLightFromSky() == 15;
}
- private void checkForRadiation(PlayerProfile profile) {
+ private void checkForRadiation(Player p, PlayerProfile profile) {
HashedArmorpiece[] armor = profile.getArmor();
- Player p = profile.getPlayer();
- // Check for a Hazmat Suit
- boolean hasHazmat = false;
- for (HashedArmorpiece armorPiece : armor) {
-
- Optional sfArmor = armorPiece.getItem();
- if (!sfArmor.isPresent()) continue;
-
- if (sfArmor.get().getID().equals("SCUBA_HELMET") ||
- sfArmor.get().getID().equals("HAZMAT_CHESTPLATE") ||
- sfArmor.get().getID().equals("HAZMAT_LEGGINGS") ||
- sfArmor.get().getID().equals("RUBBER_BOOTS")) {
- hasHazmat = true;
- }
- }
-
- if (!hasHazmat) {
+ if (!shouldProtect(armor)) {
for (ItemStack item : p.getInventory()) {
- if (isRadioactive(p, item)) {
+ if (checkAndApplyRadioactive(p, item)) {
break;
}
}
}
}
- private boolean isRadioactive(Player p, ItemStack item) {
+ private boolean checkAndApplyRadioactive(Player p, ItemStack item) {
for (SlimefunItem radioactiveItem : SlimefunPlugin.getRegistry().getRadioactiveItems()) {
if (radioactiveItem.isItem(item) && Slimefun.isEnabled(p, radioactiveItem, true)) {
// If the item is enabled in the world, then make radioactivity do its job
@@ -166,4 +151,35 @@ public class ArmorTask implements Runnable {
return false;
}
+ private boolean shouldProtect(HashedArmorpiece[] armors) {
+ int armorCount = 0;
+ boolean first = true;
+
+ String setID = null;
+ for (HashedArmorpiece armor : armors) {
+ Optional armorPiece = armor.getItem();
+ if (!armorPiece.isPresent()) return false;
+
+ if (armorPiece.get() instanceof CustomProtection) {
+ CustomProtection protectedArmor = (CustomProtection) armorPiece.get();
+
+ if (first) {
+ if (protectedArmor.requireFullSet()) setID = armorPiece.get().getSetID();
+ first = false;
+ }
+
+ for (CustomProtection.ProtectionType protectionType : protectedArmor.getProtectionTypes()) {
+ if (protectionType == CustomProtection.ProtectionType.RADIATION) {
+ if (setID == null) {
+ return true;
+ }
+ armorCount++;
+ }
+ }
+
+ }
+ }
+
+ return armorCount == 4;
+ }
}