Skip to content

Commit

Permalink
👌 Fallback value for bossbar color
Browse files Browse the repository at this point in the history
This will prevent console errors if you use the 1.6 config for 1.6.2.
  • Loading branch information
nkomarn committed Apr 20, 2020
1 parent 560f0f1 commit b5eaeeb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/main/java/xyz/nkomarn/Harbor/task/Checker.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ private void checkWorld(final World world) {

if (sleeping > 0 && needed > 0) {
final double sleepingPercentage = Math.min(1, (double) sleeping / getSkipAmount(world));

Messages.sendBossBarMessage(world, Config.getString("messages.bossbar.players-sleeping.message"),
BarColor.valueOf(Config.getString("messages.bossbar.players-sleeping.color")), sleepingPercentage);
Config.getString("messages.bossbar.players-sleeping.color"), sleepingPercentage);

Messages.sendActionBarMessage(world, Config.getString("messages.actionbar.players-sleeping"));
} else if (needed == 0 && sleeping > 0) {
Messages.sendBossBarMessage(world, Config.getString("messages.bossbar.night-skipping.message"),
BarColor.valueOf(Config.getString("messages.bossbar.night-skipping.color")), 1);
Config.getString("messages.bossbar.night-skipping.color"), 1);

Messages.sendActionBarMessage(world, Config.getString("messages.actionbar.night-skipping"));

Expand Down
14 changes: 12 additions & 2 deletions src/main/java/xyz/nkomarn/Harbor/util/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public static void sendActionBarMessage(final World world, final String message)
TextComponent.fromLegacyText(prepareMessage(world, message))));
}

public static void sendBossBarMessage(final World world, final String message, final BarColor color, final double percentage) {
public static void sendBossBarMessage(final World world, final String message, final String color, final double percentage) {
if (!Config.getBoolean("messages.bossbar.enabled") || message.length() < 1) return;
BossBar bar = Bukkit.createBossBar(Messages.prepareMessage(world, message), color, BarStyle.SOLID);
BossBar bar = Bukkit.createBossBar(Messages.prepareMessage(world, message), getBarColor(color), BarStyle.SOLID);
bar.setProgress(percentage);
world.getPlayers().forEach(bar::addPlayer);
Bukkit.getScheduler().runTaskLater(Harbor.getHarbor(), bar::removeAll, Config.getInteger("interval") * 20);
Expand All @@ -49,4 +49,14 @@ private static String prepareMessage(final World world, final String message) {
.replace("[needed]", String.valueOf(Checker.getSkipAmount(world)))
.replace("[more]", String.valueOf(Checker.getNeeded(world))));
}

private static BarColor getBarColor(final String enumString) {
BarColor barColor;
try {
barColor = BarColor.valueOf(enumString.toUpperCase().trim());
} catch (IllegalArgumentException e) {
barColor = BarColor.BLUE;
}
return barColor;
}
}
3 changes: 2 additions & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# https://github.com/nkomarn/Harbor

# Important note regarding Essentials:
# Please make sure you negate the permission "essentials.sleepingignored" to prevent issues with Harbor and server operators
# Please make sure you negate the permission "essentials.sleepingignored" to
# prevent issues with Harbor and server operators when running Essentials.

night-skip:
enabled: true # Skip the night if a percentage of the players in a world are sleeping
Expand Down

0 comments on commit b5eaeeb

Please sign in to comment.