Skip to content

fix: keep the seal when a right-click uses a block instead of reading - #41

Merged
XxFran10xX merged 1 commit into
mainfrom
fix/sealed-letter-block-click
Oct 20, 2026
Merged

XxFran10xX merged 1 commit into
mainfrom
fix/sealed-letter-block-click

Conversation

@XxFran10xX

Copy link
Copy Markdown
Contributor

Problem

Right-clicking a barrel (or a door, lever or any other usable block) while holding a sealed letter broke its seal. BirdMessenger treated every right-click as reading, but on those clicks vanilla uses the block and the book never opens.

Fix

The seal now breaks on PlayerStatisticIncrementEvent for USE_ITEM / WRITTEN_BOOK. In Paper 1.21.10, WrittenBookItem#use opens the reading screen and then counts the book as used, and nothing else counts a written book that way. (ItemStack#useOn, hurtEnemy and mineBlock only count items with weapon or tool components, or a successful useOn.) So:

  • Barrel, door, lever and other block uses: the book doesn't open, nothing is counted, and the seal holds.
  • Lectern: the book is placed without being counted. The explicit lectern and chiseled bookshelf guard is no longer needed.
  • Clicks another plugin denies: use never runs, so the seal holds. (Before, the old NORMAL-priority interact handler ignored denials.)
  • Sneak-click on a block, a click on a plain block, a click in the air: the book opens and the seal breaks, as before.

The handler runs at MONITOR and also handles cancelled counts, because a cancelled count still means the book opened. The hand comes from the inventory: a client only tries the off hand when the main-hand item does nothing, and a written book always opens. Everything after that (character checks, next-tick swap, resolved-flag tolerance) is unchanged.

Testing

  • mvn verify on Linux: 259 tests, 0 failures, line-coverage gate met. New tests cover other counts and materials, a main-hand book beating an off-hand letter, and the handler's priority. On Windows, the estate/mail-store tests fail the same way on main (directory fsync).
  • TFMCDev01, character bot that signs a real MMOItems letter (~/seal-test/test.js):
    • On 1.3.2 (EXPECT=bug): barrel and lever clicks broke the seal (bug reproduced).
    • With this branch: 8/8 PASS. Barrel click and lever click keep the seal. The lectern takes the letter still sealed. Sneak-click on the barrel, a click on stone and a click in the air open it, with the "seal breaks" message.
    • Off-hand reading is covered by unit tests only, because Dev's MMOInventory overwrites anything put in the off hand.

🤖 Generated with Claude Code

Right-clicking a barrel, door, lever or other usable block while holding a
sealed letter broke the seal even though the book never opened. Break it
only when vanilla counts the written book as used, which happens right after
the reading screen opens and on no other click.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@XxFran10xX

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 62886adb-2d32-4009-bafc-dd96596304a4
📥 Commits

Reviewing files that changed from the base of the PR and between e1b4425 and 6f66348.

📒 Files selected for processing: 2
  • src/main/java/net/tfminecraft/birdmessenger/letters/LetterListener.java
  • src/test/java/net/tfminecraft/birdmessenger/letters/LetterListenerTest.java

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved written-letter opening detection for more reliable processing.
    • Ensured letters are handled from the correct active hand, including when the held item changes shortly after opening.
    • Unrelated item interactions and statistics are now ignored.
    • Sealed-letter validation continues to be applied before processing.

The listener now detects written-book openings through PlayerStatisticIncrementEvent at MONITOR priority. It infers the hand from the player's inventory, validates sealed letters and updates the selected slot after a delay. Tests cover event filtering, hand selection, event priority and delayed replacement.

Changes: Letter opening

Layer / File(s) Summary
Detect openings and replace letters
src/main/java/net/tfminecraft/birdmessenger/letters/LetterListener.java, src/test/java/net/tfminecraft/birdmessenger/letters/LetterListenerTest.java
The listener filters statistic events for written-book use, infers the hand from the inventory and updates the selected slot after a delay. Tests cover filtering, hand selection, monitor priority, cancelled events and delayed item changes.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: ryanbarlow97

Merge Risk: ⚪ Minimal · up to 6f663

The change is ready to merge after normal checks. The investigated off-hand scenario does not expose a seal-breaking failure.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@github-actions github-actions Bot added the size:M 30-99 effective changed lines (tests excluded in mixed PRs). label Oct 20, 2026
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@XxFran10xX
XxFran10xX merged commit 56d766b into main Oct 20, 2026
3 checks passed
@XxFran10xX
XxFran10xX deleted the fix/sealed-letter-block-click branch October 20, 2026 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 effective changed lines (tests excluded in mixed PRs).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant