Skip to content

Commit

Permalink
fix: Avoid handling any packet event if it's already canceled and fix…
Browse files Browse the repository at this point in the history
… a formatting mistake in packet listeners loading method
  • Loading branch information
MemencioPerez committed May 20, 2024
1 parent 67b6cd9 commit 5713f19
Show file tree
Hide file tree
Showing 9 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,17 @@ public void onProxyInitialize(ProxyInitializeEvent event) {
PacketEvents.getAPI().load();

Stream.of(
LoginListener.class,
CommandListener.class,
ClientChatListener.class,
ServerChatListener.class,
ChatHeaderListener.class,
ChatSessionListener.class,
ServerDataListener.class,
ServerResponseListener.class
).map(injector::getInstance)
.filter(LoadablePacketListener::canBeLoaded)
.forEach(LoadablePacketListener::register);
LoginListener.class,
CommandListener.class,
ClientChatListener.class,
ServerChatListener.class,
ChatHeaderListener.class,
ChatSessionListener.class,
ServerDataListener.class,
ServerResponseListener.class
).map(injector::getInstance)
.filter(LoadablePacketListener::canBeLoaded)
.forEach(LoadablePacketListener::register);

PacketEvents.getAPI().init();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public boolean canBeLoaded() {

@Override
public void onPacketReceive(final PacketReceiveEvent event) {
if (event.isCancelled()) return;
final PacketTypeCommon packetType = event.getPacketType();
if (packetType == PacketType.Play.Client.CHAT_SESSION_UPDATE) {
event.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public boolean canBeLoaded() {

@Override
public void onPacketReceive(final PacketReceiveEvent event) {
if (event.isCancelled()) return;
final PacketTypeCommon packetType = event.getPacketType();
if (packetType == PacketType.Play.Client.CHAT_SESSION_UPDATE) {
event.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public boolean canBeLoaded() {

@Override
public void onPacketReceive(final PacketReceiveEvent event) {
if (event.isCancelled()) return;
final PacketTypeCommon packetType = event.getPacketType();
if (packetType == PacketType.Play.Client.CHAT_MESSAGE) {
final WrapperPlayClientChatMessage packet = new WrapperPlayClientChatMessage(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public boolean canBeLoaded() {

@Override
public void onPacketSend(final PacketSendEvent event) {
if (event.isCancelled()) return;
final PacketTypeCommon packetType = event.getPacketType();
if (packetType == PacketType.Play.Server.CHAT_MESSAGE) {
if (event.getUser().getClientVersion().isOlderThan(ClientVersion.V_1_19)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public boolean canBeLoaded() {

@Override
public void onPacketReceive(final PacketReceiveEvent event) {
if (event.isCancelled()) return;
final PacketTypeCommon packetType = event.getPacketType();
if (packetType == PacketType.Play.Client.CHAT_COMMAND) {
final WrapperPlayClientChatCommand packet = new WrapperPlayClientChatCommand(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public boolean canBeLoaded() {

@Override
public void onPacketSend(final PacketSendEvent event) {
if (event.isCancelled()) return;
final User user = event.getUser();
final PacketTypeCommon packetType = event.getPacketType();
if (packetType == PacketType.Play.Server.SERVER_DATA) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void onPacketReceive(PacketReceiveEvent event) {

@Override
public void onPacketSend(PacketSendEvent event) {
if (event.isCancelled()) return;
final User user = event.getUser();
final PacketTypeCommon packetType = event.getPacketType();
if (packetType == PacketType.Login.Server.ENCRYPTION_REQUEST) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public boolean canBeLoaded() {

@Override
public void onPacketSend(final PacketSendEvent event) {
if (event.isCancelled()) return;
final User user = event.getUser();
final PacketTypeCommon packetType = event.getPacketType();
if (packetType == PacketType.Status.Server.RESPONSE) {
Expand Down

0 comments on commit 5713f19

Please sign in to comment.