- 
          
 - 
                Notifications
    
You must be signed in to change notification settings  - Fork 3
 
fix: Improve progress calculation and reduce update interval in BossB… #110
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
base: master
Are you sure you want to change the base?
Conversation
          Summary of ChangesHello @ChudziudgiToJa, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on enhancing the BossBar functionality by improving the accuracy of its progress calculation and increasing the frequency of its updates. The changes ensure that BossBars display progress with higher precision and animate more smoothly, leading to a more polished and reliable user interface element. Highlights
 Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either  
 Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a  Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request focuses on improving the progress calculation and reducing the update interval for the BossBar in the Multification plugin. The changes involve adjusting the progress calculation to use milliseconds for better precision and reducing the scheduler update interval from 500ms to 100ms. The review focuses on correctness and efficiency.
| float progress = (float) (remainingMillis / totalMillis); | ||
| progress = Math.max(0.0f, Math.min(1.0f, progress)); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The progress value is clamped between 0.0 and 1.0, which is good for preventing out-of-bounds values. However, the logic is flawed. The progress should represent the percentage of time that has elapsed, not the time remaining. The current calculation shows the remaining time. This should be inverted to represent elapsed time.
Consider inverting the progress calculation to reflect elapsed time instead of remaining time.
| float progress = (float) (remainingMillis / totalMillis); | |
| progress = Math.max(0.0f, Math.min(1.0f, progress)); | |
| double totalMillis = duration.toMillis(); | |
| double remainingMillis = Math.max(0, remaining.toMillis()); | |
| float progress = (float) (1.0 - (remainingMillis / totalMillis)); // Invert the progress calculation | |
| progress = Math.max(0.0f, Math.min(1.0f, progress)); | 
| double totalMillis = duration.toMillis(); | ||
| double remainingMillis = Math.max(0, remaining.toMillis()); | ||
| float progress = (float) (remainingMillis / totalMillis); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current progress calculation might lead to unexpected behavior due to integer division. Specifically, remainingMillis / totalMillis could result in 0 if remainingMillis is less than totalMillis but still greater than 0, causing the boss bar to appear empty prematurely. To fix this, ensure that the division is performed with double precision before casting to float.
Consider swapping the order of the cast and the division to ensure floating point division is performed.
| double totalMillis = duration.toMillis(); | |
| double remainingMillis = Math.max(0, remaining.toMillis()); | |
| float progress = (float) (remainingMillis / totalMillis); | |
| double totalMillis = duration.toMillis(); | |
| double remainingMillis = Math.max(0, remaining.toMillis()); | |
| float progress = (float) remainingMillis / (float) totalMillis; // Explicitly cast both operands to float before division | 
| bossBar.progress(progress); | ||
| 
               | 
          ||
| this.scheduler.schedule(() -> updateProgress(expiration, duration, bossBar, viewer), 500L, TimeUnit.MILLISECONDS); | ||
| this.scheduler.schedule(() -> updateProgress(expiration, duration, bossBar, viewer), 100L, TimeUnit.MILLISECONDS); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reducing the scheduler interval to 100ms can lead to increased CPU usage, especially if there are many boss bars being updated simultaneously. While this provides a smoother visual update, it's important to consider the performance implications. Make sure this value is configurable or that performance is carefully monitored.
Consider making the update interval configurable to allow administrators to tune performance.
        long updateInterval = 100L; // Make this configurable
        this.scheduler.schedule(() -> updateProgress(expiration, duration, bossBar, viewer), updateInterval, TimeUnit.MILLISECONDS);
          2025-10-17.14-22-59.mp4 | 
    
No description provided.