mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-20 03:35:51 +00:00
Did the requested changes + fixes.
This commit is contained in:
parent
a456034005
commit
64a1b247b4
@ -78,7 +78,7 @@ public final class HashedArmorpiece {
|
||||
*/
|
||||
public boolean hasDiverged(ItemStack stack) {
|
||||
if (stack == null || stack.getType() == Material.AIR) {
|
||||
return hash == 0;
|
||||
return hash != 0;
|
||||
}
|
||||
else {
|
||||
ItemStack copy = stack.clone();
|
||||
|
@ -19,6 +19,7 @@ import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -31,9 +32,12 @@ import io.github.thebusybiscuit.cscorelib2.chat.ChatColors;
|
||||
import io.github.thebusybiscuit.cscorelib2.config.Config;
|
||||
import io.github.thebusybiscuit.slimefun4.api.gps.Waypoint;
|
||||
import io.github.thebusybiscuit.slimefun4.api.items.HashedArmorpiece;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.CustomProtection;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType;
|
||||
import io.github.thebusybiscuit.slimefun4.core.guide.GuideHistory;
|
||||
import io.github.thebusybiscuit.slimefun4.core.researching.Research;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
|
||||
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
|
||||
import me.mrCookieSlime.Slimefun.api.Slimefun;
|
||||
@ -449,6 +453,39 @@ public final class PlayerProfile {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isProtected(ProtectionType type) {
|
||||
int armorCount = 0;
|
||||
boolean first = true;
|
||||
|
||||
NamespacedKey setId = null;
|
||||
for (HashedArmorpiece armor : armor) {
|
||||
Optional<SlimefunArmorPiece> armorPiece = armor.getItem();
|
||||
if (!armorPiece.isPresent()) return false;
|
||||
|
||||
if (armorPiece.get() instanceof CustomProtection) {
|
||||
CustomProtection protectedArmor = (CustomProtection) armorPiece.get();
|
||||
|
||||
if (first) {
|
||||
if (protectedArmor.isFullSetRequired()) setId = armorPiece.get().getSetId();
|
||||
first = false;
|
||||
}
|
||||
|
||||
for (ProtectionType protectionType : protectedArmor.getProtectionTypes()) {
|
||||
if (protectionType == type) {
|
||||
if (setId == null) {
|
||||
return true;
|
||||
} else if (setId.equals(armorPiece.get().getSetId())) {
|
||||
armorCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return armorCount == 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return uuid.hashCode();
|
||||
|
@ -37,12 +37,5 @@ public interface CustomProtection extends ItemAttribute {
|
||||
*
|
||||
* @return The {@link ProtectionType}s
|
||||
*/
|
||||
boolean requireFullSet();
|
||||
|
||||
enum ProtectionType {
|
||||
|
||||
RADIATION,
|
||||
|
||||
BEES;
|
||||
}
|
||||
boolean isFullSetRequired();
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
package io.github.thebusybiscuit.slimefun4.core.attributes;
|
||||
|
||||
public enum ProtectionType {
|
||||
|
||||
RADIATION,
|
||||
BEES;
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.CustomProtection;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType;
|
||||
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
|
||||
import me.mrCookieSlime.Slimefun.Objects.Category;
|
||||
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
@ -24,7 +25,7 @@ public class HazmatArmorPiece extends SlimefunArmorPiece implements CustomProtec
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requireFullSet() {
|
||||
public boolean isFullSetRequired() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
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;
|
||||
@ -11,7 +13,7 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
|
||||
|
||||
public class SlimefunArmorPiece extends SlimefunItem {
|
||||
|
||||
private String setID = null;
|
||||
private NamespacedKey id = null;
|
||||
private final PotionEffect[] effects;
|
||||
|
||||
public SlimefunArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects) {
|
||||
@ -20,10 +22,10 @@ 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) {
|
||||
public SlimefunArmorPiece(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, PotionEffect[] effects, String setId) {
|
||||
this(category, item, recipeType, recipe, effects);
|
||||
|
||||
this.setID = setID;
|
||||
this.id = new NamespacedKey(SlimefunPlugin.instance, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -37,11 +39,11 @@ public class SlimefunArmorPiece extends SlimefunItem {
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the armor set ID of this {@link SlimefunArmorPiece}.
|
||||
* This returns the armor set {@link NamespacedKey} of this {@link SlimefunArmorPiece}.
|
||||
*
|
||||
* @return The set ID, <code>null</code> if no set ID is found.
|
||||
* @return The set {@link NamespacedKey}, <code>null</code> if none is found.
|
||||
*/
|
||||
public String getSetID() {
|
||||
return setID;
|
||||
public NamespacedKey getSetId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
@ -10,11 +10,9 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
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.core.attributes.CustomProtection;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.ProtectionType;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece;
|
||||
|
||||
/**
|
||||
* The listener for Hazmat Suit's {@link Bee} sting protection.
|
||||
@ -39,10 +37,9 @@ public class BeeListener implements Listener {
|
||||
PlayerProfile.request(p);
|
||||
return;
|
||||
}
|
||||
PlayerProfile profile = optional.get();
|
||||
|
||||
HashedArmorpiece[] armors = profile.getArmor();
|
||||
if (shouldProtect(armors)) {
|
||||
PlayerProfile profile = optional.get();
|
||||
if (profile.isProtected(ProtectionType.BEES)) {
|
||||
for (ItemStack armor : p.getInventory().getArmorContents()) {
|
||||
ItemUtils.damageItem(armor, 1, false);
|
||||
}
|
||||
@ -51,35 +48,4 @@ public class BeeListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldProtect(HashedArmorpiece[] armors) {
|
||||
int armorCount = 0;
|
||||
boolean first = true;
|
||||
|
||||
String setID = null;
|
||||
for (HashedArmorpiece armor : armors) {
|
||||
Optional<SlimefunArmorPiece> 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.BEES) {
|
||||
if (setID == null) {
|
||||
return true;
|
||||
}
|
||||
armorCount++;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return armorCount == 4;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package io.github.thebusybiscuit.slimefun4.implementation.tasks;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -15,7 +14,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.ProtectionType;
|
||||
import io.github.thebusybiscuit.slimefun4.core.attributes.Radioactive;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
|
||||
@ -122,18 +121,16 @@ public class ArmorTask implements Runnable {
|
||||
}
|
||||
|
||||
private void checkForRadiation(Player p, PlayerProfile profile) {
|
||||
HashedArmorpiece[] armor = profile.getArmor();
|
||||
|
||||
if (!shouldProtect(armor)) {
|
||||
if (!profile.isProtected(ProtectionType.RADIATION)) {
|
||||
for (ItemStack item : p.getInventory()) {
|
||||
if (checkAndApplyRadioactive(p, item)) {
|
||||
if (checkAndApplyRadiation(p, item)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkAndApplyRadioactive(Player p, ItemStack item) {
|
||||
private boolean checkAndApplyRadiation(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
|
||||
@ -150,36 +147,4 @@ 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<SlimefunArmorPiece> 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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user