package org.xfurkanadenia.xBlackMarket.tasks; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.scheduler.BukkitRunnable; import org.xfurkanadenia.xBlackMarket.XBlackMarket; import org.xfurkanadenia.xBlackMarket.utils.Webhook; import java.time.LocalTime; import java.util.Arrays; import java.util.List; public class MarketRunnable extends BukkitRunnable { private final XBlackMarket plugin; public MarketRunnable(XBlackMarket plugin) { this.plugin = plugin; } @Override public void run() { Long timestamp = System.currentTimeMillis() / 1000; Long marketDuration = plugin.getConfig().getLong("blackMarketStayDuration"); Long blackMarketStartingInterval = plugin.getConfig().getLong("blackMarketStartingInterval"); LocalTime now = LocalTime.now(); int hours = now.getHour(); int minutes = now.getMinute(); List startingTimes = plugin.getConfig().getStringList("blackMarketStartingTimes"); boolean timeMatch = startingTimes.stream() .map(time -> time.split(":")) .filter(parts -> parts.length == 2) .anyMatch(parts -> { try { int configHour = Integer.parseInt(parts[0]); int configMinute = Integer.parseInt(parts[1]); return configHour == hours && configMinute == minutes; } catch (NumberFormatException e) { plugin.getLogger().warning("Geçersiz saat formatı: " + Arrays.toString(parts)); return false; } }); if ( ( plugin.blackMarketStartingMode == XBlackMarket.blackMarketStartingModes.INTERVAL && !plugin.blackMarketStarted && (timestamp - plugin.blackMarketEndedTime) >= blackMarketStartingInterval ) || ( !plugin.blackMarketStarted && plugin.blackMarketStartingMode == XBlackMarket.blackMarketStartingModes.TIME && timeMatch ) ) { XBlackMarket.getInstance().startBlackMarket(true); FileConfiguration config = plugin.getConfig(); if(plugin.getConfig().getBoolean("sendWebhook", false)) { Webhook.sendDiscordWebhook(config.getConfigurationSection("webhooks.marketStart")); } } else if (plugin.blackMarketStarted) { FileConfiguration config = plugin.getConfig(); if ((timestamp - plugin.blackMarketStartedTime) >= marketDuration) { plugin.stopBlackMarket(true); if(plugin.getConfig().getBoolean("sendWebhook", false)) Webhook.sendDiscordWebhook(config.getConfigurationSection("webhooks.marketEnd")); } } } }