Skip to content

Implement in-GUI sort and filter controls for shop search results#108

Open
myzticbean wants to merge 4 commits into
snapshot/v2.0from
feature/in-gui-sort-filter
Open

Implement in-GUI sort and filter controls for shop search results#108
myzticbean wants to merge 4 commits into
snapshot/v2.0from
feature/in-gui-sort-filter

Conversation

@myzticbean
Copy link
Copy Markdown
Owner

@myzticbean myzticbean commented May 20, 2026

Summary

  • Adds a sort button (HOPPER, nav bar slot 47) that cycles through Default → Price ↑ → Price ↓ → Distance ↑
  • Adds three filter toggle buttons (slots 48/50/51): Has Stock/Space, Same World Only, Exclude Own Shops
  • Per-player preferences persist across server restarts via player_prefs.json (Gson, async saves)
  • Sort/filter applied lazily at render time via Java stream — raw result list never copied or modified; zero overhead when no preferences are active

New files

  • models/enums/SortMode.java
  • models/PlayerSortFilterPrefs.java
  • utils/json/PlayerPrefsStorageUtil.java

Modified files

  • FindItemAddOn.java — lifecycle hooks (load on startup, sync save on disable)
  • PaginatedMenu.java — freed nav bar slots 47/48/50/51 (previously idle fillers)
  • FoundShopsMenu.javaapplyPrefs(), setSortFilterButtons(), updated setMenuItems(), 4 new click handler cases

Test plan

  • Open /finditem TO_SELL diamond — 4 new buttons visible in nav bar
  • Sort button cycles through all 4 modes, display name updates each time
  • Each filter toggle switches green ↔ gray and result list updates immediately
  • All 3 filters active simultaneously — results are intersection of all conditions
  • Applying a filter while on page 3 returns to page 1
  • Close GUI, reopen — same sort/filter state shown (session persistence)
  • Restart server, reopen GUI — state still applied (disk persistence)
  • Empty result after aggressive filtering — no crash, empty inventory
  • Folia server — no thread-safety errors in logs

- Add SortMode enum (DEFAULT, PRICE_ASC, PRICE_DESC, DISTANCE_ASC) with next() cycle
- Add PlayerSortFilterPrefs model (sort mode + 3 filter toggles, Gson-serializable)
- Add PlayerPrefsStorageUtil: ConcurrentHashMap-backed, async saves via VirtualThreadScheduler,
  persists to player_prefs.json on disable
- Hook load/save into FindItemAddOn lifecycle (runPluginStartupTasks / onDisable)
- Free nav bar slots 47/48/50/51 in PaginatedMenu (previously idle fillers)
- FoundShopsMenu: lazy applyPrefs() stream applies filters+sort only at render time,
  raw result list never modified; setSortFilterButtons() populates slots 47/48/50/51
  with HOPPER sort button and LIME/GRAY_DYE filter toggles; click handlers cycle
  sort mode and toggle each filter with page reset and async prefs save
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 20, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1a6085f5-32a1-498b-9ef9-f6c319b0b17b

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/in-gui-sort-filter

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 and usage tips.

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