Skip to content

Commit 78eb61a

Browse files
authored
Improvement - Include the packet sender in Packet Enrichment Events (#220)
* Add sender to Packet Enrichment events * Add the sender field to the event documentation
1 parent 756ea70 commit 78eb61a

File tree

6 files changed

+44
-0
lines changed

6 files changed

+44
-0
lines changed

api/src/main/java/com/lunarclient/apollo/event/packetenrichment/chat/ApolloPlayerChatCloseEvent.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import com.lunarclient.apollo.event.Event;
2727
import com.lunarclient.apollo.module.packetenrichment.PlayerInfo;
28+
import com.lunarclient.apollo.player.ApolloPlayer;
2829
import lombok.Value;
2930

3031
/**
@@ -35,6 +36,14 @@
3536
@Value
3637
public class ApolloPlayerChatCloseEvent implements Event {
3738

39+
/**
40+
* The player that sent the packet.
41+
*
42+
* @return the player
43+
* @since 1.1.9
44+
*/
45+
ApolloPlayer player;
46+
3847
/**
3948
* The {@code long} representing the unix timestamp
4049
* when the packet was created.

api/src/main/java/com/lunarclient/apollo/event/packetenrichment/chat/ApolloPlayerChatOpenEvent.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import com.lunarclient.apollo.event.Event;
2727
import com.lunarclient.apollo.module.packetenrichment.PlayerInfo;
28+
import com.lunarclient.apollo.player.ApolloPlayer;
2829
import lombok.Value;
2930

3031
/**
@@ -35,6 +36,14 @@
3536
@Value
3637
public class ApolloPlayerChatOpenEvent implements Event {
3738

39+
/**
40+
* The player that sent the packet.
41+
*
42+
* @return the player
43+
* @since 1.1.9
44+
*/
45+
ApolloPlayer player;
46+
3847
/**
3948
* The {@code long} representing the unix timestamp
4049
* when the packet was created.

api/src/main/java/com/lunarclient/apollo/event/packetenrichment/melee/ApolloPlayerAttackEvent.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import com.lunarclient.apollo.event.Event;
2727
import com.lunarclient.apollo.module.packetenrichment.PlayerInfo;
28+
import com.lunarclient.apollo.player.ApolloPlayer;
2829
import lombok.Value;
2930

3031
/**
@@ -35,6 +36,14 @@
3536
@Value
3637
public class ApolloPlayerAttackEvent implements Event {
3738

39+
/**
40+
* The player that sent the packet.
41+
*
42+
* @return the player
43+
* @since 1.1.9
44+
*/
45+
ApolloPlayer player;
46+
3847
/**
3948
* The {@code long} representing the unix timestamp
4049
* when the packet was created.

api/src/main/java/com/lunarclient/apollo/event/packetenrichment/world/ApolloPlayerUseItemEvent.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import com.lunarclient.apollo.event.Event;
2727
import com.lunarclient.apollo.module.packetenrichment.PlayerInfo;
28+
import com.lunarclient.apollo.player.ApolloPlayer;
2829
import lombok.Value;
2930

3031
/**
@@ -35,6 +36,14 @@
3536
@Value
3637
public class ApolloPlayerUseItemEvent implements Event {
3738

39+
/**
40+
* The player that sent the packet.
41+
*
42+
* @return the player
43+
* @since 1.1.9
44+
*/
45+
ApolloPlayer player;
46+
3847
/**
3948
* The {@code long} representing the unix timestamp
4049
* when the packet was created.

common/src/main/java/com/lunarclient/apollo/module/packetenrichment/PacketEnrichmentImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public PacketEnrichmentImpl() {
5555
private void onReceivePacket(ApolloReceivePacketEvent event) {
5656
event.unpack(PlayerAttackMessage.class).ifPresent(packet -> {
5757
ApolloPlayerAttackEvent playerAttackEvent = new ApolloPlayerAttackEvent(
58+
event.getPlayer(),
5859
NetworkTypes.fromProtobuf(packet.getPacketInfo().getInstantiationTime()),
5960
NetworkTypes.fromProtobuf(packet.getTargetInfo()),
6061
NetworkTypes.fromProtobuf(packet.getAttackerInfo()),
@@ -70,6 +71,7 @@ private void onReceivePacket(ApolloReceivePacketEvent event) {
7071

7172
event.unpack(PlayerChatOpenMessage.class).ifPresent(packet -> {
7273
ApolloPlayerChatOpenEvent playerChatOpenEvent = new ApolloPlayerChatOpenEvent(
74+
event.getPlayer(),
7375
NetworkTypes.fromProtobuf(packet.getPacketInfo().getInstantiationTime()),
7476
NetworkTypes.fromProtobuf(packet.getPlayerInfo()));
7577

@@ -82,6 +84,7 @@ private void onReceivePacket(ApolloReceivePacketEvent event) {
8284

8385
event.unpack(PlayerChatCloseMessage.class).ifPresent(packet -> {
8486
ApolloPlayerChatCloseEvent playerChatCloseEvent = new ApolloPlayerChatCloseEvent(
87+
event.getPlayer(),
8588
NetworkTypes.fromProtobuf(packet.getPacketInfo().getInstantiationTime()),
8689
NetworkTypes.fromProtobuf(packet.getPlayerInfo()));
8790

@@ -94,6 +97,7 @@ private void onReceivePacket(ApolloReceivePacketEvent event) {
9497

9598
event.unpack(PlayerUseItemMessage.class).ifPresent(packet -> {
9699
ApolloPlayerUseItemEvent playerUseItemEvent = new ApolloPlayerUseItemEvent(
100+
event.getPlayer(),
97101
NetworkTypes.fromProtobuf(packet.getPacketInfo().getInstantiationTime()),
98102
NetworkTypes.fromProtobuf(packet.getPlayerInfo()),
99103
packet.getMainHand()

docs/developers/events.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ _Called when the player closes their chat._
183183

184184
| Field | Description |
185185
| -------------------------- | -------------------------------------------------- |
186+
| `ApolloPlayer player` | The Apollo player that sent the packet. |
186187
| `long instantiationTimeMs` | The unix timestamp when the packet was created. |
187188
| `PlayerInfo playerInfo` | The player's general information. |
188189

@@ -197,6 +198,7 @@ _Called when the player opens their chat._
197198

198199
| Field | Description |
199200
| -------------------------- | -------------------------------------------------- |
201+
| `ApolloPlayer player` | The Apollo player that sent the packet. |
200202
| `long instantiationTimeMs` | The unix timestamp when the packet was created. |
201203
| `PlayerInfo playerInfo` | The player's general information. |
202204

@@ -211,6 +213,7 @@ _Called when the player attacks another player._
211213

212214
| Field | Description |
213215
| -------------------------- | -------------------------------------------------- |
216+
| `ApolloPlayer player` | The Apollo player that sent the packet. |
214217
| `long instantiationTimeMs` | The unix timestamp when the packet was created. |
215218
| `PlayerInfo targetInfo` | The target player general information. |
216219
| `PlayerInfo attackerInfo` | The attacker player general information. |
@@ -227,6 +230,7 @@ _Called when the player uses an item (1.16.1+)._
227230

228231
| Field | Description |
229232
| -------------------------- | -------------------------------------------------- |
233+
| `ApolloPlayer player` | The Apollo player that sent the packet. |
230234
| `long instantiationTimeMs` | The unix timestamp when the packet was created. |
231235
| `PlayerInfo playerInfo` | The player's general information. |
232236
| `boolean mainHand` | Whether the item was in the player's main hand. |

0 commit comments

Comments
 (0)