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 de76ba87..0296be4c 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -386,6 +386,10 @@ public class CosmeticUser { return this.userBackpackManager != null; } + public boolean isBalloonSpawned() { + return this.userBalloonManager != null; + } + public void spawnBalloon(CosmeticBalloonType cosmeticBalloonType) { if (this.userBalloonManager != null) return; @@ -424,6 +428,7 @@ public class CosmeticUser { if (!hasCosmeticInSlot(CosmeticSlot.BALLOON)) return; final Cosmetic cosmetic = getCosmetic(CosmeticSlot.BALLOON); despawnBalloon(); + if (hideCosmetics) return; spawnBalloon((CosmeticBalloonType) cosmetic); MessagesUtil.sendDebugMessages("Respawned Balloon for " + getEntity().getName()); } @@ -511,8 +516,9 @@ public class CosmeticUser { hideCosmetics = true; hiddenReason = reason; if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) { - getBalloonManager().removePlayerFromModel(getPlayer()); - getBalloonManager().sendRemoveLeashPacket(); + despawnBalloon(); + //getBalloonManager().removePlayerFromModel(getPlayer()); + //getBalloonManager().sendRemoveLeashPacket(); } if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { despawnBackpack(); @@ -533,6 +539,7 @@ public class CosmeticUser { hideCosmetics = false; hiddenReason = HiddenReason.NONE; if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) { + if (!isBalloonSpawned()) respawnBalloon(); CosmeticBalloonType balloonType = (CosmeticBalloonType) getCosmetic(CosmeticSlot.BALLOON); getBalloonManager().addPlayerToModel(this, balloonType); List viewer = HMCCPlayerUtils.getNearbyPlayers(getEntity().getLocation()); diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java index 9944c329..48a16193 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserWardrobeManager.java @@ -144,15 +144,18 @@ public class UserWardrobeManager { } if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) { - CosmeticBalloonType cosmetic = (CosmeticBalloonType) user.getCosmetic(CosmeticSlot.BALLOON); - user.getBalloonManager().sendRemoveLeashPacket(viewer); - user.getBalloonManager().sendLeashPacket(NPC_ID); - //PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), NPC_ID, viewer); + if (user.getBalloonManager() == null) user.respawnBalloon(); + if (user.isBalloonSpawned()) { + CosmeticBalloonType cosmetic = (CosmeticBalloonType) user.getCosmetic(CosmeticSlot.BALLOON); + user.getBalloonManager().sendRemoveLeashPacket(viewer); + user.getBalloonManager().sendLeashPacket(NPC_ID); + //PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), NPC_ID, viewer); - Location balloonLocation = npcLocation.clone().add(cosmetic.getBalloonOffset()); - HMCCPacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), balloonLocation , false, viewer); - user.getBalloonManager().getModelEntity().teleport(balloonLocation); - user.getBalloonManager().setLocation(balloonLocation); + Location balloonLocation = npcLocation.clone().add(cosmetic.getBalloonOffset()); + HMCCPacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), balloonLocation, false, viewer); + user.getBalloonManager().getModelEntity().teleport(balloonLocation); + user.getBalloonManager().setLocation(balloonLocation); + } } if (WardrobeSettings.isEnabledBossbar()) { @@ -214,7 +217,7 @@ public class UserWardrobeManager { } // NPC - if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) user.getBalloonManager().sendRemoveLeashPacket(); + if (user.isBalloonSpawned()) user.getBalloonManager().sendRemoveLeashPacket(); HMCCPacketManager.sendEntityDestroyPacket(NPC_ID, viewer); // Success HMCCPacketManager.sendRemovePlayerPacket(player, WARDROBE_UUID, viewer); // Success @@ -304,7 +307,7 @@ public class UserWardrobeManager { HMCCPacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers); } - if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) { + if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON) && user.isBalloonSpawned()) { // The two lines below broke, solved by listening to PlayerCosmeticPostEquipEvent //PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), npcLocation.add(Settings.getBalloonOffset()), false, viewer); //user.getBalloonManager().getModelEntity().teleport(npcLocation.add(Settings.getBalloonOffset()));