Skip to content

Commit

Permalink
make bossbar style configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
steve4744 committed Oct 31, 2023
1 parent 240ef09 commit c13c292
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.boss.BarColor;
import org.bukkit.boss.BarStyle;
import org.bukkit.configuration.file.FileConfiguration;

import com.google.common.base.Enums;
Expand Down Expand Up @@ -176,6 +177,11 @@ public int getBossBarTimeout() {
return config.getInt("Display.bossbar.timeout", 60);
}

public String getBossBarStyle() {
int segments = config.getInt("Display.bossbar.style", 1);
return validateBarStyle(segments);
}

public int getScoreboardTimeout() {
return config.getInt("Display.scoreboard.timeout", 60);
}
Expand Down Expand Up @@ -206,4 +212,12 @@ private String validateChatColor(String colour) {
}
return colour;
}

private String validateBarStyle(int segments) {
String style = "SEGMENTED_" + segments;
if (segments == 1 || Enums.getIfPresent(BarStyle.class, style).orNull() == null) {
style = "SOLID";
}
return style;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public BossBarManager(WhatIsThis plugin) {

private void createBar(Player player) {
String colour = plugin.getSettings().getBossBarColor();
BossBar bar = Bukkit.createBossBar(null, BarColor.valueOf(colour), BarStyle.SOLID);
String style = plugin.getSettings().getBossBarStyle();
BossBar bar = Bukkit.createBossBar(null, BarColor.valueOf(colour), BarStyle.valueOf(style));
bar.addPlayer(player);
barmap.put(player.getName(), bar);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ Display:
barcolor: GREEN
# Maximum number of ticks that bossbar remains visible (default 60 = 3 seconds)
timeout: 60
# Style refers to the number of segments the bar is divided into. Valid options are 1, 6, 10, 12 and 20.
style: 1
chat:
enabled: false
on_sneak: false
Expand Down

0 comments on commit c13c292

Please sign in to comment.