From 5ecfb0841256b6563cfe8e285ab6588b0e2b059a Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Sun, 5 Feb 2023 12:28:37 -0600 Subject: [PATCH] Refactor entities into managers --- .../hmccosmetics/command/CosmeticCommand.java | 2 +- .../cosmetic/types/CosmeticBackpackType.java | 12 +-- .../cosmetic/types/CosmeticBalloonType.java | 20 +++-- .../listener/PlayerGameListener.java | 4 +- .../hmccosmetics/nms/NMSHandler.java | 4 +- .../hmccosmetics/user/CosmeticUser.java | 81 ++++++------------- .../hmccosmetics/user/Wardrobe.java | 10 +-- .../user/manager/UserBackpackManager.java | 72 +++++++++++++++++ .../manager/UserBalloonManager.java} | 6 +- .../hmccosmetics/nms/v1_17_R1/NMSHandler.java | 20 ++--- .../hmccosmetics/nms/v1_18_R2/NMSHandler.java | 20 ++--- .../hmccosmetics/nms/v1_19_R1/NMSHandler.java | 20 ++--- .../hmccosmetics/nms/v1_19_R2/NMSHandler.java | 20 ++--- 13 files changed, 163 insertions(+), 128 deletions(-) create mode 100644 common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBackpackManager.java rename common/src/main/java/com/hibiscusmc/hmccosmetics/{entities/BalloonEntity.java => user/manager/UserBalloonManager.java} (97%) 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 bc1c67a9..335b62a7 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/command/CosmeticCommand.java @@ -317,7 +317,7 @@ public class CosmeticCommand implements CommandExecutor { } player.sendMessage("Passengers -> " + player.getPassengers()); if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { - player.sendMessage("Backpack Location -> " + user.getBackpackEntity().getLocation()); + player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getArmorstand().getLocation()); } player.sendMessage("Cosmetics -> " + user.getCosmetic()); 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 65bea7d3..86681c49 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 @@ -25,15 +25,15 @@ public class CosmeticBackpackType extends Cosmetic { if (user.isInWardrobe()) return; - if (loc.getWorld() != user.getBackpackEntity().getWorld()) { - user.getBackpackEntity().teleport(loc); + if (loc.getWorld() != user.getUserBackpackManager().getArmorstand().getWorld()) { + user.getUserBackpackManager().getArmorstand().teleport(loc); } - user.getBackpackEntity().teleport(loc); + user.getUserBackpackManager().getArmorstand().teleport(loc); - PacketManager.sendRidingPacket(player.getEntityId(), user.getBackpackEntity().getEntityId(), loc); + PacketManager.sendRidingPacket(player.getEntityId(), user.getUserBackpackManager().getFirstArmorstandId(), loc); - user.getBackpackEntity().setRotation(loc.getYaw(), loc.getPitch()); - user.showBackpack(); + user.getUserBackpackManager().getArmorstand().setRotation(loc.getYaw(), loc.getPitch()); + user.getUserBackpackManager().showBackpack(); } } 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 65c8b6bb..43791605 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 @@ -2,10 +2,9 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types; import com.hibiscusmc.hmccosmetics.config.Settings; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; -import com.hibiscusmc.hmccosmetics.entities.BalloonEntity; +import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; -import org.apache.commons.lang3.EnumUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -13,7 +12,6 @@ import org.bukkit.util.Vector; import org.spongepowered.configurate.ConfigurationNode; import org.spongepowered.configurate.serialize.SerializationException; -import java.util.HashMap; import java.util.List; public class CosmeticBalloonType extends Cosmetic { @@ -58,20 +56,20 @@ public class CosmeticBalloonType extends Cosmetic { List viewer = PacketManager.getViewers(player.getLocation()); viewer.add(player); - BalloonEntity balloonEntity = user.getBalloonEntity(); + UserBalloonManager userBalloonManager = user.getBalloonEntity(); - if (player.getLocation().getWorld() != balloonEntity.getLocation().getWorld()) { - balloonEntity.getModelEntity().teleport(newLocation); - PacketManager.sendTeleportPacket(balloonEntity.getPufferfishBalloonId(), newLocation, false, viewer); + if (player.getLocation().getWorld() != userBalloonManager.getLocation().getWorld()) { + userBalloonManager.getModelEntity().teleport(newLocation); + PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer); return; } Vector velocity = newLocation.toVector().subtract(currentLocation.toVector()); - balloonEntity.setVelocity(velocity.multiply(1.1)); - balloonEntity.setLocation(newLocation); + userBalloonManager.setVelocity(velocity.multiply(1.1)); + userBalloonManager.setLocation(newLocation); - PacketManager.sendTeleportPacket(balloonEntity.getPufferfishBalloonId(), newLocation, false, viewer); - if (!user.getHidden()) PacketManager.sendLeashPacket(balloonEntity.getPufferfishBalloonId(), player.getEntityId(), viewer); + PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer); + if (!user.getHidden()) PacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), player.getEntityId(), viewer); } public String getModelName() { 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 83a88697..b0cfd68b 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/listener/PlayerGameListener.java @@ -99,9 +99,9 @@ public class PlayerGameListener implements Listener { } if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { - user.hideBackpack(); + user.getUserBackpackManager().hideBackpack(); - user.getBackpackEntity().teleport(event.getTo()); + user.getUserBackpackManager().getArmorstand().teleport(event.getTo()); Bukkit.getScheduler().runTaskLater(HMCCosmeticsPlugin.getInstance(), () -> { user.updateCosmetic(); diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/nms/NMSHandler.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/nms/NMSHandler.java index 58d35b81..90f2e097 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/nms/NMSHandler.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/nms/NMSHandler.java @@ -3,7 +3,7 @@ package com.hibiscusmc.hmccosmetics.nms; import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType; -import com.hibiscusmc.hmccosmetics.entities.BalloonEntity; +import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import org.bukkit.Location; import org.bukkit.entity.ArmorStand; @@ -25,7 +25,7 @@ public interface NMSHandler { Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType); - BalloonEntity spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType); + UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType); void equipmentSlotUpdate( int entityId, 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 925ddabb..b2c32d2d 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -10,7 +10,8 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType; -import com.hibiscusmc.hmccosmetics.entities.BalloonEntity; +import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager; +import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager; import com.hibiscusmc.hmccosmetics.nms.NMSHandlers; import com.hibiscusmc.hmccosmetics.util.InventoryUtils; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; @@ -35,19 +36,14 @@ public class CosmeticUser { private int taskId; private HashMap playerCosmetics = new HashMap<>(); private Wardrobe wardrobe; - private ArmorStand invisibleArmorstand; - private BalloonEntity balloonEntity; + private UserBalloonManager userBalloonManager; + private UserBackpackManager userBackpackManager; // Cosmetic Settings/Toggles - private boolean hideBackpack; private boolean hideCosmetics; private HiddenReason hiddenReason; private HashMap colors = new HashMap<>(); - public CosmeticUser() { - // Empty - } - public CosmeticUser(UUID uuid) { this.uniqueId = uuid; tick(); @@ -84,16 +80,8 @@ public class CosmeticUser { public Collection getCosmetic() { return playerCosmetics.values(); } - - public int getArmorstandId() { - return invisibleArmorstand.getEntityId(); - } - - public Entity getBackpackEntity() { - return this.invisibleArmorstand; - } - public BalloonEntity getBalloonEntity() { - return this.balloonEntity; + public UserBalloonManager getBalloonEntity() { + return this.userBalloonManager; } public void addPlayerCosmetic(Cosmetic cosmetic) { @@ -287,22 +275,25 @@ public class CosmeticUser { } public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) { - MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Start"); - Player player = Bukkit.getPlayer(getUniqueId()); + this.userBackpackManager = new UserBackpackManager(this); + userBackpackManager.spawnBackpack(cosmeticBackpackType); + } - if (this.invisibleArmorstand != null) return; + public void despawnBackpack() { + userBackpackManager.despawnBackpack(); + userBackpackManager = null; + } - this.invisibleArmorstand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(this, cosmeticBackpackType); - - MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish"); + public UserBackpackManager getUserBackpackManager() { + return userBackpackManager; } public void spawnBalloon(CosmeticBalloonType cosmeticBalloonType) { Player player = Bukkit.getPlayer(getUniqueId()); - if (this.balloonEntity != null) return; + if (this.userBalloonManager != null) return; - this.balloonEntity = NMSHandlers.getHandler().spawnBalloon(this, cosmeticBalloonType); + this.userBalloonManager = NMSHandlers.getHandler().spawnBalloon(this, cosmeticBalloonType); List viewer = PlayerUtils.getNearbyPlayers(player); viewer.add(player); @@ -311,21 +302,13 @@ public class CosmeticUser { } public void despawnBalloon() { - if (this.balloonEntity == null) return; + if (this.userBalloonManager == null) return; List sentTo = PlayerUtils.getNearbyPlayers(getPlayer().getLocation()); - PacketManager.sendEntityDestroyPacket(balloonEntity.getPufferfishBalloonId(), sentTo); + PacketManager.sendEntityDestroyPacket(userBalloonManager.getPufferfishBalloonId(), sentTo); - this.balloonEntity.remove(); - this.balloonEntity = null; - } - - public void despawnBackpack() { - Player player = Bukkit.getPlayer(getUniqueId()); - if (invisibleArmorstand == null) return; - invisibleArmorstand.setHealth(0); - invisibleArmorstand.remove(); - this.invisibleArmorstand = null; + this.userBalloonManager.remove(); + this.userBalloonManager = null; } public void respawnBackpack() { @@ -388,24 +371,6 @@ public class CosmeticUser { } } - public void hideBackpack() { - if (hideBackpack == true) return; - if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { - invisibleArmorstand.getEquipment().clear(); - hideBackpack = true; - } - } - - public void showBackpack() { - if (hideBackpack == false) return; - if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { - CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK); - ItemStack item = getUserCosmeticItem(cosmeticBackpackType); - invisibleArmorstand.getEquipment().setHelmet(item); - hideBackpack = false; - } - } - public void hideCosmetics(HiddenReason reason) { if (hideCosmetics == true) return; PlayerCosmeticHideEvent event = new PlayerCosmeticHideEvent(this, reason); @@ -422,7 +387,7 @@ public class CosmeticUser { PacketManager.sendLeashPacket(getBalloonEntity().getPufferfishBalloonId(), -1, viewer); } if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { - invisibleArmorstand.getEquipment().clear(); + userBackpackManager.getArmorstand().getEquipment().clear(); } updateCosmetic(); MessagesUtil.sendDebugMessages("HideCosmetics"); @@ -448,7 +413,7 @@ public class CosmeticUser { if (hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) getCosmetic(CosmeticSlot.BACKPACK); ItemStack item = getUserCosmeticItem(cosmeticBackpackType); - invisibleArmorstand.getEquipment().setHelmet(item); + userBackpackManager.getArmorstand().getEquipment().setHelmet(item); } updateCosmetic(); MessagesUtil.sendDebugMessages("ShowCosmetics"); diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/Wardrobe.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/Wardrobe.java index fbdd60ea..09c7ca46 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/Wardrobe.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/Wardrobe.java @@ -100,7 +100,7 @@ public class Wardrobe { // Misc if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { - PacketManager.ridingMountPacket(NPC_ID, VIEWER.getBackpackEntity().getEntityId(), viewer); + PacketManager.ridingMountPacket(NPC_ID, VIEWER.getUserBackpackManager().getFirstArmorstandId(), viewer); } if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) { @@ -236,10 +236,10 @@ public class Wardrobe { } if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { - PacketManager.sendTeleportPacket(VIEWER.getArmorstandId(), location, false, viewer); - PacketManager.ridingMountPacket(NPC_ID, VIEWER.getBackpackEntity().getEntityId(), viewer); - VIEWER.getBackpackEntity().setRotation(nextyaw, 0); - PacketManager.sendEntityDestroyPacket(VIEWER.getArmorstandId(), outsideViewers); + PacketManager.sendTeleportPacket(VIEWER.getUserBackpackManager().getFirstArmorstandId(), location, false, viewer); + PacketManager.ridingMountPacket(NPC_ID, VIEWER.getUserBackpackManager().getFirstArmorstandId(), viewer); + VIEWER.getUserBackpackManager().getArmorstand().setRotation(nextyaw, 0); + PacketManager.sendEntityDestroyPacket(VIEWER.getUserBackpackManager().getFirstArmorstandId(), outsideViewers); } if (VIEWER.hasCosmeticInSlot(CosmeticSlot.BALLOON)) { 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 new file mode 100644 index 00000000..ef3f8941 --- /dev/null +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBackpackManager.java @@ -0,0 +1,72 @@ +package com.hibiscusmc.hmccosmetics.user.manager; + +import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot; +import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType; +import com.hibiscusmc.hmccosmetics.nms.NMSHandlers; +import com.hibiscusmc.hmccosmetics.user.CosmeticUser; +import com.hibiscusmc.hmccosmetics.util.MessagesUtil; +import org.bukkit.entity.ArmorStand; +import org.bukkit.inventory.ItemStack; + +public class UserBackpackManager { + + private boolean hideBackpack; + private ArmorStand invisibleArmorstand; + private CosmeticUser user; + private BackpackType backpackType; + + public UserBackpackManager(CosmeticUser user) { + this.user = user; + hideBackpack = false; + backpackType = BackpackType.NORMAL; + } + + public int getFirstArmorstandId() { + return invisibleArmorstand.getEntityId(); + } + + public ArmorStand getArmorstand() { + return invisibleArmorstand; + } + + public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) { + MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Start"); + + if (this.invisibleArmorstand != null) return; + + this.invisibleArmorstand = (ArmorStand) NMSHandlers.getHandler().spawnBackpack(user, cosmeticBackpackType); + + + MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish"); + } + + public void despawnBackpack() { + if (invisibleArmorstand == null) return; + invisibleArmorstand.setHealth(0); + invisibleArmorstand.remove(); + this.invisibleArmorstand = null; + } + + public void hideBackpack() { + if (user.getHidden() == true) return; + getArmorstand().getEquipment().clear(); + hideBackpack = true; + } + + public void showBackpack() { + if (hideBackpack == false) return; + CosmeticBackpackType cosmeticBackpackType = (CosmeticBackpackType) user.getCosmetic(CosmeticSlot.BACKPACK); + ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType); + getArmorstand().getEquipment().setHelmet(item); + hideBackpack = false; + } + + public void setVisibility(boolean shown) { + hideBackpack = shown; + } + + public enum BackpackType { + NORMAL, + FIRST_PERSON // First person not yet implemented + } +} diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/entities/BalloonEntity.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBalloonManager.java similarity index 97% rename from common/src/main/java/com/hibiscusmc/hmccosmetics/entities/BalloonEntity.java rename to common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBalloonManager.java index 56b83b63..d8f2eada 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/entities/BalloonEntity.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBalloonManager.java @@ -1,4 +1,4 @@ -package com.hibiscusmc.hmccosmetics.entities; +package com.hibiscusmc.hmccosmetics.user.manager; import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; import com.hibiscusmc.hmccosmetics.config.Settings; @@ -19,14 +19,14 @@ import org.bukkit.util.Vector; import java.util.UUID; import java.util.logging.Level; -public class BalloonEntity { +public class UserBalloonManager { private BalloonType balloonType; private final int balloonID; private final UUID uniqueID; private final ArmorStand modelEntity; - public BalloonEntity(Location location) { + public UserBalloonManager(Location location) { this.uniqueID = UUID.randomUUID(); this.balloonID = NMSHandlers.getHandler().getNextEntityId(); this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset())); 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 772bf01f..fd25fe47 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 @@ -6,7 +6,7 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType; -import com.hibiscusmc.hmccosmetics.entities.BalloonEntity; +import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.util.InventoryUtils; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; @@ -94,22 +94,22 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override - public BalloonEntity spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { + public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { Player player = user.getPlayer(); Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset()); - BalloonEntity balloonEntity1 = new BalloonEntity(user.getPlayer().getLocation()); + UserBalloonManager userBalloonManager1 = new UserBalloonManager(user.getPlayer().getLocation()); List sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); - balloonEntity1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); + userBalloonManager1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); - balloonEntity1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); - balloonEntity1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); + userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); + userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); - PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getPufferfishBalloonId(), EntityType.PUFFERFISH, balloonEntity1.getPufferfishBalloonUniqueId(), sentTo); - PacketManager.sendInvisibilityPacket(balloonEntity1.getPufferfishBalloonId(), sentTo); - PacketManager.sendLeashPacket(balloonEntity1.getPufferfishBalloonId(), player.getEntityId(), sentTo); + PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); + PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); + PacketManager.sendLeashPacket(userBalloonManager1.getPufferfishBalloonId(), player.getEntityId(), sentTo); - return balloonEntity1; + return userBalloonManager1; } @Override 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 1d610c35..b7ebee8e 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 @@ -6,7 +6,7 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType; -import com.hibiscusmc.hmccosmetics.entities.BalloonEntity; +import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.util.InventoryUtils; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; @@ -96,22 +96,22 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override - public BalloonEntity spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { + public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { Player player = user.getPlayer(); Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset()); - BalloonEntity balloonEntity1 = new BalloonEntity(user.getPlayer().getLocation()); + UserBalloonManager userBalloonManager1 = new UserBalloonManager(user.getPlayer().getLocation()); List sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); - balloonEntity1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); + userBalloonManager1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); - balloonEntity1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); - balloonEntity1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); + userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); + userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); - PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getPufferfishBalloonId(), EntityType.PUFFERFISH, balloonEntity1.getPufferfishBalloonUniqueId(), sentTo); - PacketManager.sendInvisibilityPacket(balloonEntity1.getPufferfishBalloonId(), sentTo); - PacketManager.sendLeashPacket(balloonEntity1.getPufferfishBalloonId(), player.getEntityId(), sentTo); + PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); + PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); + PacketManager.sendLeashPacket(userBalloonManager1.getPufferfishBalloonId(), player.getEntityId(), sentTo); - return balloonEntity1; + return userBalloonManager1; } @Override 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 aa0a9749..37dae16c 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 @@ -6,7 +6,7 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType; -import com.hibiscusmc.hmccosmetics.entities.BalloonEntity; +import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.util.InventoryUtils; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; @@ -96,22 +96,22 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override - public BalloonEntity spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { + public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { Player player = user.getPlayer(); Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset()); - BalloonEntity balloonEntity1 = new BalloonEntity(user.getPlayer().getLocation()); + UserBalloonManager userBalloonManager1 = new UserBalloonManager(user.getPlayer().getLocation()); List sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); - balloonEntity1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); + userBalloonManager1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); - balloonEntity1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); - balloonEntity1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); + userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); + userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); - PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getPufferfishBalloonId(), EntityType.PUFFERFISH, balloonEntity1.getPufferfishBalloonUniqueId(), sentTo); - PacketManager.sendInvisibilityPacket(balloonEntity1.getPufferfishBalloonId(), sentTo); - PacketManager.sendLeashPacket(balloonEntity1.getPufferfishBalloonId(), player.getEntityId(), sentTo); + PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); + PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); + PacketManager.sendLeashPacket(userBalloonManager1.getPufferfishBalloonId(), player.getEntityId(), sentTo); - return balloonEntity1; + return userBalloonManager1; } @Override 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 b698b74d..6564f6f5 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 @@ -6,7 +6,7 @@ import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticArmorType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBackpackType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticBalloonType; import com.hibiscusmc.hmccosmetics.cosmetic.types.CosmeticMainhandType; -import com.hibiscusmc.hmccosmetics.entities.BalloonEntity; +import com.hibiscusmc.hmccosmetics.user.manager.UserBalloonManager; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.util.InventoryUtils; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; @@ -96,22 +96,22 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override - public BalloonEntity spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { + public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { Player player = user.getPlayer(); Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset()); - BalloonEntity balloonEntity1 = new BalloonEntity(user.getPlayer().getLocation()); + UserBalloonManager userBalloonManager1 = new UserBalloonManager(user.getPlayer().getLocation()); List sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); - balloonEntity1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); + userBalloonManager1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); - balloonEntity1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); - balloonEntity1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); + userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); + userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); - PacketManager.sendEntitySpawnPacket(newLoc, balloonEntity1.getPufferfishBalloonId(), EntityType.PUFFERFISH, balloonEntity1.getPufferfishBalloonUniqueId(), sentTo); - PacketManager.sendInvisibilityPacket(balloonEntity1.getPufferfishBalloonId(), sentTo); - PacketManager.sendLeashPacket(balloonEntity1.getPufferfishBalloonId(), player.getEntityId(), sentTo); + PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); + PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); + PacketManager.sendLeashPacket(userBalloonManager1.getPufferfishBalloonId(), player.getEntityId(), sentTo); - return balloonEntity1; + return userBalloonManager1; } @Override