9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-23 00:49:28 +00:00

Start balloon stuff

This commit is contained in:
MasterOfTheFish
2022-02-23 19:38:49 -05:00
parent 59dbee34ae
commit 35c6b01f34
16 changed files with 200 additions and 89 deletions

Binary file not shown.

View File

@@ -13,6 +13,7 @@ import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
import io.github.fisher2911.hmccosmetics.hook.HookManager; import io.github.fisher2911.hmccosmetics.hook.HookManager;
import io.github.fisher2911.hmccosmetics.hook.item.CitizensHook; import io.github.fisher2911.hmccosmetics.hook.item.CitizensHook;
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; 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.BaseUser;
import io.github.fisher2911.hmccosmetics.user.NPCUser; import io.github.fisher2911.hmccosmetics.user.NPCUser;
import io.github.fisher2911.hmccosmetics.user.User; import io.github.fisher2911.hmccosmetics.user.User;
@@ -83,6 +84,7 @@ public class Database {
public void loadUser(final Entity entity, final Consumer<User> onComplete) { public void loadUser(final Entity entity, final Consumer<User> onComplete) {
final UUID uuid = entity.getUniqueId(); final UUID uuid = entity.getUniqueId();
final int armorStandId = FAKE_ENTITY_ID.getAndDecrement(); final int armorStandId = FAKE_ENTITY_ID.getAndDecrement();
final int balloonId = FAKE_ENTITY_ID.getAndDecrement();
final Wardrobe wardrobe = this.createNewWardrobe(uuid); final Wardrobe wardrobe = this.createNewWardrobe(uuid);
Threads.getInstance().execute( Threads.getInstance().execute(
() -> { () -> {
@@ -97,10 +99,13 @@ public class Database {
final User actualUser = user.toUser( final User actualUser = user.toUser(
this.plugin.getCosmeticManager(), this.plugin.getCosmeticManager(),
entity.getEntityId(), new EntityIds(
entity.getEntityId(),
armorStandId,
balloonId
),
armorItems, armorItems,
wardrobe, wardrobe
armorStandId
); );
Bukkit.getScheduler().runTask(this.plugin, Bukkit.getScheduler().runTask(this.plugin,
() -> onComplete.accept(actualUser) () -> onComplete.accept(actualUser)
@@ -112,15 +117,14 @@ public class Database {
}); });
onComplete.accept(new User( onComplete.accept(new User(
uuid, uuid,
entity.getEntityId(),
PlayerArmor.empty(), PlayerArmor.empty(),
wardrobe, new EntityIds(entity.getEntityId(), armorStandId, balloonId)
armorStandId
)); ));
} }
public void loadNPCUser(final int id, final Entity entity, final Consumer<NPCUser> onComplete) { public void loadNPCUser(final int id, final Entity entity, final Consumer<NPCUser> onComplete) {
final int armorStandId = FAKE_ENTITY_ID.getAndDecrement(); final int armorStandId = FAKE_ENTITY_ID.getAndDecrement();
final int balloonId = FAKE_ENTITY_ID.getAndDecrement();
Threads.getInstance().execute( Threads.getInstance().execute(
() -> { () -> {
try { try {
@@ -134,9 +138,12 @@ public class Database {
final NPCUser actualUser = citizen.toUser( final NPCUser actualUser = citizen.toUser(
this.plugin.getCosmeticManager(), this.plugin.getCosmeticManager(),
entity.getEntityId(), new EntityIds(
armorItems, entity.getEntityId(),
armorStandId armorStandId,
balloonId
),
armorItems
); );
Bukkit.getScheduler().runTask(this.plugin, 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) { public void saveUser(final User user) {
@@ -219,11 +231,13 @@ public class Database {
return new Wardrobe( return new Wardrobe(
this.plugin, this.plugin,
UUID.randomUUID(), UUID.randomUUID(),
FAKE_ENTITY_ID.getAndDecrement(),
ownerUUID, ownerUUID,
PlayerArmor.empty(), PlayerArmor.empty(),
FAKE_ENTITY_ID.getAndDecrement(), new EntityIds(
FAKE_ENTITY_ID.getAndDecrement(), FAKE_ENTITY_ID.getAndDecrement(),
FAKE_ENTITY_ID.getAndDecrement(),
FAKE_ENTITY_ID.getAndDecrement()
),
false false
); );
} }

View File

@@ -3,6 +3,7 @@ package io.github.fisher2911.hmccosmetics.database;
import io.github.fisher2911.hmccosmetics.HMCCosmetics; import io.github.fisher2911.hmccosmetics.HMCCosmetics;
import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
import io.github.fisher2911.hmccosmetics.packet.EntityIds;
import io.github.fisher2911.hmccosmetics.user.User; import io.github.fisher2911.hmccosmetics.user.User;
import java.io.File; import java.io.File;
@@ -93,10 +94,13 @@ public class DatabaseConverter {
final UUID uuid = UUID.fromString(results.getString(1)); final UUID uuid = UUID.fromString(results.getString(1));
final User user = new User( final User user = new User(
uuid, uuid,
-1,
playerArmor, playerArmor,
this.database.createNewWardrobe(uuid), 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 backpackId = results.getString(2);
final String hatId = results.getString(3); final String hatId = results.getString(3);

View File

@@ -5,6 +5,7 @@ import com.j256.ormlite.table.DatabaseTable;
import io.github.fisher2911.hmccosmetics.cosmetic.CosmeticManager; import io.github.fisher2911.hmccosmetics.cosmetic.CosmeticManager;
import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; 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.BaseUser;
import io.github.fisher2911.hmccosmetics.user.NPCUser; import io.github.fisher2911.hmccosmetics.user.NPCUser;
import io.github.fisher2911.hmccosmetics.user.User; import io.github.fisher2911.hmccosmetics.user.User;
@@ -34,9 +35,8 @@ public class CitizenDAO {
@Nullable @Nullable
public NPCUser toUser( public NPCUser toUser(
final CosmeticManager cosmeticManager, final CosmeticManager cosmeticManager,
final int entityId, final EntityIds entityIds,
final List<ArmorItemDAO> armorItems, final List<ArmorItemDAO> armorItems
final int armorStandId
) { ) {
final PlayerArmor playerArmor = PlayerArmor.empty(); final PlayerArmor playerArmor = PlayerArmor.empty();
@@ -48,7 +48,7 @@ public class CitizenDAO {
playerArmor.setItem(armorItem); playerArmor.setItem(armorItem);
} }
return new NPCUser(this.citizensId, entityId, playerArmor, armorStandId); return new NPCUser(this.citizensId, playerArmor, entityIds);
} }
@Override @Override

View File

@@ -5,6 +5,7 @@ import com.j256.ormlite.table.DatabaseTable;
import io.github.fisher2911.hmccosmetics.cosmetic.CosmeticManager; import io.github.fisher2911.hmccosmetics.cosmetic.CosmeticManager;
import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; 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.BaseUser;
import io.github.fisher2911.hmccosmetics.user.NPCUser; import io.github.fisher2911.hmccosmetics.user.NPCUser;
import io.github.fisher2911.hmccosmetics.user.User; import io.github.fisher2911.hmccosmetics.user.User;
@@ -35,10 +36,9 @@ public class UserDAO {
@Nullable @Nullable
public User toUser( public User toUser(
final CosmeticManager cosmeticManager, final CosmeticManager cosmeticManager,
final int entityId, final EntityIds entityIds,
final List<ArmorItemDAO> armorItems, final List<ArmorItemDAO> armorItems,
final Wardrobe wardrobe, final Wardrobe wardrobe
final int armorStandId
) { ) {
final PlayerArmor playerArmor = PlayerArmor.empty(); final PlayerArmor playerArmor = PlayerArmor.empty();
@@ -50,7 +50,7 @@ public class UserDAO {
playerArmor.setItem(armorItem); playerArmor.setItem(armorItem);
} }
return new User(this.uuid, entityId, playerArmor, wardrobe, armorStandId); return new User(this.uuid, playerArmor, wardrobe, entityIds);
} }
@Override @Override

View File

@@ -49,7 +49,7 @@ public class CitizensHook implements Hook, Listener {
if (!user.isValid()) { if (!user.isValid()) {
continue; continue;
} }
user.updateArmorStand(settings); user.updateOutsideCosmetics(settings);
} }
}) })
); );

View File

@@ -0,0 +1,42 @@
package io.github.fisher2911.hmccosmetics.packet;
import java.util.EnumMap;
import java.util.Map;
public class EntityIds {
private final Map<Type, Integer> ids;
public EntityIds(final Map<Type, Integer> ids) {
this.ids = ids;
}
public EntityIds(final int self, final int armorStand, final int balloon) {
final Map<Type, Integer> 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
}
}

View File

@@ -96,6 +96,12 @@ public class PacketManager {
return packet; 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( public static PacketContainer getEquipmentPacket(
final List<Pair<EnumWrappers.ItemSlot, ItemStack>> equipmentList, final List<Pair<EnumWrappers.ItemSlot, ItemStack>> equipmentList,
final int entityId final int entityId

View File

@@ -7,6 +7,7 @@ import io.github.fisher2911.hmccosmetics.config.CosmeticSettings;
import io.github.fisher2911.hmccosmetics.config.Settings; import io.github.fisher2911.hmccosmetics.config.Settings;
import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; 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.packet.PacketManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@@ -26,22 +27,21 @@ import java.util.UUID;
public abstract class BaseUser<T> { public abstract class BaseUser<T> {
protected final T id; protected final T id;
protected final int entityId; protected final EntityIds entityIds;
protected final PlayerArmor playerArmor; protected final PlayerArmor playerArmor;
protected ArmorItem lastSetItem = ArmorItem.empty(ArmorItem.Type.HAT); protected ArmorItem lastSetItem = ArmorItem.empty(ArmorItem.Type.HAT);
protected boolean hasArmorStand; protected boolean hasArmorStand;
protected final int armorStandId; protected boolean hasBallon;
// List of players that are currently viewing the armor stand // List of players that are currently viewing the armor stand
protected final Set<UUID> viewing = new HashSet<>(); protected final Set<UUID> 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.id = id;
this.entityId = entityId; this.entityIds = entityIds;
this.playerArmor = playerArmor; this.playerArmor = playerArmor;
this.armorStandId = armorStandId;
} }
@Nullable @Nullable
@@ -68,7 +68,11 @@ public abstract class BaseUser<T> {
} }
public int getArmorStandId() { public int getArmorStandId() {
return armorStandId; return this.entityIds.armorStand();
}
public int getBalloonId() {
return this.entityIds.balloon();
} }
protected ArmorItem setItem(final ArmorItem armorItem) { protected ArmorItem setItem(final ArmorItem armorItem) {
@@ -80,47 +84,78 @@ public abstract class BaseUser<T> {
return this.setItem(ArmorItem.empty(type)); return this.setItem(ArmorItem.empty(type));
} }
public void spawnArmorStand(final Player other, final Location location, final CosmeticSettings settings) { public void spawnOutsideCosmetics(final Player other, final Location location, final Settings settings) {
if (!this.isInViewDistance(this.getLocation(), other.getLocation(), settings) || !shouldShow(other)) return; if (this.getLocation() == null) return;
this.updateOutsideCosmetics(other, location, settings);
}
final PacketContainer packet = PacketManager.getEntitySpawnPacket(location, this.armorStandId, EntityType.ARMOR_STAND); private void despawnBalloon(final Player other) {
this.viewing.add(other.getUniqueId()); 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); PacketManager.sendPacket(other, packet);
} }
public void spawnArmorStand(final Settings settings) { // private void spawnArmorStand(final Settings settings) {
if (this.hasArmorStand) { // if (this.hasArmorStand) {
this.updateArmorStand(settings); // this.updateArmorStand(settings);
return; // return;
} // }
//
// for (final Player p : Bukkit.getOnlinePlayers()) {
// this.spawnArmorStand(p, this.getLocation(), settings.getCosmeticSettings());
// }
//
// this.hasArmorStand = true;
// }
for (final Player p : Bukkit.getOnlinePlayers()) { public void updateOutsideCosmetics(final Player player, final Settings settings) {
this.spawnArmorStand(p, this.getLocation(), settings.getCosmeticSettings()); this.updateOutsideCosmetics(player, this.getLocation(), settings);
}
this.hasArmorStand = true;
} }
public void updateArmorStand(final Settings settings) { public void updateOutsideCosmetics(final Settings settings) {
if (!this.hasArmorStand) {
this.spawnArmorStand(settings);
}
for (final Player player : Bukkit.getOnlinePlayers()) { 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) { public void updateOutsideCosmetics(final Player other, final Location location, final Settings settings) {
this.updateArmorStand(other, settings, this.getLocation());
}
public void updateArmorStand(final Player other, final Settings settings, final Location location) {
final boolean inViewDistance = this.isInViewDistance(this.getLocation(), other.getLocation(), settings.getCosmeticSettings()); final boolean inViewDistance = this.isInViewDistance(this.getLocation(), other.getLocation(), settings.getCosmeticSettings());
if (!this.viewing.contains(other.getUniqueId())) { if (!this.viewing.contains(other.getUniqueId())) {
if (!inViewDistance || !shouldShow(other)) return; if (!inViewDistance || !shouldShow(other)) return;
this.spawnArmorStand(other, location, settings.getCosmeticSettings()); this.spawnArmorStand(other, location, settings.getCosmeticSettings());
this.spawnBalloon(other, location, settings.getCosmeticSettings());
} else if (!inViewDistance || !shouldShow(other)) { } else if (!inViewDistance || !shouldShow(other)) {
this.despawnAttached(other); this.despawnAttached(other);
this.despawnBalloon(other);
this.viewing.remove(other.getUniqueId()); this.viewing.remove(other.getUniqueId());
return; return;
} }
@@ -136,15 +171,18 @@ public abstract class BaseUser<T> {
)); ));
} }
final PacketContainer armorPacket = PacketManager.getEquipmentPacket(equipmentList, this.armorStandId); final int armorStandId = this.getArmorStandId();
final PacketContainer rotationPacket = PacketManager.getRotationPacket(this.armorStandId, location); final PacketContainer armorPacket = PacketManager.getEquipmentPacket(equipmentList, armorStandId);
final PacketContainer ridingPacket = PacketManager.getRidingPacket(this.getEntityId(), this.armorStandId); final PacketContainer rotationPacket = PacketManager.getRotationPacket(armorStandId, location);
final PacketContainer armorStandMetaContainer = PacketManager.getArmorStandMetaContainer(this.armorStandId); final PacketContainer ridingPacket = PacketManager.getRidingPacket(this.getEntityId(), armorStandId);
final PacketContainer armorStandMetaContainer = PacketManager.getArmorStandMetaContainer(armorStandId);
PacketManager.sendPacket(other, armorPacket, armorStandMetaContainer, rotationPacket, ridingPacket); PacketManager.sendPacket(other, armorPacket, armorStandMetaContainer, rotationPacket, ridingPacket);
if (hidden) return; if (hidden) return;
this.updateBalloon(other, location, settings.getCosmeticSettings());
final int lookDownPitch = settings.getCosmeticSettings().getLookDownPitch(); final int lookDownPitch = settings.getCosmeticSettings().getLookDownPitch();
if (lookDownPitch != -1 && if (lookDownPitch != -1 &&
@@ -154,7 +192,7 @@ public abstract class BaseUser<T> {
)); ));
if (!this.id.equals(other.getUniqueId())) return; 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<T> {
} }
public void despawnAttached(final Player other) { 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.viewing.remove(other.getUniqueId());
this.hasArmorStand = false; this.hasArmorStand = false;
} }
public void despawnAttached() { public void despawnAttached() {
PacketManager.sendPacketToOnline(PacketManager.getEntityDestroyPacket(this.armorStandId)); PacketManager.sendPacketToOnline(PacketManager.getEntityDestroyPacket(this.getArmorStandId()));
this.hasArmorStand = false; this.hasArmorStand = false;
} }
@@ -189,7 +227,7 @@ public abstract class BaseUser<T> {
} }
public int getEntityId() { public int getEntityId() {
return this.entityId; return this.entityIds.self();
} }
public abstract Equipment getEquipment(); public abstract Equipment getEquipment();

View File

@@ -3,6 +3,7 @@ package io.github.fisher2911.hmccosmetics.user;
import io.github.fisher2911.hmccosmetics.hook.HookManager; import io.github.fisher2911.hmccosmetics.hook.HookManager;
import io.github.fisher2911.hmccosmetics.hook.item.CitizensHook; import io.github.fisher2911.hmccosmetics.hook.item.CitizensHook;
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
import io.github.fisher2911.hmccosmetics.packet.EntityIds;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
@@ -14,13 +15,13 @@ public class NPCUser extends BaseUser<Integer> {
private final CitizensHook hook; private final CitizensHook hook;
public NPCUser(final int id, final int entityId, final PlayerArmor playerArmor, final int armorStandId) { public NPCUser(final int id, final PlayerArmor playerArmor, final EntityIds entityIds) {
super(id, entityId, playerArmor, armorStandId); super(id, playerArmor, entityIds);
this.hook = HookManager.getInstance().getCitizensHook(); this.hook = HookManager.getInstance().getCitizensHook();
} }
public NPCUser(final PlayerArmor playerArmor, final int armorStandId, final NPC npc) { public NPCUser(final PlayerArmor playerArmor, final NPC npc, final EntityIds entityIds) {
this(npc.getId(), npc.getId(), playerArmor, armorStandId); this(npc.getId(), playerArmor, entityIds);
} }
@Nullable @Nullable

View File

@@ -3,6 +3,7 @@ package io.github.fisher2911.hmccosmetics.user;
import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
import io.github.fisher2911.hmccosmetics.gui.CosmeticGui; import io.github.fisher2911.hmccosmetics.gui.CosmeticGui;
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
import io.github.fisher2911.hmccosmetics.packet.EntityIds;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
@@ -18,13 +19,13 @@ public class User extends BaseUser<UUID> {
private CosmeticGui openGui; private CosmeticGui openGui;
private boolean hidden; private boolean hidden;
public User(final UUID uuid, final int entityId, final PlayerArmor playerArmor, final Wardrobe wardrobe, final int armorStandId) { public User(final UUID uuid, final PlayerArmor playerArmor, final Wardrobe wardrobe, final EntityIds entityIds) {
super(uuid, entityId, playerArmor, armorStandId); super(uuid, playerArmor, entityIds);
this.wardrobe = wardrobe; this.wardrobe = wardrobe;
} }
public User(final UUID uuid, final int entityId, final PlayerArmor playerArmor, final int armorStandId) { public User(final UUID uuid, final PlayerArmor playerArmor, final EntityIds entityIds) {
super(uuid, entityId, playerArmor, armorStandId); super(uuid, playerArmor, entityIds);
} }
public @Nullable Player getPlayer() { public @Nullable Player getPlayer() {

View File

@@ -4,6 +4,7 @@ import io.github.fisher2911.hmccosmetics.HMCCosmetics;
import io.github.fisher2911.hmccosmetics.hook.HookManager; import io.github.fisher2911.hmccosmetics.hook.HookManager;
import io.github.fisher2911.hmccosmetics.hook.item.CitizensHook; import io.github.fisher2911.hmccosmetics.hook.item.CitizensHook;
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
import io.github.fisher2911.hmccosmetics.packet.EntityIds;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
@@ -24,17 +25,21 @@ public class UserFactory {
public static <T extends BaseUser> T createUser( public static <T extends BaseUser> T createUser(
final Class<T> type, final Class<T> type,
final Entity entity, final Entity entity,
final int armorStandId final int armorStandId,
final int balloonId
) { ) {
final UUID uuid = entity.getUniqueId(); final UUID uuid = entity.getUniqueId();
final int entityId = entity.getEntityId(); final int entityId = entity.getEntityId();
if (type.equals(User.class)) { if (type.equals(User.class)) {
return (T) new User( return (T) new User(
uuid, uuid,
entityId,
PlayerArmor.empty(), PlayerArmor.empty(),
plugin.getDatabase().createNewWardrobe(uuid), 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); final int citizensId = HookManager.getInstance().getCitizensHook().getCitizensId(entity);
return (T) new NPCUser( return (T) new NPCUser(
citizensId, citizensId,
entityId,
PlayerArmor.empty(), PlayerArmor.empty(),
armorStandId new EntityIds(
entityId,
armorStandId,
balloonId
)
); );
} }

View File

@@ -89,7 +89,7 @@ public class UserManager {
this.plugin.getTaskManager().submit(new InfiniteTask( this.plugin.getTaskManager().submit(new InfiniteTask(
() -> { () -> {
for (final User user : this.userMap.values()) { 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()) { for (final User user : this.userMap.values()) {
final Player p = user.getPlayer(); final Player p = user.getPlayer();
if (p == null) continue; if (p == null) continue;
user.spawnArmorStand(player, p.getLocation(), this.settings.getCosmeticSettings()); user.updateOutsideCosmetics(player, p.getLocation(), this.settings);
this.updateCosmetics(user, player); this.updateCosmetics(user, player);
} }
} }
@@ -202,7 +202,7 @@ public class UserManager {
this.updateCosmetics(user); this.updateCosmetics(user);
} }
case BACKPACK -> { case BACKPACK -> {
if (user instanceof Wardrobe) user.updateArmorStand(settings); if (user instanceof Wardrobe) user.updateOutsideCosmetics(settings);
} }
} }
}); });

View File

@@ -6,6 +6,7 @@ import io.github.fisher2911.hmccosmetics.config.Settings;
import io.github.fisher2911.hmccosmetics.config.WardrobeSettings; import io.github.fisher2911.hmccosmetics.config.WardrobeSettings;
import io.github.fisher2911.hmccosmetics.gui.ArmorItem; import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor; 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.packet.PacketManager;
import io.github.fisher2911.hmccosmetics.task.SupplierTask; import io.github.fisher2911.hmccosmetics.task.SupplierTask;
import io.github.fisher2911.hmccosmetics.task.Task; import io.github.fisher2911.hmccosmetics.task.Task;
@@ -23,7 +24,6 @@ public class Wardrobe extends User {
private final HMCCosmetics plugin; private final HMCCosmetics plugin;
private final UUID ownerUUID; private final UUID ownerUUID;
private final int viewerId;
private boolean active; private boolean active;
private boolean cameraLocked; private boolean cameraLocked;
@@ -34,16 +34,13 @@ public class Wardrobe extends User {
public Wardrobe( public Wardrobe(
final HMCCosmetics plugin, final HMCCosmetics plugin,
final UUID uuid, final UUID uuid,
final int entityId,
final UUID ownerUUID, final UUID ownerUUID,
final PlayerArmor playerArmor, final PlayerArmor playerArmor,
final int armorStandId, final EntityIds entityIds,
final int viewerId,
final boolean active) { final boolean active) {
super(uuid, entityId, playerArmor, armorStandId); super(uuid, playerArmor, entityIds);
this.plugin = plugin; this.plugin = plugin;
this.ownerUUID = ownerUUID; this.ownerUUID = ownerUUID;
this.viewerId = viewerId;
this.active = active; this.active = active;
this.wardrobe = this; this.wardrobe = this;
} }
@@ -106,8 +103,8 @@ public class Wardrobe extends User {
this.plugin, this.plugin,
() -> { () -> {
PacketManager.sendPacket(viewer, playerInfoPacket, playerSpawnPacket); PacketManager.sendPacket(viewer, playerInfoPacket, playerSpawnPacket);
this.spawnArmorStand(viewer, this.currentLocation, this.plugin.getSettings().getCosmeticSettings()); this.spawnOutsideCosmetics(viewer, this.currentLocation, this.plugin.getSettings());
this.updateArmorStand(viewer, plugin.getSettings(), this.currentLocation); this.updateOutsideCosmetics(viewer, this.currentLocation, plugin.getSettings());
PacketManager.sendPacket( PacketManager.sendPacket(
viewer, viewer,
PacketManager.getLookPacket(this.getEntityId(), this.currentLocation), PacketManager.getLookPacket(this.getEntityId(), this.currentLocation),
@@ -123,8 +120,8 @@ public class Wardrobe extends User {
} }
@Override @Override
public void updateArmorStand(final Player player, final Settings settings) { public void updateOutsideCosmetics(final Player player, final Settings settings) {
this.updateArmorStand(player, settings, this.currentLocation); this.updateOutsideCosmetics(player, this.currentLocation, settings);
} }
public void despawnFakePlayer(final Player viewer) { public void despawnFakePlayer(final Player viewer) {
@@ -168,7 +165,7 @@ public class Wardrobe extends User {
final int yaw = data.get(); final int yaw = data.get();
location.setYaw(yaw); location.setYaw(yaw);
PacketManager.sendPacket(player, PacketManager.getLookPacket(this.getEntityId(), location)); 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)); location.setYaw(this.getNextYaw(yaw - 30, rotationSpeed));
PacketManager.sendPacket(player, PacketManager.getRotationPacket(this.getEntityId(), location)); PacketManager.sendPacket(player, PacketManager.getRotationPacket(this.getEntityId(), location));
data.set(this.getNextYaw(yaw, rotationSpeed)); data.set(this.getNextYaw(yaw, rotationSpeed));