-
Notifications
You must be signed in to change notification settings - Fork 0
fix: rework boss bar feature #6
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: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,55 +1,77 @@ | ||
| package de.drolpi.gamecore.api.feature.def; | ||
|
|
||
| import com.google.gson.annotations.Expose; | ||
| import com.google.inject.Inject; | ||
| import de.drolpi.gamecore.api.counter.Counter; | ||
| import de.drolpi.gamecore.api.game.Game; | ||
| import de.drolpi.gamecore.api.phase.Phase; | ||
| import org.bukkit.boss.BossBar; | ||
| import net.kyori.adventure.bossbar.BossBar; | ||
| import net.kyori.adventure.text.Component; | ||
| import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder; | ||
| import org.bukkit.entity.Player; | ||
|
|
||
| public class BossBarCounterFeature extends AbstractCounterProgressFeature { | ||
|
|
||
| private final BossBarFeature bossBarFeature; | ||
|
|
||
| private BossBar bossBar; | ||
| @Expose | ||
| private final String replaceBossBarId = "counter"; | ||
| private final Component component; | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See field order :) |
||
| @Expose | ||
| private BossBar.Color color = BossBar.Color.RED; | ||
| @Expose | ||
| private BossBar.Overlay overlay = BossBar.Overlay.PROGRESS; | ||
|
|
||
| @Inject | ||
| public BossBarCounterFeature(Game game, Phase phase) { | ||
| super(game, phase); | ||
| this.bossBarFeature = phase.feature(BossBarFeature.class); | ||
| this.component = Component.translatable(phase.key() + "counter_bossbar"); | ||
| } | ||
|
|
||
| @Override | ||
| public void enable() { | ||
| super.enable(); | ||
| this.bossBar = this.bossBarFeature.bossBar(); | ||
| } | ||
|
|
||
| @Override | ||
| public void disable() { | ||
| super.disable(); | ||
| this.bossBar = null; | ||
| protected void start(Counter counter) { | ||
| super.start(counter); | ||
| if (!this.bossBarFeature.isRegistered(replaceBossBarId)) { | ||
| this.bossBarFeature.register(this.replaceBossBarId, this.color, this.overlay); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should register a boss bar during the runtime of a phase. If at all, this should happen in the constructor, because it is called during the configuration of a phase / game or directly after loading the configuration file |
||
| } | ||
| this.bossBarFeature.setColor(this.replaceBossBarId, this.color); | ||
| this.bossBarFeature.setOverlay(this.replaceBossBarId, this.overlay); | ||
| } | ||
|
|
||
| @Override | ||
| protected void start(Counter counter) { | ||
| this.bossBar.setVisible(true); | ||
| protected void cancel(Counter counter) { | ||
| this.resetName(); | ||
| } | ||
|
|
||
| @Override | ||
| protected void cancel(Counter counter) { | ||
| super.cancel(counter); | ||
| this.bossBar.setTitle(this.bossBarFeature.message()); | ||
| if (!this.bossBarFeature.message().isBlank()) { | ||
| return; | ||
| } | ||
| this.bossBar.setVisible(false); | ||
| protected void finish(Counter counter) { | ||
| this.resetName(); | ||
| } | ||
|
|
||
| private void resetName() { | ||
| this.bossBarFeature.resetName(this.replaceBossBarId); | ||
| } | ||
|
|
||
| @Override | ||
| protected void tick(Counter counter) { | ||
| this.set(null, counter.currentCount(), super.progress(counter)); | ||
| } | ||
|
|
||
| @Override | ||
| protected void set(Player player, int count, float progress) { | ||
| //TODO: Lang | ||
| this.bossBar.setTitle("" + count); | ||
| this.bossBar.setProgress(progress); | ||
| protected void set(Player player, long count, float progress) { | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The player is not used, is it?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we should change the AbstractCounterProgressFeature so that there is no player loop and move it to the LevelCounterFeature, because it is not needed for the BossBarCounterFeature and the method is called unnecessarily often. |
||
| if (!this.bossBarFeature.isRegistered(replaceBossBarId)) { | ||
| this.bossBarFeature.register(this.replaceBossBarId, this.color, this.overlay); | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, here too we should not register during the term of a phase |
||
| this.bossBarFeature.setColor(this.replaceBossBarId, this.color); | ||
| this.bossBarFeature.setOverlay(this.replaceBossBarId, this.overlay); | ||
| } | ||
| this.bossBarFeature.setName(this.replaceBossBarId, component); | ||
| this.bossBarFeature.setResolvers(this.replaceBossBarId, Placeholder.component("count", Component.text(count))); | ||
| this.bossBarFeature.setProgress(this.replaceBossBarId, 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.
Maybe rename?, a little bit long and redundant.