Refactor/Clarify logic of tracking and collecting player and entity's death context#200
Merged
Dreeam-qwq merged 4 commits intomasterfrom Feb 9, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Some class or variable namings refer to the suggestions of ChatGPT, to follow the "best practice" of related project standards. I'm not sure whether they are entirely correct.
If you have any better ideas or naming, welcome to contact me, open an issue, or any other way to let me know.
Renamed PlayerManager / EntityManager to PlayerCtx / EntityCtx, meaning the "context of the player / entity", to be more consistent with its actual function. Related variable names are also renamed.
The original name *Manager does not describe the function of the class clearly; it actually has no relationship with "managing" or managing the states of players.
The player context functions as a "wrapper" of the Player instance, but stores additional useful context of the death, like last entity damager, etc., used for building death messages.
Also, only create a new instance for the player context on player join and plugin load, and remove it when the player quits to prevent a memory leak happens and be friendly to big networks.
The original logic actually has a memory leak, because the map keeps adding players, but doesn't remove them when a player quits.
Player context creation in other stages is also removed, like during the entity damage stage, which is unnecessary, and the condition will never be reached.
Useless player online checks are removed in many places; we can assume that the player is online when the damage event or death event is triggered.