Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add boss bar animation when it appears #300

Merged
merged 9 commits into from
Jul 8, 2024

Conversation

IamMusavaRibica
Copy link
Contributor

@IamMusavaRibica IamMusavaRibica commented Jul 1, 2024

Here is a brief summary of the changes:

  • Removed code duplication: calculating progress as double and casting it to float in bossBar#progress(float) method.
double progress = currentXp / levelXp;
if (progress > 1 || progress < 0) {
    progress = 1.0;
}
  • Changed signature of methods handleNewBossBar andhandleExistingBossBar to take progress instead of currentXp and levelXp, and progress as float instead of double
  • Added a comment that explains it

2024-07-0121-05-48-ezgif com-video-to-gif-converter (1)

note that the first commit bf80e34 should have been amended but git complained with merge conflicts, so it looks like it got duplicated at 10c922e

@Archy-X Archy-X self-requested a review July 2, 2024 04:20
@Archy-X
Copy link
Owner

Archy-X commented Jul 2, 2024

Is the animation really needed in the case where the player already has the boss bar visible? Because it already "animates" between progress when the previous XP amount is already showing. Maybe add some way to detect if there's one actively showing for that skill and set the progress immediately?

@IamMusavaRibica
Copy link
Contributor Author

Is the animation really needed in the case where the player already has the boss bar visible?

Maybe. It would require an if in the handleExistingBossBar method. BossBarManager keeps a reference to distinct boss bars for every player and skill, and when the player doesn't actively see it, it's not deleted and recreated later, it is created only once for every player and skill. That's why it can also "appear" even in handleExistingBossBar.

Maybe add some way to detect if there's one actively showing for that skill and set the progress immediately?

The only way to check is using the data in currentActions and checkCurrentActions

@Archy-X
Copy link
Owner

Archy-X commented Jul 6, 2024

I just added an option to toggle it off since detecting if its showing wasn't as straightforward as I thought. Can you verify that it is still working as intended?

@IamMusavaRibica
Copy link
Contributor Author

IamMusavaRibica commented Jul 8, 2024

I just added an option to toggle it off since detecting if its showing wasn't as straightforward as I thought. Can you verify that it is still working as intended?

Unfortunately it does not, you didn't account for the fact that BossBarManager is reused after /skill reload, not recreated, so if you change the boss_bar.animate_progress boolean in the config, it will not update. I decided not to touch ReloadExecutor for this, and instead modified BossBarManager's methods for handling boss bars - so that the option is looked up every time the method is called. I'm sure it doesn't have large performance deficiency.

@IamMusavaRibica
Copy link
Contributor Author

In 584eecd I just changed code flow and comments to a way I feel would be easier to comprehend

@Archy-X
Copy link
Owner

Archy-X commented Jul 8, 2024

I actually made ANIMATE_PROGRESS a class field that didn't update on reload on purpose so it would be slightly more performant, especially since the boss bar is known to be a source of lag on larger servers. I would prefer if it was set back to a class field and updated through the existing BossBarManager#loadOptions method which is already called by ReloadExecutor.

@IamMusavaRibica
Copy link
Contributor Author

What's the reasoning behind making it final then? I don't know why one would have to restart the entire server instead of just the plugin in order to update boss_bar.animate_progress option, but I have also never came across a server where boss bar causes performance issues.

@Archy-X
Copy link
Owner

Archy-X commented Jul 8, 2024

You can make it non-final and update it in loadOptions.

@Archy-X Archy-X merged commit dd473ea into Archy-X:master Jul 8, 2024
1 check passed
@IamMusavaRibica IamMusavaRibica deleted the fork1 branch July 8, 2024 19:19
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