diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java index 1d080173..7faa70cb 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/config/Wardrobe.java @@ -52,7 +52,7 @@ public class Wardrobe { public boolean canEnter(CosmeticUser user) { Location wardrobeLocation = location.getNpcLocation(); - Location location = user.getPlayer().getLocation(); + Location location = user.getEntity().getLocation(); if (wardrobeLocation == null) return false; if (distance == -1) return true; if (!wardrobeLocation.getWorld().equals(location.getWorld())) return false; diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticArmorType.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticArmorType.java index b6c5ef70..948f29ee 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticArmorType.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/cosmetic/types/CosmeticArmorType.java @@ -8,6 +8,8 @@ import com.hibiscusmc.hmccosmetics.util.InventoryUtils; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import org.bukkit.Bukkit; +import org.bukkit.entity.Entity; +import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; import org.bukkit.inventory.EquipmentSlot; import org.bukkit.inventory.ItemStack; @@ -26,19 +28,20 @@ public class CosmeticArmorType extends Cosmetic { @Override public void update(@NotNull CosmeticUser user) { - Player player = Bukkit.getPlayer(user.getUniqueId()); - if (player == null) return; + Entity entity = Bukkit.getEntity(user.getUniqueId()); + if (entity == null) return; if (user.getUserEmoteManager().isPlayingEmote()) return; // There has to be a better way of doing this... ItemStack cosmeticItem = user.getUserCosmeticItem(this); + if (!(entity instanceof HumanEntity humanEntity)) return; if (equipSlot.equals(EquipmentSlot.OFF_HAND)) { - if (!player.getInventory().getItemInOffHand().getType().isAir()) return; + if (!humanEntity.getInventory().getItemInOffHand().getType().isAir()) return; } - ItemStack equippedItem = player.getInventory().getItem(equipSlot); + ItemStack equippedItem = humanEntity.getInventory().getItem(equipSlot); if (Settings.getShouldAddEnchants(equipSlot)) { cosmeticItem.addUnsafeEnchantments(equippedItem.getEnchantments()); } - NMSHandlers.getHandler().equipmentSlotUpdate(player.getEntityId(), equipSlot, cosmeticItem, PacketManager.getViewers(player.getLocation())); + NMSHandlers.getHandler().equipmentSlotUpdate(entity.getEntityId(), equipSlot, cosmeticItem, PacketManager.getViewers(entity.getLocation())); //PacketManager.equipmentSlotUpdate(player, getSlot(), PacketManager.getViewers(player.getLocation())); Old method } 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 08c9da44..49f09427 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 @@ -7,6 +7,7 @@ import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import org.spongepowered.configurate.ConfigurationNode; @@ -27,10 +28,10 @@ public class CosmeticBackpackType extends Cosmetic { @Override public void update(@NotNull CosmeticUser user) { - Player player = Bukkit.getPlayer(user.getUniqueId()); - if (player == null) return; + Entity entity = Bukkit.getEntity(user.getUniqueId()); + if (entity == null) return; - Location loc = player.getLocation().clone().add(0, 2, 0); + Location loc = entity.getLocation().clone().add(0, 2, 0); if (user.isInWardrobe() || !user.isBackpackSpawned()) return; if (!user.getUserBackpackManager().IsValidBackpackEntity()) { @@ -46,10 +47,10 @@ public class CosmeticBackpackType extends Cosmetic { if (user.getUserBackpackManager().getBackpackType().equals(UserBackpackManager.BackpackType.FIRST_PERSON)) { user.getUserBackpackManager().teleportEffectEntity(loc); - PacketManager.sendRidingPacket(player.getEntityId(), user.getUserBackpackManager().getAreaEffectEntityId(), loc); + PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getAreaEffectEntityId(), loc); PacketManager.sendRidingPacket(user.getUserBackpackManager().getAreaEffectEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc); } else { - PacketManager.sendRidingPacket(player.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc); + PacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getFirstArmorStandId(), loc); } user.getUserBackpackManager().getArmorStand().setRotation(loc.getYaw(), loc.getPitch()); 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 1564c8a2..27102443 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 @@ -7,6 +7,8 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; @@ -42,10 +44,10 @@ public class CosmeticBalloonType extends Cosmetic { @Override public void update(@NotNull CosmeticUser user) { - Player player = Bukkit.getPlayer(user.getUniqueId()); + Entity entity = Bukkit.getEntity(user.getUniqueId()); UserBalloonManager userBalloonManager = user.getBalloonManager(); - if (player == null || userBalloonManager == null) return; + if (entity == null || userBalloonManager == null) return; if (user.isInWardrobe()) return; if (!userBalloonManager.getModelEntity().isValid()) { @@ -53,14 +55,13 @@ public class CosmeticBalloonType extends Cosmetic { return; } - Location newLocation = player.getLocation(); + Location newLocation = entity.getLocation(); Location currentLocation = user.getBalloonManager().getLocation(); newLocation = newLocation.clone().add(Settings.getBalloonOffset()); - List viewer = PacketManager.getViewers(player.getLocation()); - viewer.add(player); + List viewer = PacketManager.getViewers(entity.getLocation()); - if (player.getLocation().getWorld() != userBalloonManager.getLocation().getWorld()) { + if (entity.getLocation().getWorld() != userBalloonManager.getLocation().getWorld()) { userBalloonManager.getModelEntity().teleport(newLocation); PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer); return; @@ -71,7 +72,12 @@ public class CosmeticBalloonType extends Cosmetic { userBalloonManager.setLocation(newLocation); PacketManager.sendTeleportPacket(userBalloonManager.getPufferfishBalloonId(), newLocation, false, viewer); - if (!user.getHidden() && showLead) PacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), player.getEntityId(), viewer); + if (!user.getHidden() && showLead) { + List sendTo = userBalloonManager.getPufferfish().refreshViewers(newLocation); + PacketManager.sendEntitySpawnPacket(newLocation, userBalloonManager.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager.getPufferfishBalloonUniqueId(), sendTo); + PacketManager.sendInvisibilityPacket(userBalloonManager.getPufferfishBalloonId(), sendTo); + PacketManager.sendLeashPacket(userBalloonManager.getPufferfishBalloonId(), entity.getEntityId(), viewer); + } } public String getModelName() { diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/database/types/Data.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/database/types/Data.java index d1974f09..17a5ee27 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/database/types/Data.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/database/types/Data.java @@ -50,10 +50,13 @@ public abstract class Data { return data; } - @NotNull public final Map> deserializeData(CosmeticUser user, @NotNull String raw) { + return deserializeData(user, raw, Settings.getForcePermissionJoin()); + } + + @NotNull + public final Map> deserializeData(CosmeticUser user, @NotNull String raw, boolean checkpermissions) { Map> cosmetics = new HashMap<>(); - boolean checkPermission = Settings.getForcePermissionJoin(); String[] rawData = raw.split(","); for (String a : rawData) { @@ -75,8 +78,8 @@ public abstract class Data { String[] colorSplitData = splitData[1].split("&"); if (Cosmetics.hasCosmetic(colorSplitData[0])) cosmetic = Cosmetics.getCosmetic(colorSplitData[0]); if (slot == null || cosmetic == null) continue; - if (cosmetic.requiresPermission() && checkPermission) { - if (!user.getPlayer().hasPermission(cosmetic.getPermission())) { + if (checkpermissions && cosmetic.requiresPermission()) { + if (user.getPlayer() != null && !user.getPlayer().hasPermission(cosmetic.getPermission())) { continue; } } @@ -84,8 +87,8 @@ public abstract class Data { } else { if (Cosmetics.hasCosmetic(splitData[1])) cosmetic = Cosmetics.getCosmetic(splitData[1]); if (slot == null || cosmetic == null) continue; - if (cosmetic.requiresPermission() && checkPermission) { - if (!user.getPlayer().hasPermission(cosmetic.getPermission())) { + if (checkpermissions && cosmetic.requiresPermission()) { + if (user.getPlayer() != null && !user.getPlayer().hasPermission(cosmetic.getPermission())) { continue; } } 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 5d6bbcb9..66df56a8 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/CosmeticUser.java @@ -22,11 +22,13 @@ import com.hibiscusmc.hmccosmetics.util.PlayerUtils; import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; import me.clip.placeholderapi.PlaceholderAPI; import org.bukkit.*; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.*; import org.bukkit.persistence.PersistentDataType; import org.bukkit.scheduler.BukkitTask; +import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.logging.Level; @@ -261,7 +263,7 @@ public class CosmeticUser { } } itemMeta.getPersistentDataContainer().set(InventoryUtils.getCosmeticKey(), PersistentDataType.STRING, cosmetic.getId()); - itemMeta.getPersistentDataContainer().set(InventoryUtils.getOwnerKey(), PersistentDataType.STRING, getPlayer().getUniqueId().toString()); + itemMeta.getPersistentDataContainer().set(InventoryUtils.getOwnerKey(), PersistentDataType.STRING, getEntity().getUniqueId().toString()); item.setItemMeta(itemMeta); } @@ -360,19 +362,13 @@ public class CosmeticUser { } public void spawnBalloon(CosmeticBalloonType cosmeticBalloonType) { - Player player = Bukkit.getPlayer(getUniqueId()); - if (this.userBalloonManager != null) return; - this.userBalloonManager = NMSHandlers.getHandler().spawnBalloon(this, cosmeticBalloonType); - - List viewer = PlayerUtils.getNearbyPlayers(player); - viewer.add(player); } public void despawnBalloon() { if (this.userBalloonManager == null) return; - List sentTo = PlayerUtils.getNearbyPlayers(getPlayer().getLocation()); + List sentTo = PlayerUtils.getNearbyPlayers(getEntity().getLocation()); PacketManager.sendEntityDestroyPacket(userBalloonManager.getPufferfishBalloonId(), sentTo); @@ -395,13 +391,27 @@ public class CosmeticUser { } public void removeArmor(CosmeticSlot slot) { - PacketManager.equipmentSlotUpdate(getPlayer().getEntityId(), this, slot, PlayerUtils.getNearbyPlayers(getPlayer())); + PacketManager.equipmentSlotUpdate(getEntity().getEntityId(), this, slot, PlayerUtils.getNearbyPlayers(getEntity().getLocation())); } + /** + * This returns the player associated with the user. Some users may not have a player attached, ie, they are npcs + * wearing cosmetics through an addon. If you need to get locations, use getEntity instead. + * @return Player + */ + @Nullable public Player getPlayer() { return Bukkit.getPlayer(uniqueId); } + /** + * This gets the entity associated with the user. + * @return Entity + */ + public Entity getEntity() { + return Bukkit.getEntity(uniqueId); + } + public Color getCosmeticColor(CosmeticSlot slot) { return colors.get(slot); } 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 e649beba..3bebcbf0 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 @@ -15,6 +15,7 @@ import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.entity.ArmorStand; import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; @@ -27,13 +28,11 @@ public class UserBalloonManager { private BalloonType balloonType; private CosmeticBalloonType cosmeticBalloonType; - private final int balloonID; - private final UUID uniqueID; + private UserBalloonPufferfish pufferfish; private final ArmorStand modelEntity; public UserBalloonManager(@NotNull Location location) { - this.uniqueID = UUID.randomUUID(); - this.balloonID = NMSHandlers.getHandler().getNextEntityId(); + this.pufferfish = new UserBalloonPufferfish(NMSHandlers.getHandler().getNextEntityId(), UUID.randomUUID()); this.modelEntity = NMSHandlers.getHandler().getMEGEntity(location.add(Settings.getBalloonOffset())); } @@ -136,10 +135,10 @@ public class UserBalloonManager { public int getPufferfishBalloonId() { - return balloonID; + return pufferfish.getId(); } public UUID getPufferfishBalloonUniqueId() { - return uniqueID; + return pufferfish.getUuid(); } public UUID getModelUnqiueId() { @@ -172,7 +171,13 @@ public class UserBalloonManager { public void sendLeashPacket(int entityId) { if (cosmeticBalloonType == null) return; - if (cosmeticBalloonType.isShowLead()) PacketManager.sendLeashPacket(getPufferfishBalloonId(), entityId, getLocation()); + if (cosmeticBalloonType.isShowLead()) { + PacketManager.sendLeashPacket(getPufferfishBalloonId(), entityId, getLocation()); + } + } + + public UserBalloonPufferfish getPufferfish() { + return pufferfish; } public enum BalloonType { 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 new file mode 100644 index 00000000..4be51b3e --- /dev/null +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/user/manager/UserBalloonPufferfish.java @@ -0,0 +1,54 @@ +package com.hibiscusmc.hmccosmetics.user.manager; + +import com.hibiscusmc.hmccosmetics.util.PlayerUtils; +import com.hibiscusmc.hmccosmetics.util.packets.PacketManager; +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +public class UserBalloonPufferfish { + + private int id; + private UUID uuid; + private List viewers = new ArrayList<>(); + + public UserBalloonPufferfish(int id, UUID uuid) { + this.id = id; + this.uuid = uuid; + } + + public int getId() { + return id; + } + + public UUID getUuid() { + return uuid; + } + + public List refreshViewers(Location location) { + 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); + return newPlayers; + } +} diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/packets/PacketManager.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/packets/PacketManager.java index 49c3ab23..cea4d660 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/packets/PacketManager.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/packets/PacketManager.java @@ -97,7 +97,7 @@ public class PacketManager extends BasePacket { CosmeticSlot cosmeticSlot, List sendTo ) { - equipmentSlotUpdate(user.getPlayer().getEntityId(), user, cosmeticSlot, sendTo); + equipmentSlotUpdate(user.getEntity().getEntityId(), user, cosmeticSlot, sendTo); } public static void equipmentSlotUpdate( 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 1ab1763c..30871ca9 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 @@ -47,7 +47,7 @@ import java.util.List; public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public int getNextEntityId() { - return Entity.nextEntityId(); + return net.minecraft.world.entity.Entity.nextEntityId(); } @Override @@ -85,19 +85,16 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) { - HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getPlayer().getLocation()); + HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getEntity().getLocation()); ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType); invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item)); - ((CraftWorld) user.getPlayer().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM); + ((CraftWorld) user.getEntity().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM); MessagesUtil.sendDebugMessages("spawnBackpack NMS"); return invisibleArmorstand.getBukkitLivingEntity(); - //PacketManager.armorStandMetaPacket(invisibleArmorstand.getBukkitEntity(), sentTo); - //PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo); - } @Override @@ -106,23 +103,21 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { } - - @Override public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { - Player player = user.getPlayer(); - Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset()); + org.bukkit.entity.Entity entity = user.getEntity(); + Location newLoc = entity.getLocation().clone().add(Settings.getBalloonOffset()); - UserBalloonManager userBalloonManager1 = new UserBalloonManager(user.getPlayer().getLocation()); - List sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); - userBalloonManager1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); + UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation()); + List sentTo = PlayerUtils.getNearbyPlayers(entity.getLocation()); + userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(Settings.getBalloonOffset())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); - userBalloonManager1.sendLeashPacket(player.getEntityId()); + userBalloonManager1.sendLeashPacket(entity.getEntityId()); return userBalloonManager1; } 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 cceb9d8d..8693bba9 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 @@ -47,7 +47,7 @@ import java.util.List; public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public int getNextEntityId() { - return Entity.nextEntityId(); + return net.minecraft.world.entity.Entity.nextEntityId(); } @Override @@ -85,19 +85,16 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) { - HMCArmorStand HMCArmorStand = new HMCArmorStand(user.getPlayer().getLocation()); + HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getEntity().getLocation()); ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType); - HMCArmorStand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item)); - ((CraftWorld) user.getPlayer().getWorld()).getHandle().addFreshEntity(HMCArmorStand, CreatureSpawnEvent.SpawnReason.CUSTOM); + invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item)); + ((CraftWorld) user.getEntity().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM); MessagesUtil.sendDebugMessages("spawnBackpack NMS"); - return HMCArmorStand.getBukkitLivingEntity(); - //PacketManager.armorStandMetaPacket(invisibleArmorstand.getBukkitEntity(), sentTo); - //PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo); - + return invisibleArmorstand.getBukkitLivingEntity(); } @Override @@ -110,19 +107,19 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { - Player player = user.getPlayer(); - Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset()); + org.bukkit.entity.Entity entity = user.getEntity(); + Location newLoc = entity.getLocation().clone().add(Settings.getBalloonOffset()); - UserBalloonManager userBalloonManager1 = new UserBalloonManager(user.getPlayer().getLocation()); - List sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); - userBalloonManager1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); + UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation()); + List sentTo = PlayerUtils.getNearbyPlayers(entity.getLocation()); + userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(Settings.getBalloonOffset())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); - userBalloonManager1.sendLeashPacket(player.getEntityId()); + userBalloonManager1.sendLeashPacket(entity.getEntityId()); return userBalloonManager1; } 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 f2cde43e..0239c97c 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 @@ -47,7 +47,7 @@ import java.util.List; public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public int getNextEntityId() { - return Entity.nextEntityId(); + return net.minecraft.world.entity.Entity.nextEntityId(); } @Override @@ -85,19 +85,16 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) { - HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getPlayer().getLocation()); + HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getEntity().getLocation()); ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType); invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item)); - ((CraftWorld) user.getPlayer().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM); + ((CraftWorld) user.getEntity().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM); MessagesUtil.sendDebugMessages("spawnBackpack NMS"); return invisibleArmorstand.getBukkitLivingEntity(); - //PacketManager.armorStandMetaPacket(invisibleArmorstand.getBukkitEntity(), sentTo); - //PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo); - } @Override @@ -109,19 +106,19 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { - Player player = user.getPlayer(); - Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset()); + org.bukkit.entity.Entity entity = user.getEntity(); + Location newLoc = entity.getLocation().clone().add(Settings.getBalloonOffset()); - UserBalloonManager userBalloonManager1 = new UserBalloonManager(user.getPlayer().getLocation()); - List sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); - userBalloonManager1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); + UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation()); + List sentTo = PlayerUtils.getNearbyPlayers(entity.getLocation()); + userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(Settings.getBalloonOffset())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); - userBalloonManager1.sendLeashPacket(player.getEntityId()); + userBalloonManager1.sendLeashPacket(entity.getEntityId()); return userBalloonManager1; } 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 b0775116..4a55c1a1 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 @@ -22,7 +22,6 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.network.ServerPlayerConnection; import net.minecraft.world.entity.Display; -import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.player.Inventory; import net.minecraft.world.scores.PlayerTeam; @@ -36,6 +35,7 @@ import org.bukkit.craftbukkit.v1_19_R3.entity.CraftPlayer; import org.bukkit.craftbukkit.v1_19_R3.inventory.CraftItemStack; import org.bukkit.craftbukkit.v1_19_R3.scoreboard.CraftScoreboard; import org.bukkit.entity.ArmorStand; +import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.event.entity.CreatureSpawnEvent; @@ -48,7 +48,7 @@ import java.util.List; public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public int getNextEntityId() { - return Entity.nextEntityId(); + return net.minecraft.world.entity.Entity.nextEntityId(); } @Override @@ -86,18 +86,16 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) { - HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getPlayer().getLocation()); + HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getEntity().getLocation()); ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType); invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item)); - ((CraftWorld) user.getPlayer().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM); + ((CraftWorld) user.getEntity().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM); MessagesUtil.sendDebugMessages("spawnBackpack NMS"); return invisibleArmorstand.getBukkitLivingEntity(); - //PacketManager.armorStandMetaPacket(invisibleArmorstand.getBukkitEntity(), sentTo); - //PacketManager.ridingMountPacket(player.getEntityId(), invisibleArmorstand.getId(), sentTo); } @Override @@ -115,19 +113,19 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { - Player player = user.getPlayer(); - Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset()); + Entity entity = user.getEntity(); + Location newLoc = entity.getLocation().clone().add(Settings.getBalloonOffset()); - UserBalloonManager userBalloonManager1 = new UserBalloonManager(user.getPlayer().getLocation()); - List sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); - userBalloonManager1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); + UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation()); + List sentTo = PlayerUtils.getNearbyPlayers(entity.getLocation()); + userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(Settings.getBalloonOffset())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); - userBalloonManager1.sendLeashPacket(player.getEntityId()); + userBalloonManager1.sendLeashPacket(entity.getEntityId()); return userBalloonManager1; } 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 744a4e13..baa7042b 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 @@ -48,7 +48,7 @@ import java.util.List; public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public int getNextEntityId() { - return Entity.nextEntityId(); + return net.minecraft.world.entity.Entity.nextEntityId(); } @Override @@ -86,12 +86,12 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public org.bukkit.entity.Entity spawnBackpack(CosmeticUser user, CosmeticBackpackType cosmeticBackpackType) { - HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getPlayer().getLocation()); + HMCArmorStand invisibleArmorstand = new HMCArmorStand(user.getEntity().getLocation()); ItemStack item = user.getUserCosmeticItem(cosmeticBackpackType); invisibleArmorstand.setItemSlot(EquipmentSlot.HEAD, CraftItemStack.asNMSCopy(item)); - ((CraftWorld) user.getPlayer().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM); + ((CraftWorld) user.getEntity().getWorld()).getHandle().addFreshEntity(invisibleArmorstand, CreatureSpawnEvent.SpawnReason.CUSTOM); MessagesUtil.sendDebugMessages("spawnBackpack NMS"); @@ -115,19 +115,19 @@ public class NMSHandler implements com.hibiscusmc.hmccosmetics.nms.NMSHandler { @Override public UserBalloonManager spawnBalloon(CosmeticUser user, CosmeticBalloonType cosmeticBalloonType) { - Player player = user.getPlayer(); - Location newLoc = player.getLocation().clone().add(Settings.getBalloonOffset()); + org.bukkit.entity.Entity entity = user.getEntity(); + Location newLoc = entity.getLocation().clone().add(Settings.getBalloonOffset()); - UserBalloonManager userBalloonManager1 = new UserBalloonManager(user.getPlayer().getLocation()); - List sentTo = PlayerUtils.getNearbyPlayers(player.getLocation()); - userBalloonManager1.getModelEntity().teleport(user.getPlayer().getLocation().add(Settings.getBalloonOffset())); + UserBalloonManager userBalloonManager1 = new UserBalloonManager(entity.getLocation()); + List sentTo = PlayerUtils.getNearbyPlayers(entity.getLocation()); + userBalloonManager1.getModelEntity().teleport(entity.getLocation().add(Settings.getBalloonOffset())); userBalloonManager1.spawnModel(cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); userBalloonManager1.addPlayerToModel(user, cosmeticBalloonType, user.getCosmeticColor(cosmeticBalloonType.getSlot())); PacketManager.sendEntitySpawnPacket(newLoc, userBalloonManager1.getPufferfishBalloonId(), EntityType.PUFFERFISH, userBalloonManager1.getPufferfishBalloonUniqueId(), sentTo); PacketManager.sendInvisibilityPacket(userBalloonManager1.getPufferfishBalloonId(), sentTo); - userBalloonManager1.sendLeashPacket(player.getEntityId()); + userBalloonManager1.sendLeashPacket(entity.getEntityId()); return userBalloonManager1; }