aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-03-18 13:39:58 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2026-03-18 13:39:58 +0100
commit5221052b004117e8aa2763c2a8085372391b13c4 (patch)
treed87c658fe0148f2e27003300bcc7c01954a273c1 /src/main
parent02965b5cf44e64f12fd41fb32e0a7cc300541753 (diff)
fix(game): #18 (last one was not fixing)HEAD1.3.0main
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/world/anhgelus/molehunt/Molehunt.java4
-rw-r--r--src/main/java/world/anhgelus/molehunt/game/Game.java18
2 files changed, 13 insertions, 9 deletions
diff --git a/src/main/java/world/anhgelus/molehunt/Molehunt.java b/src/main/java/world/anhgelus/molehunt/Molehunt.java
index 74687d1..d31be6b 100644
--- a/src/main/java/world/anhgelus/molehunt/Molehunt.java
+++ b/src/main/java/world/anhgelus/molehunt/Molehunt.java
@@ -166,13 +166,13 @@ public class Molehunt implements ModInitializer {
false);
} else if (player.isSpectator()) {
source.sendFeedback(
- () -> Text.translatable("commands.molehunt.role.survivor.mole_count", game.getMoles().size()),
+ () -> Text.translatable("commands.molehunt.role.survivor.mole_count", game.getMolesCount()),
false);
} else {
source.sendFeedback(
() -> Text.translatable("commands.molehunt.role.survivor")
.append("\n\n")
- .append(Text.translatable("commands.molehunt.role.survivor.mole_count", game.getMoles().size())),
+ .append(Text.translatable("commands.molehunt.role.survivor.mole_count", game.getMolesCount())),
false);
}
diff --git a/src/main/java/world/anhgelus/molehunt/game/Game.java b/src/main/java/world/anhgelus/molehunt/game/Game.java
index 35c45fa..98784c3 100644
--- a/src/main/java/world/anhgelus/molehunt/game/Game.java
+++ b/src/main/java/world/anhgelus/molehunt/game/Game.java
@@ -22,6 +22,7 @@ import world.anhgelus.molehunt.utils.TimeUtils;
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
+import java.util.stream.Stream;
public class Game {
@@ -157,17 +158,19 @@ public class Game {
return Text.of("§c" + TimeUtils.generateShortString(remaining));
}
- public List<ServerPlayerEntity> getMoles() {
+ private Stream<ServerPlayerEntity> getMoles() {
return moles.stream()
.map(uuid -> server.getPlayerManager().getPlayer(uuid))
.filter(Objects::nonNull)
- .filter(p -> !p.isSpectator())
- .toList();
+ .filter(p -> !p.isSpectator() && !p.isCreative());
+ }
+
+ public int getMolesCount() {
+ return getMoles().toArray().length;
}
public String getMolesAsString() {
- return getMoles().stream()
- .map(PlayerEntity::getDisplayName)
+ return getMoles().map(PlayerEntity::getDisplayName)
.filter(Objects::nonNull)
.map(Object::toString)
.collect(Collectors.joining(", "));
@@ -178,7 +181,8 @@ public class Game {
}
public boolean wonByMoles() {
- return new HashSet<>(moles).containsAll(
+ final var moles = getMoles().map(PlayerEntity::getUuid).toList();
+ return !moles.isEmpty() && new HashSet<>(moles).containsAll(
server.getPlayerManager()
.getPlayerList()
.stream()
@@ -195,6 +199,6 @@ public class Game {
private void changeState(boolean hasStarted) {
started = hasStarted;
final var payload = new GamePayload(hasStarted);
- server.getPlayerManager().getPlayerList().forEach(p -> ServerPlayNetworking.send(p, payload));
+ server.getPlayerManager().sendToAll(ServerPlayNetworking.createS2CPacket(payload));
}
}