1
0
mirror of https://github.com/nkomarn/harbor.git synced 2025-01-05 07:07:34 +01:00

👌 Fallback value for bossbar color

This will prevent console errors if you use the 1.6 config for 1.6.2.
This commit is contained in:
Mykyta 2020-04-20 09:28:31 -07:00
parent 560f0f1a8d
commit b5eaeeb7f1
No known key found for this signature in database
GPG Key ID: C147E30C19EA3570
3 changed files with 17 additions and 5 deletions

View File

@ -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"));

View File

@ -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;
}
}

View File

@ -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