From 82f13c349fecbf604a92ecd9898a81514fae2ffc Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Sat, 19 Aug 2023 14:30:29 -0500 Subject: [PATCH] feat: packet backpacks --- .../hmccosmetics/command/CosmeticCommand.java | 2 +- .../cosmetic/types/CosmeticBackpackType.java | 25 +++---- .../listener/PlayerGameListener.java | 2 - .../user/manager/UserBackpackManager.java | 73 ++++++++----------- .../user/manager/UserBalloonManager.java | 4 +- .../user/manager/UserBalloonPufferfish.java | 37 ++-------- ...kpackCloudManager.java => UserEntity.java} | 53 +++++++++----- .../user/manager/UserWardrobeManager.java | 31 ++++---- .../hmccosmetics/nms/v1_18_R2/NMSHandler.java | 2 +- .../hmccosmetics/nms/v1_19_R1/NMSHandler.java | 2 +- .../hmccosmetics/nms/v1_19_R2/NMSHandler.java | 2 +- .../hmccosmetics/nms/v1_19_R3/NMSHandler.java | 2 +- .../hmccosmetics/nms/v1_20_R1/NMSHandler.java | 2 +- 13 files changed, 103 insertions(+), 134 deletions(-) rename common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/{UserBackpackCloudManager.java => UserEntity.java} (52%) diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java index a36b24da..67f711f4 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java @@ -368,7 +368,7 @@ public class CosmeticCommand implements CommandExecutor { } player.sendMessage("Passengers -> " + player.getPassengers()); if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { - player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getArmorStand().getLocation()); + player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getEntityManager().getLocation()); } player.sendMessage("Cosmetics -> " + user.getCosmetics()); player.sendMessage("EntityId -> " + player.getEntityId()); diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBackpackType.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBackpackType.java index 49ad4c7d..b62f20be 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBackpackType.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticBackpackType.java @@ -3,15 +3,13 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; import com.hibiscusmc.hmccosmetics.nms.NMSHandlers; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; -import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import lombok.Getter; import org.bukkit.Bukkit; import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.entity.AreaEffectCloud; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; @@ -20,6 +18,7 @@ import org.spongepowered.configurate.ConfigurationNode; import java.util.ArrayList; import java.util.List; +import java.util.UUID; import java.util.logging.Level; public class CosmeticBackpackType extends Cosmetic { @@ -50,19 +49,16 @@ public class CosmeticBackpackType extends Cosmetic { if (user.isInWardrobe() || !user.isBackpackSpawned()) return; // This needs to be moved to purely packet based, there are far to many plugin doing dumb stuff that prevents spawning armorstands ignoring our spawn reason. - if (!user.getUserBackpackManager().IsValidBackpackEntity()) { - MessagesUtil.sendDebugMessages("Invalid Backpack Entity[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!"); - user.respawnBackpack(); - return; - } - if (loc.getWorld() != user.getUserBackpackManager().getArmorStand().getWorld()) { - user.getUserBackpackManager().getArmorStand().teleport(loc); - } + List outsideViewers = user.getUserBackpackManager().getEntityManager().refreshViewers(loc); - user.getUserBackpackManager().getArmorStand().teleport(loc); - user.getUserBackpackManager().getArmorStand().setRotation(loc.getYaw(), loc.getPitch()); + user.getUserBackpackManager().getEntityManager().teleport(loc); + user.getUserBackpackManager().getEntityManager().setRotation((int) loc.getYaw()); + + PacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), user.getUserBackpackManager().getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers); + PacketManager.sendInvisibilityPacket(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers); + NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), outsideViewers); + PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers); - List outsideViewers = user.getUserBackpackManager().getCloudManager().refreshViewers(loc); if (!user.isInWardrobe() && isFirstPersonCompadible() && user.getPlayer() != null) { List owner = List.of(user.getPlayer()); @@ -82,7 +78,6 @@ public class CosmeticBackpackType extends Cosmetic { } MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO); } - PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers); user.getUserBackpackManager().showBackpack(); } 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 423e5263..97264234 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java @@ -194,7 +194,6 @@ public class PlayerGameListener implements Listener { event.setCancelled(true); return; } - // Really need to look into optimization of this user.updateCosmetic(CosmeticSlot.BACKPACK); user.updateCosmetic(CosmeticSlot.BALLOON); } @@ -301,7 +300,6 @@ public class PlayerGameListener implements Listener { //NMSHandlers.getHandler().slotUpdate(event.getPlayer(), event.getPreviousSlot()); Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> { user.updateCosmetic(CosmeticSlot.MAINHAND); - user.updateCosmetic(CosmeticSlot.OFFHAND); }, 2); // #84, Riptides mess with backpacks diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBackpackManager.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBackpackManager.java index f7db7479..ac09bdcc 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBackpackManager.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBackpackManager.java @@ -8,11 +8,8 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; 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; import lombok.Getter; import org.bukkit.Material; -import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -20,42 +17,34 @@ import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; import java.util.ArrayList; -import java.util.Collections; import java.util.List; import java.util.UUID; import java.util.logging.Level; public class UserBackpackManager { - private boolean hideBackpack; - private ArmorStand invisibleArmorStand; + @Getter + private boolean backpackHidden; + @Getter + private int invisibleArmorStand; private ArrayList particleCloud = new ArrayList<>(); + @Getter private final CosmeticUser user; @Getter - private UserBackpackCloudManager cloudManager; + private UserEntity entityManager; public UserBackpackManager(CosmeticUser user) { this.user = user; - this.hideBackpack = false; - this.cloudManager = new UserBackpackCloudManager(user.getUniqueId()); + this.backpackHidden = false; + this.invisibleArmorStand = NMSHandlers.getHandler().getNextEntityId(); + this.entityManager = new UserEntity(user.getUniqueId()); + this.entityManager.refreshViewers(user.getEntity().getLocation()); } public int getFirstArmorStandId() { - return invisibleArmorStand.getEntityId(); - } - - public ArmorStand getArmorStand() { return invisibleArmorStand; } - public boolean IsValidBackpackEntity() { - if (invisibleArmorStand == null) { - MessagesUtil.sendDebugMessages("InvisibleArmorStand is Null!"); - return false; - } - return getArmorStand().isValid(); - } - public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) { MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Start"); @@ -63,8 +52,11 @@ public class UserBackpackManager { } private void spawn(CosmeticBackpackType cosmeticBackpackType) { - if (this.invisibleArmorStand != null) return; - this.invisibleArmorStand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(user, cosmeticBackpackType); + getEntityManager().setIds(List.of(invisibleArmorStand)); + getEntityManager().teleport(user.getEntity().getLocation()); + List outsideViewers = getEntityManager().getViewers(); + PacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), getEntityManager().getViewers()); + PacketManager.sendInvisibilityPacket(getFirstArmorStandId(), outsideViewers); Entity entity = user.getEntity(); @@ -76,9 +68,6 @@ public class UserBackpackManager { passengerIDs[passengerIDs.length - 1] = this.getFirstArmorStandId(); - List outsideViewers = user.getUserBackpackManager().getCloudManager().refreshViewers(user.getEntity().getLocation()); - PacketManager.sendRidingPacket(user.getEntity().getEntityId(), passengerIDs, outsideViewers); - ArrayList owner = new ArrayList<>(); if (user.getPlayer() != null) owner.add(user.getPlayer()); @@ -95,8 +84,9 @@ public class UserBackpackManager { else PacketManager.sendRidingPacket(particleCloud.get(i - 1), particleCloud.get(i) , owner); } PacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), owner); - if (!user.getHidden()) NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, cosmeticBackpackType.getFirstPersonBackpack(), owner); + if (!user.getHidden()) NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(cosmeticBackpackType, cosmeticBackpackType.getFirstPersonBackpack()), owner); } + NMSHandlers.getHandler().equipmentSlotUpdate(getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(cosmeticBackpackType), outsideViewers); PacketManager.sendRidingPacket(entity.getEntityId(), passengerIDs, outsideViewers); // No one should be using ME because it barely works but some still use it, so it's here @@ -105,24 +95,22 @@ public class UserBackpackManager { MessagesUtil.sendDebugMessages("Invalid Model Engine Blueprint " + cosmeticBackpackType.getModelName(), Level.SEVERE); return; } - ModeledEntity modeledEntity = ModelEngineAPI.getOrCreateModeledEntity(invisibleArmorStand); + /* TODO: Readd ModelEngine support + ModeledEntity modeledEntity = ModelEngineAPI.createModeledEntity(new PacketBaseEntity(getFirstArmorStandId(), UUID.randomUUID(), entity.getLocation())); ActiveModel model = ModelEngineAPI.createActiveModel(ModelEngineAPI.getBlueprint(cosmeticBackpackType.getModelName())); model.setCanHurt(false); modeledEntity.addModel(model, false); + */ } MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish"); } public void despawnBackpack() { - if (invisibleArmorStand != null) { - invisibleArmorStand.setHealth(0); - invisibleArmorStand.remove(); - this.invisibleArmorStand = null; - } + PacketManager.sendEntityDestroyPacket(invisibleArmorStand, getEntityManager().getViewers()); if (particleCloud != null) { for (Integer entityId : particleCloud) { - PacketManager.sendEntityDestroyPacket(entityId, getCloudManager().getViewers()); + PacketManager.sendEntityDestroyPacket(entityId, getEntityManager().getViewers()); } this.particleCloud = null; } @@ -130,20 +118,20 @@ public class UserBackpackManager { public void hideBackpack() { if (user.getHidden()) return; - getArmorStand().getEquipment().clear(); - hideBackpack = true; + //getArmorStand().getEquipment().clear(); + backpackHidden = true; } public void showBackpack() { - if (!hideBackpack) return; + if (!backpackHidden) return; CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK); ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType); - getArmorStand().getEquipment().setHelmet(item); - hideBackpack = false; + //getArmorStand().getEquipment().setHelmet(item); + backpackHidden = false; } public void setVisibility(boolean shown) { - hideBackpack = shown; + backpackHidden = shown; } public ArrayList getAreaEffectEntityId() { @@ -151,12 +139,11 @@ public class UserBackpackManager { } public void setItem(ItemStack item) { - getArmorStand().getEquipment().setHelmet(item); + NMSHandlers.getHandler().equipmentSlotUpdate(getFirstArmorStandId(), EquipmentSlot.HEAD, item, getEntityManager().getViewers()); } public void clearItems() { ItemStack item = new ItemStack(Material.AIR); - getArmorStand().getEquipment().setHelmet(item); + NMSHandlers.getHandler().equipmentSlotUpdate(getFirstArmorStandId(), EquipmentSlot.HEAD, item, getEntityManager().getViewers()); } - } 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 181d6d82..ef7970a6 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 @@ -32,8 +32,8 @@ public class UserBalloonManager { private UserBalloonPufferfish pufferfish; private final ArmorStand modelEntity; - public UserBalloonManager(@NotNull Location location) { - this.pufferfish = new UserBalloonPufferfish(NMSHandlers.getHandler().getNextEntityId(), UUID.randomUUID()); + public UserBalloonManager(CosmeticUser user, @NotNull Location location) { + this.pufferfish = new UserBalloonPufferfish(user.getUniqueId(), NMSHandlers.getHandler().getNextEntityId(), UUID.randomUUID()); this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset())); } 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 4c4fad8e..e0fd8a9d 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 @@ -9,17 +9,15 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -public class UserBalloonPufferfish { +public class UserBalloonPufferfish extends UserEntity { private int id; private UUID uuid; - private List viewers = new ArrayList<>(); - private Long lastUpdate; - public UserBalloonPufferfish(int id, UUID uuid) { + public UserBalloonPufferfish(UUID owner, int id, UUID uuid) { + super(owner); this.id = id; this.uuid = uuid; - this.lastUpdate = 0L; } public int getId() { @@ -30,33 +28,8 @@ public class UserBalloonPufferfish { return uuid; } - public List refreshViewers(Location location) { - if (System.currentTimeMillis() - lastUpdate <= 1000) return List.of(); //Prevents mass refreshes - ArrayList newPlayers = new ArrayList<>(); - ArrayList removePlayers = new ArrayList<>(); - List players = PlayerUtils.getNearbyPlayers(location); - - for (Player player : players) { - if (!viewers.contains(player)) { - viewers.add(player); - newPlayers.add(player); - continue; - } - // bad loopdy loops - for (Player viewerPlayer : viewers) { - if (!players.contains(viewerPlayer)) { - removePlayers.add(viewerPlayer); - PacketManager.sendEntityDestroyPacket(id, List.of(viewerPlayer)); // prevents random leashes - } - } - } - viewers.removeAll(removePlayers); - lastUpdate = System.currentTimeMillis(); - return newPlayers; - } - public void hidePufferfish() { - PacketManager.sendEntityDestroyPacket(id, viewers); - viewers.clear(); + PacketManager.sendEntityDestroyPacket(id, getViewers()); + getViewers().clear(); } } diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBackpackCloudManager.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEntity.java similarity index 52% rename from common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBackpackCloudManager.java rename to common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEntity.java index a685cd85..0c7b00ec 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBackpackCloudManager.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserEntity.java @@ -1,7 +1,11 @@ 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 lombok.Getter; +import lombok.Setter; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -9,25 +13,25 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -public class UserBackpackCloudManager { +public class UserEntity { - private ArrayList ids; + @Getter private UUID owner; + @Getter private List viewers = new ArrayList<>(); - private Long lastUpdate; + @Getter @Setter + private Long lastUpdate = 0L; + @Getter @Setter + private List ids = new ArrayList<>(); + @Getter + private Location location; - public UserBackpackCloudManager(UUID owner) { - this.ids = new ArrayList<>(); + public UserEntity(UUID owner) { this.owner = owner; - this.lastUpdate = 0L; } - public ArrayList getId() { - return ids; - } - - public UUID getOwner() { - return owner; + public List refreshViewers() { + return refreshViewers(location); } public List refreshViewers(Location location) { @@ -37,7 +41,12 @@ public class UserBackpackCloudManager { List players = PlayerUtils.getNearbyPlayers(location); for (Player player : players) { - //if (player.getUniqueId().toString().equalsIgnoreCase(owner.toString())) continue; + CosmeticUser user = CosmeticUsers.getUser(player); + if (user != null && user.isInWardrobe()) { // Fixes issue where players in wardrobe would see other players cosmetics if they were not in wardrobe + removePlayers.add(player); + PacketManager.sendEntityDestroyPacket(ids, List.of(player)); + continue; + } if (!viewers.contains(player)) { viewers.add(player); newPlayers.add(player); @@ -47,7 +56,7 @@ public class UserBackpackCloudManager { for (Player viewerPlayer : viewers) { if (!players.contains(viewerPlayer)) { removePlayers.add(viewerPlayer); - PacketManager.sendEntityDestroyPacket(ids, List.of(viewerPlayer)); // prevents random leashes + PacketManager.sendEntityDestroyPacket(ids, List.of(viewerPlayer)); } } } @@ -56,13 +65,17 @@ public class UserBackpackCloudManager { return newPlayers; } - public void hideEffects() { - PacketManager.sendEntityDestroyPacket(ids, viewers); - viewers.clear(); + public void teleport(Location location) { + this.location = location; + for (Integer entity : ids) { + PacketManager.sendTeleportPacket(entity, location, false, getViewers()); + } } - public List getViewers() { - return viewers; + public void setRotation(int yaw) { + location.setYaw(yaw); + for (Integer entity : ids) { + PacketManager.sendLookPacket(entity, location, getViewers()); + } } - } 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 a4c30468..904855f8 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 @@ -1,7 +1,6 @@ package com.hibiscusmc.hmccosmetics.user.manager; import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; -import com.hibiscusmc.hmccosmetics.config.Settings; import com.hibiscusmc.hmccosmetics.config.Wardrobe; import com.hibiscusmc.hmccosmetics.config.WardrobeLocation; import com.hibiscusmc.hmccosmetics.config.WardrobeSettings; @@ -15,6 +14,7 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.ServerUtils; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; +import lombok.Getter; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.bossbar.BossBar; import net.kyori.adventure.platform.bukkit.BukkitAudiences; @@ -37,19 +37,33 @@ import java.util.concurrent.atomic.AtomicInteger; public class UserWardrobeManager { + @Getter private final int NPC_ID; + @Getter private final int ARMORSTAND_ID; + @Getter private final UUID WARDROBE_UUID; + @Getter private String npcName; + @Getter private GameMode originalGamemode; + @Getter private final CosmeticUser user; + @Getter private final Wardrobe wardrobe; + @Getter private final WardrobeLocation wardrobeLocation; + @Getter private final Location viewingLocation; + @Getter private final Location npcLocation; + @Getter private Location exitLocation; + @Getter private BossBar bossBar; + @Getter private boolean active; + @Getter private WardrobeStatus wardrobeStatus; public UserWardrobeManager(CosmeticUser user, Wardrobe wardrobe) { @@ -117,7 +131,7 @@ public class UserWardrobeManager { if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { // Maybe null as backpack maybe despawned before entering if (user.getUserBackpackManager() == null) user.respawnBackpack(); - user.getUserBackpackManager().getArmorStand().teleport(npcLocation.clone().add(0, 2, 0)); + user.getUserBackpackManager().getEntityManager().teleport(npcLocation.clone().add(0, 2, 0)); NMSHandlers.getHandler().equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(user.getCosmetic(CosmeticSlot.BACKPACK)), viewer); PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer); } @@ -277,7 +291,7 @@ public class UserWardrobeManager { if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { PacketManager.sendTeleportPacket(user.getUserBackpackManager().getFirstArmorStandId(), location, false, viewer); PacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer); - user.getUserBackpackManager().getArmorStand().setRotation(nextyaw, 0); + user.getUserBackpackManager().getEntityManager().setRotation(nextyaw); PacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers); } @@ -299,14 +313,6 @@ public class UserWardrobeManager { runnable.runTaskTimer(HMCCosmeticsPlugin.getInstance(), 0, 2); } - public int getCameraId() { - return ARMORSTAND_ID; - } - - public WardrobeStatus getWardrobeStatus() { - return wardrobeStatus; - } - public void setWardrobeStatus(WardrobeStatus status) { this.wardrobeStatus = status; } @@ -318,7 +324,4 @@ public class UserWardrobeManager { STOPPING, } - public Location getNpcLocation() { - return npcLocation; - } } 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 0a0a7216..d2183735 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 @@ -96,7 +96,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { org.bukkit.entity.Entity entity = user.getEntity(); - UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation()); + UserBalloonManager userBalloonManager1 = new UserBalloonManager(user, entity.getLocation()); userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(cosmeticBalloonType.getBalloonOffset())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); 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 c0822b45..45d083d9 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 @@ -98,7 +98,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { org.bukkit.entity.Entity entity = user.getEntity(); - UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation()); + UserBalloonManager userBalloonManager1 = new UserBalloonManager(user, entity.getLocation()); userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(cosmeticBalloonType.getBalloonOffset())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); 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 34b667cb..b6c1bc8d 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 @@ -97,7 +97,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { org.bukkit.entity.Entity entity = user.getEntity(); - UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation()); + UserBalloonManager userBalloonManager1 = new UserBalloonManager(user, entity.getLocation()); userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(cosmeticBalloonType.getBalloonOffset())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); 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 04ed2ee7..104b3e40 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 @@ -106,7 +106,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { Entity entity = user.getEntity(); - UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation()); + UserBalloonManager userBalloonManager1 = new UserBalloonManager(user, entity.getLocation()); userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(cosmeticBalloonType.getBalloonOffset())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); 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 fe17bcc2..c704b215 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 @@ -107,7 +107,7 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { org.bukkit.entity.Entity entity = user.getEntity(); - UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation()); + UserBalloonManager userBalloonManager1 = new UserBalloonManager(user, entity.getLocation()); userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(cosmeticBalloonType.getBalloonOffset())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot()));