Skip to content

End an operation when the patient or surgeon changes character - #29

Merged
ryanbarlow97 merged 2 commits into
mainfrom
fix/surgery-original-patient
Oct 11, 2026
Merged

ryanbarlow97 merged 2 commits into
mainfrom
fix/surgery-original-patient

Conversation

@ryanbarlow97

@ryanbarlow97 ryanbarlow97 commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

A surgery's cure, penalty or configured command could land on whichever character the patient happened to be playing when the operation ended, so switching character mid-operation moved the result onto someone else.

The operation now records both the surgeon's and the patient's character when it starts. It ends as soon as RPCharacters reports a switch or a permakill for either of them, including the permakill of an account's last character, where no switch follows. A patient who switches or is permakilled fails the operation with no penalty and no command. A surgeon who switches or dies gives up the operation; no command runs, and the unchanged patient still takes the built-in penalty. The configured success and failure commands only run when neither character has changed. The presence check now treats a dead patient, or one playing a different character, as having left the table.

A patient who logs off still counts as unchanged and takes the penalty, so quitting is not a way out. Surgery's quit listener now runs before RPCharacters unloads the quitting player's characters; before, it would have read no character and skipped the penalty.

Tested with mvn clean verify on Java 21 (107 tests, 100% line coverage). Separate tests cover a switched patient, a switched surgeon, the cure on changed and unchanged patients, permakills, the presence check and quit listener order. Removing each guard makes its tests fail.

Part of TF-Minecraft/RPCharacters#89. Docs: TF-Minecraft/Docs#151.

🤖 Generated with Claude Code

The operation records the patient's character when it begins. A character
switch or permakill now ends it, and the cure or failure penalty only
lands on the character who was on the table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the size:M 30-99 effective changed lines (tests excluded in mixed PRs). label Oct 11, 2026
@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 13 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2d60c796-b666-4412-ac96-9f7a9b50250f

📥 Commits

Reviewing files that changed from the base of the PR and between 7ae6182 and 99c2c4a.


📒 Files selected for processing (8)
  • src/main/java/net/tfminecraft/surgery/listeners/PlayerListener.java
  • src/main/java/net/tfminecraft/surgery/managers/SurgeryCompletionHandler.java
  • src/main/java/net/tfminecraft/surgery/managers/SurgeryMechanicsManager.java
  • src/main/java/net/tfminecraft/surgery/managers/SurgeryMenuManager.java
  • src/main/java/net/tfminecraft/surgery/managers/SurgeryStateManager.java
  • src/test/java/net/tfminecraft/surgery/SurgeryLifecycleTest.java
  • src/test/java/net/tfminecraft/surgery/managers/SurgeryCompletionTest.java
  • src/test/java/net/tfminecraft/surgery/managers/SurgeryMechanicsManagerTest.java

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: a5781f6c-df92-469c-b980-bb8c892f0ab5


📥 Commits

Reviewing files that changed from the base of the PR and between 069e210 and 7ae6182.



📒 Files selected for processing (7)
  • src/main/java/net/tfminecraft/surgery/listeners/PlayerListener.java
  • src/main/java/net/tfminecraft/surgery/managers/SurgeryCompletionHandler.java
  • src/main/java/net/tfminecraft/surgery/managers/SurgeryMenuManager.java
  • src/main/java/net/tfminecraft/surgery/managers/SurgeryStateManager.java
  • src/main/java/net/tfminecraft/surgery/procedures/Ailments.java
  • src/test/java/net/tfminecraft/surgery/SurgeryLifecycleTest.java
  • src/test/java/net/tfminecraft/surgery/managers/SurgeryCompletionTest.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
    • Surgery outcomes now apply only to the patient character involved in the procedure, preventing effects or notifications from reaching a different active character.
    • Changing characters during surgery now ends the session appropriately: the surgeon’s menu closes, and the surgery fails when the patient switches characters.
📝 Summary

Walkthrough

Surgery sessions now record the patient’s active character ID. Character activation can end an active surgery, and completion handling checks the recorded ID before applying surgery effects.

Changes

Surgery character identity

Layer / File(s) Summary
Record patient character identity
src/main/java/net/tfminecraft/surgery/procedures/Ailments.java, src/main/java/net/tfminecraft/surgery/managers/SurgeryStateManager.java, src/main/java/net/tfminecraft/surgery/managers/SurgeryMenuManager.java
Ailments.characterId returns the active character ID or null when player data or an active character is unavailable. Surgery state stores that ID when the surgery menu opens.
Handle character activation
src/main/java/net/tfminecraft/surgery/listeners/PlayerListener.java, src/main/java/net/tfminecraft/surgery/managers/SurgeryMenuManager.java, src/test/java/net/tfminecraft/surgery/SurgeryLifecycleTest.java
PlayerListener forwards character activation to SurgeryMenuManager. The manager ends a surgeon’s active session, or fails the surgery when the patient activates a different character. Lifecycle tests cover these cases and event forwarding.
Validate patient character at completion
src/main/java/net/tfminecraft/surgery/managers/SurgeryCompletionHandler.java, src/test/java/net/tfminecraft/surgery/managers/SurgeryCompletionTest.java
Completion handling rejects a patient whose current character ID differs from the recorded ID. Tests cover matching and mismatched character IDs.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant CharacterActivatedEvent
  participant PlayerListener
  participant SurgeryMenuManager
  participant SurgeryStateManager
  CharacterActivatedEvent->>PlayerListener: activated owner UUID and character ID
  PlayerListener->>SurgeryMenuManager: handleCharacterActivated(owner UUID, character ID)
  SurgeryMenuManager->>SurgeryStateManager: read surgery session and recorded patient character ID
  SurgeryMenuManager->>SurgeryMenuManager: end surgeon session or fail surgery for changed patient character
Loading


Merge Risk: ⚪ Minimal · up to 7ae61

The change ends or fails a surgery when the patient or surgeon changes character, and it skips the cure and penalty when the patient's active character differs from the recorded one. No actionable merge-blocking risk was identified, and the PR reports 100 passing tests.

  • 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.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Oct 11, 2026
The operation now records both participants' characters. Configured
completion commands name accounts, so they are skipped once either
participant has switched character or been permakilled; the built-in
failure penalty still lands on a patient who is unchanged.

A confirmed permakill ends the operation on its own, which covers an
account's last character where no other character takes over. The
presence check also turns away a dead patient or one now playing another
character. The quit listener runs before RPCharacters unloads the quitting
player, so a quit still finds the same character.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added size:L 100-499 effective changed lines (tests excluded in mixed PRs). and removed size:M 30-99 effective changed lines (tests excluded in mixed PRs). labels Oct 11, 2026
@ryanbarlow97
ryanbarlow97 merged commit 4653379 into main Oct 11, 2026
3 checks passed
@ryanbarlow97
ryanbarlow97 deleted the fix/surgery-original-patient branch October 11, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 effective changed lines (tests excluded in mixed PRs).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant