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

feat: Option to make lead invisible for balloons, resolves #95

This commit is contained in:
LoJoSho
2023-04-17 10:31:27 -05:00
parent 60aaf0cff6
commit bd41c5b9ff
9 changed files with 38 additions and 15 deletions

View File

@@ -19,12 +19,15 @@ public class CosmeticBalloonType extends Cosmetic {
private final String modelName; private final String modelName;
private List<String> dyableParts; private List<String> dyableParts;
private boolean showLead;
public CosmeticBalloonType(String id, ConfigurationNode config) { public CosmeticBalloonType(String id, ConfigurationNode config) {
super(id, config); super(id, config);
String modelId = config.node("model").getString(); String modelId = config.node("model").getString();
showLead = config.node("show-lead").getBoolean(true);
try { try {
if (!config.node("dyable-parts").virtual()) { if (!config.node("dyable-parts").virtual()) {
dyableParts = config.node("dyable-parts").getList(String.class); dyableParts = config.node("dyable-parts").getList(String.class);
@@ -68,7 +71,7 @@ public class CosmeticBalloonType extends Cosmetic {
userBalloonManager.setLocation(newLocation); userBalloonManager.setLocation(newLocation);
PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer); 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() { public String getModelName() {
@@ -85,4 +88,8 @@ public class CosmeticBalloonType extends Cosmetic {
if (dyableParts.isEmpty()) return true; if (dyableParts.isEmpty()) return true;
return dyableParts.contains(name); return dyableParts.contains(name);
} }
public boolean isShowLead() {
return showLead;
}
} }

View File

@@ -322,8 +322,6 @@ public class CosmeticUser {
List<Player> viewer = PlayerUtils.getNearbyPlayers(player); List<Player> viewer = PlayerUtils.getNearbyPlayers(player);
viewer.add(player); viewer.add(player);
PacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), player.getEntityId(), viewer);
} }
public void despawnBalloon() { public void despawnBalloon() {
@@ -408,8 +406,7 @@ public class CosmeticUser {
hiddenReason = reason; hiddenReason = reason;
if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) { if (hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
getBalloonManager().removePlayerFromModel(getPlayer()); getBalloonManager().removePlayerFromModel(getPlayer());
List<Player> viewer = PlayerUtils.getNearbyPlayers(getPlayer()); getBalloonManager().sendRemoveLeashPacket();
PacketManager.sendLeashPacket(getBalloonManager().getPufferfishBalloonId(), -1, viewer);
} }
if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
userBackpackManager.clearItems(); userBackpackManager.clearItems();

View File

@@ -6,6 +6,8 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers; import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil; 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.ModelEngineAPI;
import com.ticxo.modelengine.api.model.ActiveModel; import com.ticxo.modelengine.api.model.ActiveModel;
import com.ticxo.modelengine.api.model.ModeledEntity; import com.ticxo.modelengine.api.model.ModeledEntity;
@@ -17,12 +19,14 @@ import org.bukkit.entity.Player;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.logging.Level; import java.util.logging.Level;
public class UserBalloonManager { public class UserBalloonManager {
private BalloonType balloonType; private BalloonType balloonType;
private CosmeticBalloonType cosmeticBalloonType;
private final int balloonID; private final int balloonID;
private final UUID uniqueID; private final UUID uniqueID;
private final ArmorStand modelEntity; private final ArmorStand modelEntity;
@@ -44,6 +48,7 @@ public class UserBalloonManager {
balloonType = BalloonType.NONE; balloonType = BalloonType.NONE;
} }
} }
this.cosmeticBalloonType = cosmeticBalloonType;
MessagesUtil.sendDebugMessages("balloontype is " + balloonType); MessagesUtil.sendDebugMessages("balloontype is " + balloonType);
if (balloonType == BalloonType.MODELENGINE) { if (balloonType == BalloonType.MODELENGINE) {
@@ -85,6 +90,7 @@ public class UserBalloonManager {
} }
modelEntity.remove(); modelEntity.remove();
cosmeticBalloonType = null;
} }
public void addPlayerToModel(final CosmeticUser user, final CosmeticBalloonType cosmeticBalloonType) { public void addPlayerToModel(final CosmeticUser user, final CosmeticBalloonType cosmeticBalloonType) {
@@ -156,6 +162,19 @@ public class UserBalloonManager {
this.getModelEntity().setVelocity(vector); this.getModelEntity().setVelocity(vector);
} }
public void sendRemoveLeashPacket(List<Player> 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 { public enum BalloonType {
MODELENGINE, MODELENGINE,
ITEM, ITEM,

View File

@@ -109,8 +109,8 @@ public class UserWardrobeManager {
} }
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) { if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
PacketManager.sendLeashPacket(user.getBalloonManager().getPufferfishBalloonId(), -1, viewer); user.getBalloonManager().sendRemoveLeashPacket(viewer);
PacketManager.sendLeashPacket(user.getBalloonManager().getPufferfishBalloonId(), NPC_ID, viewer); // This needs a possible fix user.getBalloonManager().sendLeashPacket(NPC_ID);
//PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), NPC_ID, viewer); //PacketManager.sendLeashPacket(VIEWER.getBalloonEntity().getModelId(), NPC_ID, viewer);
PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), npcLocation.clone().add(Settings.getBalloonOffset()), false, viewer); PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), npcLocation.clone().add(Settings.getBalloonOffset()), false, viewer);
@@ -162,7 +162,7 @@ public class UserWardrobeManager {
this.active = false; this.active = false;
// NPC // 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.sendEntityDestroyPacket(NPC_ID, viewer); // Success
PacketManager.sendRemovePlayerPacket(player, WARDROBE_UUID, viewer); // Success PacketManager.sendRemovePlayerPacket(player, WARDROBE_UUID, viewer); // Success
@@ -254,9 +254,9 @@ public class UserWardrobeManager {
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) { if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON)) {
PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()), false, viewer); PacketManager.sendTeleportPacket(user.getBalloonManager().getPufferfishBalloonId(), WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset()), false, viewer);
user.getBalloonManager().getModelEntity().teleport(WardrobeSettings.getWardrobeLocation().add(Settings.getBalloonOffset())); 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.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()) { if (WardrobeSettings.isEquipPumpkin()) {

View File

@@ -113,7 +113,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo);
PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo);
PacketManager.sendLeashPacket(userBalloonManager1.getPufferfishBalloonId(), player.getEntityId(), sentTo); userBalloonManager1.sendLeashPacket(player.getEntityId());
return userBalloonManager1; return userBalloonManager1;
} }

View File

@@ -115,7 +115,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo);
PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo);
PacketManager.sendLeashPacket(userBalloonManager1.getPufferfishBalloonId(), player.getEntityId(), sentTo); userBalloonManager1.sendLeashPacket(player.getEntityId());
return userBalloonManager1; return userBalloonManager1;
} }

View File

@@ -115,7 +115,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo);
PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo);
PacketManager.sendLeashPacket(userBalloonManager1.getPufferfishBalloonId(), player.getEntityId(), sentTo); userBalloonManager1.sendLeashPacket(player.getEntityId());
return userBalloonManager1; return userBalloonManager1;
} }

View File

@@ -115,7 +115,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo);
PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo);
PacketManager.sendLeashPacket(userBalloonManager1.getPufferfishBalloonId(), player.getEntityId(), sentTo); userBalloonManager1.sendLeashPacket(player.getEntityId());
return userBalloonManager1; return userBalloonManager1;
} }

View File

@@ -115,7 +115,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler {
PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo);
PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo);
PacketManager.sendLeashPacket(userBalloonManager1.getPufferfishBalloonId(), player.getEntityId(), sentTo); userBalloonManager1.sendLeashPacket(player.getEntityId());
return userBalloonManager1; return userBalloonManager1;
} }