Fix worth line duplication and visibility in creative mode - #18
Merged
Conversation
The worth line is applied purely via outgoing item packets, which caused two issues: - Items received while a non-decoratable inventory was open (server shop purchases, /give while a menu is open, pickups) stayed bare until the next full inventory resend, i.e. a relog. Added WorthRefreshListener, which re-sends the player's inventory on the next tick after pickups, inventory closes, and join so the packet listener can decorate them without requiring a rejoin. - In creative mode the client echoes displayed items back to the server (SET_CREATIVE_SLOT), baking the injected worth line into the real item and producing duplicate lines on the next decoration. The injected line now carries an invisible marker; an inbound SET_CREATIVE_SLOT listener strips it before the server stores the item, and decoration always removes any pre-existing worth line before re-adding one. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016mt4AzbsKNLtCpekgmSGGU
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.
Summary
This PR fixes issues with the worth line display in item lore by preventing duplication when items are echoed back from creative mode clients, and ensuring worth lines are refreshed when items enter the player's inventory through various means.
Key Changes
Invisible marker system: Added a
WORTH_MARKERconstant composed of invisible formatting codes (§9§8§9§8§r) to reliably identify and strip injected worth lines without affecting item appearance.Creative mode packet handling: Added a new
creativeListenerthat interceptsSET_CREATIVE_SLOTpackets from creative-mode clients and strips any injected worth lines before they get baked into the ItemStack, preventing duplicate lines.Improved lore management:
addWorthLore()to always remove stale worth lines before adding new ones, preventing accumulation of duplicatesstripWorthLore()method to cleanly remove worth markers from itemsremoveWorthLines()helper that removes worth lines and their preceding blank separators in reverse iteration orderloreHasWorthLine()to detect if an item already has an injected worth lineNew WorthRefreshListener: Created a new listener that triggers inventory updates when items arrive outside of normal packet flows (pickup events, inventory close, player join), ensuring worth lines are applied to items that wouldn't otherwise be resent to the client.
Plugin registration: Registered the new
WorthRefreshListenerin the main plugin class.Improved cleanup: Enhanced the
unregister()method to properly clean up both packet listeners with null checks.Notable Implementation Details
https://claude.ai/code/session_016mt4AzbsKNLtCpekgmSGGU