diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java index 977b9eba..26ca6ff9 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBalloonType.java @@ -73,6 +73,10 @@ public class CosmeticBalloonType extends Cosmetic { PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer); PacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), entity.getEntityId(), viewer); + if (user.getHidden()) { + userBalloonManager.getPufferfish().hidePufferfish(); + return; + } if (!user.getHidden() && showLead) { List sendTo = userBalloonManager.getPufferfish().refreshViewers(newLocation); if (sendTo.isEmpty()) return; diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java index 6ca8411f..b83babd9 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java @@ -114,22 +114,17 @@ public class PlayerGameListener implements Listener { return; } - if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && user.getUserBackpackManager() != null) { - Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> { + Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> { + if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && user.getUserBackpackManager() != null) { user.respawnBackpack(); - user.updateCosmetic(); - }, 1); - } + } + if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) { + user.respawnBalloon(); + } + user.updateCosmetic(); + }, 1); if (event.getCause().equals(PlayerTeleportEvent.TeleportCause.NETHER_PORTAL) || event.getCause().equals(PlayerTeleportEvent.TeleportCause.END_PORTAL)) return; - - if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) { - final CosmeticBalloonType cosmeticBalloonType = (CosmeticBalloonType) user.getCosmetic(CosmeticSlot.BALLOON); - user.despawnBalloon(); - Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> { - user.spawnBalloon(cosmeticBalloonType); - }, 2); - } if (user.getUserEmoteManager().isPlayingEmote()) { user.getUserEmoteManager().stopEmote(UserEmoteManager.StopEmoteReason.TELEPORT); } 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 fd4a31b9..8df0f4af 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -365,6 +365,7 @@ public class CosmeticUser { public void spawnBalloon(CosmeticBalloonType cosmeticBalloonType) { if (this.userBalloonManager != null) return; this.userBalloonManager = NMSHandlers.getHandler().spawnBalloon(this, cosmeticBalloonType); + updateCosmetic(cosmeticBalloonType); } public void despawnBalloon() { diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBalloonPufferfish.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBalloonPufferfish.java index d5f73c1b..55a9f8e6 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBalloonPufferfish.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBalloonPufferfish.java @@ -20,7 +20,7 @@ public class UserBalloonPufferfish { public UserBalloonPufferfish(int id, UUID uuid) { this.id = id; this.uuid = uuid; - this.lastUpdate = System.currentTimeMillis(); + this.lastUpdate = 0L; } public int getId() { @@ -55,4 +55,9 @@ public class UserBalloonPufferfish { lastUpdate = System.currentTimeMillis(); return newPlayers; } + + public void hidePufferfish() { + PacketManager.sendEntityDestroyPacket(id, viewers); + viewers.clear(); + } } diff --git a/v1_18_R2/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_18_R2/NMSHandler.java b/v1_18_R2/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_18_R2/NMSHandler.java index 30871ca9..6a4f03e3 100644 --- a/v1_18_R2/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_18_R2/NMSHandler.java +++ b/v1_18_R2/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_18_R2/NMSHandler.java @@ -106,19 +106,13 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { org.bukkit.entity.Entity entity = user.getEntity(); - Location newLoc = entity.getLocation().clone().add(Settings.getBalloonOffset()); UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation()); - List sentTo = PlayerUtils.getNearbyPlayers(entity.getLocation()); userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(Settings.getBalloonOffset())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); - PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); - PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); - userBalloonManager1.sendLeashPacket(entity.getEntityId()); - return userBalloonManager1; } diff --git a/v1_19_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R1/NMSHandler.java b/v1_19_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R1/NMSHandler.java index 8693bba9..4cb03819 100644 --- a/v1_19_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R1/NMSHandler.java +++ b/v1_19_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R1/NMSHandler.java @@ -108,19 +108,13 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { org.bukkit.entity.Entity entity = user.getEntity(); - Location newLoc = entity.getLocation().clone().add(Settings.getBalloonOffset()); UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation()); - List sentTo = PlayerUtils.getNearbyPlayers(entity.getLocation()); userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(Settings.getBalloonOffset())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); - PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); - PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); - userBalloonManager1.sendLeashPacket(entity.getEntityId()); - return userBalloonManager1; } diff --git a/v1_19_R2/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R2/NMSHandler.java b/v1_19_R2/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R2/NMSHandler.java index 0239c97c..743524f8 100644 --- a/v1_19_R2/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R2/NMSHandler.java +++ b/v1_19_R2/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R2/NMSHandler.java @@ -107,19 +107,13 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { org.bukkit.entity.Entity entity = user.getEntity(); - Location newLoc = entity.getLocation().clone().add(Settings.getBalloonOffset()); UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation()); - List sentTo = PlayerUtils.getNearbyPlayers(entity.getLocation()); userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(Settings.getBalloonOffset())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); - PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); - PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); - userBalloonManager1.sendLeashPacket(entity.getEntityId()); - return userBalloonManager1; } diff --git a/v1_19_R3/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R3/NMSHandler.java b/v1_19_R3/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R3/NMSHandler.java index 4a55c1a1..d22d2a32 100644 --- a/v1_19_R3/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R3/NMSHandler.java +++ b/v1_19_R3/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_19_R3/NMSHandler.java @@ -114,19 +114,13 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { Entity entity = user.getEntity(); - Location newLoc = entity.getLocation().clone().add(Settings.getBalloonOffset()); UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation()); - List sentTo = PlayerUtils.getNearbyPlayers(entity.getLocation()); userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(Settings.getBalloonOffset())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); - PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); - PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); - userBalloonManager1.sendLeashPacket(entity.getEntityId()); - return userBalloonManager1; } diff --git a/v1_20_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_20_R1/NMSHandler.java b/v1_20_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_20_R1/NMSHandler.java index baa7042b..baf98b6e 100644 --- a/v1_20_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_20_R1/NMSHandler.java +++ b/v1_20_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_20_R1/NMSHandler.java @@ -116,19 +116,13 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { org.bukkit.entity.Entity entity = user.getEntity(); - Location newLoc = entity.getLocation().clone().add(Settings.getBalloonOffset()); UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation()); - List sentTo = PlayerUtils.getNearbyPlayers(entity.getLocation()); userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(Settings.getBalloonOffset())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); - PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); - PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); - userBalloonManager1.sendLeashPacket(entity.getEntityId()); - return userBalloonManager1; }