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 59589194..1564c8a2 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 @@ -19,12 +19,15 @@ public class CosmeticBalloonType extends Cosmetic { private final String modelName; private List dyableParts; + private boolean showLead; public CosmeticBalloonType(String id, ConfigurationNode config) { super(id, config); String modelId = config.node("model").getString(); + showLead = config.node("show-lead").getBoolean(true); + try { if (!config.node("dyable-parts").virtual()) { dyableParts = config.node("dyable-parts").getList(String.class); @@ -68,7 +71,7 @@ public class CosmeticBalloonType extends Cosmetic { userBalloonManager.setLocation(newLocation); PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer); - if (!user.getHidden()) PacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), player.getEntityId(), viewer); + if (!user.getHidden() && showLead) PacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), player.getEntityId(), viewer); } public String getModelName() { @@ -85,4 +88,8 @@ public class CosmeticBalloonType extends Cosmetic { if (dyableParts.isEmpty()) return true; return dyableParts.contains(name); } + + public boolean isShowLead() { + return showLead; + } } 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 702bcebc..0fbe3658 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -322,8 +322,6 @@ public class CosmeticUser { List viewer = PlayerUtils.getNearbyPlayers(player); viewer.add(player); - - PacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), player.getEntityId(), viewer); } public void despawnBalloon() { @@ -408,8 +406,7 @@ public class CosmeticUser { hiddenReason = reason; if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) { getBalloonManager().removePlayerFromModel(getPlayer()); - List viewer = PlayerUtils.getNearbyPlayers(getPlayer()); - PacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), -1, viewer); + getBalloonManager().sendRemoveLeashPacket(); } if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { userBackpackManager.clearItems(); diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBalloonManager.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBalloonManager.java index 7c544b3c..e649beba 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBalloonManager.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBalloonManager.java @@ -6,6 +6,8 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType; import com.hibiscusmc.hmccosmetics.nms.NMSHandlers; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; +import com.hibiscusmc.hmccosmetics.util.PlayerUtils; +import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import com.ticxo.modelengine.api.ModelEngineAPI; import com.ticxo.modelengine.api.model.ActiveModel; import com.ticxo.modelengine.api.model.ModeledEntity; @@ -17,12 +19,14 @@ import org.bukkit.entity.Player; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; +import java.util.List; import java.util.UUID; import java.util.logging.Level; public class UserBalloonManager { private BalloonType balloonType; + private CosmeticBalloonType cosmeticBalloonType; private final int balloonID; private final UUID uniqueID; private final ArmorStand modelEntity; @@ -44,6 +48,7 @@ public class UserBalloonManager { balloonType = BalloonType.NONE; } } + this.cosmeticBalloonType = cosmeticBalloonType; MessagesUtil.sendDebugMessages("balloontype is " + balloonType); if (balloonType == BalloonType.MODELENGINE) { @@ -85,6 +90,7 @@ public class UserBalloonManager { } modelEntity.remove(); + cosmeticBalloonType = null; } public void addPlayerToModel(final CosmeticUser user, final CosmeticBalloonType cosmeticBalloonType) { @@ -156,6 +162,19 @@ public class UserBalloonManager { this.getModelEntity().setVelocity(vector); } + public void sendRemoveLeashPacket(List viewer) { + PacketManager.sendLeashPacket(getPufferfishBalloonId(), -1, viewer); + } + + public void sendRemoveLeashPacket() { + PacketManager.sendLeashPacket(getPufferfishBalloonId(), -1, getLocation()); + } + + public void sendLeashPacket(int entityId) { + if (cosmeticBalloonType == null) return; + if (cosmeticBalloonType.isShowLead()) PacketManager.sendLeashPacket(getPufferfishBalloonId(), entityId, getLocation()); + } + public enum BalloonType { MODELENGINE, ITEM, 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 83c409cf..56e696f9 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 @@ -109,8 +109,8 @@ public class UserWardrobeManager { } if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) { - PacketManager.sendLeashPacket(user.getBalloonManager().getPufferfishBalloonId(), -1, viewer); - PacketManager.sendLeashPacket(user.getBalloonManager().getPufferfishBalloonId(), NPC_ID, viewer); // This needs a possible fix + user.getBalloonManager().sendRemoveLeashPacket(viewer); + user.getBalloonManager().sendLeashPacket(NPC_ID); //PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), NPC_ID, viewer); PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), npcLocation.clone().add(Settings.getBalloonOffset()), false, viewer); @@ -162,7 +162,7 @@ public class UserWardrobeManager { this.active = false; // NPC - if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) PacketManager.sendLeashPacket(user.getBalloonManager().getModelId(), -1, viewer); + if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) user.getBalloonManager().sendRemoveLeashPacket(); PacketManager.sendEntityDestroyPacket(NPC_ID, viewer); // Success PacketManager.sendRemovePlayerPacket(player, WARDROBE_UUID, viewer); // Success @@ -254,9 +254,9 @@ public class UserWardrobeManager { if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) { PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()), false, viewer); user.getBalloonManager().getModelEntity().teleport(WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset())); - PacketManager.sendLeashPacket(user.getBalloonManager().getPufferfishBalloonId(), -1, outsideViewers); + user.getBalloonManager().sendRemoveLeashPacket(outsideViewers); PacketManager.sendEntityDestroyPacket(user.getBalloonManager().getModelId(), outsideViewers); - PacketManager.sendLeashPacket(user.getBalloonManager().getPufferfishBalloonId(), NPC_ID, viewer); // Pufferfish goes away for some reason? + user.getBalloonManager().sendLeashPacket(NPC_ID); } if (WardrobeSettings.isEquipPumpkin()) { diff --git a/v1_17_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_17_R1/NMSHandler.java b/v1_17_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_17_R1/NMSHandler.java index 9e6d8444..e5901a56 100644 --- a/v1_17_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_17_R1/NMSHandler.java +++ b/v1_17_R1/src/main/java/com/hibiscusmc/hmccosmetics/nms/v1_17_R1/NMSHandler.java @@ -113,7 +113,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); - PacketManager.sendLeashPacket(userBalloonManager1.getPufferfishBalloonId(), player.getEntityId(), sentTo); + userBalloonManager1.sendLeashPacket(player.getEntityId()); return userBalloonManager1; } 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 0f525bfb..11e4089e 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 @@ -115,7 +115,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); - PacketManager.sendLeashPacket(userBalloonManager1.getPufferfishBalloonId(), player.getEntityId(), sentTo); + userBalloonManager1.sendLeashPacket(player.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 ea23e4a9..e72063e2 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 @@ -115,7 +115,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); - PacketManager.sendLeashPacket(userBalloonManager1.getPufferfishBalloonId(), player.getEntityId(), sentTo); + userBalloonManager1.sendLeashPacket(player.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 ecc79d1c..dd6e80c6 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 @@ -115,7 +115,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); - PacketManager.sendLeashPacket(userBalloonManager1.getPufferfishBalloonId(), player.getEntityId(), sentTo); + userBalloonManager1.sendLeashPacket(player.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 00619feb..61c8d33a 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 @@ -115,7 +115,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); - PacketManager.sendLeashPacket(userBalloonManager1.getPufferfishBalloonId(), player.getEntityId(), sentTo); + userBalloonManager1.sendLeashPacket(player.getEntityId()); return userBalloonManager1; }