From 7a2868a165f170a34d5f6f5eea20993b36ad0653 Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Wed, 4 Aug 2021 00:42:22 +0300 Subject: [PATCH] Implement toggling value update message --- .../olliejw/oremarket/Chat/ValueUpdates.java | 26 ++++++++++--------- src/main/resources/config.yml | 1 + 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/olliejw/oremarket/Chat/ValueUpdates.java b/src/main/java/com/olliejw/oremarket/Chat/ValueUpdates.java index f58172c..e2a56e6 100644 --- a/src/main/java/com/olliejw/oremarket/Chat/ValueUpdates.java +++ b/src/main/java/com/olliejw/oremarket/Chat/ValueUpdates.java @@ -12,22 +12,24 @@ public class ValueUpdates { Placeholders plh = new Placeholders(); public void announceValue() { - Bukkit.getScheduler().scheduleSyncRepeatingTask(OreMarket.main(), () -> { - for (String key : Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getKeys(false)) { - ConfigurationSection keySection = Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getConfigurationSection(key); - String message = OreMarket.main().getConfig().getString("valuemessage.format"); + if(OreMarket.main().getConfig().getBoolean("valuemessage.enabled")) { + Bukkit.getScheduler().scheduleSyncRepeatingTask(OreMarket.main(), () -> { + for (String key : Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getKeys(false)) { + ConfigurationSection keySection = Objects.requireNonNull(OreMarket.main().getGuiConfig().getConfigurationSection("items")).getConfigurationSection(key); + String message = OreMarket.main().getConfig().getString("valuemessage.format"); - assert keySection != null; - assert message != null; + assert keySection != null; + assert message != null; - for (Player player: Bukkit.getOnlinePlayers()) { - if (keySection.getBoolean("hide")) { - return; + for (Player player: Bukkit.getOnlinePlayers()) { + if (keySection.getBoolean("hide")) { + return; + } + player.sendMessage(plh.format(message, player, keySection)); } - player.sendMessage(plh.format(message, player, keySection)); } - } - }, 0L, (OreMarket.main().getConfig().getInt("valuemessage.time")* 20L*60)); + }, 0L, (OreMarket.main().getConfig().getInt("valuemessage.time")* 20L*60)); + } } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c2f636b..60944c1 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -5,6 +5,7 @@ prefix: '&bOreMarket ' valuemessage: + enabled: true # Time (in minutes) to send this message time: 5 # The below will look like: (These values are just examples)