Skip to content

Added methods to Hologram to improve changing the lines#79

Open
ThomasWega wants to merge 3 commits intodenmeh:masterfrom
ThomasWega:master
Open

Added methods to Hologram to improve changing the lines#79
ThomasWega wants to merge 3 commits intodenmeh:masterfrom
ThomasWega:master

Conversation

@ThomasWega
Copy link
Contributor

@ThomasWega ThomasWega commented Aug 30, 2025

Hey. First of all thanks for adding the per-player function to the lines. That was a great addition.

I however found that if I ever want to replace the amount of lines in a hologram it starts getting a bit messy and I wasn't really able to do it. If the amount of lines were the same I could just use the function and update the lines to whatever I need but what if the amount is different? I start with 2 lines and then I need to update to 3 lines with different text.

So in this commit I've address this issue of mine and also just added few @NotNull for better API clarity.

Now, I'm not considering this to be a final version. While I tested it and it seems to work I'd definitely want at least an opinion of one other person first and him testing it as well.

This is how the usage would look. I'm also wondering if we can add default offset and just keep it optional if someone wants it different?

Usage example
public class PetEggHologram extends Hologram {
  private static final IHologramPool<PetEggHologram> POOL = MLPSkyblock.INSTANCE.getHoloEasy().startPool(100, false);

  private final @NotNull PetEggInstance petEggInstance;

  public PetEggHologram(@NotNull PetEggInstance petEggInstance) {
      super(
              MLPSkyblock.INSTANCE.getHoloEasy(),
              petEggInstance.getMob().getLocation().clone()
      );
      this.petEggInstance = petEggInstance;

      this.initialize();
      this.show(POOL);
  }

  private void initialize() {
      this.getLines().addAll(this.getNewLines());
  }

  private List<TextLine> getNewLines() {
      final List<String> hatchedLines = PetConfig.Egg.Hologram.HATCHING.getValue();
      final List<String> readyLines = PetConfig.Egg.Hologram.READY.getValue();

      final AtomicDouble offsetCounter = new AtomicDouble(0);
      final long timeLeftSec = (this.petEggInstance.getPetEgg().hatchTimestamp() - System.currentTimeMillis()) / 1000;
      if (timeLeftSec > 0) {
          return hatchedLines.stream()
                  .map(str -> new TextLine(
                                  this,
                                  player -> ColorUtils.toColoredLegacy(
                                          str.replace("<time>", TimeUtils.formatTime(
                                                  (this.petEggInstance.getPetEgg().hatchTimestamp() - System.currentTimeMillis()) / 1000
                                          ))
                                  )
                          ).yOffset(offsetCounter.getAndAdd(-0.25))
                  )
                  .toList();
      } else {
          return readyLines.stream()
                  .map(str -> new TextLine(
                                  this,
                                  player -> ColorUtils.toColoredLegacy(str)
                          ).yOffset(offsetCounter.getAndAdd(-0.25))
                  )
                  .toList();
      }
  }

  public void update() {
      this.replaceLines(this.getNewLines());
  }
}

I'm also thinking if this can be done in a better and more customizable way or if this is enough? Just looking for a feedback first. I'm happy to do any changes needed as I use this util in all my projects so I'm only happy to give back some of the time the existence of this has saved me.

@ThomasWega ThomasWega marked this pull request as draft August 30, 2025 11:04
@denmeh denmeh requested a review from Copilot October 7, 2025 15:49
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds methods to the Hologram class to improve management of hologram lines when the number of lines changes. The PR introduces functionality to update existing lines and completely replace the line collection with new lines.

  • Added updateLines() method to update all existing lines
  • Added replaceLines() method to replace the entire line collection with a new set of lines
  • Enhanced API clarity by adding @NotNull annotations to method parameters and return types

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@ThomasWega
Copy link
Contributor Author

Any thoughts? @unldenis

@denmeh
Copy link
Owner

denmeh commented Oct 16, 2025

Thanks for the contribution, sorry but I was quite busy and I tried Copilot also for PR but it didn't give useful info.

Thanks for the @NotNull annotations that are helpful.

One of the most difficult things is the yOffset, at the beginning I had loaders but perhaps it is better customizable in this way.

I left you only a small comment, I have to test it but I think it's fine and then I merge it.

@ThomasWega
Copy link
Contributor Author

Hey. Apologies for forgetting about this. What note have you left me please? If there's anything more to do, I'll do it so we can get this merged finally :D

@ThomasWega ThomasWega marked this pull request as ready for review January 30, 2026 15:39
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.

3 participants