diff --git a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/DyeSelectorGui.class b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/DyeSelectorGui.class index 6fb87d82..8c371dda 100644 Binary files a/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/DyeSelectorGui.class and b/common/build/classes/java/main/io/github/fisher2911/hmccosmetics/gui/DyeSelectorGui.class differ diff --git a/common/build/libs/HMCCosmetics.jar b/common/build/libs/HMCCosmetics.jar index ba8c99aa..f0b2c9d2 100644 Binary files a/common/build/libs/HMCCosmetics.jar and b/common/build/libs/HMCCosmetics.jar differ diff --git a/common/build/tmp/compileJava/previous-compilation-data.bin b/common/build/tmp/compileJava/previous-compilation-data.bin index 317537c5..9c91554e 100644 Binary files a/common/build/tmp/compileJava/previous-compilation-data.bin and b/common/build/tmp/compileJava/previous-compilation-data.bin differ diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/database/Database.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/database/Database.java index 15517c3e..26212f2f 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/database/Database.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/database/Database.java @@ -13,6 +13,7 @@ import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.hook.HookManager; import io.github.fisher2911.hmccosmetics.hook.item.CitizensHook; import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; +import io.github.fisher2911.hmccosmetics.packet.EntityIds; import io.github.fisher2911.hmccosmetics.user.BaseUser; import io.github.fisher2911.hmccosmetics.user.NPCUser; import io.github.fisher2911.hmccosmetics.user.User; @@ -83,6 +84,7 @@ public class Database { public void loadUser(final Entity entity, final Consumer onComplete) { final UUID uuid = entity.getUniqueId(); final int armorStandId = FAKE_ENTITY_ID.getAndDecrement(); + final int balloonId = FAKE_ENTITY_ID.getAndDecrement(); final Wardrobe wardrobe = this.createNewWardrobe(uuid); Threads.getInstance().execute( () -> { @@ -97,10 +99,13 @@ public class Database { final User actualUser = user.toUser( this.plugin.getCosmeticManager(), - entity.getEntityId(), + new EntityIds( + entity.getEntityId(), + armorStandId, + balloonId + ), armorItems, - wardrobe, - armorStandId + wardrobe ); Bukkit.getScheduler().runTask(this.plugin, () -> onComplete.accept(actualUser) @@ -112,15 +117,14 @@ public class Database { }); onComplete.accept(new User( uuid, - entity.getEntityId(), PlayerArmor.empty(), - wardrobe, - armorStandId + new EntityIds(entity.getEntityId(), armorStandId, balloonId) )); } public void loadNPCUser(final int id, final Entity entity, final Consumer onComplete) { final int armorStandId = FAKE_ENTITY_ID.getAndDecrement(); + final int balloonId = FAKE_ENTITY_ID.getAndDecrement(); Threads.getInstance().execute( () -> { try { @@ -134,9 +138,12 @@ public class Database { final NPCUser actualUser = citizen.toUser( this.plugin.getCosmeticManager(), - entity.getEntityId(), - armorItems, - armorStandId + new EntityIds( + entity.getEntityId(), + armorStandId, + balloonId + ), + armorItems ); Bukkit.getScheduler().runTask(this.plugin, @@ -148,7 +155,12 @@ public class Database { } }); - onComplete.accept(new NPCUser(id, entity.getEntityId(), PlayerArmor.empty(), armorStandId)); + onComplete.accept(new NPCUser( + id, + PlayerArmor.empty(), + new EntityIds(entity.getEntityId(), armorStandId, balloonId) + ) + ); } public void saveUser(final User user) { @@ -219,11 +231,13 @@ public class Database { return new Wardrobe( this.plugin, UUID.randomUUID(), - FAKE_ENTITY_ID.getAndDecrement(), ownerUUID, PlayerArmor.empty(), - FAKE_ENTITY_ID.getAndDecrement(), - FAKE_ENTITY_ID.getAndDecrement(), + new EntityIds( + FAKE_ENTITY_ID.getAndDecrement(), + FAKE_ENTITY_ID.getAndDecrement(), + FAKE_ENTITY_ID.getAndDecrement() + ), false ); } diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/database/DatabaseConverter.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/database/DatabaseConverter.java index 426c73da..1bbb39a3 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/database/DatabaseConverter.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/database/DatabaseConverter.java @@ -3,6 +3,7 @@ package io.github.fisher2911.hmccosmetics.database; import io.github.fisher2911.hmccosmetics.HMCCosmetics; import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; +import io.github.fisher2911.hmccosmetics.packet.EntityIds; import io.github.fisher2911.hmccosmetics.user.User; import java.io.File; @@ -93,10 +94,13 @@ public class DatabaseConverter { final UUID uuid = UUID.fromString(results.getString(1)); final User user = new User( uuid, - -1, playerArmor, this.database.createNewWardrobe(uuid), - this.database.FAKE_ENTITY_ID.getAndDecrement() + new EntityIds( + -1, + this.database.FAKE_ENTITY_ID.getAndDecrement(), + this.database.FAKE_ENTITY_ID.getAndDecrement() + ) ); final String backpackId = results.getString(2); final String hatId = results.getString(3); diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/database/dao/CitizenDAO.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/database/dao/CitizenDAO.java index fd2452c3..1a46cc63 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/database/dao/CitizenDAO.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/database/dao/CitizenDAO.java @@ -5,6 +5,7 @@ import com.j256.ormlite.table.DatabaseTable; import io.github.fisher2911.hmccosmetics.cosmetic.CosmeticManager; import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; +import io.github.fisher2911.hmccosmetics.packet.EntityIds; import io.github.fisher2911.hmccosmetics.user.BaseUser; import io.github.fisher2911.hmccosmetics.user.NPCUser; import io.github.fisher2911.hmccosmetics.user.User; @@ -34,9 +35,8 @@ public class CitizenDAO { @Nullable public NPCUser toUser( final CosmeticManager cosmeticManager, - final int entityId, - final List armorItems, - final int armorStandId + final EntityIds entityIds, + final List armorItems ) { final PlayerArmor playerArmor = PlayerArmor.empty(); @@ -48,7 +48,7 @@ public class CitizenDAO { playerArmor.setItem(armorItem); } - return new NPCUser(this.citizensId, entityId, playerArmor, armorStandId); + return new NPCUser(this.citizensId, playerArmor, entityIds); } @Override diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/database/dao/UserDAO.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/database/dao/UserDAO.java index 8f7ba54d..2b78b5ea 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/database/dao/UserDAO.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/database/dao/UserDAO.java @@ -5,6 +5,7 @@ import com.j256.ormlite.table.DatabaseTable; import io.github.fisher2911.hmccosmetics.cosmetic.CosmeticManager; import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; +import io.github.fisher2911.hmccosmetics.packet.EntityIds; import io.github.fisher2911.hmccosmetics.user.BaseUser; import io.github.fisher2911.hmccosmetics.user.NPCUser; import io.github.fisher2911.hmccosmetics.user.User; @@ -35,10 +36,9 @@ public class UserDAO { @Nullable public User toUser( final CosmeticManager cosmeticManager, - final int entityId, + final EntityIds entityIds, final List armorItems, - final Wardrobe wardrobe, - final int armorStandId + final Wardrobe wardrobe ) { final PlayerArmor playerArmor = PlayerArmor.empty(); @@ -50,7 +50,7 @@ public class UserDAO { playerArmor.setItem(armorItem); } - return new User(this.uuid, entityId, playerArmor, wardrobe, armorStandId); + return new User(this.uuid, playerArmor, wardrobe, entityIds); } @Override diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/hook/item/CitizensHook.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/hook/item/CitizensHook.java index 62ae7d29..9a7be5e6 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/hook/item/CitizensHook.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/hook/item/CitizensHook.java @@ -49,7 +49,7 @@ public class CitizensHook implements Hook, Listener { if (!user.isValid()) { continue; } - user.updateArmorStand(settings); + user.updateOutsideCosmetics(settings); } }) ); diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/packet/EntityIds.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/packet/EntityIds.java new file mode 100644 index 00000000..8447776c --- /dev/null +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/packet/EntityIds.java @@ -0,0 +1,42 @@ +package io.github.fisher2911.hmccosmetics.packet; + +import java.util.EnumMap; +import java.util.Map; + +public class EntityIds { + + private final Map ids; + + public EntityIds(final Map ids) { + this.ids = ids; + } + + public EntityIds(final int self, final int armorStand, final int balloon) { + final Map ids = new EnumMap<>(Type.class); + ids.put(Type.SELF, self); + ids.put(Type.ARMOR_STAND, armorStand); + ids.put(Type.BALLOON, balloon); + this.ids = ids; + } + + public int self() { + return ids.getOrDefault(Type.SELF, -1); + } + + public int armorStand() { + return ids.getOrDefault(Type.ARMOR_STAND, -1); + } + + public int balloon() { + return ids.getOrDefault(Type.BALLOON, -1); + } + + public enum Type { + + SELF, + ARMOR_STAND, + BALLOON + + } + +} diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/packet/PacketManager.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/packet/PacketManager.java index bc7b4e47..ace6654a 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/packet/PacketManager.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/packet/PacketManager.java @@ -96,6 +96,12 @@ public class PacketManager { return packet; } + public static PacketContainer getLeashPacket(final int entityId, final int balloonId) { + final PacketContainer packet = new PacketContainer(PacketType.Play.Server.ATTACH_ENTITY); + packet.getIntegers().write(0, balloonId).write(1, entityId); + return packet; + } + public static PacketContainer getEquipmentPacket( final List> equipmentList, final int entityId diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/BaseUser.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/BaseUser.java index e07766a8..81773c44 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/BaseUser.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/BaseUser.java @@ -7,6 +7,7 @@ import io.github.fisher2911.hmccosmetics.config.CosmeticSettings; import io.github.fisher2911.hmccosmetics.config.Settings; import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; +import io.github.fisher2911.hmccosmetics.packet.EntityIds; import io.github.fisher2911.hmccosmetics.packet.PacketManager; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -26,22 +27,21 @@ import java.util.UUID; public abstract class BaseUser { protected final T id; - protected final int entityId; + protected final EntityIds entityIds; protected final PlayerArmor playerArmor; protected ArmorItem lastSetItem = ArmorItem.empty(ArmorItem.Type.HAT); protected boolean hasArmorStand; - protected final int armorStandId; + protected boolean hasBallon; // List of players that are currently viewing the armor stand protected final Set viewing = new HashSet<>(); - public BaseUser(final T id, final int entityId, final PlayerArmor playerArmor, final int armorStandId) { + public BaseUser(final T id, final PlayerArmor playerArmor, final EntityIds entityIds) { this.id = id; - this.entityId = entityId; + this.entityIds = entityIds; this.playerArmor = playerArmor; - this.armorStandId = armorStandId; } @Nullable @@ -68,7 +68,11 @@ public abstract class BaseUser { } public int getArmorStandId() { - return armorStandId; + return this.entityIds.armorStand(); + } + + public int getBalloonId() { + return this.entityIds.balloon(); } protected ArmorItem setItem(final ArmorItem armorItem) { @@ -80,47 +84,78 @@ public abstract class BaseUser { return this.setItem(ArmorItem.empty(type)); } - public void spawnArmorStand(final Player other, final Location location, final CosmeticSettings settings) { - if (!this.isInViewDistance(this.getLocation(), other.getLocation(), settings) || !shouldShow(other)) return; + public void spawnOutsideCosmetics(final Player other, final Location location, final Settings settings) { + if (this.getLocation() == null) return; + this.updateOutsideCosmetics(other, location, settings); + } - final PacketContainer packet = PacketManager.getEntitySpawnPacket(location, this.armorStandId, EntityType.ARMOR_STAND); - this.viewing.add(other.getUniqueId()); + private void despawnBalloon(final Player other) { + final PacketContainer removePacket = PacketManager.getEntityDestroyPacket(this.getBalloonId()); + PacketManager.sendPacket(other, removePacket); + } + + private void spawnBalloon(final Player other, final Location location, final CosmeticSettings settings) { + final Location actual = location.add(0, 5, 0); + final PacketContainer spawnPacket = PacketManager.getEntitySpawnPacket(actual, this.getBalloonId(), EntityType.PIG); + final PacketContainer leashPacket = PacketManager.getLeashPacket(this.getBalloonId(), this.getEntityId()); + PacketManager.sendPacket(other, spawnPacket, leashPacket); + } + + private void updateBalloon(final CosmeticSettings settings) { + final Location location = this.getLocation(); + for (final Player player : Bukkit.getOnlinePlayers()) { + if (!this.hasBallon) { + this.spawnBalloon(player, location, settings); + } else { + this.updateBalloon(player, location, settings); + } + } + this.hasBallon = true; + } + + private void updateBalloon(final Player other, final Location location, final CosmeticSettings settings) { +// final PacketContainer spawnPacket = PacketManager.getEntitySpawnPacket(location, this.getBalloonId(), EntityType.PARROT); +// PacketManager.sendPacket(other, spawnPacket, spawnPacket); + } + + private void spawnArmorStand(final Player other, final Location location, final CosmeticSettings settings) { +// if (!this.isInViewDistance(this.getLocation(), other.getLocation(), settings) || !shouldShow(other)) return; + final PacketContainer packet = PacketManager.getEntitySpawnPacket(location, this.getArmorStandId(), EntityType.ARMOR_STAND); PacketManager.sendPacket(other, packet); } - public void spawnArmorStand(final Settings settings) { - if (this.hasArmorStand) { - this.updateArmorStand(settings); - return; - } +// private void spawnArmorStand(final Settings settings) { +// if (this.hasArmorStand) { +// this.updateArmorStand(settings); +// return; +// } +// +// for (final Player p : Bukkit.getOnlinePlayers()) { +// this.spawnArmorStand(p, this.getLocation(), settings.getCosmeticSettings()); +// } +// +// this.hasArmorStand = true; +// } - for (final Player p : Bukkit.getOnlinePlayers()) { - this.spawnArmorStand(p, this.getLocation(), settings.getCosmeticSettings()); - } - - this.hasArmorStand = true; + public void updateOutsideCosmetics(final Player player, final Settings settings) { + this.updateOutsideCosmetics(player, this.getLocation(), settings); } - public void updateArmorStand(final Settings settings) { - if (!this.hasArmorStand) { - this.spawnArmorStand(settings); - } + public void updateOutsideCosmetics(final Settings settings) { for (final Player player : Bukkit.getOnlinePlayers()) { - this.updateArmorStand(player, settings); + this.spawnOutsideCosmetics(player, this.getLocation(), settings); } } - public void updateArmorStand(final Player other, final Settings settings) { - this.updateArmorStand(other, settings, this.getLocation()); - } - - public void updateArmorStand(final Player other, final Settings settings, final Location location) { + public void updateOutsideCosmetics(final Player other, final Location location, final Settings settings) { final boolean inViewDistance = this.isInViewDistance(this.getLocation(), other.getLocation(), settings.getCosmeticSettings()); if (!this.viewing.contains(other.getUniqueId())) { if (!inViewDistance || !shouldShow(other)) return; this.spawnArmorStand(other, location, settings.getCosmeticSettings()); + this.spawnBalloon(other, location, settings.getCosmeticSettings()); } else if (!inViewDistance || !shouldShow(other)) { this.despawnAttached(other); + this.despawnBalloon(other); this.viewing.remove(other.getUniqueId()); return; } @@ -136,15 +171,18 @@ public abstract class BaseUser { )); } - final PacketContainer armorPacket = PacketManager.getEquipmentPacket(equipmentList, this.armorStandId); - final PacketContainer rotationPacket = PacketManager.getRotationPacket(this.armorStandId, location); - final PacketContainer ridingPacket = PacketManager.getRidingPacket(this.getEntityId(), this.armorStandId); - final PacketContainer armorStandMetaContainer = PacketManager.getArmorStandMetaContainer(this.armorStandId); + final int armorStandId = this.getArmorStandId(); + final PacketContainer armorPacket = PacketManager.getEquipmentPacket(equipmentList, armorStandId); + final PacketContainer rotationPacket = PacketManager.getRotationPacket(armorStandId, location); + final PacketContainer ridingPacket = PacketManager.getRidingPacket(this.getEntityId(), armorStandId); + final PacketContainer armorStandMetaContainer = PacketManager.getArmorStandMetaContainer(armorStandId); PacketManager.sendPacket(other, armorPacket, armorStandMetaContainer, rotationPacket, ridingPacket); if (hidden) return; + this.updateBalloon(other, location, settings.getCosmeticSettings()); + final int lookDownPitch = settings.getCosmeticSettings().getLookDownPitch(); if (lookDownPitch != -1 && @@ -154,7 +192,7 @@ public abstract class BaseUser { )); if (!this.id.equals(other.getUniqueId())) return; - PacketManager.sendPacket(other, PacketManager.getEquipmentPacket(equipmentList, this.armorStandId)); + PacketManager.sendPacket(other, PacketManager.getEquipmentPacket(equipmentList, armorStandId)); } } @@ -170,13 +208,13 @@ public abstract class BaseUser { } public void despawnAttached(final Player other) { - PacketManager.sendPacket(other, PacketManager.getEntityDestroyPacket(this.armorStandId)); + PacketManager.sendPacket(other, PacketManager.getEntityDestroyPacket(this.getArmorStandId())); this.viewing.remove(other.getUniqueId()); this.hasArmorStand = false; } public void despawnAttached() { - PacketManager.sendPacketToOnline(PacketManager.getEntityDestroyPacket(this.armorStandId)); + PacketManager.sendPacketToOnline(PacketManager.getEntityDestroyPacket(this.getArmorStandId())); this.hasArmorStand = false; } @@ -189,7 +227,7 @@ public abstract class BaseUser { } public int getEntityId() { - return this.entityId; + return this.entityIds.self(); } public abstract Equipment getEquipment(); diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/NPCUser.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/NPCUser.java index cad9f4d9..c9e0a18d 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/NPCUser.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/NPCUser.java @@ -3,6 +3,7 @@ package io.github.fisher2911.hmccosmetics.user; import io.github.fisher2911.hmccosmetics.hook.HookManager; import io.github.fisher2911.hmccosmetics.hook.item.CitizensHook; import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; +import io.github.fisher2911.hmccosmetics.packet.EntityIds; import net.citizensnpcs.api.npc.NPC; import org.bukkit.Location; import org.bukkit.entity.Entity; @@ -14,13 +15,13 @@ public class NPCUser extends BaseUser { private final CitizensHook hook; - public NPCUser(final int id, final int entityId, final PlayerArmor playerArmor, final int armorStandId) { - super(id, entityId, playerArmor, armorStandId); + public NPCUser(final int id, final PlayerArmor playerArmor, final EntityIds entityIds) { + super(id, playerArmor, entityIds); this.hook = HookManager.getInstance().getCitizensHook(); } - public NPCUser(final PlayerArmor playerArmor, final int armorStandId, final NPC npc) { - this(npc.getId(), npc.getId(), playerArmor, armorStandId); + public NPCUser(final PlayerArmor playerArmor, final NPC npc, final EntityIds entityIds) { + this(npc.getId(), playerArmor, entityIds); } @Nullable diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java index 7fd7892a..18890a40 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/User.java @@ -3,6 +3,7 @@ package io.github.fisher2911.hmccosmetics.user; import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.gui.CosmeticGui; import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; +import io.github.fisher2911.hmccosmetics.packet.EntityIds; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; @@ -18,13 +19,13 @@ public class User extends BaseUser { private CosmeticGui openGui; private boolean hidden; - public User(final UUID uuid, final int entityId, final PlayerArmor playerArmor, final Wardrobe wardrobe, final int armorStandId) { - super(uuid, entityId, playerArmor, armorStandId); + public User(final UUID uuid, final PlayerArmor playerArmor, final Wardrobe wardrobe, final EntityIds entityIds) { + super(uuid, playerArmor, entityIds); this.wardrobe = wardrobe; } - public User(final UUID uuid, final int entityId, final PlayerArmor playerArmor, final int armorStandId) { - super(uuid, entityId, playerArmor, armorStandId); + public User(final UUID uuid, final PlayerArmor playerArmor, final EntityIds entityIds) { + super(uuid, playerArmor, entityIds); } public @Nullable Player getPlayer() { diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/UserFactory.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/UserFactory.java index 9aae535d..d8e66864 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/UserFactory.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/UserFactory.java @@ -4,6 +4,7 @@ import io.github.fisher2911.hmccosmetics.HMCCosmetics; import io.github.fisher2911.hmccosmetics.hook.HookManager; import io.github.fisher2911.hmccosmetics.hook.item.CitizensHook; import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; +import io.github.fisher2911.hmccosmetics.packet.EntityIds; import org.bukkit.entity.Entity; import org.jetbrains.annotations.Nullable; @@ -24,17 +25,21 @@ public class UserFactory { public static T createUser( final Class type, final Entity entity, - final int armorStandId + final int armorStandId, + final int balloonId ) { final UUID uuid = entity.getUniqueId(); final int entityId = entity.getEntityId(); if (type.equals(User.class)) { return (T) new User( uuid, - entityId, PlayerArmor.empty(), plugin.getDatabase().createNewWardrobe(uuid), - armorStandId + new EntityIds( + entityId, + armorStandId, + balloonId + ) ); } @@ -43,9 +48,12 @@ public class UserFactory { final int citizensId = HookManager.getInstance().getCitizensHook().getCitizensId(entity); return (T) new NPCUser( citizensId, - entityId, PlayerArmor.empty(), - armorStandId + new EntityIds( + entityId, + armorStandId, + balloonId + ) ); } diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/UserManager.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/UserManager.java index a5335333..f1339d44 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/UserManager.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/UserManager.java @@ -89,7 +89,7 @@ public class UserManager { this.plugin.getTaskManager().submit(new InfiniteTask( () -> { for (final User user : this.userMap.values()) { - user.updateArmorStand(this.plugin.getSettings()); + user.updateOutsideCosmetics(this.plugin.getSettings()); } } )); @@ -99,7 +99,7 @@ public class UserManager { for (final User user : this.userMap.values()) { final Player p = user.getPlayer(); if (p == null) continue; - user.spawnArmorStand(player, p.getLocation(), this.settings.getCosmeticSettings()); + user.updateOutsideCosmetics(player, p.getLocation(), this.settings); this.updateCosmetics(user, player); } } @@ -202,7 +202,7 @@ public class UserManager { this.updateCosmetics(user); } case BACKPACK -> { - if (user instanceof Wardrobe) user.updateArmorStand(settings); + if (user instanceof Wardrobe) user.updateOutsideCosmetics(settings); } } }); diff --git a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/Wardrobe.java b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/Wardrobe.java index 900a4d36..5e02d5f3 100644 --- a/common/src/main/java/io/github/fisher2911/hmccosmetics/user/Wardrobe.java +++ b/common/src/main/java/io/github/fisher2911/hmccosmetics/user/Wardrobe.java @@ -6,6 +6,7 @@ import io.github.fisher2911.hmccosmetics.config.Settings; import io.github.fisher2911.hmccosmetics.config.WardrobeSettings; import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; +import io.github.fisher2911.hmccosmetics.packet.EntityIds; import io.github.fisher2911.hmccosmetics.packet.PacketManager; import io.github.fisher2911.hmccosmetics.task.SupplierTask; import io.github.fisher2911.hmccosmetics.task.Task; @@ -23,7 +24,6 @@ public class Wardrobe extends User { private final HMCCosmetics plugin; private final UUID ownerUUID; - private final int viewerId; private boolean active; private boolean cameraLocked; @@ -34,16 +34,13 @@ public class Wardrobe extends User { public Wardrobe( final HMCCosmetics plugin, final UUID uuid, - final int entityId, final UUID ownerUUID, final PlayerArmor playerArmor, - final int armorStandId, - final int viewerId, + final EntityIds entityIds, final boolean active) { - super(uuid, entityId, playerArmor, armorStandId); + super(uuid, playerArmor, entityIds); this.plugin = plugin; this.ownerUUID = ownerUUID; - this.viewerId = viewerId; this.active = active; this.wardrobe = this; } @@ -106,8 +103,8 @@ public class Wardrobe extends User { this.plugin, () -> { PacketManager.sendPacket(viewer, playerInfoPacket, playerSpawnPacket); - this.spawnArmorStand(viewer, this.currentLocation, this.plugin.getSettings().getCosmeticSettings()); - this.updateArmorStand(viewer, plugin.getSettings(), this.currentLocation); + this.spawnOutsideCosmetics(viewer, this.currentLocation, this.plugin.getSettings()); + this.updateOutsideCosmetics(viewer, this.currentLocation, plugin.getSettings()); PacketManager.sendPacket( viewer, PacketManager.getLookPacket(this.getEntityId(), this.currentLocation), @@ -123,8 +120,8 @@ public class Wardrobe extends User { } @Override - public void updateArmorStand(final Player player, final Settings settings) { - this.updateArmorStand(player, settings, this.currentLocation); + public void updateOutsideCosmetics(final Player player, final Settings settings) { + this.updateOutsideCosmetics(player, this.currentLocation, settings); } public void despawnFakePlayer(final Player viewer) { @@ -168,7 +165,7 @@ public class Wardrobe extends User { final int yaw = data.get(); location.setYaw(yaw); PacketManager.sendPacket(player, PacketManager.getLookPacket(this.getEntityId(), location)); - this.updateArmorStand(player, this.plugin.getSettings(), location); + this.updateOutsideCosmetics(player, location, this.plugin.getSettings()); location.setYaw(this.getNextYaw(yaw - 30, rotationSpeed)); PacketManager.sendPacket(player, PacketManager.getRotationPacket(this.getEntityId(), location)); data.set(this.getNextYaw(yaw, rotationSpeed));