mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-21 16:09:27 +00:00
Compare commits
5 Commits
nms_packet
...
display_en
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42fec4d2c6 | ||
|
|
fdc2d06663 | ||
|
|
9909ab5832 | ||
|
|
a6220fa704 | ||
|
|
f6b86079fc |
@@ -86,7 +86,7 @@ allprojects {
|
||||
compileOnly("io.github.toxicity188:BetterCommand:1.3") //BetterCommand library
|
||||
//compileOnly("it.unimi.dsi:fastutil:8.5.14")
|
||||
compileOnly("org.projectlombok:lombok:1.18.34")
|
||||
compileOnly("me.lojosho:HibiscusCommons:0.6.2-d21ebed8")
|
||||
compileOnly("me.lojosho:HibiscusCommons:0.6.3")
|
||||
|
||||
// Handled by Spigot Library Loader
|
||||
compileOnly("net.kyori:adventure-api:4.19.0")
|
||||
|
||||
@@ -2,22 +2,25 @@ package com.hibiscusmc.hmccosmetics.cosmetic.types;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic;
|
||||
import com.hibiscusmc.hmccosmetics.cosmetic.CosmeticSlot;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserEntity;
|
||||
import com.hibiscusmc.hmccosmetics.user.manager.UserBackpackManager;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||
import me.lojosho.shaded.configurate.ConfigurationNode;
|
||||
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.entity.*;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -44,9 +47,6 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
Entity entity = user.getEntity();
|
||||
if (entity == null) return;
|
||||
|
||||
Location entityLocation = entity.getLocation();
|
||||
Location loc = entityLocation.clone().add(0, 2, 0);
|
||||
|
||||
if (user.isInWardrobe() || !user.isBackpackSpawned()) return;
|
||||
if (user.isHidden()) {
|
||||
// Sometimes the backpack is not despawned when the player is hidden (weird ass logic happening somewhere)
|
||||
@@ -55,21 +55,22 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
}
|
||||
|
||||
UserBackpackManager backpackManager = user.getUserBackpackManager();
|
||||
UserEntity entityManager = backpackManager.getEntityManager();
|
||||
int firstArmorStandId = backpackManager.getFirstArmorStandId();
|
||||
Location loc = entity.getLocation();
|
||||
loc.setPitch(0);
|
||||
|
||||
List<Player> outsideViewers = entityManager.refreshViewers(loc);
|
||||
List<Player> addedViewers = user.getUserBackpackManager().getEntityManager().refreshViewers(loc);
|
||||
int entityId = user.getUserBackpackManager().getDisplayEntityId();
|
||||
ItemStack backpackItem = user.getUserCosmeticItem(CosmeticSlot.BACKPACK);
|
||||
|
||||
entityManager.teleport(loc);
|
||||
entityManager.setRotation((int) loc.getYaw(), isFirstPersonCompadible());
|
||||
user.getUserBackpackManager().getEntityManager().teleport(loc);
|
||||
|
||||
HMCCPacketManager.sendEntitySpawnPacket(entityLocation, firstArmorStandId, EntityType.ARMOR_STAND, UUID.randomUUID(), outsideViewers);
|
||||
HMCCPacketManager.sendArmorstandMetadata(firstArmorStandId, outsideViewers);
|
||||
PacketManager.equipmentSlotUpdate(firstArmorStandId, EquipmentSlot.HEAD, user.getUserCosmeticItem(this, getItem()), outsideViewers);
|
||||
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), entityId, EntityType.ITEM_DISPLAY, UUID.randomUUID(), addedViewers);
|
||||
HMCCPacketManager.sendDisplayEntityMetadataPacket(backpackManager.getDisplayEntityId(), backpackItem, addedViewers);
|
||||
// If true, it will send the riding packet to all players. If false, it will send the riding packet only to new players
|
||||
if (Settings.isBackpackForceRidingEnabled()) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), firstArmorStandId, entityManager.getViewers());
|
||||
else HMCCPacketManager.sendRidingPacket(entity.getEntityId(), firstArmorStandId, outsideViewers);
|
||||
if (Settings.isBackpackForceRidingEnabled()) HMCCPacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getDisplayEntityId(), user.getUserBackpackManager().getEntityManager().getViewers());
|
||||
else HMCCPacketManager.sendRidingPacket(entity.getEntityId(), user.getUserBackpackManager().getDisplayEntityId(), addedViewers);
|
||||
|
||||
/*
|
||||
if (!user.isInWardrobe() && isFirstPersonCompadible() && user.getPlayer() != null) {
|
||||
List<Player> owner = List.of(user.getPlayer());
|
||||
|
||||
@@ -89,6 +90,7 @@ public class CosmeticBackpackType extends Cosmetic {
|
||||
}
|
||||
//MessagesUtil.sendDebugMessages("First Person Backpack Update[owner=" + user.getUniqueId() + ",player_location=" + loc + "]!", Level.INFO);
|
||||
}
|
||||
*/
|
||||
|
||||
backpackManager.showBackpack();
|
||||
}
|
||||
|
||||
@@ -6,16 +6,19 @@ import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.HMCCPacketManager;
|
||||
import com.ticxo.modelengine.api.ModelEngineAPI;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import lombok.Getter;
|
||||
import me.lojosho.hibiscuscommons.hooks.Hooks;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import me.lojosho.hibiscuscommons.util.ServerUtils;
|
||||
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -27,7 +30,7 @@ public class UserBackpackManager {
|
||||
@Getter
|
||||
private boolean backpackHidden;
|
||||
@Getter
|
||||
private final int invisibleArmorStand;
|
||||
private final int displayEntityId;
|
||||
private ArrayList<Integer> particleCloud = new ArrayList<>();
|
||||
@Getter
|
||||
private final CosmeticUser user;
|
||||
@@ -37,13 +40,18 @@ public class UserBackpackManager {
|
||||
public UserBackpackManager(CosmeticUser user) {
|
||||
this.user = user;
|
||||
this.backpackHidden = false;
|
||||
this.invisibleArmorStand = ServerUtils.getNextEntityId();
|
||||
this.displayEntityId = ServerUtils.getNextEntityId();
|
||||
this.entityManager = new UserEntity(user.getUniqueId());
|
||||
if (user.getEntity() != null) this.entityManager.refreshViewers(user.getEntity().getLocation()); // Fixes an issue where a player, who somehow removes their potions, but doesn't have an entity produces an NPE (it's dumb)
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public int getFirstArmorStandId() {
|
||||
return invisibleArmorStand;
|
||||
return getDisplayEntityId();
|
||||
}
|
||||
|
||||
public int getDisplayEntityId() {
|
||||
return displayEntityId;
|
||||
}
|
||||
|
||||
public void spawnBackpack(CosmeticBackpackType cosmeticBackpackType) {
|
||||
@@ -53,25 +61,28 @@ public class UserBackpackManager {
|
||||
}
|
||||
|
||||
private void spawn(CosmeticBackpackType cosmeticBackpackType) {
|
||||
getEntityManager().setIds(List.of(invisibleArmorStand));
|
||||
getEntityManager().teleport(user.getEntity().getLocation());
|
||||
Location loc = user.getEntity().getLocation();
|
||||
|
||||
getEntityManager().setIds(List.of(displayEntityId));
|
||||
getEntityManager().teleport(loc);
|
||||
List<Player> outsideViewers = getEntityManager().getViewers();
|
||||
HMCCPacketManager.sendEntitySpawnPacket(user.getEntity().getLocation(), getFirstArmorStandId(), EntityType.ARMOR_STAND, UUID.randomUUID(), getEntityManager().getViewers());
|
||||
HMCCPacketManager.sendArmorstandMetadata(getFirstArmorStandId(), outsideViewers);
|
||||
ItemStack backpackItem = user.getUserCosmeticItem(CosmeticSlot.BACKPACK);
|
||||
|
||||
HMCCPacketManager.sendEntitySpawnPacket(loc, getDisplayEntityId(), EntityType.ITEM_DISPLAY, UUID.randomUUID(), outsideViewers);
|
||||
HMCCPacketManager.sendDisplayEntityMetadataPacket(getDisplayEntityId(), backpackItem, outsideViewers);
|
||||
|
||||
Entity entity = user.getEntity();
|
||||
|
||||
int[] passengerIDs = new int[entity.getPassengers().size() + 1];
|
||||
|
||||
for (int i = 0; i < entity.getPassengers().size(); i++) {
|
||||
passengerIDs[i] = entity.getPassengers().get(i).getEntityId();
|
||||
}
|
||||
|
||||
passengerIDs[passengerIDs.length - 1] = this.getFirstArmorStandId();
|
||||
passengerIDs[passengerIDs.length - 1] = this.getDisplayEntityId();
|
||||
|
||||
ArrayList<Player> owner = new ArrayList<>();
|
||||
if (user.getPlayer() != null) owner.add(user.getPlayer());
|
||||
|
||||
/*
|
||||
if (cosmeticBackpackType.isFirstPersonCompadible()) {
|
||||
for (int i = particleCloud.size(); i < cosmeticBackpackType.getHeight(); i++) {
|
||||
int entityId = ServerUtils.getNextEntityId();
|
||||
@@ -87,14 +98,14 @@ public class UserBackpackManager {
|
||||
HMCCPacketManager.sendRidingPacket(particleCloud.get(particleCloud.size() - 1), user.getUserBackpackManager().getFirstArmorStandId(), owner);
|
||||
if (!user.isHidden()) PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(cosmeticBackpackType, cosmeticBackpackType.getFirstPersonBackpack()), owner);
|
||||
}
|
||||
PacketManager.equipmentSlotUpdate(getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(cosmeticBackpackType), outsideViewers);
|
||||
*/
|
||||
HMCCPacketManager.sendRidingPacket(entity.getEntityId(), passengerIDs, outsideViewers);
|
||||
|
||||
MessagesUtil.sendDebugMessages("spawnBackpack Bukkit - Finish");
|
||||
}
|
||||
|
||||
public void despawnBackpack() {
|
||||
HMCCPacketManager.sendEntityDestroyPacket(invisibleArmorStand, getEntityManager().getViewers());
|
||||
NMSHandlers.getHandler().getPacketHandler().sendEntityDestroyPacket(IntList.of(getDisplayEntityId()), getEntityManager().getViewers());
|
||||
if (particleCloud != null) {
|
||||
for (Integer entityId : particleCloud) {
|
||||
HMCCPacketManager.sendEntityDestroyPacket(entityId, getEntityManager().getViewers());
|
||||
@@ -122,7 +133,7 @@ public class UserBackpackManager {
|
||||
}
|
||||
|
||||
public ArrayList<Integer> getAreaEffectEntityId() {
|
||||
return particleCloud;
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setItem(ItemStack item) {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.hibiscusmc.hmccosmetics.user.manager;
|
||||
|
||||
import com.hibiscusmc.hmccosmetics.config.Settings;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
|
||||
import com.hibiscusmc.hmccosmetics.user.CosmeticUsers;
|
||||
import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
|
||||
@@ -80,7 +79,7 @@ public class UserEntity {
|
||||
if (this.getLocation() != null && this.getLocation().getWorld() == location.getWorld()) {
|
||||
// Was thinking about using schedulers to just send the packet later... but that would be a lot of tasks and
|
||||
// would probably cause more lag. Furthermore, the server "ticks" the cosmetics every second by defualt. So it's fine like this.
|
||||
if (System.currentTimeMillis() - getLastPositionUpdate() <= Settings.getPacketEntityTeleportCooldown()) return;
|
||||
//if (System.currentTimeMillis() - getLastPositionUpdate() <= Settings.getPacketEntityTeleportCooldown()) return;
|
||||
}
|
||||
this.location = location;
|
||||
for (Integer entity : ids) {
|
||||
|
||||
@@ -151,7 +151,7 @@ public class UserWardrobeManager {
|
||||
if (user.getUserBackpackManager() == null) user.respawnBackpack();
|
||||
if (user.isBackpackSpawned()) {
|
||||
user.getUserBackpackManager().getEntityManager().teleport(npcLocation.clone().add(0, 2, 0));
|
||||
PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(user.getCosmetic(CosmeticSlot.BACKPACK)), viewer);
|
||||
//PacketManager.equipmentSlotUpdate(user.getUserBackpackManager().getFirstArmorStandId(), EquipmentSlot.HEAD, user.getUserCosmeticItem(user.getCosmetic(CosmeticSlot.BACKPACK)), viewer);
|
||||
HMCCPacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
|
||||
}
|
||||
}
|
||||
@@ -323,11 +323,12 @@ public class UserWardrobeManager {
|
||||
HMCCPacketManager.equipmentSlotUpdate(NPC_ID, user, slot, viewer);
|
||||
}
|
||||
|
||||
// Handle backpacks
|
||||
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK) && user.getUserBackpackManager() != null) {
|
||||
HMCCPacketManager.sendTeleportPacket(user.getUserBackpackManager().getFirstArmorStandId(), location, false, viewer);
|
||||
HMCCPacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getFirstArmorStandId(), viewer);
|
||||
user.getUserBackpackManager().getEntityManager().setRotation(nextyaw);
|
||||
HMCCPacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getFirstArmorStandId(), outsideViewers);
|
||||
HMCCPacketManager.sendTeleportPacket(user.getUserBackpackManager().getDisplayEntityId(), location, false, viewer);
|
||||
HMCCPacketManager.ridingMountPacket(NPC_ID, user.getUserBackpackManager().getDisplayEntityId(), viewer);
|
||||
//user.getUserBackpackManager().getEntityManager().setRotation(nextyaw);
|
||||
HMCCPacketManager.sendEntityDestroyPacket(user.getUserBackpackManager().getDisplayEntityId(), outsideViewers);
|
||||
}
|
||||
|
||||
if (user.hasCosmeticInSlot(CosmeticSlot.BALLOON) && user.isBalloonSpawned()) {
|
||||
@@ -358,5 +359,4 @@ public class UserWardrobeManager {
|
||||
RUNNING,
|
||||
STOPPING,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,14 +15,16 @@ import com.hibiscusmc.hmccosmetics.util.HMCCPlayerUtils;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerNamedEntitySpawn;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerPlayerInfo;
|
||||
import com.hibiscusmc.hmccosmetics.util.packets.wrappers.WrapperPlayServerRelEntityMove;
|
||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||
import me.lojosho.hibiscuscommons.util.packets.PacketManager;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.*;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -46,16 +48,7 @@ public class HMCCPacketManager extends PacketManager {
|
||||
final UUID uuid,
|
||||
final @NotNull List<Player> sendTo
|
||||
) {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
|
||||
packet.getModifier().writeDefaults();
|
||||
packet.getUUIDs().write(0, uuid);
|
||||
packet.getIntegers().write(0, entityId);
|
||||
packet.getEntityTypeModifier().write(0, entityType);
|
||||
packet.getDoubles().
|
||||
write(0, location.getX()).
|
||||
write(1, location.getY()).
|
||||
write(2, location.getZ());
|
||||
for (Player p : sendTo) sendPacket(p, packet);
|
||||
NMSHandlers.getHandler().getPacketHandler().sendSpawnEntityPacket(entityId, uuid, entityType, location, sendTo);
|
||||
}
|
||||
|
||||
public static void equipmentSlotUpdate(
|
||||
@@ -382,6 +375,38 @@ public class HMCCPacketManager extends PacketManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendDisplayEntityMetadataPacket(int entityid, ItemStack backpackItem, List<Player> sendTo) {
|
||||
// TODO: Make the default values adjustable
|
||||
Vector3f translation = new Vector3f(0, 3, 0);
|
||||
Vector3f scale = new Vector3f(1, 1, 1);
|
||||
Quaternionf rotationLeft = new Quaternionf();
|
||||
Quaternionf rotationRight = new Quaternionf();
|
||||
Display.Billboard billboard = Display.Billboard.FIXED;
|
||||
int blockLight = 15;
|
||||
int skylight = 15;
|
||||
int viewRange = Settings.getViewDistance();
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
ItemDisplay.ItemDisplayTransform transform = ItemDisplay.ItemDisplayTransform.HEAD;
|
||||
|
||||
NMSHandlers.getHandler().getPacketHandler().sendItemDisplayMetadata(
|
||||
entityid,
|
||||
translation,
|
||||
scale,
|
||||
rotationLeft,
|
||||
rotationRight,
|
||||
billboard,
|
||||
blockLight,
|
||||
skylight,
|
||||
viewRange,
|
||||
width,
|
||||
height,
|
||||
transform,
|
||||
backpackItem,
|
||||
sendTo
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the nearby players (or viewers) of a location through the view distance set in the config. If the view distance is 0, it will return all players in the world.
|
||||
* @param location
|
||||
|
||||
Reference in New Issue
Block a user