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

chore: move getNearbyPlayers from HMCCPlayerUtils to getViewers HMCCPacketManager

This commit is contained in:
LoJoSho
2025-01-16 13:11:30 -06:00
parent 93b1c20c40
commit 5cc19ab2db
5 changed files with 25 additions and 8 deletions

View File

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

View File

@@ -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<Player> viewer = HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation());
List<Player> viewer = HMCCPacketManager.getViewers(getEntity().getLocation());
HMCCPacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), getPlayer().getEntityId(), viewer);
}
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {

View File

@@ -43,7 +43,7 @@ public class UserEntity {
if (System.currentTimeMillis() - viewerLastUpdate <= 1000) return List.of(); //Prevents mass refreshes
ArrayList<Player> newPlayers = new ArrayList<>();
ArrayList<Player> removePlayers = new ArrayList<>();
List<Player> players = HMCCPlayerUtils.getNearbyPlayers(location);
List<Player> players = HMCCPacketManager.getViewers(location);
Player ownerPlayer = Bukkit.getPlayer(owner);
if (ownerPlayer == null) {
MessagesUtil.sendDebugMessages("Owner is null (refreshViewers), returning empty list");

View File

@@ -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<Player> 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<Player> getNearbyPlayers(@NotNull Location location) {
return PacketManager.getViewers(location, Settings.getViewDistance());
}

View File

@@ -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<Player> getViewers(Location location) {
public static List<Player> getViewers(@NotNull Location location) {
ArrayList<Player> 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;
}