From 4ee93b59dda1f537e8c8bc0c1d3278f05eb38179 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 25 Oct 2023 14:35:15 +0200 Subject: [PATCH] Fix AutostartListener for specific GameMode configs --- .../features/autostart/AutostartListener.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java index 232962a1..7da0fea1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java @@ -31,6 +31,8 @@ import de.steamwar.linkage.Linked; import lombok.Getter; import org.bukkit.Material; import org.bukkit.block.data.type.Chest; +import org.bukkit.configuration.file.FileConfiguration; +import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -39,11 +41,9 @@ import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; +import java.io.File; import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Date; -import java.util.HashMap; -import java.util.Map; +import java.util.*; @Linked public class AutostartListener implements Listener { @@ -117,15 +117,24 @@ public class AutostartListener implements Listener { if (regionStartTime.isEmpty()) { return; } + event.blockList().forEach(block -> { Region region = Region.getRegion(block.getLocation()); if (!regionStartTime.containsKey(region)) return; if (!region.hasType(RegionType.TESTBLOCK)) return; if (!region.inRegion(block.getLocation(), RegionType.TESTBLOCK, RegionExtensionType.EXTENSION)) return; long tickDiff = TPSUtils.currentRealTick.get() - regionStartTime.remove(region); + long preFightDurationInSeconds = getPreFightDurationInSeconds(region); RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT1", tickDiff); - RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT2", 30, (600 - tickDiff)); + RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT2", preFightDurationInSeconds, ((preFightDurationInSeconds * 20) - tickDiff)); RegionUtils.message(region, "AUTOSTART_MESSAGE_RESULT3"); }); } + + private int getPreFightDurationInSeconds(Region region) { + File file = region.gameModeConfig(); + if (file == null) return 30; + FileConfiguration config = YamlConfiguration.loadConfiguration(file); + return config.getInt("Times.PreFightDuration", 30); + } }