Skip to content

Conversation

Pantera07
Copy link

@Pantera07 Pantera07 commented Jul 20, 2025

I tested it with ChatControl plugin and it works fine.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of chat message components to prevent empty messages from being processed.
    • Enhanced processing of system chat messages for better handling and delivery.
    • Ensured all chat message types are sent without interruption.
  • Chores

    • Disabled debug logging in configuration.
    • Downgraded library dependency version to improve stability.

Copy link

coderabbitai bot commented Jul 20, 2025

Walkthrough

The updates add checks to avoid processing empty message components in various packet handlers, restrict packet handling to SYSTEM_CHAT_MESSAGE type with unconditional event cancellation, and refine sender determination logic. Packet sending no longer skips system chat message packets. Debugging is disabled in the config. The byte-buddy dependency version was downgraded in both pom.xml and plugin.yml.

Changes

File(s) Change Summary
Packet handling logic
src/main/java/net/skullian/listeners/PEOutMessagePacket.java
Added checks for non-empty message components before setting them in packets; restricted handling to SYSTEM_CHAT_MESSAGE packets with unconditional event cancellation; refined sender determination; commented out debug print.
Packet sending executor
src/main/java/net/skullian/platform/PacketEventsAsyncChatSendingExecutor.java
Removed early return for WrapperPlayServerSystemChatMessage; all packets now sent silently without skipping.
Configuration
src/main/resources/config.yml
Changed debugging setting from true to false.
Dependency version downgrade
pom.xml, src/main/resources/plugin.yml
Downgraded byte-buddy dependency version from 1.17.6 to 1.17.5.

Estimated code review effort

File(s) Effort Estimate
src/main/java/net/skullian/listeners/PEOutMessagePacket.java 🎯 3 (Moderate)
src/main/java/net/skullian/platform/PacketEventsAsyncChatSendingExecutor.java 🎯 2 (Simple)
src/main/resources/config.yml 🎯 1 (Trivial)
pom.xml, src/main/resources/plugin.yml 🎯 1 (Trivial)

Poem

A rabbit hops through packets sent,
With careful checks, its code is meant.
No more debug, the logs are still,
Each message sent with practiced skill.
The config’s calm, no noisy trace,
Just silent hops in cyberspace. 🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Pantera07
Copy link
Author

This PR is not a proper fix, it is a temporary fix, but it works fine.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (1)
src/main/java/net/skullian/listeners/PEOutMessagePacket.java (1)

331-331: Debug statement should be removed instead of commented out

For a production-ready fix (even temporary), commented-out debug statements should be removed entirely.

-        //System.out.println(event.getPacketType());
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 91a2cd6 and b8797e6.

📒 Files selected for processing (1)
  • src/main/java/net/skullian/listeners/PEOutMessagePacket.java (10 hunks)
🔇 Additional comments (1)
src/main/java/net/skullian/listeners/PEOutMessagePacket.java (1)

359-359: Verify per-packet sender mapping and fallback
I wasn’t able to find any new PacketHandler(…) calls that provide a non-null sender function (the 2nd constructor parameter); it looks like every handler falls back to the default UNDETERMINED_SENDER (which returns null) and then your existing ICPlayerFactory.getICPlayer(…) logic. Please double-check that:

  • Every new PacketHandler(…) instantiation in PEOutMessagePacket.java explicitly passes the intended Function<PacketSendEvent, ICPlayer> as its second argument.
  • The default UNDETERMINED_SENDER and any subsequent fallback to ICPlayerFactory.getICPlayer(event.getSender()) produce the correct ICPlayer for all packet types (chat, title, etc.).

@@ -62,7 +62,7 @@ private void initializeModernPacketHandlers() {
packet -> {
net.kyori.adventure.text.Component nativeComponment = ((WrapperPlayServerDisguisedChat) packet).getMessage();
return new PacketAccessorResult(
nativeComponment != null ? NativeAdventureConverter.componentFromNative(nativeComponment) : Component.empty(),
(nativeComponment != null && nativeComponment.children().size() > 0) ? NativeAdventureConverter.componentFromNative(nativeComponment) : Component.empty(),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Potential NPE when nativeComponment is null

The check nativeComponment != null && nativeComponment.children().size() > 0 could throw NPE if children() returns null. Consider using a more defensive approach.

Apply this safer null check pattern:

-                        (nativeComponment != null && nativeComponment.children().size() > 0) ? NativeAdventureConverter.componentFromNative(nativeComponment) : Component.empty(),
+                        (nativeComponment != null && nativeComponment.children() != null && !nativeComponment.children().isEmpty()) ? NativeAdventureConverter.componentFromNative(nativeComponment) : Component.empty(),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
(nativeComponment != null && nativeComponment.children().size() > 0) ? NativeAdventureConverter.componentFromNative(nativeComponment) : Component.empty(),
(nativeComponment != null
&& nativeComponment.children() != null
&& !nativeComponment.children().isEmpty())
? NativeAdventureConverter.componentFromNative(nativeComponment)
: Component.empty(),
🤖 Prompt for AI Agents
In src/main/java/net/skullian/listeners/PEOutMessagePacket.java at line 65, the
current null check on nativeComponment does not account for the possibility that
nativeComponment.children() might return null, which could cause a
NullPointerException. Update the condition to first check if nativeComponment is
not null, then verify that nativeComponment.children() is not null, and finally
check that nativeComponment.children().size() is greater than 0 before calling
NativeAdventureConverter.componentFromNative. This defensive null check will
prevent potential NPEs.

Comment on lines +84 to +86
if (component.children().size() > 0) {
chatPacket.setMessage((net.kyori.adventure.text.Component) type.convertTo(component, legacyRGB));
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Inconsistent empty component handling

The code checks if component.children().size() > 0 but doesn't handle the case when the component itself has content but no children. This might skip processing valid text components.

Consider checking if the component has any content instead:

-                if (component.children().size() > 0) {
-                    chatPacket.setMessage((net.kyori.adventure.text.Component) type.convertTo(component, legacyRGB));
-                }
+                if (!component.equals(Component.empty())) {
+                    chatPacket.setMessage((net.kyori.adventure.text.Component) type.convertTo(component, legacyRGB));
+                }
🤖 Prompt for AI Agents
In src/main/java/net/skullian/listeners/PEOutMessagePacket.java around lines 84
to 86, the current check only processes the component if it has children,
ignoring components with content but no children. Modify the condition to check
if the component itself has any content or text instead of just children,
ensuring all valid text components are processed by chatPacket.setMessage.

Comment on lines +140 to +145
return new PacketAccessorResult(
(nativeComponent != null && nativeComponent.children().size() > 0) ? NativeAdventureConverter.componentFromNative(nativeComponent) : Component.empty(),
ChatComponentType.NativeAdventureComponent,
0,
false
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Same NPE risk in chat handler

Similar to line 65, this has the same potential NPE issue with the children() check.

Apply the same defensive null check:

-                    return new PacketAccessorResult(
-                            (nativeComponent != null && nativeComponent.children().size() > 0) ? NativeAdventureConverter.componentFromNative(nativeComponent) : Component.empty(),
-                            ChatComponentType.NativeAdventureComponent,
-                            0,
-                            false
-                    );
+                    return new PacketAccessorResult(
+                            (nativeComponent != null && nativeComponent.children() != null && !nativeComponent.children().isEmpty()) ? NativeAdventureConverter.componentFromNative(nativeComponent) : Component.empty(),
+                            ChatComponentType.NativeAdventureComponent,
+                            0,
+                            false
+                    );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return new PacketAccessorResult(
(nativeComponent != null && nativeComponent.children().size() > 0) ? NativeAdventureConverter.componentFromNative(nativeComponent) : Component.empty(),
ChatComponentType.NativeAdventureComponent,
0,
false
);
return new PacketAccessorResult(
(nativeComponent != null
&& nativeComponent.children() != null
&& !nativeComponent.children().isEmpty())
? NativeAdventureConverter.componentFromNative(nativeComponent)
: Component.empty(),
ChatComponentType.NativeAdventureComponent,
0,
false
);
🤖 Prompt for AI Agents
In src/main/java/net/skullian/listeners/PEOutMessagePacket.java around lines 140
to 145, the code checks nativeComponent.children() without ensuring
nativeComponent is not null, risking a NullPointerException. Add a defensive
null check for nativeComponent before calling children(), similar to the fix
applied at line 65, to prevent NPE by verifying nativeComponent is not null
before accessing its children.

Comment on lines +164 to 170
if (component.children().size() > 0) {
if (InteractiveChat.version.isNewerOrEqualTo(MCVersion.V1_19_3)) {
((ChatMessage_v1_19_3) chatMessage.getMessage()).setUnsignedChatContent((net.kyori.adventure.text.Component) type.convertTo(component, legacyRGB));
} else {
chatMessage.getMessage().setChatContent((net.kyori.adventure.text.Component) type.convertTo(component, legacyRGB));
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Repeated pattern of checking children().size() > 0

The same pattern of checking component.children().size() > 0 is repeated multiple times throughout the code. This:

  1. Has the same issue of potentially missing components with content but no children
  2. Creates code duplication
  3. Makes maintenance harder

Extract this logic into a helper method:

private static boolean hasContent(Component component) {
    return component != null && !component.equals(Component.empty());
}

private static boolean hasContent(net.kyori.adventure.text.Component component) {
    return component != null && 
           (component.children() != null && !component.children().isEmpty() || 
            !net.kyori.adventure.text.Component.empty().equals(component));
}

Then use it consistently throughout the code.

Also applies to: 182-184, 194-203, 253-255, 298-307

🤖 Prompt for AI Agents
In src/main/java/net/skullian/listeners/PEOutMessagePacket.java around lines
164-170 and also at 182-184, 194-203, 253-255, and 298-307, the code repeatedly
checks if component.children().size() > 0 to determine if a component has
content, which can miss components with content but no children and causes
duplication. To fix this, create a helper method named hasContent that checks if
the component is not null and not empty, considering both children and content
presence as shown in the suggested method signatures. Replace all repeated
children().size() > 0 checks with calls to this new hasContent method to reduce
duplication and improve correctness.

Comment on lines +347 to +355
// Allow only SystemChat - start
if (event.getPacketType() != PacketType.Play.Server.SYSTEM_CHAT_MESSAGE) {
return;
}
// Allow only SystemChat - end

Player receiver = event.getPlayer();

if (!(event.getLastUsedWrapper() instanceof WrapperPlayServerSystemChatMessage)) {
event.setCancelled(true);
}
event.setCancelled(true);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Restrictive packet filtering may cause issues

This change restricts processing to only SYSTEM_CHAT_MESSAGE packets and unconditionally cancels them. This is a significant behavioral change that:

  1. Ignores all other chat message types (CHAT_MESSAGE, DISGUISED_CHAT, etc.)
  2. Always cancels the original event regardless of processing outcome

This aligns with the "temp fix" nature but may break other chat functionality.

Given this is described as a temporary fix for ChatControl compatibility, verify if this restrictive filtering affects other chat features:


🏁 Script executed:

#!/bin/bash
# Search for other usages of the ignored packet types
echo "=== Searching for CHAT_MESSAGE packet usage ==="
rg -A 5 "PacketType\.Play\.Server\.CHAT_MESSAGE" --type java

echo -e "\n=== Searching for DISGUISED_CHAT packet usage ==="
rg -A 5 "PacketType\.Play\.Server\.DISGUISED_CHAT" --type java

echo -e "\n=== Searching for ChatControl plugin integration ==="
fd -e java -e yml | xargs rg -i "chatcontrol" -A 3

Length of output: 5036


Refine chat packet filtering to preserve other message handlers

The current guard in src/main/java/net/skullian/listeners/PEOutMessagePacket.java (lines 347–355)

// Allow only SystemChat
if (event.getPacketType() != PacketType.Play.Server.SYSTEM_CHAT_MESSAGE) {
    return;
}
Player receiver = event.getPlayer();
event.setCancelled(true);

unconditionally skips all non-system chat packets—bypassing existing handlers for:

  • CHAT_MESSAGE (PERedispatchSignedPacket.java & PACKET_HANDLERS in PEOutMessagePacket.java)
  • DISGUISED_CHAT, DELETE_CHAT, CUSTOM_CHAT_COMPLETIONS, DISPLAY_CHAT_PREVIEW, PLAYER_CHAT_HEADER, etc.

To avoid breaking other chat features, narrow the early return and cancellation to only the SystemChat case. For example:

--- a/src/main/java/net/skullian/listeners/PEOutMessagePacket.java
+++ b/src/main/java/net/skullian/listeners/PEOutMessagePacket.java
@@ -346,9 +346,12 @@
-    // Allow only SystemChat
-    if (event.getPacketType() != PacketType.Play.Server.SYSTEM_CHAT_MESSAGE) {
-        return;
-    }
-    Player receiver = event.getPlayer();
-    event.setCancelled(true);
+    switch (event.getPacketType()) {
+        case SYSTEM_CHAT_MESSAGE -> {
+            Player receiver = event.getPlayer();
+            event.setCancelled(true);
+            // existing SystemChat handling…
+        }
+        default -> {
+            // continue so PACKET_HANDLERS for CHAT_MESSAGE, DISGUISED_CHAT, etc. run
+        }
+    }

This ensures other chat packet handlers remain in effect while still isolating the temporary SystemChat fix.

🤖 Prompt for AI Agents
In src/main/java/net/skullian/listeners/PEOutMessagePacket.java around lines 347
to 355, the current code returns early for all non-SystemChat packets, which
prevents other chat packet handlers from running. Modify the logic so that only
SystemChat packets are cancelled and returned early, while other packet types
continue processing normally. This means removing the unconditional return for
non-SystemChat packets and applying cancellation only within the SystemChat
packet check block to preserve handling of other chat message types.

@Pantera07 Pantera07 marked this pull request as draft August 4, 2025 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant