Skip to content

fix: relic inventory dupe and drag-in storage, autosave relics, silent mob-drop checks - #10

Open
happyc0der wants to merge 1 commit into
VoperAD:mainfrom
happyc0der:fix/relic-inventory-dupe
Open

happyc0der wants to merge 1 commit into
VoperAD:mainfrom
happyc0der:fix/relic-inventory-dupe

Conversation

@happyc0der

Copy link
Copy Markdown

Four fixes in the relic inventory and mob drops. All of them have run on our Paper 26.2 server (Slimefun Legacy) since 2026-10-13, built from the SlimefunNewHorizons fork, whose copies of these three files match main here line for line apart from import names.

1. Duplication on a partial shift-click (RelicInventoryListener.onInventoryClick)

Shift-clicking a relic stack when it only partly fits into the player's inventory: addItem gives the player the part that fits, but ItemUtils.consumeItem only runs when everything fit (nonAddedItems.isEmpty()). Nothing leaves the relic inventory, so the moved relics are duplicated. The amount that actually moved (wanted - sum(leftovers)) is now removed and the slot is written back. "Your inventory is full!" shows only when something was left over.

2. Any item can be stored by dragging (new onInventoryDrag)

The click handler only lets relics come out, but an InventoryDragEvent isn't covered. Dragging any item over the relic inventory's slots stores it there for good, which turns it into a 54-slot backpack that opens anywhere. Drags that touch a top-inventory raw slot while the top inventory is the player's relic inventory are now cancelled. Drags inside the player's own inventory are unaffected.

3. Relics are lost on a crash (RelicInventoryManager)

saveConfig() is only called from SlimeFrame.onDisable, so a crash or kill loses every relic earned since the last clean stop. A runTaskTimer now checks once a minute and saves only when saveToString() changed. It writes a temp file and moves it over the old one (atomic move where the filesystem supports it), so a crash mid-write can't leave a truncated file. Save errors are logged instead of printStackTrace.

4. A message per locked drop on every kill (AdvancedMobDropListener.canDrop)

canDrop called sfItem.canUse(p, true) for every Slimefun item registered as a drop of that mob, from any addon, before checking instanceof AdvancedMobDrop. Each kill therefore sent a "no permission" / "not researched" message per locked drop, on top of Slimefun's own MobDropListener. It now returns early for anything that isn't an AdvancedMobDrop, and checks canUse(p, false), so a locked drop is still withheld, just silently. Drop logic and chances are unchanged.

Testing

The three changed files compile against Slimefun 4 (Legacy 4.1.78) and paper-api 1.21.11. I didn't run the full Maven build against RC-34; the code only uses APIs from Java 16 and Bukkit that were already in use here.

🤖 Generated with Claude Code

…t mob-drop checks

- RelicInventoryListener.onInventoryClick: a shift-click whose stack only
  partly fit into the player's inventory added the part that fit but took
  nothing out of the relic inventory (ItemUtils.consumeItem only ran when
  everything fit), duplicating those relics. Now the amount that actually
  moved is removed and the slot is written back; "Your inventory is full!"
  is shown only when something was left over.
- New onInventoryDrag: dragging items into the relic inventory bypassed the
  click guard, so any item could be stored there permanently. Drags that
  touch the top (relic) inventory are cancelled.
- RelicInventoryManager: relic inventories were only saved in
  SlimeFrame.onDisable, so a crash lost every relic earned since the last
  restart. A once-a-minute task saves when the YAML changed, through a temp
  file that is moved over the old one.
- AdvancedMobDropListener.canDrop called canUse(p, true) on every
  registered Slimefun mob drop, before checking that it is an
  AdvancedMobDrop, so each kill sent a no-permission/not-researched message
  per locked drop of that mob, on top of Slimefun's own MobDropListener.
  It now returns early for non-AdvancedMobDrop items and checks silently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant