9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-30 12:29:16 +00:00

fix: balloon pufferfish not properly being destroyed out of range

This commit is contained in:
LoJoSho
2023-08-29 17:41:35 -05:00
parent b5787f22bf
commit 8b0fcc5da9
2 changed files with 46 additions and 7 deletions

View File

@@ -135,7 +135,7 @@ public class UserBalloonManager {
public int getPufferfishBalloonId() {
return pufferfish.getId();
return pufferfish.getPufferFishEntityId();
}
public UUID getPufferfishBalloonUniqueId() {
return pufferfish.getUuid();

View File

@@ -1,22 +1,29 @@
package com.hibiscusmc.hmccosmetics.user.manager;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
import com.hibiscusmc.hmccosmetics.util.PlayerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
public class UserBalloonPufferfish extends UserEntity {
private int id;
private int pufferFishEntityId;
private UUID uuid;
public UserBalloonPufferfish(UUID owner, int id, UUID uuid) {
public UserBalloonPufferfish(UUID owner, int pufferFishEntityId, UUID uuid) {
super(owner);
this.id = id;
this.pufferFishEntityId = pufferFishEntityId;
this.uuid = uuid;
}
public int getId() {
return id;
public int getPufferFishEntityId() {
return pufferFishEntityId;
}
public UUID getUuid() {
@@ -24,7 +31,39 @@ public class UserBalloonPufferfish extends UserEntity {
}
public void hidePufferfish() {
PacketManager.sendEntityDestroyPacket(id, getViewers());
PacketManager.sendEntityDestroyPacket(pufferFishEntityId, getViewers());
getViewers().clear();
}
@Override
public List<Player> refreshViewers(Location location) {
if (System.currentTimeMillis() - getViewerLastUpdate() <= 1000) return List.of(); //Prevents mass refreshes
ArrayList<Player> newPlayers = new ArrayList<>();
ArrayList<Player> removePlayers = new ArrayList<>();
List<Player> players = PlayerUtils.getNearbyPlayers(location);
for (Player player : players) {
CosmeticUser user = CosmeticUsers.getUser(player);
if (user != null && getOwner() != user.getUniqueId() && user.isInWardrobe()) { // Fixes issue where players in wardrobe would see other players cosmetics if they were not in wardrobe
removePlayers.add(player);
PacketManager.sendEntityDestroyPacket(getPufferFishEntityId(), List.of(player));
continue;
}
if (!getViewers().contains(player)) {
getViewers().add(player);
newPlayers.add(player);
continue;
}
// bad loopdy loops
for (Player viewerPlayer : getViewers()) {
if (!players.contains(viewerPlayer)) {
removePlayers.add(viewerPlayer);
PacketManager.sendEntityDestroyPacket(getPufferFishEntityId(), List.of(viewerPlayer));
}
}
}
getViewers().removeAll(removePlayers);
setViewerLastUpdate(System.currentTimeMillis());
return newPlayers;
}
}