diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java index 291f5a26..ff0bebb3 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java @@ -16,6 +16,7 @@ import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -130,11 +131,18 @@ public class User { this.updateArmorStand(other, settings, player.getLocation()); } - public void updateArmorStand(final Player other, final Settings settings, final Location location) { + public void updateArmorStand(final Player other, final Settings settings, final Location location) { final List> equipmentList = new ArrayList<>(); - equipmentList.add(new Pair<>(EnumWrappers.ItemSlot.HEAD, - this.playerArmor.getBackpack().getColored() - )); + final boolean hidden = this.isHidden(other); + if (hidden) { + equipmentList.add(new Pair<>(EnumWrappers.ItemSlot.HEAD, + new ItemStack(Material.AIR) + )); + } else { + equipmentList.add(new Pair<>(EnumWrappers.ItemSlot.HEAD, + this.playerArmor.getBackpack().getColored() + )); + } final PacketContainer armorPacket = PacketManager.getEquipmentPacket(equipmentList, this.armorStandId); final PacketContainer rotationPacket = PacketManager.getRotationPacket(this.armorStandId, location); @@ -154,6 +162,8 @@ public class User { PacketManager.sendPacket(other, armorPacket, metaContainer, rotationPacket, ridingPacket); + if (hidden) return; + final int lookDownPitch = settings.getCosmeticSettings().getLookDownPitch(); if (lookDownPitch != -1 && @@ -166,6 +176,11 @@ public class User { } } + public boolean isHidden(final Player other) { + final Player player = this.getPlayer(); + return player != null && (player.hasPotionEffect(PotionEffectType.INVISIBILITY) || !other.canSee(player)); + } + private boolean isFacingDown(final Location location, final int pitchLimit) { return location.getPitch() > pitchLimit; } diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/UserManager.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/UserManager.java index d4e08f35..a8684c7e 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/UserManager.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/UserManager.java @@ -134,12 +134,19 @@ public class UserManager { final PlayerArmor playerArmor = user.getPlayerArmor(); final List> equipmentList = new ArrayList<>(); + final boolean hidden = user.isHidden(other); equipmentList.add( - new Pair<>(EnumWrappers.ItemSlot.HEAD, this.getCosmeticItem(equipment, playerArmor.getHat(), EquipmentSlot.HEAD, ignoreRestrictions)) + new Pair<>( + EnumWrappers.ItemSlot.HEAD, + this.getCosmeticItem(equipment, playerArmor.getHat(), EquipmentSlot.HEAD, ignoreRestrictions, hidden) + ) ); equipmentList.add( - new Pair<>(EnumWrappers.ItemSlot.OFFHAND, this.getCosmeticItem(equipment, playerArmor.getOffHand(), EquipmentSlot.OFF_HAND, ignoreRestrictions)) + new Pair<>( + EnumWrappers.ItemSlot.OFFHAND, + this.getCosmeticItem(equipment, playerArmor.getOffHand(), EquipmentSlot.OFF_HAND, ignoreRestrictions, hidden) + ) ); PacketManager.sendPacket( @@ -155,7 +162,9 @@ public class UserManager { final Equipment equipment, final ArmorItem armorItem, final EquipmentSlot slot, - final boolean ignoreRestrictions) { + final boolean ignoreRestrictions, + final boolean hidden) { + if (hidden) return new ItemStack(Material.AIR); final CosmeticSettings cosmeticSettings = this.settings.getCosmeticSettings(); final Map placeholders = Map.of(Placeholder.ALLOWED, "true", diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/Wardrobe.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/Wardrobe.java index 13bd1ba5..5ecb6be7 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/Wardrobe.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/Wardrobe.java @@ -9,6 +9,7 @@ import io.github.fisher2911.hmccosmetics.packet.PacketManager; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.jetbrains.annotations.Nullable; import java.util.UUID; @@ -82,8 +83,9 @@ public class Wardrobe extends User { } @Override + @Nullable public Player getPlayer() { - return Bukkit.getPlayer(this.ownerUUID); + return null; } }