diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticMainhandType.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticMainhandType.java index b4dc3685..96a4a46f 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticMainhandType.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticMainhandType.java @@ -18,6 +18,6 @@ public class CosmeticMainhandType extends Cosmetic { public void update(@NotNull CosmeticUser user) { Player player = user.getPlayer(); - HMCCPacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), HMCCPlayerUtils.getNearbyPlayers(player)); + HMCCPacketManager.equipmentSlotUpdate(player.getEntityId(), user, getSlot(), HMCCPacketManager.getViewers(player.getLocation())); } } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java index 8b44d3dc..3d323775 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -268,7 +268,7 @@ public class CosmeticUser { } } if (items.isEmpty() || getEntity() == null) return; - PacketManager.equipmentSlotUpdate(getEntity().getEntityId(), items, HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation())); + PacketManager.equipmentSlotUpdate(getEntity().getEntityId(), items, HMCCPacketManager.getViewers(getEntity().getLocation())); MessagesUtil.sendDebugMessages("updateCosmetic (All) - end - " + items.size()); } @@ -538,9 +538,9 @@ public class CosmeticUser { EquipmentSlot equipmentSlot = HMCCInventoryUtils.getEquipmentSlot(slot); if (equipmentSlot == null) return; if (getPlayer() != null) { - PacketManager.equipmentSlotUpdate(getEntity().getEntityId(), equipmentSlot, getPlayer().getInventory().getItem(equipmentSlot), HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation())); + PacketManager.equipmentSlotUpdate(getEntity().getEntityId(), equipmentSlot, getPlayer().getInventory().getItem(equipmentSlot), HMCCPacketManager.getViewers(getEntity().getLocation())); } else { - HMCCPacketManager.equipmentSlotUpdate(getEntity().getEntityId(), this, slot, HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation())); + HMCCPacketManager.equipmentSlotUpdate(getEntity().getEntityId(), this, slot, HMCCPacketManager.getViewers(getEntity().getLocation())); } } @@ -649,7 +649,7 @@ public class CosmeticUser { if (!isBalloonSpawned()) respawnBalloon(); CosmeticBalloonType balloonType = (CosmeticBalloonType) getCosmetic(CosmeticSlot.BALLOON); getBalloonManager().addPlayerToModel(this, balloonType); - List viewer = HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation()); + List viewer = HMCCPacketManager.getViewers(getEntity().getLocation()); HMCCPacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), getPlayer().getEntityId(), viewer); } if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEntity.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEntity.java index 6d142514..0d781ad5 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEntity.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEntity.java @@ -43,7 +43,7 @@ public class UserEntity { if (System.currentTimeMillis() - viewerLastUpdate <= 1000) return List.of(); //Prevents mass refreshes ArrayList newPlayers = new ArrayList<>(); ArrayList removePlayers = new ArrayList<>(); - List players = HMCCPlayerUtils.getNearbyPlayers(location); + List players = HMCCPacketManager.getViewers(location); Player ownerPlayer = Bukkit.getPlayer(owner); if (ownerPlayer == null) { MessagesUtil.sendDebugMessages("Owner is null (refreshViewers), returning empty list"); diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/HMCCPlayerUtils.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/HMCCPlayerUtils.java index 98b9216c..7fd79487 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/HMCCPlayerUtils.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/HMCCPlayerUtils.java @@ -24,12 +24,24 @@ public class HMCCPlayerUtils { return new WrappedSignedProperty("textures", skinData.getValue(), skinData.getSignature()); } + /** + * Get nearby players. {@link com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager#getViewers(Location)} + * @param player + * @return + */ @NotNull + @Deprecated(since = "2.7.5", forRemoval = true) public static List getNearbyPlayers(@NotNull Player player) { return getNearbyPlayers(player.getLocation()); } + /** + * Get nearby players. {@link com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager#getViewers(Location)} + * @param location + * @return + */ @NotNull + @Deprecated(since = "2.7.5", forRemoval = true) public static List getNearbyPlayers(@NotNull Location location) { return PacketManager.getViewers(location, Settings.getViewDistance()); } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/packets/HMCCPacketManager.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/packets/HMCCPacketManager.java index a52847a4..876e63ae 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/packets/HMCCPacketManager.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/packets/HMCCPacketManager.java @@ -379,13 +379,18 @@ public class HMCCPacketManager extends PacketManager { } } + /** + * Gets the nearby players (or viewers) of a location through the view distance set in the config. If the view distance is 0, it will return all players in the world. + * @param location + * @return + */ @NotNull - public static List getViewers(Location location) { + public static List getViewers(@NotNull Location location) { ArrayList viewers = new ArrayList<>(); if (Settings.getViewDistance() <= 0) { viewers.addAll(location.getWorld().getPlayers()); } else { - viewers.addAll(HMCCPlayerUtils.getNearbyPlayers(location)); + viewers.addAll(PacketManager.getViewers(location, Settings.getViewDistance())); } return viewers; }