Skip to content

feat: support searching and sorting items by enchantment name and level - #17

Merged
DerMoha merged 4 commits into
DerMoha:mainfrom
ags816710:feat/enchantment-search-and-sort
Jul 25, 2026
Merged

feat: support searching and sorting items by enchantment name and level#17
DerMoha merged 4 commits into
DerMoha:mainfrom
ags816710:feat/enchantment-search-and-sort

Conversation

@ags816710

Copy link
Copy Markdown
Contributor

Adds the ability to search for items in the terminal by their enchantment names and levels (e.g., typing "Fortune 3" or "Sharpness IV"). It also updates the alphabetical sorting logic so that enchanted books and gear are grouped by their base name, but sorted logically by their specific enchantment and level (e.g., Sharpness I appears before Sharpness V).

Roman numerals are currently hardcoded from I -> X, might change this to something better if needed though.

ags816710 added 2 commits June 9, 2026 18:12
…e 3", "fortune iii", etc)

- Update enchantment matching logic to parse search queries word-by-word.
- Add Roman numeral conversion to support Minecraft's native level formatting (I, II, III, etc.) - hardcoded for now
- Ensure both regular enchanted items and Enchanted Books are correctly filtered by their specific enchantment levels.
- Add `getSortName` utility to append the primary enchantment name to the base item name and and zero-padded level for sorting.
- Ensures enchanted books remain grouped together under "Enchanted Book" while sorting logically by their specific enchantment (e.g., "Enchanted Book - Mending" before "Enchanted Book - Sharpness").
- Ensures enchanted books display in ascending order of level (e.g. Efficiency IV appears after Efficiency II)
- Applies to both stored enchants (books) and regular enchanted gear.
@DerMoha

DerMoha commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Thanks, i really like and missed this feature but was too lazy to add this in. While looking at this i found that in formatEnchantmentName word.substring(1) is appended twice which could maybe double the tail of every word like "sharpness" → "Ssharpnessharpness". Did you check that?
Im fine with roman numerals being hardcoded, no need for some real conversion for now :D
If you can, please add some unit tests, maybe cover formatEnchantmentName and getSortableName for enchanted books

@ags816710

Copy link
Copy Markdown
Contributor Author

Made the fix to the formatEnchantmentName function, not sure what I was thinking when I wrote that. I will attempt to add unit tests soon(ish), when I get the chance, I'm rather swamped with other work currently and my initial attempts aren't getting anywhere.

@DerMoha
DerMoha merged commit 0633baf into DerMoha:main Jul 25, 2026
DerMoha added a commit that referenced this pull request Jul 25, 2026
…ent helpers (#22)

Companion follow-up to #17. The substring-duplicate bug fix landed via ags816710's PR; this adds the regression coverage that was prepared alongside it but got lost in the rebasing race.

- Package-private matchesEnchantment(String, int, String) and formatEnchantmentName(String) overloads so the helpers can be unit-tested without instantiating Enchantment (whose static initializer requires a live Bukkit server).
- Move formatNumber up next to applyCustomModelData so related formatting helpers cluster together (was buried at the end of the file).
- New ItemUtilsTest with 24 cases covering formatEnchantmentName, toRoman, and matchesEnchantment across name/level/raw-key/case/whitespace paths.

Local mvn test is green: 30/30 (24 new + 6 existing NetworkTest).
@DerMoha

DerMoha commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Hey, just wanted to say sorry for jumping in and doing the tests myself :D I know you said you wanted to do them but i had some time and wanted to get this added.

Thanks again for the PRs, youre actually my first ever contributor, which is pretty cool. The changes are merged now and will ship with version 1.5.0 whenever I find the time to release it.

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.

2 participants