diff --git a/src/main/java/xyz/nkomarn/Harbor/task/Checker.java b/src/main/java/xyz/nkomarn/Harbor/task/Checker.java index 731acd0..e96e843 100644 --- a/src/main/java/xyz/nkomarn/Harbor/task/Checker.java +++ b/src/main/java/xyz/nkomarn/Harbor/task/Checker.java @@ -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")); diff --git a/src/main/java/xyz/nkomarn/Harbor/util/Messages.java b/src/main/java/xyz/nkomarn/Harbor/util/Messages.java index 1a18c4b..0f82e0f 100644 --- a/src/main/java/xyz/nkomarn/Harbor/util/Messages.java +++ b/src/main/java/xyz/nkomarn/Harbor/util/Messages.java @@ -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); @@ -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; + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index a766b0f..08d83e1 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -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