wrapping split recorder in try/catch

This commit is contained in:
Stachelbeere1248 2023-11-11 16:56:56 +01:00
parent 3f53bb335a
commit a7a206d273
3 changed files with 15 additions and 9 deletions

View file

@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xmx2g
baseGroup = com.github.stachelbeere1248.zombiesutils baseGroup = com.github.stachelbeere1248.zombiesutils
mcVersion = 1.8.9 mcVersion = 1.8.9
modid = zombiesutils modid = zombiesutils
version = 1.1.1 version = 1.1.2

View file

@ -9,7 +9,7 @@ import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class RecordManager { 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(); sendBar();
TimesFile timesFile = category.getByGameMode(GameMode.getCurrentGameMode()); TimesFile timesFile = category.getByGameMode(GameMode.getCurrentGameMode());
short bestSegment = timesFile.getBestSegment(round); short bestSegment = timesFile.getBestSegment(round);
@ -36,7 +36,7 @@ public class RecordManager {
} }
sendBar(); 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(); sendBar();
TimesFile timesFile = category.getByGameMode(GameMode.getCurrentGameMode()); TimesFile timesFile = category.getByGameMode(GameMode.getCurrentGameMode());
int personalBest = timesFile.getPersonalBest(round); int personalBest = timesFile.getPersonalBest(round);

View file

@ -7,6 +7,7 @@ import com.github.stachelbeere1248.zombiesutils.game.Map;
import com.github.stachelbeere1248.zombiesutils.game.sla.SLA; import com.github.stachelbeere1248.zombiesutils.game.sla.SLA;
import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category; import com.github.stachelbeere1248.zombiesutils.timer.recorder.Category;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.util.ChatComponentText;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.Optional; import java.util.Optional;
@ -46,18 +47,23 @@ public class Timer {
*/ */
public void split(byte passedRound) { public void split(byte passedRound) {
final int gameTime = gameTime(); 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"); ZombiesUtils.getInstance().getLogger().debug("SPLIT CANCELLED");
return; return;
} }
if (passedRound == (byte) 1) pbTracking = true; if (passedRound == (byte) 1) pbTracking = true;
final short roundTime = (short) (gameTime - passedRoundsTickSum);
ZombiesUtils.getInstance().getLogger().debug("Passed round: " + passedRound); try {
RecordManager.compareSegment(passedRound, roundTime, category);
RecordManager.compareSegment(passedRound, roundTime, category); if (pbTracking) RecordManager.compareBest(passedRound, gameTime, 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; passedRoundsTickSum = gameTime;
dontDupeSplitPlease = passedRound; dontDupeSplitPlease = passedRound;
} }