Skip to content

fix WrapperPlayer.java packet order according to mc protocol#58

Merged
Tofaa2 merged 3 commits into
Tofaa2:masterfrom
3add:feat/fix-wrapper-player-packet-order
May 13, 2026
Merged

fix WrapperPlayer.java packet order according to mc protocol#58
Tofaa2 merged 3 commits into
Tofaa2:masterfrom
3add:feat/fix-wrapper-player-packet-order

Conversation

@3add
Copy link
Copy Markdown
Contributor

@3add 3add commented May 12, 2026

Fixes #57

Summary by CodeRabbit

  • Bug Fixes
    • Fixed player spawn behavior to prevent duplicate spawns and ensure proper player list initialization is sent to all viewers.

Review Change Stack

Copilot AI review requested due to automatic review settings May 12, 2026 14:56
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 12, 2026

📝 Walkthrough

Walkthrough

This PR fixes the Minecraft protocol packet ordering in WrapperPlayer by adding a spawn() method override that sends the player info update (tab-list) packet to viewers before the spawn packet is sent, aligning with the protocol requirements.

Changes

Tab-list packet ordering

Layer / File(s) Summary
Spawn method with tab-list packet ordering
api/src/main/java/me/tofaa/entitylib/wrapper/WrapperPlayer.java
Adds imports for Location and EntityContainer, then overrides spawn(Location, EntityContainer) to guard against duplicate spawns, send the player info update packet to all viewers, and delegate to the parent spawn() method. This ensures the tab-list packet is transmitted before the spawn packet, matching Minecraft protocol requirements.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A player spawns with packet care,
Tab-list first, then spawn to share!
Order fixed, the protocol's right,
EntityLib shines ever bright!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing packet order in WrapperPlayer.java to match Minecraft protocol requirements.
Linked Issues check ✅ Passed The PR addresses issue #57 by overriding spawn() to send tablist packet before entity spawn packet, aligning with MC protocol requirements.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing packet order in WrapperPlayer.java; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@3add 3add changed the title feat/fix-wrapper-player-packet-order fix WrapperPlayer.java packet order according to mc protocol May 12, 2026
Copy link
Copy Markdown

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@api/src/main/java/me/tofaa/entitylib/wrapper/WrapperPlayer.java`:
- Around line 60-65: The code sends the tab-list add packet before calling
spawn, which can leave a ghost entry if super.spawn(Location, EntityContainer)
returns false or throws; wrap the call to super.spawn(...) in a try/catch and
check its boolean result, and if it returns false or an exception occurs send
the corresponding tab-list removal packet to viewers (e.g. a
tabListRemovePacket() or the inverse of tabListPacket()) before
returning/propagating the error, so viewers never keep a stale entry; use the
existing spawn(Location, EntityContainer), isSpawned(), tabListPacket() methods
to locate the spot to add the rollback send.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c4f8db28-0c13-4122-9e1c-325205a022f2

📥 Commits

Reviewing files that changed from the base of the PR and between 87ec596 and 4ae42f9.

📒 Files selected for processing (1)
  • api/src/main/java/me/tofaa/entitylib/wrapper/WrapperPlayer.java

Comment on lines +60 to +65
public boolean spawn(Location location, EntityContainer parent) {
if (isSpawned()) return false;

sendPacketToViewers(tabListPacket());

return super.spawn(location, parent);
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot May 12, 2026

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid stale tab-list entries when super.spawn(...) fails.

Line 63 sends player info before spawn (good for protocol), but if super.spawn(location, parent) returns false or errors, viewers can keep a ghost tab-list entry for this wrapper.

Proposed fix
 `@Override`
 public boolean spawn(Location location, EntityContainer parent) {
     if (isSpawned()) return false;

     sendPacketToViewers(tabListPacket());
-    return super.spawn(location, parent);
+    try {
+        boolean spawned = super.spawn(location, parent);
+        if (!spawned) {
+            sendPacketToViewers(new WrapperPlayServerPlayerInfoRemove(getUuid()));
+        }
+        return spawned;
+    } catch (RuntimeException ex) {
+        sendPacketToViewers(new WrapperPlayServerPlayerInfoRemove(getUuid()));
+        throw ex;
+    }
 }
📝 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
public boolean spawn(Location location, EntityContainer parent) {
if (isSpawned()) return false;
sendPacketToViewers(tabListPacket());
return super.spawn(location, parent);
public boolean spawn(Location location, EntityContainer parent) {
if (isSpawned()) return false;
sendPacketToViewers(tabListPacket());
try {
boolean spawned = super.spawn(location, parent);
if (!spawned) {
sendPacketToViewers(new WrapperPlayServerPlayerInfoRemove(getUuid()));
}
return spawned;
} catch (RuntimeException ex) {
sendPacketToViewers(new WrapperPlayServerPlayerInfoRemove(getUuid()));
throw ex;
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@api/src/main/java/me/tofaa/entitylib/wrapper/WrapperPlayer.java` around lines
60 - 65, The code sends the tab-list add packet before calling spawn, which can
leave a ghost entry if super.spawn(Location, EntityContainer) returns false or
throws; wrap the call to super.spawn(...) in a try/catch and check its boolean
result, and if it returns false or an exception occurs send the corresponding
tab-list removal packet to viewers (e.g. a tabListRemovePacket() or the inverse
of tabListPacket()) before returning/propagating the error, so viewers never
keep a stale entry; use the existing spawn(Location, EntityContainer),
isSpawned(), tabListPacket() methods to locate the spot to add the rollback
send.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Currently only way spawn could return false if it's already spawned (which I'm checking for), could add this if you want.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Find the spawn method in WrapperEntity and WrapperLivingEntity
ast-grep --pattern 'public boolean spawn($_, $_) {
  $$$
}'

# Also check with rg for context
rg -n "boolean spawn" --type java -A 10

Length of output: 7764


@3add, you're right — after inspecting WrapperEntity.spawn() in WrapperEntity.java (lines 87–96), the only return false path is:

public boolean spawn(Location location, EntityContainer parent) {
    if (spawned) return false;  // only false path
    this.location = location;
    this.spawned = true;
    // ... always proceeds from here
}

Since WrapperPlayer.spawn() already guards with if (isSpawned()) return false; before sending the tab-list packet, super.spawn() is guaranteed to see spawned == false and will never return false again. The current implementation is correct and the extra rollback logic I suggested would be dead code under normal conditions. The suggestion can be safely ignored.

( ˘ ・ ᴗ・ ˘ )

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #57 by ensuring WrapperPlayer sends the player-info update packet to viewers before sending the player spawn packet, aligning WrapperPlayer’s spawn flow with the expected Minecraft protocol ordering (matching the already-correct per-viewer add logic in WrapperEntity.addViewer).

Changes:

  • Override WrapperPlayer.spawn(Location, EntityContainer) to send tabListPacket() to current viewers before delegating to WrapperEntity.spawn(...).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Tofaa2
Copy link
Copy Markdown
Owner

Tofaa2 commented May 13, 2026

Is this a logic breaking change?

@Tofaa2
Copy link
Copy Markdown
Owner

Tofaa2 commented May 13, 2026

LGTM

@Tofaa2 Tofaa2 merged commit 8039667 into Tofaa2:master May 13, 2026
5 of 6 checks passed
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.

WrapperPlayer.java has invalid packet order according to mc protocol

3 participants