From 6401c130571f5dbd069cd04e7b1c58fb97d6de08 Mon Sep 17 00:00:00 2001 From: anhgelus Date: Fri, 23 Aug 2024 22:26:50 +0000 Subject: fix(game): ending game just after the start --- src/main/java/world/anhgelus/molehunt/Game.java | 4 ++-- src/main/java/world/anhgelus/molehunt/Molehunt.java | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/main/java/world/anhgelus/molehunt/Game.java b/src/main/java/world/anhgelus/molehunt/Game.java index 89ee9b3..ce6f335 100644 --- a/src/main/java/world/anhgelus/molehunt/Game.java +++ b/src/main/java/world/anhgelus/molehunt/Game.java @@ -89,7 +89,6 @@ public class Game { // reset time and weather server.getOverworld().setTimeOfDay(0); server.getOverworld().resetWeather(); - started = true; timer.scheduleAtFixedRate(new TimerTask() { @@ -137,6 +136,7 @@ public class Game { pm.sendToAll(new SubtitleS2CPacket(Text.translatable("molehunt.game.end.winners.subtitle").append(getMolesAsString()))); pm.sendToAll(winner); pm.sendToAll(timing); + moles.clear(); } }, 4*1000); } @@ -158,7 +158,7 @@ public class Game { } public boolean isAMole(ServerPlayerEntity player) { - return hasStarted() && moles.contains(player); + return moles.contains(player); } public boolean gameWonByMoles() { diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java index 7a55450..c6ce7c7 100644 --- a/src/main/java/world/anhgelus/molehunt/Molehunt.java +++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java @@ -102,7 +102,7 @@ public class Molehunt implements ModInitializer { if (game == null || !game.hasStarted()) { player.networkHandler.sendPacket(new OverlayMessageS2CPacket( - Text.translatable("commands.molehunt.stop.failed").setStyle(Style.EMPTY.withColor(16733525)) + Text.translatable("commands.molehunt.stop.failed").setStyle(Style.EMPTY.withColor(16733525)) )); } else { player.networkHandler.sendPacket(new OverlayMessageS2CPacket(Text.of(game.getShortRemainingText()))); @@ -144,6 +144,7 @@ public class Molehunt implements ModInitializer { ServerLivingEntityEvents.AFTER_DEATH.register((entity, damageSource) -> { if (!(entity instanceof ServerPlayerEntity) || game == null) return; + if (!game.hasStarted()) return; if (game.gameWonByMoles()) game.end(); }); -- cgit v1.2.3