From b5eaeeb7f197b66c5b41067744760544c6a87e79 Mon Sep 17 00:00:00 2001 From: Mykyta Date: Mon, 20 Apr 2020 09:28:31 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=8C=20Fallback=20value=20for=20bossbar?= =?UTF-8?q?=20color=20This=20will=20prevent=20console=20errors=20if=20you?= =?UTF-8?q?=20use=20the=201.6=20config=20for=201.6.2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/xyz/nkomarn/Harbor/task/Checker.java | 5 +++-- .../java/xyz/nkomarn/Harbor/util/Messages.java | 14 ++++++++++++-- src/main/resources/config.yml | 3 ++- 3 files changed, 17 insertions(+), 5 deletions(-) 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 @@ public class Checker implements Runnable { 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 class Messages { 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 @@ public class Messages { .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