Skip to content

Refactor lore display methods to use LoreBuilder utility #37

Description

@FirebrickRed

Problem

The methods in , , , and contain significant code duplication for displaying list sections and player choices.

Duplicated Patterns

  1. List display pattern (~10 occurrences):
lore.add(Component.text("Header:").color(color));
for (String item : items) {
    lore.add(Component.text("  • " + item).color(color));
}
  1. Language choice display (duplicated in Race, SubRace, Background):
for (ChoiceEntry choice : playerChoices) {
    if (choice.type() == PlayersChoice.ChoiceType.LANGUAGE) {
        // ... 10+ lines of similar code
    }
}

Proposed Solution

Create a LoreBuilder utility class in io.papermc.jkvttplugin.util with fluent API methods:

  • addListSection(header, items, color) - For displaying bulleted lists
  • addLanguageChoices(fixedLanguages, playerChoices) - For language display
  • blankLine() - For spacing
  • build() - Returns the final lore list

Benefits

  • DRY principle - eliminate ~50+ lines of duplicated code
  • Consistent formatting across all menus
  • Easier to modify display format in one place
  • More readable lore methods

Files to Update

  • src/main/java/io/papermc/jkvttplugin/data/model/DndRace.java
  • src/main/java/io/papermc/jkvttplugin/data/model/DndClass.java
  • src/main/java/io/papermc/jkvttplugin/data/model/DndBackground.java
  • src/main/java/io/papermc/jkvttplugin/data/model/DndSubRace.java
  • (new) src/main/java/io/papermc/jkvttplugin/util/LoreBuilder.java

Notes

This refactoring was identified after implementing Issue #33. The current implementation works correctly, but would benefit from this cleanup once the pattern is stable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions