-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
127 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...mdmk/automessage/notification/implementation/bossbar/audience/BossBarAudienceService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.github.imdmk.automessage.notification.implementation.bossbar.audience; | ||
|
||
import com.github.imdmk.automessage.notification.implementation.bossbar.BossBarNotification; | ||
import net.kyori.adventure.audience.Audience; | ||
import net.kyori.adventure.bossbar.BossBar; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
|
||
public class BossBarAudienceService { | ||
|
||
private final BossBarAudienceManager bossBarAudienceManager; | ||
|
||
public BossBarAudienceService(BossBarAudienceManager bossBarAudienceManager) { | ||
this.bossBarAudienceManager = bossBarAudienceManager; | ||
} | ||
|
||
public void update(BossBarAudience bossBarAudience) { | ||
BossBar bossBar = bossBarAudience.bossBar(); | ||
|
||
Instant now = Instant.now(); | ||
Instant endOfBossBar = bossBarAudience.endOfBossBar(); | ||
|
||
if (now.isAfter(endOfBossBar)) { | ||
this.hide(bossBarAudience); | ||
return; | ||
} | ||
|
||
float audienceProgress = bossBarAudience.progress(); | ||
|
||
if (audienceProgress < 0.0F) { | ||
Duration between = Duration.between(now, endOfBossBar); | ||
Duration audienceTime = bossBarAudience.time(); | ||
|
||
float difference = (float) between.toMillis() / audienceTime.toMillis(); | ||
float progress = Math.max(0.0F, Math.min(1.0F, difference)); | ||
|
||
bossBar.progress(progress); | ||
} | ||
} | ||
|
||
public BossBarAudience create(Audience audience, BossBarNotification notification) { | ||
BossBar bossBar = notification.create(); | ||
BossBarAudience bossBarAudience = new BossBarAudience(audience, bossBar, notification); | ||
|
||
this.bossBarAudienceManager.add(bossBarAudience); | ||
return bossBarAudience; | ||
} | ||
|
||
public void hide(BossBarAudience bossBarAudience) { | ||
Audience audience = bossBarAudience.audience(); | ||
BossBar bossBar = bossBarAudience.bossBar(); | ||
|
||
audience.hideBossBar(bossBar); | ||
this.bossBarAudienceManager.remove(bossBarAudience); | ||
} | ||
} |
32 changes: 4 additions & 28 deletions
32
...b/imdmk/automessage/notification/implementation/bossbar/audience/BossBarAudienceTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,19 @@ | ||
package com.github.imdmk.automessage.notification.implementation.bossbar.audience; | ||
|
||
import net.kyori.adventure.audience.Audience; | ||
import net.kyori.adventure.bossbar.BossBar; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
|
||
public class BossBarAudienceTask implements Runnable { | ||
|
||
private final BossBarAudienceManager bossBarAudienceManager; | ||
private final BossBarAudienceService bossBarAudienceService; | ||
|
||
public BossBarAudienceTask(BossBarAudienceManager bossBarAudienceManager) { | ||
public BossBarAudienceTask(BossBarAudienceManager bossBarAudienceManager, BossBarAudienceService bossBarAudienceService) { | ||
this.bossBarAudienceManager = bossBarAudienceManager; | ||
this.bossBarAudienceService = bossBarAudienceService; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
for (BossBarAudience bossBarAudience : this.bossBarAudienceManager.getBossBarAudiences()) { | ||
Audience audience = bossBarAudience.audience(); | ||
BossBar bossBar = bossBarAudience.bossBar(); | ||
|
||
Instant now = Instant.now(); | ||
Instant endOfBossBar = bossBarAudience.endOfBossBar(); | ||
|
||
if (now.isAfter(endOfBossBar)) { | ||
audience.hideBossBar(bossBar); | ||
this.bossBarAudienceManager.remove(bossBarAudience); | ||
return; | ||
} | ||
|
||
if (bossBarAudience.timeChangesProgress()) { | ||
Duration between = Duration.between(now, endOfBossBar); | ||
Duration time = bossBarAudience.time(); | ||
|
||
float difference = (float) between.toMillis() / time.toMillis(); | ||
float progress = Math.max(0.0F, Math.min(1.0F, difference)); | ||
|
||
bossBar.progress(progress); | ||
} | ||
this.bossBarAudienceService.update(bossBarAudience); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters