diff --git a/common/src/main/java/me/lojosho/hibiscuscommons/util/packets/PacketManager.java b/common/src/main/java/me/lojosho/hibiscuscommons/util/packets/PacketManager.java index 70951ac..07e8fad 100644 --- a/common/src/main/java/me/lojosho/hibiscuscommons/util/packets/PacketManager.java +++ b/common/src/main/java/me/lojosho/hibiscuscommons/util/packets/PacketManager.java @@ -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 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 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 ids, @NotNull List 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); } /**