> For the complete documentation index, see [llms.txt](https://docs.polyfrost.org/oneconfig/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.polyfrost.org/oneconfig/events/available-events/packet-events.md).

# Packet Events

## SendPacketEvent

SendPacketEvent is (as the name suggests) an event that is fired every time the client sends a packet.

This event also gets the packet that is going to be sent, as a `Packet<?>`. You can use code like the code below to do things with it.

{% hint style="warning" %}
This event is cancellable, meaning you can stop the packet from getting into the games code. Be careful with what you cancel!
{% endhint %}

```java
@Subscribe
public void onPacketSend(SendPacketEvent event) {
    // check if the packet is the right type
    if(event.packet instanceof S0FPacketSpawnMob) {
        // cast the packet to the right type
        S0FPacketSpawnMob packet = (S0FPacketSpawnMob) event.packet;
        // do something with it
        System.out.println("Entity attempted to be spawned with ID: " + packet.getEntityID());
        // cancel the event afterwards, rendering this packet useless.
        event.isCancelled = true;
    }
}
```

## ReceivePacketEvent

ReceivePacketEvent is (as the name suggests) an event that is fired every time the client receives a packet.

This event also gets the packet that has been received, as a `Packet<?>`. You can use code like the code below to do things with it.

{% hint style="warning" %}
This event is Cancel-able, meaning you can stop the packet from getting into the games code. Be careful with what you cancel!
{% endhint %}

```java
@Subscribe
public void onPacketReceive(ReceivePacketEvent event) {
    // check if the packet is the right type
    if(event.packet instanceof S0FPacketSpawnMob) {
        // cast the packet to the right type
        S0FPacketSpawnMob packet = (S0FPacketSpawnMob) event.packet;
        // do something with it
        System.out.println("Received data from server about an entity spawned with ID: " + packet.getEntityID());
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.polyfrost.org/oneconfig/events/available-events/packet-events.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
