9
0
mirror of https://github.com/HibiscusMC/HibiscusCommons.git synced 2025-12-19 15:09:26 +00:00

chore: move destroy entity packet and spawn entity packet to NMS

This commit is contained in:
LoJoSho
2025-01-02 10:41:17 -06:00
parent 0ce7b138b5
commit f8a9eb0f4e

View File

@@ -4,6 +4,7 @@ import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
import me.lojosho.hibiscuscommons.util.MessagesUtil;
import org.bukkit.Location;
@@ -28,16 +29,7 @@ public class 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 gamemodeChangePacket(
@@ -124,9 +116,7 @@ public class PacketManager {
* @param sendTo The players the packet should be sent to
*/
public static void sendEntityDestroyPacket(final int entityId, @NotNull List<Player> sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
packet.getModifier().write(0, new IntArrayList(new int[]{entityId}));
for (final Player p : sendTo) sendPacket(p, packet);
NMSHandlers.getHandler().getPacketHandler().sendEntityDestroyPacket(IntList.of(entityId), sendTo);
}
/**
@@ -134,11 +124,7 @@ public class PacketManager {
* @param sendTo The players the packet should be sent to
*/
public static void sendEntityDestroyPacket(final List<Integer> ids, @NotNull List<Player> sendTo) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
IntArrayList entities = new IntArrayList(new int[]{});
for (int id : ids) entities.add(id);
packet.getModifier().write(0, entities);
for (final Player p : sendTo) sendPacket(p, packet);
NMSHandlers.getHandler().getPacketHandler().sendEntityDestroyPacket(new IntArrayList(ids), sendTo);
}
/**