9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-25 18:09:27 +00:00

Stopped displaying of cosmetics if player is hidden

This commit is contained in:
HeroBrineGoat
2022-02-06 12:32:57 -05:00
parent 23a5ffa068
commit 0b4e2a6966
3 changed files with 34 additions and 8 deletions

View File

@@ -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<Pair<EnumWrappers.ItemSlot, ItemStack>> 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;
}

View File

@@ -134,12 +134,19 @@ public class UserManager {
final PlayerArmor playerArmor = user.getPlayerArmor();
final List<Pair<EnumWrappers.ItemSlot, ItemStack>> 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<String, String> placeholders = Map.of(Placeholder.ALLOWED, "true",

View File

@@ -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;
}
}