From a7a206d273049cc6747616f98c63a7da90a03c01 Mon Sep 17 00:00:00 2001 From: Stachelbeere1248 Date: Sat, 11 Nov 2023 16:56:56 +0100 Subject: [PATCH] wrapping split recorder in try/catch --- gradle.properties | 2 +- .../zombiesutils/timer/RecordManager.java | 4 ++-- .../zombiesutils/timer/Timer.java | 18 ++++++++++++------ 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/gradle.properties b/gradle.properties index 3603e71..398e13f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g baseGroup = com.github.stachelbeere1248.zombiesutils mcVersion = 1.8.9 modid = zombiesutils -version = 1.1.1 \ No newline at end of file +version = 1.1.2 \ No newline at end of file diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/RecordManager.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/RecordManager.java index 678aa11..908e79d 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/RecordManager.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/RecordManager.java @@ -9,7 +9,7 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; public class RecordManager { - public static void compareSegment(byte round, short roundTime, @NotNull Category category) { + public static void compareSegment(byte round, short roundTime, @NotNull Category category) throws IndexOutOfBoundsException { sendBar(); TimesFile timesFile = category.getByGameMode(GameMode.getCurrentGameMode()); short bestSegment = timesFile.getBestSegment(round); @@ -36,7 +36,7 @@ public class RecordManager { } sendBar(); } - public static void compareBest(byte round, int gameTime, @NotNull Category category) { + public static void compareBest(byte round, int gameTime, @NotNull Category category) throws IndexOutOfBoundsException { sendBar(); TimesFile timesFile = category.getByGameMode(GameMode.getCurrentGameMode()); int personalBest = timesFile.getPersonalBest(round); diff --git a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java index 85b6678..85b0dc4 100644 --- a/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java +++ b/src/main/java/com/github/stachelbeere1248/zombiesutils/timer/Timer.java @@ -7,6 +7,7 @@ import com.github.stachelbeere1248.zombiesutils.game.Map; import com.github.stachelbeere1248.zombiesutils.game.sla.SLA; import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category; import net.minecraft.client.Minecraft; +import net.minecraft.util.ChatComponentText; import org.jetbrains.annotations.NotNull; import java.util.Optional; @@ -46,18 +47,23 @@ public class Timer { */ public void split(byte passedRound) { final int gameTime = gameTime(); - if (dontDupeSplitPlease == passedRound || passedRound == 0 || gameTime == 0) { + final short roundTime = (short) (gameTime - passedRoundsTickSum); + + if (dontDupeSplitPlease == passedRound || passedRound == 0 || roundTime == 0) { ZombiesUtils.getInstance().getLogger().debug("SPLIT CANCELLED"); return; } if (passedRound == (byte) 1) pbTracking = true; - final short roundTime = (short) (gameTime - passedRoundsTickSum); - ZombiesUtils.getInstance().getLogger().debug("Passed round: " + passedRound); - - RecordManager.compareSegment(passedRound, roundTime, category); - if (pbTracking) RecordManager.compareBest(passedRound, gameTime, category); + try { + RecordManager.compareSegment(passedRound, roundTime, category); + if (pbTracking) RecordManager.compareBest(passedRound, gameTime, category); + } catch (IndexOutOfBoundsException exception) { + Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText( + String.format("Split not recorded. (invalid round parsed from scoreboard: %s)", passedRound) + )); + } passedRoundsTickSum = gameTime; dontDupeSplitPlease = passedRound; }